akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }

int main(){
    ll N,M;
    string S;
    cin >> N >> M;
    vector<ll> A(M);
    ll sum = 0;
    rep(i,M){
        cin >> A[i];
        sum += A[i];
    }
    if(N-sum < 0){
        cout << -1 << endl;
    }else{
        cout << N-sum <<endl;
    }

}

Measured memory_bytes: 3676
#include<iostream>
#include<vector>
#include<set>
#define MOD 1000000007
using namespace std;
typedef long long ll;
ll modinv(ll a, ll m){
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
ll mod_powinv(ll a,ll m){
  ll ans=1;
  for(int i=1;i<=a;i++){
    ans *= modinv(i,m);
    ans %= m;
  }
  return ans;
}
ll mod_pow(ll a,ll m){
  ll ans=1;
  for(int i=1;i<=a;i++){
    ans *= i;
    ans %= m;
  }
  return ans;
}
ll conb_inv(ll n,ll r,ll m){
  return (mod_pow(n,m)*(mod_powinv(r,m)*mod_powinv(n-r,m)%MOD))%MOD;
}
int main(){
  ll n,m,ans=1,tmp,cnt;
  vector<ll> val;
  set<ll> st;
  cin >> n >> m;
  vector<bool> cp_list(m+1,true);
  for(ll i=2;i<=m;i++){
    if(m%i==0){
      cnt=0;
      while(m%i==0){
        cnt++;
        m/=i;
      }
      val.push_back(cnt);
    }
  }
  for(int i=0;i<val.size();i++){
    ans *= conb_inv(val[i]+n-1,val[i],MOD);
    ans %= MOD;
  }
  cout << ans <<endl;
}


Measured memory_bytes: 122368
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[0]
C=[0]
for i in range(N):
  B.append(B[i]+max(0,A[i]))
  C.append(C[i]-min(0,A[i]))
P=10**20
for i in range(N-K+1):
  P=min(P,B[i+K]-B[i],C[i+K]-C[i])
print(B[N]-P)

Measured memory_bytes: 98192
#include<stdio.h>
int main(void)
{
	int a,flg,b,r,A,i,j,X,W,w,x[100];
	while(1){
		scanf("%d",&a);
		flg=0;
		r=0;
		if(a==0000) break;
		while(1){
			if(a%1111==0){
				flg=1;
				break;
			}
			else if(a==6174) break;
			r++;
			A=a;
			b=1000;
			for(i=0;i<4;i++){
				x[i]=a/b;
				a=a-x[i]*b;
				b/=10;
			}
			for(i=0;i<4;i++){
				for(j=i+1;j<4;j++){
					if(x[i]<x[j]){
						X=x[i];
						x[i]=x[j];
						x[j]=X;
					}
				}
			}
			w=x[0]*1000+x[1]*100+x[2]*10+x[3];
			b=1000;
			for(i=0;i<4;i++){
				x[i]=A/b;
				A=A-x[i]*b;
				b/=10;
			}
			for(i=0;i<4;i++){
				for(j=i+1;j<4;j++){
					if(x[i]>x[j]){
						X=x[i];
						x[i]=x[j];
						x[j]=X;
					}
				}
			}
			W=x[0]*1000+x[1]*100+x[2]*10+x[3];
			a=w-W;
		}
		if(flg==1){
				printf("NA\n");
		}
		else if(a==6174){
			printf("%d\n",r);
		}
	}
	return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
#include <string>

using namespace std;

int main(int argc, const char *argv[]) {
  int a, b;
  cin >> a >> b;
  if (a < 10 && b < 10) {
    cout << a * b << '\n';
  } else {
    cout << -1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a, b, c, d, e;
    int i, j, k, l;
    int x[4][3][10]={0};
    scanf("%d", &a);
    for(i=0;i<a;i++){
        scanf("%d%d%d%d", &b, &c, &d, &e);
        x[b-1][c-1][d-1] += e;
    }

    for(j=0;j<4;j++){
        for(k=0;k<3;k++){
            for(l=0;l<10;l++){
                printf(" %d",x[j][k][l]);
            }
                printf("\n");
        }
        if(j<3)
        puts("####################");

    }

    return 0;
}

Measured memory_bytes: 612
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        char[] s = sc.nextLine().toCharArray();
        char[] t = sc.nextLine().toCharArray();

        Arrays.sort(s);
        Arrays.sort(t);

        char[] newT = new char[t.length];
        for(int i=0; i<t.length; i++) {
            newT[i] = t[t.length-1-i];
        }

        String ss = new String(s);
        String tt = new String(newT);

        if(ss.compareTo(tt) < 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
inline void fff(){
	freopen("line.in","r",stdin);
	freopen("line.out","w",stdout);
}
const int N=1e5+10;
const int INF=0x3f3f3f3f;
inline int read(){
	int x=0,m=1;char ch=getchar();
	while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
	if(ch=='-') ch=getchar(),m=-1;
	while(ch<='9'&&ch>='0') 
		x=x*10+ch-'0',ch=getchar();
	return x*m;
}
int n,m;
struct Edge{
	int nxt;
	int to,w;
}edge[N<<2];
int head[N],tot=0;
inline void add(int u,int v,int w){
	edge[++tot].nxt=head[u];
	edge[tot].to=v;
	edge[tot].w=w;
	head[u]=tot;
}
bool visited[N];
int dist[N],ans,minn,maxx;
queue<int> q;
inline bool SPFA(int str){
	
	q.push(str);
	if(m) minn=INF,maxx=0;
	dist[str]=0;visited[str]=true;
	while(!q.empty()){
		int u=q.front();q.pop();
		visited[u]=false;
		for(int i=head[u];i;i=edge[i].nxt){
			Edge e=edge[i];
			if(dist[e.to]<INF){
				if(dist[e.to]!=e.w+dist[u]){
					return false;
				}
				minn=min(minn,dist[e.to]);
				maxx=max(maxx,dist[e.to]);
			}else{
				dist[e.to]=dist[u]+e.w;
				minn=min(minn,dist[e.to]);
				maxx=max(maxx,dist[e.to]);
				if(!visited[e.to]){
					visited[e.to]=true;
					q.push(e.to);
				}
			}
		}
	}
	ans=min(ans,maxx-minn);
	return true;
}
int main(){
//	fff();
	n=read();
	m=read();
	ans=INF;
	for(int i=1;i<=m;i++){
		int u,v,w;
		u=read(),v=read(),w=read();
		add(u,v,w);
		add(v,u,-w);
	}
	memset(dist,INF,sizeof(dist));
	for(int i=1;i<=n;i++){
		if(dist[i]<INF)  continue;
		if(!SPFA(i)){
			printf("No");
			return 0;
		}
	}
	printf("Yes");
}

Measured memory_bytes: 6272
n, m = map(int, input().split())
A = list(map(int,input().split()))

a_sum = sum(A)
ans = 0
for i in range(n):
    if float(A[i]) >= a_sum/(4*m):
        ans += 1


if ans >= m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main(void){
    int table[200][200]={{0}};
    int r,c;
    cin >> r >> c;
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> table[i][j];
        }
    }
    // 横計算
    for(int i = 0; i < r+1; i++){
        int sum = 0;
        for(int j =0; j < c; j++){
            sum += table[i][j];
        }
        table[i][c] = sum;
    }
    // 縦計算
    for(int i = 0; i < c+1; i++){
        int sum = 0;
        for(int j =0; j < r; j++){
            sum += table[j][i];
        }
        table[r][i] = sum;
    }
    
    for(int i = 0; i < r+1; i++){
        for(int j = 0; j < c; j++){
            cout << table[i][j] << " ";
        }
        cout << table[i][c] << endl;
    }
}


Measured memory_bytes: 3228
#include<iostream>
using namespace std;

int gcd(int x,int y){
  if(y==0)
    return x;
  return gcd(y,x%y);
}

int main(){
  int x,y;
  cin>>x>>y;
  int sum;
  sum=x+1+y+1;
  int num;
  num=gcd(x,y);
  sum=sum-num-1;
  cout<<sum<<endl;
}



Measured memory_bytes: 3100
def calc_seq(xs):
    seq = []
    count = 1
    for i in range(0, len(xs)-1):
        if xs[i] == xs[i+1]:
            count += 1
        else:
            seq.append(count)
            count = 1
    seq.append(count)
    return seq

def form_seq(xs):
    seq = calc_seq(xs)
    if xs[0] == 0:
        seq.insert(0, 0)
    if len(seq) % 2 == 0:
        seq.append(0)
    return seq

def main(n, k, xs):
    seq = form_seq(xs)
    m = len(seq)
    i = 1
    if i + 2*k > m:
        print(n)
        return
    j = i - 1
    val = sum(seq[j:j+2*k+1])
    biggest = val
    i += 2
    while i + 2*k <= m:
        j = i - 1
        val += seq[j+2*k-1] + seq[j+2*k] - seq[j-2] - seq[j-1]
        if biggest < val:
            biggest = val
        i += 2
    print(biggest)

n, k = list(map(int, input().split()))
xs = list(map(int, list(input())))

main(n, k, xs)

Measured memory_bytes: 5024
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

typedef struct {
  int64_t t, d;
} sushi;

int compare(const void *a, const void *b) {
    if (((sushi *)b)->d > ((sushi *)a)->d) {
      return 1;
    }
    if (((sushi *)b)->d < ((sushi *)a)->d) {
      return -1;
    }
    return 0;
}

int has_type(int64_t *types, int64_t type_count, int64_t type) {
  int64_t i;
  for (i = 0; i < type_count; i++) {
    if (types[i] == type) {
      return 1;
    }
  }
  return 0;
}

int64_t solv(const int64_t n, const int64_t k) {
  sushi *sushis, *dups, *dp;
  int64_t i, *original_types, type_count = 0;
  int64_t ans, max = 0, sum = 0, count = 0;

  sushis = (sushi *)malloc(sizeof (sushi) * n);
  original_types = (int64_t *)malloc(sizeof (int64_t) * k);
  dups = dp = (sushi *)malloc(sizeof (sushi) * k);

  for (i = 0; i < n; i++) {
    scanf("%lld %lld", &sushis[i].t, &sushis[i].d);
  }
  qsort(sushis, n, sizeof (sushi), compare);

  for (i = 0; i < n && type_count < k; i++) {
    if (count == k) {
      if (has_type(original_types, type_count, sushis[i].t)) {
        continue;
      }
      sum += sushis[i].d - (--dp)->d;
      original_types[type_count++] = sushis[i].t;
    } else {
      if (has_type(original_types, type_count, sushis[i].t)) {
        *(dp++) = sushis[i];
      } else {
        original_types[type_count++] = sushis[i].t;
      }
      sum += sushis[i].d;
      count++;
    }

    ans = sum + type_count * type_count;
    if (max < ans) {
      max = ans;
    }
  }

  free(original_types);
  free(sushis);
  free(dups);

  return max;
}

int main(int argc, char **argv) {
  int64_t n, k;

  while (scanf("%lld %lld", &n, &k) != EOF) {
    printf("%lld\n", solv(n, k));
  }

  return 0;
}


Measured memory_bytes: 3324
#include<cstdio>                       
                                       
using namespace std;                   
                                       
int main() {                           
        int n;                         
        scanf("%d", &n);               
        int p[200000];                 
        for (int i = 0; i < n; i++) {  
                int x;                 
                scanf("%d", &x);       
                p[x] = i + 1;          
        }                              
                                       
        for (int i = 1; i <= n; i++) { 
                printf("%d ", p[i]);    
        }
        printf("\n");
        return 0;                      
}                                      

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*既に塗った色の配列　tuple(親、子、その間の辺の色)の配列
  を用意
*/
struct edge{
    int to,color;
};

using Graph = vector<vector<edge>>;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    vector<ll> B(N);
    rep(i,N){
        B[i] = A[i] - i - 1;
    }
    sort(B.begin(),B.end());
    ll b = B[N/2];
    ll sum = 0;
    rep(i,N){
        sum += abs(B[i]-b);
    }
    cout << sum << endl;
  }

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, a, b; cin >> n >> a >> b;
  cout << min(a, b) << ' ' << max(a + b - n, 0) << '\n';
}

