akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n;
    cin>>n;
    if(n==1){
        cout<<"Hello World"<<endl;
        return 0;
    }
    int a,b;
    cin>>a>>b;
    cout<<a+b<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
const int MOD = 1000000007;

int main()
{
  int a,b,h;
  cin >> a >> b >> h;
  cout << ((a+b)*h/2) << endl;  
  return 0;
}



Measured memory_bytes: 256
import scala.io.StdIn.{readLine, readInt};
object Main {
    def main(args: Array[String]): Unit = {
        val Array(n, m) = readLine.split(" ").map(_.toInt);
        val matrix = new Array[List[Int]](n).map( i => List[Int]());
        (0 until m).foreach { i =>
            readLine.split(" ").map(_.toInt) match {
                case Array(src, dst) => {
                    matrix(src) = dst :: matrix(src);
                    matrix(dst) = src :: matrix(dst);
                }
                case _ => ();
            }
        }
        val group = genGroup(matrix);
        (0 until readInt).foreach { i =>
            val Array(src, dst) = readLine.split(" ").map(_.toInt);
            if (group(src) == group(dst)) println("yes") else println("no");
        }
    }
    
    def genGroup(matrix: Array[List[Int]]): Array[Int] = {
        val len = matrix.length;
        val group = new Array[Int](len);
        def go(que: IntQueue, gid: Int): Unit = {
            que.peek match {
                case None => ();
                case Some(e) => {
                    val nextQue = matrix(e).foldLeft(que.dequeue) { (q, child) =>
                        if (group(child) == 0) {
                            group(child) = gid;
                            q.enqueue(child);
                        } else {
                            q;
                        }
                    }
                    go(nextQue, gid);
                }
            }
        }
        (0 until len).foldLeft(1) { (gid, i) =>
            if (group(i) == 0) {
                group(i) = gid;
                go(IntQueue(i), gid);
                gid + 1;
            } else {
                gid;
            }
        }
        group;
    }
}

class IntQueue(private val addList: List[Int], private val rmList: List[Int]) {
    def peek(): Option[Int] = if (rmList == Nil) None else Some(rmList.head);
    def enqueue(e: Int): IntQueue = {
        if (rmList == Nil) {
            new IntQueue(Nil, (e :: addList).reverse);
        } else {
            new IntQueue(e :: addList, rmList);
        }
    }
    def dequeue(): IntQueue = {
        rmList match {
            case Nil => throw new NoSuchElementException();
            case e :: Nil => new IntQueue(Nil, addList.reverse);
            case e :: es => new IntQueue(addList, rmList.tail);
        }
    }
}
object IntQueue {
    def apply(): IntQueue = new IntQueue(Nil, Nil)
    def apply(es: Int*): IntQueue = new IntQueue(Nil, es.toList);
}


Measured memory_bytes: 174224
#include<iostream>
using namespace std;
int t[105];
int main(){
	int n;
	int a,b,c;
	int i,j,k;
	bool s=true;
	cin>>n;
	for(c=0,i=0;i<n;i++){
		cin>>a;
		t[a]++;
		if(c<a)c=a;
	}
	for(i=c;i>(c+1)/2;i--){
		if(t[i]<2)s=false;
	}
	if(c%2==0 && t[c/2]!=1)s=false;
	if(c%2==1 && t[(c+1)/2]!=2)s=false;
	if(s)cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
	return 0;
}
	
	


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define FOR(i, c) \
  \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef vector<VB> VBB;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}


// g++ -std=c++11 prac.cpp

int main() {
  ll z=0,k,n,m,h,w,ans=0,sum=0,Max=1,Min=1e9+1;
  bool ok = false;
  cin >> n >> m;
  n--;
  while(n>0){
    ans += n;
    n--;
  }
  m--;
  while(m>0){
    ans += m;
    m--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#ifndef ONLINE_JUDGE
//#  define LOG(x) (cerr << #x << " = " << (x) << endl)
//#else
//#  define LOG(x) 0
//#endif
#define pb push_back
#define mod 1000000007
#define endl '\n'
typedef int integer;
#define int long long
using namespace std;

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const integer NN = 200005;
int ar[NN];
int n, m, k;


integer main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    k = 1;
    while (a > 0 && c > 0){
        if (k){
            c -= b;
        } else {
            a -= d;
        }
        k ^= 1;
    }
    if (!k)
        cout << "Yes";
    else
        cout << "No";


}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		StringTokenizer st = new StringTokenizer(str, " ");
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());

		int c = a*b;
		int d = 2*a + 2*b;
		System.out.print(c);
		System.out.print(" ");
		System.out.println(d);
	}
}

Measured memory_bytes: 24164
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	LL a,s,d,f;
    cin>>a>>s>>d>>f;
    cout<<max(max(a*d,a*f),max(s*d,s*f));
}