Measured memory_bytes: 256
//============================================================================
// Author      : JCH
// Copyright   :
// Description : Contest ACM Div2
//============================================================================

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

#define pii pair<int,int>

vector<pii> A;
int n, x;

int main() {

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		A.push_back(pii(x,i));
	}

	sort(A.begin(), A.end());

	int c = 0;
	for (int i = 0; i < n; i += 2) {
		if ((A[i].second + i) % 2)
			c++;
	}
	cout << c << endl;

	return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
   int n;
   cin >> n;
   int a[n];
   int max = 0, sub_max = 0;
   rep(i, n) { 
    cin >> a[i];
    if(a[i] > max){
        max = a[i];
    } else if(a[i] > sub_max){
        sub_max = a[i];
    }
   }
   rep(i,n){
       if(a[i]==max)cout<< sub_max << endl;
       else cout<< max << endl;
   }

   return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 0x3f3f3f3f;
const int N = 5000+10;


int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(false); cout.tie(false);
    ll n;
    cin >> n;
    cout << n*n*n << endl;
	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = list(input())

n = N #現在地
ans = []
while n != 0:
    for i in range(min(n, M), 0, -1):
        if S[n - i] == '0':
            n -= i
            ans.append(i)
            break
        if i == 1:
            print (-1)
            exit()

print (*ans[::-1])



Measured memory_bytes: 55688
#include<iostream>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
     if (a==1 and b==2)cout<<"3";
else if (a==1 and b==3)cout<<"2";
else if (a==2 and b==1)cout<<"3";
else if (a==2 and b==3)cout<<"1";
else if (a==3 and b==2)cout<<"1";
else if (a==3 and b==1)cout<<"2";
  return 0;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
const int MOD = 1000000009;
const double pi = acos(-1);

struct UnionFind {
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    int N, M ; cin >> N >> M;
    UnionFind UF(N);
    UF.init(N);
    REP(i,M) {
        int a,b; cin >> a >> b;
        a--; b--;
        UF.merge(a,b);
    }
    ll ans = 0;
    REP(i,N) chmax(ans,UF.size(i));
    cout << ans << endl;
}

Measured memory_bytes: 6420
string = input()

s_list = []
for i in range(4):
  s_list.append(string[i])
  
sn_list = sorted(s_list)

if sn_list[0]==sn_list[1] and sn_list[2]==sn_list[3]:
  if sn_list[0]!=sn_list[2]:
    print('Yes')
  else:
    print('No')
else:
  print('No')

Measured memory_bytes: 3060
#include <iostream>
using namespace std;

int main() {
    int a, b, c;
    int count = 0;
    cin >> a >> b >> c;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


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

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

    int n;
    cin >> n;
    vector<int> A(n);
    REP(i, n) cin >> A[i];

    int cnt = 0;
    REP(i, n){
        if(A[A[i] - 1] - 1 == i) cnt++;
    }
    cout << cnt / 2 << endl;

    return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "{ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "}";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    return gcd(b, a%b);
}

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#ifdef LOCAL
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int M, K;
    cin >> M >> K;

    int N = 1LL << M;

    if (M == 0){
        if (K == 0) cout << "0 0" << endl;
        else cout << -1 << endl;
        return 0;
    }
    if (M == 1) {
        if (K == 0) cout << "0 0 1 1" << endl;
        else cout << -1 << endl;
        return 0;
    }

    if (K == 0) {
        REP(i, N) {
            if (i > 0) cout << " ";
            cout << i << " " << i;
        }
        cout << endl;
        return 0;
    }

    if (K >= N) {
        cout << -1 << endl;
        return 0;
    }

    set<int> o;
    vector<Pin> v;
    REP(i, N) {
        int m1 = i, m2 = i ^ K;
        if (o.count(m1) || o.count(m2)) continue;

        v.pb({m1, m2});
        o.insert(m1); o.insert(m2);
    }

    for(int i; i < v.size(); i += 2) {
        if (i > 0) cout << " ";
        cout << v[i].fi << " " << v[i].se << " ";
        cout << v[i+1].fi << " " << v[i+1].se << " ";
        cout << v[i].se << " " << v[i].fi << " ";
        cout << v[i+1].se << " " << v[i+1].fi;
    }

    cout << endl;
}


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