Measured memory_bytes: 3564
#include <string>
#include <bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include <ctype.h>
#include <algorithm> // sort
#include <map> // pair
using namespace std;

int main() {
 int x,n,m;
  cin >> x >> n >> m;
  x=x-n;
  cout << x%m << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, m, c;
    cin >> n >> m;
    int a[n][m];
    int b[m];
    for(int i = 0; i < m; i++) {
        b[i] = 0;
        for(int j = 0; j < n; j++) {
            a[j][i] = 0;
        }
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < n; i++) {
        c = 0;
        for(int j = 0; j < m; j++) {
            c += a[i][j] * b[j];
        }
        cout << c << endl;
    }
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=2e5+9;
map<ll,ll>m;
ll y[N];
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    for (int i=1;i<=x;i++){
        cin>>y[i];
        m[i-y[i]]++;
    }
    ll ans=0;
    for (int i=1;i<=x;i++){
        ans+=m[i+y[i]];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 27928
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

constexpr int M = 1000000;
int dp[M + 5];
int cnt[M + 5];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N);
    int G = 0;
    for(int i = 0; i < N; ++i){
        cin >> A[i];
        G = gcd(G, A[i]);
    }
    if(G > 1){
        cout << "not coprime\n";
        return 0;
    }
    dp[0] = dp[1] = 1;
    for(int i = 2; i <= M; ++i){
        if(dp[i])   continue;
        dp[i] = i;
        for(int j = i + i; j <= M; j += i){
            if(!dp[j])  dp[j] = i;
        }
    }
    for(int i = 0; i < N; ++i){
        vector<int> prime(1, 1);
        while(A[i] != 1){
            if(dp[A[i]] != prime.back())    prime.emplace_back(dp[A[i]]);
            A[i] /= dp[A[i]];
        }
        for(int j = 1; j < (int)prime.size(); ++j){
            if(cnt[prime[j]]){
                cout << "setwise coprime\n";
                return 0;
            }
            ++cnt[prime[j]];
        }
    }
    cout << "pairwise coprime\n";
}

Measured memory_bytes: 11408
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    bool ans=false;
    int ssize=s.size();
    REP(i,ssize){
        if(t==s)ans=true;
        s=s[s.size()-1]+s.substr(0,s.size()-1);
    }
    cout<<(ans?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,(n))
typedef long long ll;
using namespace std;