MOD = 10**9+7

class Comb:
    def __init__(self, N):
        self.fac = [1] * (N+1)
        for i in range(2, N+1): self.fac[i] = self.fac[i-1] * i % MOD

    def pow(self, a, b):
        res = 1
        while b:
            if b & 1: res = res * a % MOD
            a = a**2 % MOD
            b >>= 1
        return res

    def pow2(self, a, b):
        return pow(a, b, MOD)

    def comb(self, n, r):
        if r < 0 or r > n: return 0
        return (self.fac[n] * self.pow2(self.fac[r], MOD-2)) % MOD * self.pow2(self.fac[n-r], MOD-2) % MOD

    def permutation(self, n, r):
        if r == 0: return 1
        return self.fac[n] * self.pow2(self.fac[n-r], MOD-2) % MOD

def main():
  N, K = list(map(int, input().split()))

  comb = Comb(N)
  ans = 0

  for i in range(min(N, K)+1):
      ans = ans + (comb.comb(N, i) * comb.comb(N-1, i) % MOD)
      ans %= MOD

  print(ans) 

if __name__ == '__main__':
  main()

Measured memory_bytes: 43928
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
const double pi=3.1415926535897932384626;
int main(){
    dou l;
    std::cin >> l;
    std::cout <<keta(10)<< powl(l/3,3) << std::endl;
}

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

ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  ll sum[n - 1];
  sum[0] = 0;
  for (int i = 0; i < n - 1; i++) {
    sum[i] += a[n - i - 1];
    sum[i] %= MOD;
    if (i != n - 2) {
      sum[i + 1] = sum[i];
    }
  }

  ll ans = 0;
  for (int i = 0; i < n - 1; i++) {
    ll tmp = a[i] * sum[n - 2 - i];
    tmp %= MOD;
    ans += tmp;
    ans %= MOD;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6420
/******************************************************************************
 
рассвет. 
 
*******************************************************************************/
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define rapgame ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define all(a) (a).begin(),(a).end()
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int> 
#define vplli vector <pair <lli,lli> >
#define vvi vector <vector <int> >
#define vvlli vector <vector <lli> >
#define vvpii vector <vector <pair <int,int>> >
#define fr(i,n) for (int i = 0; i < (n); ++i)
#define frbig(i,n) for (lli i = 0; i < (n); ++i)
#define fra(i,a,n) for (int i = a; i < (n); ++i)
#define run(c,s) for(auto c:s) 
#define read(n) int n; cin >> n;
#define readchar(n) char n; cin >> n;
#define readstr(n) string n; cin >> n;
#define readarr(a,n) fr(i,n) cin >> a[i];
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;
 
const lli MOD=1e9+7;
const lli MAXN=2e5+1;
const ld PI=acos(-1);

int main(){
    rapgame
    //freopen("brokeday.in", "r", stdin);
    //freopen("richday.out", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        read(n);
        if(n%2) cout << "No";
        else{
            string s;
            cin >> s;
            fr(i,n/2){
                if(s[i+n/2]!=s[i]){ cout << "No";return 0;}
            }
            cout << "Yes";
        }
    }
    return 0;
}

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

int main(){
	int H, W;
	cin >> H >> W;
	int d[10][10];
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++){
			int c;
			cin >> c;
			d[i][j] = c;
		}
	}
	for(int k=0; k<10; k++){
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	ll ans = 0;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++){
			int a;
			cin >> a;
			if(a == -1) continue;
			ans += d[a][1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

string s;
string t;

void solve(){
    cin >> s;
    cin >> t;
    int n=s.length();
    bool ans=true;
    rep(i,n){
        if(s[i]!=t[i]) ans=false;
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 3612
n = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)

arr.each_with_index do |element, index|
  if index == 0
    puts arr.join(' ')
    next
  end
  v = element
  j = index - 1
  while(j >= 0 && arr[j] > v) do
    arr[j+1] = arr[j]
    j -= 1
  end
  arr[j + 1] = v
  puts arr.join(' ')
end



Measured memory_bytes: 6896
// https://atcoder.jp/contests/abc165/tasks/abc165_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll K, A, B;
  cin >> K >> A >> B;

  if (A % K == 0 || A / K != B / K) {
    drop("OK");
  } else {
    drop("NG");
  }
}


Measured memory_bytes: 3676
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

type pos struct {
	x, y int
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([][]int, 2)
	d := make([][]int, 2)
	for i := 0; i < 2; i++ {
		a[i] = make([]int, N)
		d[i] = make([]int, N)
		for j := 0; j < N; j++ {
			a[i][j] = getInt()
		}
	}

	s := make([]pos, 0)
	s = append(s, pos{0, 0})
	for len(s) != 0 {
		x, y := s[0].x, s[0].y
		s = s[1:]
		if x == 0 && y == 0 {
			d[y][x] = a[y][x]
		} else if y == 0 {
			d[y][x] = a[y][x] + d[y][x-1]
		} else if x == 0 {
			d[y][x] = a[y][x] + d[y-1][x]
		} else {
			d[y][x] = a[y][x] + max(d[y][x-1], d[y-1][x])
		}
		if x+1 != N {
			s = append(s, pos{x + 1, y})
		}
		if y+1 != 2 {
			s = append(s, pos{x, y + 1})
		}
	}
	out(d[1][N-1])
}


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

struct UnionFind {
	vector<int> value;
	UnionFind(int size): value(size, -1){}
	int find(int x){
		if (value[x] < 0) return x;
		return value[x] = find(value[x]);
	}
	int size(int x){
		return -value[find(x)];
	}
	bool same(int x, int y){
		return find(x) == find(y);
	}
	bool unite(int x, int y){
		x = find(x);
		y = find(y);
		if (x == y) return false;
		if (value[x] > value[y]) swap(x, y);
		value[x] += value[y];
		value[y] = x;
		return true;
	}
};

typedef tuple<int, int, int> Tp;
const int INF = 1 << 28;

int n, m;
deque<Tp> es;

int calc()
{
	int res = 0;
	UnionFind uf(n);
	for (int i = 0; i < es.size(); i++){
		int w = get<0>(es[i]);
		int a = get<1>(es[i]);
		int b = get<2>(es[i]);
		
		if (uf.unite(a, b)){
			res = w - get<0>(es[0]);
		}
	}
	
	if (uf.size(0) < n) res = INF;
	return res;
}

int main()
{
	while (scanf("%d %d", &n, &m), n){
		es.clear();
		
		for (int i = 0; i < m; i++){
			int a, b, w;
			scanf("%d %d %d", &a, &b, &w);
			es.push_back(Tp(w, --a, --b));
		}
		
		int res = INF;
		sort(es.begin(), es.end());
		while (es.size()){
			res = min(res, calc());
			es.pop_front();
		}
		
		if (res == INF) puts("-1");
		else printf("%d\n", res);
	}
}

Measured memory_bytes: 1276
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------


//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    string s;cin>>s;
    vector<char>c;
    for(int i=0;i<s.length();i++){
        if(i%2==0){
            c.pb(s[i]);
        }
    }
    for(int i=0;i<c.size();i++)
        cout<<c[i];
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
int n, q;
int leader[10050], ranking[10050];
int find(int x)
{
	if(leader[x] != x)
	{
		int setleader = find(leader[x]);
		leader[x] = setleader;
	}
	return leader[x];
}
void Union(int x, int y)
{
	int setleaderX = find(x), setleaderY = find(y);
	if(setleaderX == setleaderY)
		return;
	if(ranking[setleaderX] == ranking[setleaderY]){
		leader[setleaderY] = setleaderX;
		ranking[setleaderX]++;
	}
	else
	{
		if(ranking[setleaderX] > ranking[setleaderY])
			leader[setleaderY] = setleaderX;
		else
			leader[setleaderX] = setleaderY;
	}
}
int main()
{
	cin>>n>>q;
	for(int i =0;i<n;i++)
	{
		leader[i] = i;
		ranking[i] = 1;
	}
	for(int i =0;i<q;i++)
	{
		int type, x, y;
		cin>>type>>x>>y;
		if(type == 0)
			Union(x,y);
		else
		{
			int leaderX = find(x), leaderY = find(y);
			if(leaderX == leaderY)
				cout<<1<<endl;
			else
				cout<<0<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
int main(){
    int n,m;
    while(1){
        cin>>n>>m;
        if(n+m==0)return 0;
        int a[100],b[100];
        int sum1=0,sum2=0;
        for(int i=0;i<n;i++){cin>>a[i];sum1+=a[i];}
        for(int i=0;i<m;i++){cin>>b[i];sum2+=b[i];}
        int ans1=1e9,ans2=1e9;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                if(sum1-a[i]+b[j]==sum2-b[j]+a[i]){
                    if(a[i]+b[j]<ans1+ans2){
                        ans1=a[i];ans2=b[j];
                    }
                }
            }
        }
        if(ans1==1e9){
            cout<<-1<<endl;
        }else{
            cout<<ans1<<" "<<ans2<<endl;
        }
    }
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>

using namespace std;

bool boxs[200005];

int main() {
    int N;
    cin >> N;
    vector<int> a(N + 1);
    for (int i = 1; i < N + 1; ++i) {
        cin >> a[i];
    }
    string ans;

    int cnt = 0;
    for (int i = N; i >= 1; --i) {
        int sum = 0;
        for (int j = N / i; j > 1; --j) {
            if (boxs[j*i]) sum++;
        }
        boxs[i] = sum % 2 ^ a[i];
        if (boxs[i]) cnt++;
    }

    cout << cnt << endl;
    for (int i = 1; i <= N; ++i) {
        if (boxs[i]) {
            ans += to_string(i) + " ";
        }
    }
    ans = ans.substr(0, ans.size() - 1);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2948
#include<bits/stdc++.h>
 
using namespace std;
 
const int INF = 1 << 30;
 
int N, M;
vector< int > A, B;
bool v[51][51][51][51][2][3];
int dp[51][51][51][51][2][3];
 
int rec(vector< int >& me, vector< int >& you, int head_a, int head_b, int block_a, int block_b, bool turn, int pass)
{
  if(v[head_a][head_b][block_a][block_b][turn][pass]++) return (dp[head_a][head_b][block_a][block_b][turn][pass]);
 
  int ret = -INF;
 
  if(head_a < me.size()) {
    if(~me[head_a]) ret = max(ret, -rec(you, me, head_b, head_a + 1, block_b, block_a, turn ^ 1, 0));
    else ret = max(ret, -rec(you, me, head_b, head_a + 1, head_b, block_a, turn ^ 1, 0));
  }
 
  int cost = 0;
  for(int i = block_a; i < head_a; i++) if(~me[i]) cost += me[i];
  for(int i = block_b; i < head_b; i++) if(~you[i]) cost -= you[i];
  if(pass == 2) ret = max(ret, cost);
  else ret = max(ret, cost - rec(you, me, head_b, head_a, head_b, head_a, turn ^ 1, pass + 1));
 
  return (dp[head_a][head_b][block_a][block_b][turn][pass] = ret);
}
 
int main()
{
  cin >> N >> M;
  A.resize(N);
  B.resize(M);
  for(int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for(int i = 0; i < M; ++i) {
    cin >> B[i];
  }
  cout << rec(A, B, 0, 0, 0, 0, 0, 0) << endl;
}

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

bool check(int a, int b,int n ,int m,vector<string> &ar){
    if(a>=0 && a<n && b>=0 && b< m && ar[a][b] == '.') return true;
    
    return false;
}
void solve(){
    int n,m;
    cin>>n>>m;
    int s1,s2,d1,d2;
    cin>>s1>>s2>>d1>>d2;
    s1--;
    s2--;
    d1--;
    d2--;
    vector<string> ar(n);
    
    for(int i=0; i<n; i++){
        cin>>ar[i];
    }
    
    int dx[] = {-1,0,0,1};
    int dy[] = {0,1,-1,0};
    
    if(ar[s1][s2] == '#' || ar[d1][d2] == '#' ) {
        cout<<-1<<endl;
        return;
    }
    
    vector<vector<int>> dis(n, vector<int>(m, INT_MAX));
    
    vector<vector<bool>> vis(n, vector<bool>(m, false));
    
    deque<pair<int, int>> dq;
    
    
    dis[s1][s2] = 0;
    dq.push_front({s1,s2});
    
    while(!dq.empty()){
        int a = dq.front().first;
        int b = dq.front().second;
        dq.pop_front();
        vis[a][b] = true;
        
        for(int i=0; i<4; i++){
            int x = a+ dx[i];
            int y = b+ dy[i];
            
            if(  check(x,y,n,m,ar) && !(vis[x][y]) ){
                if(dis[x][y] > dis[a][b]){
                    dis[x][y] = dis[a][b];
                    dq.push_front({x,y});
                }
            }
        }
        
        for(int i=a-2; i<=a+2 ; i++){
          for(int j = b-2; j<=b+2; j++){
            if(  check(i,j,n,m,ar) && !(vis[i][j]) ){
                if(dis[i][j] > dis[a][b]+1){
                    dis[i][j] = dis[a][b]+1;
                    dq.push_back({i,j});
                }
            }
          }
        }
    }
    
    if(dis[d1][d2] == INT_MAX ) cout<<-1<<endl;
    
    else cout<<dis[d1][d2]<<endl;
    
    return;

}
int main() {
	// your code goes here

        solve();

    return 0;
}



Measured memory_bytes: 9788
#include <stdio.h>

#define MOD 1000000007
#define AMAX (2<<17)

int N,K;
long F[AMAX];
long I[AMAX];

long powmod( long, long );

/***********************************************************
    階乗と逆数のテーブル生成
***********************************************************/
void maketable()
{
    // 階乗を計算し記録
    F[0] = 1;
    for( int i=1; i<=N+1; i++ )
        F[i] = (long long) F[i-1] * i % MOD;

    // 階乗の逆数を計算し記録
    I[N] = powmod( F[N], MOD -2 );
    for( int i=N-1; i>=0; i-- )
        I[i] = (long long) I[i+1] * (i+1) % MOD;
}

/***********************************************************
    べき乗＋剰余
***********************************************************/
long powmod( long a, long b )
{
    long long ret = 1;

    while( b ) {
        if( b & 1 ) ret = ret * a % MOD;
        b >>= 1;
        a = (long long)a * a % MOD;
    }

    return( ret );
}

/***********************************************************
    組合せ＋剰余
***********************************************************/
long combination( long n, long r )
{
    long long ret;

    ret = F[n];
    ret = (ret * I[n-r]) % MOD;
    ret = (ret * I[r]) % MOD;

    return( ret );
}

/***********************************************************

***********************************************************/
int main( int argc, char *argv[] )
{
    // 問題を読み取る
    scanf( "%d%d", &N, &K );

    // 階乗と逆数のテーブルを生成
    maketable();

    // ΣnCr * n-1Cr を計算
    long long ans = 0;
    for(long i=0;i<N&&i<=K;i++) {
//        ans += F[N] * F[N-1] % MOD * I[N-i] % MOD * I[i] % MOD * I[N-1-i] % MOD * I[i] % MOD;
        ans += (long long) combination( N, i ) * combination( N-1, i ) % MOD;
    }

//    while( ans < 0 ) ans += MOD;
    ans %= MOD;

    printf( "%ld\n", (long)ans );
}


Measured memory_bytes: 3712
import java.util.*;
import java.io.*;

class Main
{
	int V;
	ArrayList<Integer> adj[];
    Main(int V)
    {
        this.V = V;
        adj = new ArrayList[V];
        for(int i = 0; i < V; i++)
        {
            adj[i] = new ArrayList<>();
        }
    }
    void addEdge(int p1, int p2)
    {
        adj[p1].add(p2);
    }
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int e = sc.nextInt();
	    Main g1 = new Main(n);
	    for(int i = 0; i < e; i++)
	    {
	    	int a = sc.nextInt();
	    	int b = sc.nextInt();
	    	g1.addEdge(a-1, b-1);
	    }
	    boolean[] vis = new boolean[n];
	    int[] dp = new int[n];
	    for(int i = 0; i < n; i++)
	    {
	    	dp[i] = 0;
	    	vis[i] = false;
	    }
	    int res = 0;
	    for(int i = 0; i < n; i++)
	    {
	    	if(!vis[i])
	    	{
	    		res = Math.max(res, g1.dfs(i, dp, vis));
	    	}	
	    }
		System.out.println(res);
	}
	int dfs(int v, int[] dp, boolean[] vis)
    {
    	int ans = 0;
    	vis[v] = true;
    	Iterator<Integer> itr = adj[v].iterator();
        while(itr.hasNext())
        {
        	int i = itr.next();
        	if(!vis[i])
        	{
        		ans = Math.max(ans, dfs(i, dp, vis));
        	}	
        	else
        	{
        		ans = Math.max(ans, dp[i]);
        	}  
        }
        if(adj[v].size() == 0)
        {
        	dp[v] = ans;
        }
        else
        {
        	dp[v] = ans + 1;
        }
        return dp[v];
    }
}


Measured memory_bytes: 106336
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] v = new int[n];
        for (int i = 0 ; i < n ; i++) {
            v[i] = sc.nextInt();
        }
        Arrays.sort(v);
        double ans = v[0];
        for (int i = 1 ; i < n ; i++) {
            ans = (double) (ans + v[i]) / 2.0;
        }
        System.out.println(ans);
    }

}

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

int main() {
        int n;
        cin >> n;
        string s, t;
        cin >> s >> t;
        rep(i, n) {
                cout << s[i];
                cout << t[i];
        }
        cout << endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>


using namespace std;

int main()
{
    string s,t;

    cin>>s>>t;

    int ctn = 0 ;

    for(int i = 0 ; i < s.size() ; ++i)
        if(s[i] != t[i])
            ++ctn;

    cout<<ctn;


}


Measured memory_bytes: 3840
input_line = input().split()
plus = int(input_line[0])
zero = int(input_line[1])
minus = int(input_line[2])
maisu = int(input_line[3])

if plus >= maisu:
    print(maisu)
elif plus + zero >= maisu:
    print(plus)
else:
    minus_num = maisu - (plus + zero)
    print(plus - minus_num)


Measured memory_bytes: 9024
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

typedef unsigned long long ull;

ull qtde[1000000] = { 0, 0, 1, 2 };

bool isPrime(ull x) {
  ull i = 6;
  ull root = (ull)sqrt(x) + 2;
	if (x <= 1)
		return false;
  if (x == 2 || x == 3)
    return true;
  if (x % 2 == 0 || x % 3 == 0)
    return false;

  while (i <= root) {
    if (x % (i - 1) == 0)
      return false;
    if (x % (i + 1) == 0)
      return false;
    i += 6;
  }

  return true;
}

int main(int argc, char const *argv[]) {
    ull n;
    ull i;
    
    for (int i = 3; i < 1000000; i++)
      qtde[i] = qtde[i-1] + isPrime(i);

    while (cin >> n)
      cout << qtde[n] << endl;

    return 0;
}



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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int dx[2] = {1, 0};
const int dy[2] = {0, 1};
const int INF = 1<<30;
const ll mod = 998244353LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int N,M;
    cin>>N>>M;
    vector<vector<int>> v(M,vector<int>(2));
    map<int,int> m;
    rep(i,N) {
        int x;
        cin>>x;
        m[x]++;
    }
    for(auto x:m){
        v[(x.first)%M][0] += x.second;
        v[(x.first)%M][1] += x.second%2;
    }
    int ans = 0;
    if(M%2==0){
        ans += v[0][0]/2;
        for(int i = 1; i < M/2;i++){
            if(v[i][0]>v[M-i][0]){
                if(v[i][1]>v[M-i][0]){
                    ans += v[M-i][0] + (v[i][0]-v[i][1]) / 2;
                }
                else ans += (v[i][0]+v[M-i][0])/2;
            }
            if(v[i][0]==v[M-i][0]) ans += (v[i][0]+v[M-i][0])/2;
            if(v[i][0]<v[M-i][0]) {
                if(v[i][0]<v[M-i][1]) {
                    ans += v[i][0] + (v[M-i][0]-v[M-i][1]) / 2;
                }
                else ans += (v[i][0]+v[M-i][0])/2;
            }
        }
        ans += v[M/2][0]/2;
    }
    else {
        ans += v[0][0]/2;
        for(int i = 1; i <= M/2;i++){
            if(v[i][0]>v[M-i][0]){
                if(v[i][1]>v[M-i][0]){
                    ans += v[M-i][0] + (v[i][0]-v[i][1]) / 2;
                }
                else ans += (v[i][0]+v[M-i][0])/2;
            }
            if(v[i][0]==v[M-i][0]) ans += (v[i][0]+v[M-i][0])/2;
            if(v[i][0]<v[M-i][0]) {
                if(v[i][0]<v[M-i][1]) {
                    ans += v[i][0] + (v[M-i][0]-v[M-i][1]) / 2;
                }
                else ans += (v[i][0]+v[M-i][0])/2;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 13436
import math
n = int(input())
a = list(map(int,input().split()))

a = sorted(a, reverse = True)
mid = a[0]//2
diff = abs(mid - a[0])

if n == 2:
    print(max(a[0],a[1]),min(a[0],a[1]))
else:
    for i in range(n):
        if abs(a[i] - mid) < diff:
            diff = abs(a[i] - mid)
            ans = i
    print(a[0], a[ans])

Measured memory_bytes: 14180
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int a[2000005],t[200005];

int n,k,ans=0;

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		t[a[i]]++;
	}
	sort(t+1,t+2+n);
	for(int i=1;i<=n-k+1;i++){
		ans+=t[i];
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	lint N, K;
	cin >> N >> K;

	vector<lint> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	// 2進法で表したときの各桁について注目する。（0の数が過半数ならmaxXのその桁は1となる。）
	// Kと比較してKのi桁目が1ならmaxXも1にできる。
	// (flag)上の桁から見ていってKが1なのにmaxXは0となる場合その先maxXはKによらず1,0を決めれる。
	lint one, maxX = 0;
	bool flag = false;
	for (int i = 39; i >= 0; i--) {

		// N個の入力のi桁目の1の数を数える
		one = 0;
		for (int j = 0; j < N; j++) if ((1LL << i) & A[j]) one++;

		// flagがtrueまたはKのi桁目が1 でかつ0が過半数ならmaxXのi桁目を1にする。
		if ((flag || (K & (1LL << i))) && one - N / 2 <= 0) maxX ^= (1LL << i);

		// Kが1でmaxXが0となるならそれ以降は必ずK>maxXが成立するのでflag=trueにしてmaxXの1,0は自由に決めれる。
		if (!flag && (K & (1LL << i)) && one - N / 2 > 0) flag = true;

	}

	lint ans = 0;
	for (int i = 0; i < N; i++) ans += A[i] ^ maxX;

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024