int main() {
    int x;
    rep(i, 5) {
        cin >> x;
        if (x != i + 1) {
            cout << i + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3580
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
 
public class Main {
	public static void main(String[] args) throws IOException {
		MScanner sc = new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		char in=sc.nextChar();
		switch(in) {
		case 'A':pw.println('T');
			break;
		case 'C':pw.println('G');
			break;
		case 'G':pw.println('C');
			break;
		case 'T':pw.println('A');
			break;	
		}
		pw.flush();
 
	}
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 22484
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1LL<<60
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main(){
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = 1 + n*(n-1)/2;
  ll f[26] = { };
  REP(i, n){
    f[s[i]-'a']++;
  }
  REP(i, 26){
    ans -= f[i]*(f[i]-1)/2;
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

vector<pii> g[MAXN];
int sz[MAXN], prv[MAXN];

void dfs(int s) {
	sz[s] = 1;
	REP(i, 0, SZ(g[s])) {
		int to = g[s][i]._1;
		if (to != prv[s]) {
			prv[to] = s;
			dfs(to);
			sz[s] += sz[to];
		}
	}
}

ll ans;
int n;

void dfs2(int s, int par) {
	sz[s] = 1;
	REP(i, 0, SZ(g[s])) {
		int to = g[s][i]._1;
		if (to != par) {
			dfs2(to, s);
			sz[s] += sz[to];
			ans += 2ll * (ll)g[s][i]._2 * (ll)sz[to];
		}
	}
}

void solve(){
	scanf("%d", &n);
	int a, b, c;
	REP(i, 1, n) {
		scanf("%d%d%d", &a, &b, &c);
		g[a].pb(mp(b, c));
		g[b].pb(mp(a, c));
	}
	dfs(1);
	int center = 1, center_2 = 0, cost_c = 0;
	while(1) {
		int ind = 0;
		REP(i, 0, SZ(g[center])) {
			int to = g[center][i]._1;
			if (to != prv[center]) {
				if (sz[to] * 2 > n) {
					ind = to;
					break;
				}
				if (sz[to] * 2 == n) {
					center_2 = to;
					cost_c = g[center][i]._2;
					break;
				}
			}				
		}
		if (ind) {
			center = ind;
		} else {
			break;
		}
	}
	if (center_2 != 0) {
		dfs2(center, center_2);
		dfs2(center_2, center);
		ans += (ll)cost_c * (n - 1);
	} else {
		dfs2(center, -1);
		int mn = INF;
		REP(i, 0, SZ(g[center])) {
			mn = min(mn, g[center][i]._2);
		}
		ans -= mn;
	}
	cout << ans << endl;
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 13184
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
typedef pair<int, int> P;

int dp[3010][6010];
P D[3010];
int main()
{
	int N, T;
	cin >> N >> T;
	for (int i = 0; i < N; i++) {
		cin >> D[i].first >> D[i].second;
	}
	sort(D, D + N);
	for (int i = 0; i < T; i++) {
		dp[0][i] = 0;
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = T - 1; j >= 0; j--) {
			dp[i + 1][j] = max(dp[i+1][j],dp[i][j]);
			dp[i + 1][min(T, j + D[i].first)] = max(dp[i+1][min(T, j + D[i].first)],dp[i][j] + D[i].second);
			dp[i + 1][min(T, j + D[i].first)] = max(dp[i + 1][min(T, j + D[i].first)], dp[i][min(T, j + D[i].first)]);
		}
	}
	/*for (int i = 0; i < N; i++) {
		for (int j = 0; j < T*2; j++) {
			cout << dp[i+1][j] << " ";
		}
		cout << endl;
	}*/
	for (int i = 0; i <= T * 2; i++) {
		ans = max(ans, dp[N][i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 69760
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>


using namespace std;
 
int main() {
  int N, M, A = 0;

  cin >> N;
  vector<string> blue(N);
  for (int i = 0; i < N; i++) {
    cin >> blue.at(i);
  }

  cin >> M;
  vector<string> red(M);
  for (int i = 0; i < M; i++) {
    cin >> red.at(i);
  }
  
  for (int i = 0; i < N; i++) {
    int count = 0;
    string X = blue.at(i);
    for (int j = 0; j < N; j++) {
      if (blue.at(j) == X) {
        count++;
      }
    }
    for (int j = 0; j < M; j++) {
      if (red.at(j) == X) {
        count--;
      }
    }
    if (count > A) {
      A = count;
    }
  }

  
  cout << A;
}

Measured memory_bytes: 256
#include<stdio.h>
long long f[60][2600]={0};
int main(){
	int n,a;
	scanf("%d%d",&n,&a);
	f[0][0]=1;
	for (int j=1;j<=2500;j++) f[0][j]=0;
	int sum=0;
	for (int i=1,t;i<=n;i++){
		scanf("%d",&t);
		sum+=t;
		for (int x=i;x;x--){
			for (int j=sum;j>=t;j--){
				f[x][j]+=f[x-1][j-t];
			}
		}
	}
	long long ans=0;
	for (int i=1;i<=n;i++){
		ans+=f[i][i*a];
	}
	printf("%lld",ans);
}

Measured memory_bytes: 1152
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr ll INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin>>n;
    vector<int> a(n+1); // 1-indexed
    vector<int> b(n+1, 0);
    for(int i=1; i<=n; i++) cin>>a[i];

    int ans = 0;
    vector<int> st;
    for(int i=n; i>0; i--){
        ll num = i;
        int cntb = 0;
        for(ll j=1; ; j++){
            if(n < j * num) break;

            cntb += b[j * num];
        }

        if(cntb % 2 != a[i]){
            b[i]++;
            st.emplace_back(i);
            ans++;
        }
    }

    cout << ans << endl;
    int sz = st.size();
    sort(st.begin(), st.end());
    for(int i=0; i<sz; i++){
        cout << st[i] << " \n"[i == sz-1];
    }
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll calc(ll x,ll y){
	if(x<y)swap(x,y);
	ll t=x/y;
	if(x==t*y)return (t+t-1)*y;
	return (t+t)*y+calc(y,x-t*y);
}

ll n,x;

int main(){
	scanf("%lld%lld",&n,&x);
	ll ans=n+calc(x,n-x);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
long long p = 1000000007;
long long inv[200005];
long long kin[200005];
long long n, k, t, kn, kj, ans;
long long rui(long long rui_a, long long rui_b) {
	if (rui_b == 0)return 1;
	if (rui_b == 1)return rui_a % p;
	long long rui_c;
	rui_c = rui(rui_a, rui_b / 2);
	rui_c = rui_c * rui_c % p;
	if (rui_b % 2) {
		return rui_c * rui_a % p;
	}
	return rui_c;
}
void makeinv(void) {
	long long arraynumber = sizeof inv / sizeof inv[0];
	inv[1] = 1;
	for (int invcount = 2; invcount < arraynumber; invcount++) {
		inv[invcount] = p - inv[p % invcount] * (p / invcount) % p;
	}
}
int main() {
	makeinv();
	scanf("%lld%lld", &n, &k);
	if (k >= n)k = n - 1;
	kj = 1;
	for (long long i = 1; i < n; i++) {
		kj *= i;
		kj %= p;
	}
	kn = kj * n % p;
	kin[0] = 1;
	for (long long i = 1; i <= n; i++) {
		kin[i] = kin[i - 1] * inv[i] % p;
	}
	for (long long i = 0; i <= k; i++) {
		t = kn * kj % p;
		t *= kin[i] * kin[n - i] % p;
		t %= p;
		t *= kin[i] * kin[n - 1 - i] % p;
		t %= p;
		ans += t;
		ans %= p;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  vector<ll> b; b.reserve((n * (n + 1)) / 2);

  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      ll val = 0;
      for (int k = i; k <= j; k++) {
        val += a[k];
      }
      b.push_back(val);
    }
  }

  sort(b.rbegin(), b.rend());

  int mb = 0;  // 何ビット目が最上位？

  for (int i = 0; i < 64; i++) {
    if ((b[0]>>i) & 1) mb = i;
  }

  vector<ll> c = b;

  for (int i = mb; i >= 0; i--) {
    vector<ll> tmp;  // i 番目のビットが立っている
    for (auto& v : c) if ((v>>i) & 1 == 1) tmp.push_back(v);
    if (tmp.size() >= k) c = tmp;
    else continue;  // この桁は諦めて次へ
  }

  ll ans = c[0];
  for (int i = 0; i < k; i++) {
    ans = (ans & c[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
using cost_t=int;
struct Edge {
    int from, to;
    int cost;
    Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
const int INF=1e9;
bool bellman_ford(int s,Graph& g,vector<int>& d){
    int n = g.size();
    d.assign(n,INF);
    d[s] = 0;
    bool update=true;
    for(int i=0;update;i++){
        if(i==n){
            return false;
        }
        update=false;
        for(int i=0;i<n;i++){
            if(d[i]==INF) continue;
            for(auto &e:g[i]){
                int tmp = d[i] + e.cost;
                if(tmp<d[e.to]){
                    d[e.to]=tmp;
                    update=true;
                }
            }
        }
    }
    return true;
}
int main(){
    int V,E,r;
    cin>>V>>E>>r;
    Graph g(V);
    for(int i=0;i<E;i++){
        int s,t,d;
        cin>>s>>t>>d;
        g[s].push_back(Edge(s,t,d));
    }
    vector<int> d;
    auto ret = bellman_ford(r,g,d);
    if(ret){
        for(int i=0;i<V;i++){
            if(d[i]==INF) cout<<"INF"<<endl;
            else cout<<d[i]<<endl;
        }
    }
    else{
        cout<<"NEGATIVE CYCLE"<<endl;
    }
}


Measured memory_bytes: 3144
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc103/tasks/abc103_d

int main() {
    int N, M; cin >> N >> M;
    P ab[M];
    REP(i, M) {
        int a, b; cin >> a >> b;
        ab[i] = {b, a};
    }
    sort(ab, ab + M);

    int now = 0;
    int cnt = 0;
    REP(i, M) {
        int l = ab[i].second;
        int r = ab[i].first;
        if (l >= now) {
            cnt++;
            now = r;
        }
    }

    cout << cnt << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < n;i++)
using ll = long long;

int main(){
  int n; cin >>n;
  ll cnt = 0;
  for(int i = 1; i<=n; i++){
    cnt += (n-1)/i;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3628
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall

N,M = map(int,input().split())

edge = [[int(x) for x in input().split()] for _ in range(M)]

graph = [[0] * N for _ in range(N)]
for a,b,c in edge:
  graph[a-1][b-1] = c
  
graph = csgraph_from_dense(graph)

dist = floyd_warshall(graph,directed=False)
answer = (graph > dist).sum()
print(answer)

Measured memory_bytes: 17440
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
char f[1010][1010];
int J[1010][1010];
int O[1010][1010];
int I[1010][1010];
T query(int a,int b,int c,int d)
{
	return T(P(J[c][d]-J[a-1][d]-J[c][b-1]+J[a-1][b-1],O[c][d]-O[a-1][d]-O[c][b-1]+O[a-1][b-1]),I[c][d]-I[a-1][d]-I[c][b-1]+I[a-1][b-1]);
}
int main()
{
	int n,m,k;
	cin >> n >> m;
	cin >> k;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cin >> f[i][j];
			if(f[i][j]=='J')J[i][j]++;
			else if(f[i][j]=='O')O[i][j]++;
			else I[i][j]++;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=2;j<=m;j++)
		{
			J[i][j]+=J[i][j-1];
			O[i][j]+=O[i][j-1];
			I[i][j]+=I[i][j-1];
		}
	}
	for(int j=1;j<=m;j++)
	{
		for(int i=2;i<=n;i++)
		{
			J[i][j]+=J[i-1][j];
			O[i][j]+=O[i-1][j];
			I[i][j]+=I[i-1][j];
		}
	}
	//cout << J[3][6] << ' ' << J[1][6] << ' ' << J[3][1] << ' ' << J[1][1] << endl;
	/*for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=m;j++)
		{
			cout << J[i][j] << ' ';
		}
		cout << endl;
	}*/
	for(int i=0;i<k;i++)
	{
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		T p=query(a,b,c,d);
		cout << p.fi.fi << ' ' << p.fi.sec << ' ' << p.sec << endl;
	}
	return 0;
}

Measured memory_bytes: 14092
N, M = gets.split.map(&:to_i)
A = N.times.map { gets.split.map(&:to_i) }

open_event = Array.new(M + 1, true)
ans = N

(M - 1).times do
  stop_event_id = -1
  counter = Hash.new(0)
  max_cnt = 0

  N.times do |i|
    event_id = A[i].find { |a| open_event[a] }
    counter[event_id] += 1

    if max_cnt < counter[event_id]
      max_cnt = counter[event_id]
      stop_event_id = event_id
    end
  end

  ans = max_cnt if ans > max_cnt

  if stop_event_id != -1
    open_event[stop_event_id] = false
  end
end

puts ans


Measured memory_bytes: 3068
import sys
from copy import deepcopy

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def drop(H, W, G):
    for i in range(1, H):
        for j in range(W):
            if G[i][j] == 0 and G[i - 1][j] != 0:
                k = i
                for k in range(i, 0, -1):
                    if G[k][j] != 0:
                        break
                    G[k][j], G[k - 1][j] = G[k - 1][j], 0


def main():
    H, W, K = map(int, readline().split())
    G_init = [list(map(int, readline().strip())) for _ in range(H)]

    ans = 0
    for i in range(H):
        for j in range(W):
            G = deepcopy(G_init)
            G[i][j] = 0
            drop(H, W, G)

            current_ans = 0
            scale = 1
            while True:
                score = 0
                for row in G:
                    cnt = 1
                    for k in range(1, W):
                        if row[k] == row[k - 1]:
                            cnt += 1
                        else:
                            if cnt >= K and row[k - 1] != 0:
                                score += row[k - 1] * cnt
                                row[k - cnt : k] = [0] * cnt
                            cnt = 1
                    if cnt >= K and row[W - 1] != 0:
                        score += row[W - 1] * cnt
                        row[W - cnt : W] = [0] * cnt

                if score == 0:
                    break

                current_ans += score * scale
                scale *= 2
                drop(H, W, G)

            if current_ans > ans:
                ans = current_ans

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 54236
D, G, *L = map(int, open(0).read().split())
inf = []
for m in zip(*[iter(L)]*2):
  inf.append(m)

ans = float('inf')
for i in range(2**D):
  m = 0
  cnt = 0
  log = []
  for j in range(D):
    if i%2==0:
      m += 100*(j+1)*inf[j][0]+inf[j][1]
      cnt += inf[j][0]
    else:
      log.append(j)
    i>>=1
  while m<G:
    if log==[]:
      break
    h = log.pop()
    s = 100*(h+1)
    x = (G-m)//s if (G-m)%s==0 else (G-m)//s+1
    c = min(inf[h][0]-1, x)
    m += c*s
    cnt += c
  else:
    ans = min(ans,cnt)
print(ans)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;  
#define REP(i,n) for(int i=0;i<(n);i++)  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LINF = (LLONG_MAX/2);
const double eps = 1e-14;
const double PI = M_PI;  
#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cout<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
  
#define DIV 1000000007

int main(){
  ll H,W; cin >> H >> W;
  if(H % 3 == 0 || W % 3 == 0){cout << 0 << endl;return 0;}
  if(H < W) swap(H,W);
  ll ans = INF;
  { for(ll i = 1; i <= H; i++){
    ll s1 = i*W;
    ll s23 = H*W - i*W;
    for(ll j = W/2-10; j <=W/2+10; j++){
      ll s2 = (H-i)*j;
      ll s3 = (H-i)*(W-j);
      ll now = max(abs(s1-s2),abs(s2-s3));
      now = max(now,abs(s3-s1));
      ans = min(now,ans);
    }
}}{
    swap(H,W);
  for(ll i = 1; i <= H; i++){
    ll s1 = i*W;
    ll s23 = H*W - i*W;
    for(ll j = W/2-10; j <=W/2+10; j++){
      ll s2 = (H-i)*j;
      ll s3 = (H-i)*(W-j);
      ll now = max(abs(s1-s2),abs(s2-s3));
      now = max(now,abs(s3-s1));
      ans = min(now,ans);
    }
  }}
  ans = min(ans,H);
  ans = min(ans,W);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// Author: wlzhouzhuan
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rint register int
#define rep(i, l, r) for (rint i = l; i <= r; i++)
#define per(i, l, r) for (rint i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define debug(x) cerr << #x << " = " << x << '\n';
#define pll pair <ll, ll>
#define fir first
#define sec second

inline int read() {
  int x = 0, neg = 1; char op = getchar();
  while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
  while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
  return neg * x;
}
inline void print(int x) {
  if (x < 0) { putchar('-'); x = -x; }
  if (x >= 10) print(x / 10);
  putchar(x % 10 + '0');
}

int n;

int main() {
  cin >> n;
  if (n % 1000 == 0) cout << 0;
  else cout << 1000 - n % 1000;
}

Measured memory_bytes: 3660
// #include <bits/stdc++.h>
// #define FOR(i, m, n) for (int i = m; i < (n); i++)
// #define FORR(i, m, n) for (int i = (m); i > 0; i--)
// #define REP(i, n) FOR(i, 0, n)
// #define ALL(v) v.begin(), v.end()
// #define RALL(v) v.rbegin(), v.rend()
// using namespace std;
// typedef long long ll;
// const int mod = 1e9 + 7;

// int main() {
//   int n, count = 0;
//   cin >> n;
//   vector<string> s(n);
//   REP(i, n) {
//     vector<char> tmp(10);
//     REP(j, 10) {
//       cin >> tmp[j];
//     }
//     sort(ALL(tmp));
//     REP(j, 10) {
//       s[i] += tmp[j];
//     }
//     REP(j, n - 1) {
//       if (s[j] == s[i]) {
//         count++;
//       }
//     }
//   }
//   set<string> ss;
//   map<string, int> sss;
//   REP(i, n) {
//     sss[s[i]] = 0;
//   }
//   REP(i, n) {
//      map<string, int>::iterator it = sss.find(s[i]);
//     if (it != sss.end()) { // 見つかった
//       sss[s[i]] += 1;
//     }
//   }
  
//   REP(i, n) {
//     set<string>::iterator iti = ss.find(s[i]);    // find() で要素が見つかれば、要素へのイテレータが得られる。
//     if (iti == ss.end()) {
//         // 要素が見つからなかった。
//     } else {
//         // 要素が見つかった。
//     }

//     ss.insert(s[i]);
//     cout << s[i] << endl;
//   }
//   cout << n - ss.size() << endl;
//   return 0;
// }

#include <bits/stdc++.h>
#define FOR(i, m, n) for (long long i = m; i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i > 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  map<string, int> m;
  REP(i, n) {
    string s;
    cin >> s;
    sort(ALL(s));
    m[s]++;
  }

  ll anser = 0;
  for (auto& p : m) {
    int s = p.second;
    anser += (ll)s * (s - 1) / 2;
  }

  cout << anser << endl;
  return 0;
}


Measured memory_bytes: 11136
fun main(args: Array<String>) {
	val n = readLine()!!.toInt()
	val (d, x) = readLine()!!.split(Regex("\\s"), 2).let {
		Pair(it[0].toInt(), it[1].toInt())
	}
	val a = mutableListOf<Int>()
	repeat(n) {
		a.add(readLine()!!.toInt())
	}
	var choco = x + n // 1日目はn個食べられる

	// 二日目..
	(1..d-1).forEach { day ->
		a.forEach {
			if (day%it == 0) {
				choco++
			}
		}
	}
	println("${choco}")
}

Measured memory_bytes: 34032
import sys
sys.setrecursionlimit(500000)

def dfs(v,w,c):
    if w % 2 ==1 :
        c = 1-c
    color[v] = c

    for i in a[v]:
        if color[i[0]] != -1:continue
        dfs(i[0],i[1],c)

n = int(input())

a = [[]for i in range(n)]
color = [-1 for _ in range(n)]

for i in range(n-1):
    x,y,z = map(int,input().split())
    a[x-1].append([y-1,z])
    a[y-1].append([x-1,z])
dfs(a[0][0][0],a[0][0][1],0)
print(*color,sep="\n")

Measured memory_bytes: 85204
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        long X=scan.nextLong();
        long Y=scan.nextLong();
        int cnt=0;
        while(X<=Y){
            X*=2;
            ++cnt;
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int a[] = {1, 3, 5, 7, 8, 10, 12};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, y;
    cin >> x >> y;
    if (x == 2 && y == 2)
        cout << "Yes";
    else if (x == 2 || y == 2)
        cout << "No";
    else
    {
        bool ax = false, bx = false;
        for (int i = 0; i < 7; ++i)
        {
            if (a[i] == x)
                ax = true;
            if (a[i] == y)
                bx = true;
        }
        if (ax == bx)
            cout << "Yes";
        else
            cout << "No";
    }
}


Measured memory_bytes: 256
eval'H,W,A,B='+`tr ' ' ,`
f=r=1,*(1..H+W).map{r=r*_1%M=10**9+7}
p (B...W).sum{|i|(f[h=H+~A]*f[i]*f[A-1]*f[W+~i]).pow(M-2,M)*f[h+i]*f[A+W-i-2]}%M

Measured memory_bytes: 35072
#include<bits/stdc++.h>
using namespace std;
int n;
long long int dizi[200007],height[200007],cnt[200007];

class segment{
	private:
		long long int buffer[410000];
	public:
		void update(int pos,long long int val)
		{
			pos+=n;
			buffer[pos]=val;
			pos/=2;
			while(pos>=1)
			{
				buffer[pos]=max(buffer[pos*2],buffer[pos*2+1]);
				pos/=2;
			}
		}
		long long int sorgu(int l,int r)
		{
			long long int mc=0;
			for(l+=n,r+=n;l<r;l>>=1,r>>=1)
			{
				if(l&1)
					mc=max(mc,buffer[l++]);
				if(r&1)
					mc=max(mc,buffer[--r]);
			}
			return mc;
		}
		void dump()
		{
			for(int i=0;i<n*2;i++)
				cout << buffer[i] << " ";
		}
}tree;

int main()
{
	// freopen("a.gir","r",stdin);
	// freopen("a.cik","w",stdout);
	// int n;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> height[i];
	}
	for(int i=0;i<n;i++)
	{
		cin >> dizi[i];
	}
	cnt[height[n-1]]=dizi[n-1];
	tree.update(height[n-1],dizi[n-1]);
	for(int k=n-1;k>=0;k--)
	{
		cnt[height[k]]=tree.sorgu(height[k]+1,n+1);
		cnt[height[k]]+=dizi[k];
		tree.update(height[k],cnt[height[k]]);
	}
	// tree.dump();
	// cout << cnt[0] << "\n";
	cout << tree.sorgu(0,n+1) << endl;
	// cout << endl;
	// for(int i=0;i<=n;i++)
	// 	cout << cnt[i] << " ";
}

Measured memory_bytes: 8192
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;

public class Main {
    public static void main(String[] args) throws IOException {
        for (int b=1; b<=4; b++){
            for (int f=1; f<=3; f++){
                for (int r=1; r<=10; r++){
                    Dom.allRes.add(new Dom(b, f, r, 0));
                }
            }
        }
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        int n = Integer.parseInt(br.readLine());
        String hashs =  HashMarks(20);
        for (int i=0; i<n; i++){
            String[] line = br.readLine().split(" ");
            int b = Integer.parseInt(line[0]);
            int f = Integer.parseInt(line[1]);
            int r = Integer.parseInt(line[2]);
            int v = Integer.parseInt(line[3]);
            
            for (Dom dom: Dom.allRes){
                if (dom.b == b && dom.f == f && dom.r == r){
                    dom.v += v;
                }
            }
        }
        int cnt = 0;
        for (Iterator<Dom> d = Dom.allRes.iterator(); d.hasNext();){
            Dom dom = d.next();
            cnt += 1;
            System.out.print(" " + dom.v);
            if (cnt%10==0){
                System.out.println();
            }
            if (!d.hasNext()){
                break;
            }
            if (cnt%30==0){
                System.out.println(hashs);
            }
        }
    }
    private static String HashMarks(int n){
        StringBuilder sb = new StringBuilder();
        for (int i=0; i<n; i++){
            sb.append("#");
        }
        return sb.toString();
    }
}
class Dom {
    final int b; //?£?
    final int f; //???
    final int r; //??????
    int v; //???
    static List<Dom> allRes = new ArrayList<Dom>();
    
    Dom (int b, int f, int r, int v){
        this.b = b;
        this.f = f;
        this.r = r;
        this.v = v;
    }
}

Measured memory_bytes: 20648
use std::io::BufRead;

pub struct StdinReader<R: BufRead> {
    pub buf_reader: R,
    pub buf: String,
}
impl<R: BufRead> StdinReader<R> {
    pub fn new(r: R) -> Self {
        StdinReader {
            buf_reader: r,
            buf: String::with_capacity(10000),
        }
    }
}

#[macro_export]
macro_rules! input {
    ($reader : expr, $t : ty) => { // one variable
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().parse().unwrap(); 
                reader.buf.clear();
                tmp_var
            },
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty) => { // 2 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0].clone(), tmp_var[1].clone())
            }
        }
    };
    ($reader : expr, $t0 : ty, $t1 : ty, $t2 : ty) => { // 3 tuple
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: Vec<$t0> = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                (tmp_var[0].clone(), tmp_var[1].clone(), tmp_var[2].clone())
            }
        }
    };
    ($reader : expr, $t : ty; $size : expr) => { // Vector
        match &mut $reader {
            reader => {
                use std::io::BufRead;
                reader.buf_reader.read_line(&mut reader.buf).unwrap();
                let tmp_var: $t = reader.buf.trim().split_whitespace().map(|a| a.parse().unwrap()).collect();
                reader.buf.clear();
                tmp_var
            }
        }
    };
}

fn main() {
    let handle = std::io::stdin();
    let mut r = StdinReader::new(handle.lock());
    use std::collections::HashMap;
    let mut ha = HashMap::with_capacity(4);
    for i in 0..3 {
        let (a, b): (usize, usize) = input!(r, usize, usize);
        {
            let ea = ha.entry(a).or_insert(0);
            *ea += 1;
        }
        let eb = ha.entry(b).or_insert(0);
        *eb += 1;
    }
    for (ck, cv) in ha {
        if cv >= 3 {
            println!("{}", "NO");
            return ;
        }
    }
    println!("{}", "YES");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;

long long a[1 << 20], R[1 << 20];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for (int i = 0; i <= n; i++) cin >> a[i];
	if (n == 0) {
		if (a[0] == 1) cout << 1 << endl;
		else cout << -1 << endl;
		return 0;
	}
	R[0] = 1;
	for (int i = 1; i <= n; i++) {
		R[i] = (R[i - 1] - a[i - 1]) * 2;
		if (R[i] > 1LL << 60) {
			for (int j = i + 1; j <= n; j++) R[j] = R[i];
			break;
		}
	}
	long long ans = 0;
	for (int i = n; i >= 0; i--) {
		if (a[i] > R[i]) {
			cout << -1 << endl;
			return 0;
		}
		ans += a[i];
		if (i) {
			if (a[i - 1] + (a[i] + 1) / 2 > R[i - 1]) {
				cout << -1 << endl;
				return 0;
			}
			a[i - 1] = min(a[i - 1] + a[i], R[i - 1]);
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 5192
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
	  	  	- William Butler Yeats
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#pragma comment(" -Wl,--stack=1024000000")
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#ifndef LOCAL
#define cerr if(0)cout
#define eprintf(...) 0
#else
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#endif
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
ll d[100005];
int sz[100005];
map<ll,int>mp;
vector<int>g[100005];
vector<pair<int,int> >ans;
ll sum=0;
void dfs(int x,int par,int dep){
	sum+=dep;
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		if(to!=par)dfs(to,x,dep+1);
	}
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>d[i];mp[d[i]]=i;sz[i]=1;
	}
	while(mp.size()>1){
		pair<ll,ll>p=*mp.rbegin();
		mp.erase(p.first);
		ll x=p.second,val=p.first;
		ll nxt_v=sz[x]*2+val-n;
		if(!mp.count(nxt_v)){
			puts("-1");
			return 0;
		}else{
			int y=mp[nxt_v];
			sz[y]+=sz[x];
			g[x].push_back(y);
			g[y].push_back(x);
			ans.push_back(make_pair(x,y));
		}
	}
	dfs(mp.begin()->second,-1,0);
	if(sum!=mp.begin()->first){
		puts("-1");
	}else{
		for(int i=0;i<ans.size();i++){
			cout<<ans[i].first<<" "<<ans[i].second<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 15224
use proconio::input;

fn main (){

let mut _a : i128;
let mut _b : i128;

input! {
    a: i128,
    b: i128,
   
}

if b % a == 0 {
    let  x = a +b ;
    println!("{}",x)
}else {
    let  y = b - a ;
    println!("{}",y)
}


}

Measured memory_bytes: 2096
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
void solve(){
	ll n,m;
	cin>>n>>m;
	set<ll> s;
	ll cur=1,d=n-1;
	while(m){
		if((n%2==0&&d==n/2)||s.find(n-d)!=s.end()){
			d--;
			continue;
		}
		cout<<cur<<" "<<cur+d<<"\n";
		cur++;
		s.insert(d);
		d-=2;
		m--;
	}
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll qc=1;
    for(ll i=1;i<=qc;i++)
    solve();
}


Measured memory_bytes: 7692
import sys
input = sys.stdin.readline

n = int(input())

dp = [[[[0]*4 for _ in range(4)] for _ in range(4)] for _ in range(n + 1)]
c = [0, 1, 2, 3]
import itertools
pers = itertools.product(c, repeat=3)
ng_3 = [(0, 1, 2), (0, 2, 1), (1, 0, 2)]
for p in pers:
    if p in ng_3:
        continue
    dp[3][p[0]][p[1]][p[2]] = 1
for i in range(3, n):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                for m in range(4):
                    if (m, j, k) in ng_3 or (m == 0 and k == 1 and l == 2) or (m == 0 and j == 1 and l == 2):
                        continue
                    dp[i + 1][m][j][k] += dp[i][j][k][l]
ans = 0
for j in range(4):
    for k in range(4):
        for l in range(4):
            ans += dp[-1][j][k][l]
print(ans % (10**9 + 7))

Measured memory_bytes: 45040