akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  double ave = accumulate(a.begin(), a.end(), 0.0) / a.size();
  double temp = 1111111111111;
  int ans = a.size() - 1;
  for (int i = N - 1; 0 <= i; i--) {
    if (abs(ave - a[i]) <= temp) {
      temp = abs(ave - a[i]);
      ans = i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    ll a, b, c; cin >> a >> b >> c;
    string ans = "bust";
    if(a + b + c <= 21) ans = "win";
    cout << ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 256
N, x = map(int, input().split())
if N == 2:
    if x == 2:
        print("Yes")
        for i in range(1,4):
            print(i)
    else:
        print("No")
    exit()
if 1 < x < 2*N-1:
    print("Yes")
    if x == 2:
        E = [3, 1, 2, 4]
    else:
        E = [x-1, x+1, x, x-2]
    P = [i for i in list(range(1, N*2)) if i not in E]
    P = P[:N-3] + E + P[N-3:]
    for p in P:
        print(p)
else:
    print("No")


Measured memory_bytes: 14716
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int a[100005],b[100005],c[100005],s[200005];
int main(){
	 long long sum=0;
	 int X,Y,A,B,C,i,j=1;
	 cin>>X>>Y>>A>>B>>C;
	 for(i=1;i<=A;i++)
	 cin>>a[i];
     for(i=1;i<=B;i++)
	 cin>>b[i];
	 for(i=1;i<=C;i++)
	 cin>>c[i];
	 sort(a+1,a+1+A);
	 sort(b+1,b+1+B);
	 sort(c+1,c+1+C);
	 
	 for(i=A;i>=A-X+1;i--)
	 s[j++]=a[i];
	 for(i=B;i>=B-Y+1;i--)
	 s[j++]=b[i];
	 j--;
	 sort(s+1,s+1+j);
	 j=1;
	 for(i=C;i>=1;i--)
	 if(c[i]>s[j]) s[j++]=c[i];
	 for(i=1;i<=X+Y;i++)
	 sum+=s[i];
	 cout<<sum<<endl;
	 return 0;
}

Measured memory_bytes: 2176
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int c=0;
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=in.nextInt();
			if(arr[i]%2==0 && c==0)
			{
				if(arr[i]%3!=0 && arr[i]%5!=0)
				{
					System.out.println("DENIED");
					c=1;
				}
			}
		}
		if(c==0)
		{
		System.out.println("APPROVED");
		}
	}
}

Measured memory_bytes: 23508
#include <iostream>
using namespace std;
typedef long long ll;

ll n;
ll a[200005];
ll b[200005];

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

    for (int i = n; i >= 1; i--) {
        int sum = 0;
        
        for (int j = i + i; j <= n; j += i) {
            sum += b[j];
        }

        if (sum % 2 != a[i]) {
            b[i] = 1;
        }
    }

    ll m = 0;
    for (int i = 1; i <= n; i++) {
        m += b[i];
    }

    int f = 0;
    cout << m << endl;
    for (int i = 1; i <= n; i++) {
        if (b[i]) {
            if (f) {
                cout << ' ';
            }
            cout << i;
            f = 1;
        }
    }
    if (f) {
        cout << endl;
    }

    return 0;
}


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

void insertion_sort(vector<int> &a, int g, int &cnt) {
    int n = a.size();
    for (int i = g; i > 0; i--) {
        for (int j = g-i; j < n; j += g) {
            // bool flag = false;
            for (int k = j; k-g >= 0; k -= g) {
                if (a[k] < a[k-g]) {
                    swap(a[k], a[k-g]);
                    cnt++;
                    // flag = true;
                } else break;
            }
            // if (flag) cnt++;
        }
    }
}

void shell_sort(vector<int> &a, int &cnt) {
    int n = a.size();
    vector<int> g;
    int h = 1;
    g.push_back(h);
    while (3 * h + 1 < n) {
        h = 3 * h + 1;
        g.push_back(h);
    }
    printf("%d\n", g.size());
    for (int i = g.size()-1; i >= 0; i--) {
        printf("%d", g[i]);
        if (i != 0) printf(" ");
        else printf("\n");
        insertion_sort(a, g[i], cnt);
    }
}

int main() {
    // int n = 1000;
    // vector<int> a(n);
    // rep(i, n) {
    //     a[i] = rand() % 100;
    // }
    // vector<int> a = {5,1,4,3,2};
    // int n = a.size();
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    rep(i, n) {
        scanf("%d", &a[i]);
    }

    int cnt = 0;

    shell_sort(a, cnt);

    printf("%d\n", cnt);
    rep(i, n) {
        printf("%d\n", a[i]);
    }
}


Measured memory_bytes: 6732
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int dp[200010];
vector<int> T[200010];
int a[200010];
int ans[200010];
int N; 
void dfs(int x = 0, int p = -1) {
    auto itr = lower_bound(dp, dp + N, a[x]);
    int prev = *lower_bound(dp, dp + N, a[x]);
    *lower_bound(dp, dp + N, a[x]) = a[x];
    ans[x] = lower_bound(dp, dp + N, INF) - dp;
    for(auto to: T[x]) {
        if(to == p) continue;
        dfs(to, x);
    }
    *itr = prev;
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) cin >> a[i];
    rep(i, N - 1) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        T[u].push_back(v);
        T[v].push_back(u);
    }
    rep(i, N) dp[i] = INF;
    dfs(0);
    rep(i, N) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 28260
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int main(){
    int n;
    cin >> n;
    ll ans = 1;
    for(int i=0;i<n;i++){
        ll z;
        cin >>z;
        ans = lcm(ans,z);
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
###
### atcorder test program
###

### math class
class math:
    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)


### input num
#i = input()
#A, B, T = [int(x) for x in i.split()]
#N = int(input())
#A = [int(x) for x in input().split()]

temp = 1
inputlist = []
while True:
    temp = input()
    if temp == "0":
        break
    inputlist.append(temp)

### input debug
#print("debug:{}".format(gcd(max(A),min(A))))

### output
#print(inputlist)
for i, num in enumerate(inputlist):
    print("Case {}: ".format(i+1)+num)



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

long long gcd(long long a, long long b) {
    if(b == 0) return a;
    if(a < b) {
        return gcd(b, a);
    } else {
        return gcd(b, a % b);
    }
}

long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b / gcd(a, b) * gcd(a, b);
}

int main(int argc, char const *argv[]) {
    long long A, B, C, D;
    cin >> A >> B >> C >> D;
    long long ans = B - A + 1 - B / C + (A - 1) / C - B / D + (A - 1) / D + B / lcm(C, D) - (A - 1) / lcm(C, D);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[3][101],f[3][101],maxn,h;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
			scanf("%d",&a[i][j]);
	for(int i=1;i<=n;i++)
	{
		f[1][i]=f[1][i-1]+a[1][i];
		f[2][i]=f[2][i-1]+a[2][i];
		h+=a[2][i];
	}
	for(int i=1;i<=n;i++)
		maxn=max(maxn,f[1][i]+h-f[2][i-1]);
	printf("%d",maxn);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String args[]) throws IOException{
        BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
        String str=bfr.readLine();
        String[] matome=str.split(" ");

        double a=Double.parseDouble(matome[0]);
        double b=Double.parseDouble(matome[1]);

        System.out.println(a*b/3.305785);
    }
}


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

int main(void) {
  int A, B;
  cin >> A >> B;
  
  if(A+B == 3) cout << 3 << endl;
  else if(A+B == 4) cout << 2 << endl;
  else cout << 1 << endl;
  
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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 namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(void){

  ll n,k;
  string s;
  
  cin >> n;
  cin >> k;
  cin >> s;

  //cout << n << endl;
  //cout << k << endl;


  s[k-1]=s[k-1]+32;
  //cout << s[0] << endl;
  //cout << s[1] << endl;
  //cout << s[2] << endl;

  cout << s << endl;

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int r){
    stack<int> S;

    S.push(r);
    color[r] = GRAY;
    d[r] = ++tt;

    while(!S.empty()){
        int u = S.top();
        int v = -1;
        for (int j = 0; j < n; ++j){
            if(M[u][j] == 1 && color[j] == WHITE) {
                v = j;
                break;
            }
        }
        if (v != -1){
            S.push(v);
            color[v] = GRAY;
            d[v] = ++tt;
        } else {
            color[u] = BLACK;
            f[u] = ++tt;
            S.pop();
        }
    }
}

void dfs(){
    int u;
    // initialization
    for( u = 0; u < n; ++u) color[u] = WHITE;
    tt = 0;

    for( u = 0; u < n; ++u){
        if (color[u] == WHITE) dfs_visit(u);
    }

    for( u = 0; u < n; ++u){
        printf("%d %d %d\n", u+1, d[u], f[u]);
    }
}

int main()
{
    int u, v, k, i, j;
    scanf("%d", &n);

    for (i = 0; i < n; ++i){
        for(j = 0; j < n; ++j){
            M[i][j] = 0;
        }
    }

    for (i = 0; i < n; ++i){
        scanf("%d %d", &u, &k);
        --u;
        for (j = 0; j < k; ++j){
            scanf("%d", &v);
            --v;
            M[u][v] = 1;
        }
    }

    dfs();
    
    return 0;
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;

// 1e5 < (1<<17), 1e6 < (1<<20)
const int NMAX=(1<<20);

// [1,N]
int bit[NMAX+1], N;
ll K;
ll A[202020];

int SUM(int i){
  int s=0;
  while(i>0){
    s+=bit[i];
    i-=i&-i;
  }
  return s;
}

void ADD(int i,int x){
  while(i<=NMAX){
    bit[i]+=x;
    i+=i&-i;
  }
}

int lowerBound(int w){
  if(w<=0) return 0;
  int x=0;
  for(int k=NMAX;k>0;k/=2){
    if(x+k<=NMAX && bit[x+k]<w){
      w-=bit[x+k];
      x+=k;
    }
  }
  return (x+1);
}

ll sum[202020];

int main(){
  cin>>N>>K;
  map<ll,int> mp1,mp2;
  mp1[0]++;
  rep(i,N){
    cin>>A[i]; A[i]-=K;
    sum[i+1]=sum[i]+A[i];
    mp1[sum[i+1]]++;
  }
  int cnt=1;
  for(auto m:mp1){
    mp2[m.first]=cnt;
    cnt++;
  }
  ll ans=0;
  rep(i,N+1){
    int x=mp2[sum[i]];
    ans+=SUM(x);
    ADD(x,1);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 31360
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<time.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<fstream> 
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 
 using namespace std;
 
 int arr[8];
 int term[8];
 int used[8]={false};
 long long int dp[200+5][200+5];
 int n,m,r;
 long long int result=999999999;
 long long int result2;
 
 void dfs(int cnt)
 {
   if(cnt==r)
   {
     result2=0;
     for(int i=0;i<(r-1);i++)
     {
       result2+=dp[term[i]][term[i+1]];   
     }            
     if(result2<result) result=result2;
     return;
   }
   else
   {
     for(int i=0;i<r;i++)
     {
       if(!used[i])
       {
         used[i]=true;
         term[cnt]=(arr[i]-1);
         dfs(cnt+1);
         used[i]=false;            
       }
     }
     return;            
   }          
 }

 int main()
 {
   while(cin>>n>>m>>r)
   {
     int x,y,z;
     for(int i=0;i<r;i++) cin>>arr[i];
     for(int i=0;i<n;i++) 
       for(int j=0;j<n;j++)
       {
         if(i==j) dp[i][j]=0;
         else dp[i][j]=999999999;        
       }
     for(int i=0;i<m;i++)
     {
       cin>>x>>y>>z;
       dp[x-1][y-1]=z;
       dp[y-1][x-1]=z;      
     }    
     for(int k=0;k<n;k++)
       for(int i=0;i<n;i++)
         for(int j=0;j<n;j++)
           { 
             if(dp[i][j]>(dp[i][k]+dp[k][j])) dp[i][j]=(dp[i][k]+dp[k][j]);
             if(dp[j][i]>(dp[j][k]+dp[k][i])) dp[j][i]=(dp[j][k]+dp[k][i]);
           }
           /*
      for(int i=0;i<n;i++)
      {
        cout<<endl;
        for(int j=0;j<n;j++)
        {
          cout<<dp[i][j]<<" ";        
        }
      }
      */
      dfs(0);
      cout<<result<<endl; 
   }
   return 0;    
 }
 
 
 
 
 

Measured memory_bytes: 512
#include<iostream>
using namespace std;
#define RENT 100000
int main(){
    int n;
    while(cin>>n){
        int ans=0;
        for(int a=0;a<10;a++){
            for(int b=0;b<10;b++){
                for(int c=0;c<10;c++){
                    for(int d=0;d<10;d++){
                        if(a+b+c+d==n)ans++;
                    }
                }
            }
        }
         
        cout<<ans<<endl;
    }
}
 

Measured memory_bytes: 3100
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;


int main() {

  string s;cin>>s;
  int n=s.size();
  int k=1;
  bool e=false;int c;
  string t,p;
  rep(i,0,n){
    if(e){i=c;t=p;e=false;}
    else t+=s[i];
    p="";
    rep(j,i+1,n){
      p+=s[j];
      if(t==p)continue;
      else {k++;e=true;c=j;break;}
    }
  }
  out(k);


  return 0;
}


Measured memory_bytes: 1152
#include<stdio.h>
#define MAX 100
#define INFTY 100000
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n,M[MAX][MAX];

int prim(){
  int u,minv,i,v,sum=0;
  int d[MAX],p[MAX],color[MAX];
  for(i=0;i<n;i++){
    d[i]=INFTY;
    p[i]=-1;
    color[i]=WHITE;
  }
  d[0]=0;
  while(1){
    minv=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(minv>d[i]&&color[i]!=BLACK){
	u=i;
	minv=d[i];
      }
    }
    if(u==-1){
      break;
    }
    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(color[v]!=BLACK && M[u][v] != INFTY){
	if(d[v] >M[u][v]){
	  d[v]=M[u][v];
	  p[v]=u;
	  color[v]=GRAY;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    if(p[i]!=-1){
      sum+=M[i][p[i]];
    }
  }
  return sum;
}

int main(){
  int i,j,e;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&e);
      M[i][j]=(e==-1)?INFTY : e;
    }
  }
  printf("%d\n",prim());
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, l;
    cin >> n >> l;
    string s[n], k;
    for (int i = 0; i < n; ++i)
        cin >> s[i];
    sort(s, s + n);
    for (int i = 0; i < n; ++i)
        k += s[i];
    cout << k;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
using namespace std;
#define vel vector<long long>
#define vvel vector<vel>
#define int long long
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
long long p = 998244353;
vel kai(4001, 1);
vel ink(4001, 1);
vel uni(vel &list) {
	if (list.size() == 0) { return list; }
	sort(list.begin(), list.end());
	vel ql(1, list[0]);
	rep(i, list.size() - 1) {
		if (list[i] != list[i + 1]) { ql.push_back(list[i + 1]); }
	}
	return ql;
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, 4000) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, 4001) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
int dig(int n, int b) {
	int ans = 0;
	while (n > 0) {
		ans += n % b; n = n / b;
	}
	return ans;
}
signed main() {
	int n, s; cin >> n >> s;
	int dif = n - s;
	if (dif == 0) {
		cout << n + 1 << endl; return 0;
	}
	else if (dif < 0) { cout << -1 << endl; return 0; }
	else {
		vel ans(0);
		for (int i = 1; i*i <= dif; i++) {
			if (dif%i == 0) {
				int mi = i;
				if (dig(n, mi + 1) == s) { ans.push_back(mi + 1); }
				mi = dif / mi;
				if (dig(n, mi + 1) == s) { ans.push_back(mi + 1); }
			}
		}
		sor(ans);
		if (ans.size() > 0) { cout << ans[0] << endl; }
		else { cout << -1 << endl; }
	}
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	lint N;
	cin >> N;
	vector<lint> vec(N);
	REP(i, N) {
		cin >> vec[i];
	}
	sort(ALL(vec));
	lint sum = 0;
	if (N % 2 == 0) {
		REP(i, N / 2 - 1) {
			sum += (vec[N - i - 1] * 2);
			sum -= (vec[i] * 2);
		}
		sum += vec[N / 2];
		sum -= vec[N / 2 - 1];
	}
	else {
		lint sum1 = 0, sum2 = 0;
		REP(i, N / 2 - 1) {
			sum1 += (vec[N - i - 1] * 2);
			sum1 -= (vec[i] * 2);
		}
		sum1 += (vec[N / 2 + 1] * 2);
		sum1 -= (vec[N / 2] + vec[N / 2 - 1]);
		REP(i, N / 2 - 1) {
			sum2 += (vec[N - i - 1] * 2);
			sum2 -= (vec[i] * 2);
		}
		sum2 -= (vec[N / 2 - 1] * 2);
		sum2 += (vec[N / 2] + vec[N / 2 + 1]);
		sum = max(sum1, sum2);
	}
	cout << sum << endl;
}


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

using namespace std;

typedef long long ll;


void solve()
{
	ll n,r;
	cin>>n>>r;
	if(n>=10)
		cout<<r<<endl;
	else
	{
		ll x=r+100*(10-n);
		cout<<x<<endl;
	}
	return;
}
int main()
{
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> p;
    int e;
    int ans=0;
    for(int i=0;i<N;i++){
        cin >> e;
        ans+=e;
        p.push_back(e);
    }
    sort(p.rbegin(),p.rend());
    cout << ans-p[0]/2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
/*??????????????????????????¨?????????????????¨?????????*/
typedef struct{
	long long int prev;//?????¨????????????????????????????????????????´?
	long long int next;//?????¨??????????????????????¬?????????????????´?
	long long int data;
} list;

list L[2000000];

long long int ff = -1,bb = -1;//ff:???????????????????????´??? bb:????????????????°??????´???
long long int num = 0,usecnt = -1; //num:????????????????´???° usecnt:????????????????????§?????¨?????????

int main(){
	int i,j,k;
	long long int n;
	scanf("%lld",&n);
	for(i=0; i<n; i++){
		char op[20];
		scanf("%s",op);
		if(strcmp(op,"insert")==0){
			long long int p;
			scanf("%lld",&p);

			if(num==0){
				// L[usecnt+1]??????????????¨??§??°????????´???????????????????????????
				L[usecnt+1].data = p; 
				/*?????????????°????usecnt+1*/
				ff = usecnt+1;
				bb = usecnt+1;
				usecnt++;
				num++;
			}else{
				L[usecnt+1].data = p;
				L[usecnt+1].next = ff; /*??°??????????´?????¬????????´????????????§???????????£?????´???*/
				L[ff].prev = usecnt+1; /*????????§???????????£?????¨?????????????????°??????????????£???????´?*/
				ff = usecnt+1; /*???????????°?????????????????´??°*/
				usecnt++;
				num++;
			}
		}else if(strcmp(op,"delete")==0){
			long long int p;
			scanf("%lld",&p);
			long long int nowcnt = 0; /*??????????´????????????????*/
			long long int nowpos = ff; /*?????¨?????????*/
			long long int tg = L[nowpos].data; /*????±?*/
			while(nowcnt<num){
				if(tg==p){ /*???????????£??????*/
					if(nowcnt==0){
						ff = L[ff].next; /*?????????????????§?????????????¬????????´??????????*/
						num--;
					}else if(nowcnt==num-1){ /*?????????????°????????´?????????????????´??????????*/
						bb = L[bb].prev;
						num--;
					}else{
						/*A -> B -> C?????? A -> C????????????*/
						L[L[nowpos].prev].next = L[nowpos].next;
						L[L[nowpos].next].prev = L[nowpos].prev;
						num--;
					}
					//L[nowpos]?????????????????§????????????????????§?????????????????????????????¢????????¨???????????????????????¢????§£???
					break;
				}
				nowcnt++;
				/*?????????????±???¨????????????????????´??°*/
				tg = L[L[nowpos].next].data;
				nowpos = L[nowpos].next;
			}
		}else if(strcmp(op,"deleteFirst")==0){ /*??????delete???nowcnt==0?????¨?????¨??????*/
			ff = L[ff].next;
			num--;
		}else if(strcmp(op,"deleteLast")==0){ /*??????delete???nowcnt==num-1?????¨?????¨??????*/
			bb = L[bb].prev;
			num--;
		}
		/*long long  int pos = ff;
		while(pos!=bb){
			printf("%lld ",L[pos].data);
			pos = L[pos].next;
		}
		printf("%lld\n",L[pos].data);
		printf("\n");*/
	}

	//?????????????????????????????£????????£?????????*/
	long long  int pos = ff;
	while(pos!=bb){
		printf("%lld ",L[pos].data);
		pos = L[pos].next;
	}
	printf("%lld\n",L[pos].data);
	
	return 0;
}

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

int main(){
  int n;
  cin >> n;

  int l,sum=0,max=0;
  rep(i,n){
    cin >> l;
    sum += l;
    if(l>max) max=l;
  }

  if(max < (sum-max)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/







int A, B;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> A >> B;

    int d = B - A;
    int ans = d * (d + 1) / 2 - B;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

ll f(ll x,ll c,ll d){
    ll res =x;
    res -=x/c;
    res -=x/d;
    res+= x/lcm(c,d);
    return res;
}

int main(){
   ll h,w,k;
   cin>>h>>w>>k;
   vector<string>s(h);
   rep(i,h){
       cin>>s[i];
   }
   ll ans=0;
   for(ll i=0;i<(1<<h);i++){
       for(ll j=0;j<(1<<w);j++){
           ll cnt=0;
           for(ll is=0;is<h;is++){
               for(ll js=0;js<w;js++){
                   if(i>>is&1)continue;
                   if(j>>js&1)continue;
                   if(s[is][js]=='#')cnt++;
               }
           }
           if(cnt==k)ans++;
       }
   }
   cout<<ans<<endl;
}


Measured memory_bytes: 3624
import sys
input = sys.stdin.readline
from bisect import bisect_left

def main():
    n=int(input())
    xy=[list(map(int,input().split())) for _ in range(n)]
    ans=0
    for i in range(n-1):
        for j in range(i+1,n):
            ans+=((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**0.5
    ans/=n/2
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef vector <ll> vi;                 // Vector of long long
typedef vector <vi> vvi;                // Vector of vi
typedef vector <pair<ll,ll>> ii;        // Vector of pairs
#define ff first                        // For pairs
#define ss second                       // For pairs
#define sz(a) int((a).size())           // Function to determine size of any container
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree < ll ,  null_type ,  less<ll> ,  rb_tree_tag ,  tree_order_statistics_node_update >

int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, a, b;
    cin >> n >> a >> b;
    
    if (!((b - a) & 1LL))
        cout << (b - a) / 2LL << "\n";
    else
    {
        if (a - 1 < n - b)
            cout << ((b - a - 1) / 2) + a << "\n";
        else
            cout << ((b - a - 1) / 2) + (n - b + 1) << "\n";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  int a=S.size();
  if(S.at(a-1)=='s'){
    S.push_back('e');
  S.push_back('s');
  }
  else
    S.push_back('s');
  cout<<S<<endl;
}
    

Measured memory_bytes: 3628
#pragma GCC optimize ("Ofast","unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define F first
#define S second
#define MEM(a,b) memset(a,b,sizeof a)
#define Tie ios::sync_with_stdio(0),cin.tie(0);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll dp[3001][3001],x,y;
string a,b,s;

int main()
{Tie
	cin>>a>>b;
	for(int i=1;i<=a.size();i++)
		for(int j=1;j<=b.size();j++)
		{
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			if(a[i-1]==b[j-1])
				dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
		}
	x=a.size(),y=b.size();
	while(x!=0&&y!=0)
	{
		if(a[x-1]==b[y-1])
			s=a[x-1]+s,x--,y--;
		else if(dp[x][y]==dp[x-1][y])
			x--;
		else
			y--;
	}
	cout<<s << '\n';
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void vprn(vector<int> &v){ for(int i=0;i<v.size();i++) cout<<v[i]<<(i<v.size()-1?",\t":"\n"); }


ll solve(int N, vi &P){
	// vprn(P);//
	ll ans = 0;
	rp(i,1,N){
		if(P[i-1]-1==i-1){//L=X
			swap(P[i-1], P[i]);
			ans += 1;
			i++;
			// if(P[i]==i){//LR=XX
			// 	swap(P[i-1], P[i]);
			// 	ans += 1;
			// }
		}
	}
	// i=N の処理
	if(P[N-1]-1==N-1){
		swap(P[N-1],P[N-2]);
		ans += 1;
	}
	return ans;
}

int main(){
	int N; cin>>N;
	vi P(N);
	rp(i, 0, N) cin>>P[i];
	ote(solve(N, P));
}


Measured memory_bytes: 640
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
//#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (X == 0) {
		*di++ = '0';
		*di++ = '\n';
		return;
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

int N, M;
int K[100001];
int to[200001], ne[200001], he[100001], num[200001];
int dame[100001];
vector<int> S1[100001], S2[100001];

int dfs(int v, int prev) {
	if (dame[v]) {
		if (dame[v] >= 2) {
			ll tmp = dfs(to[dame[v]], dame[v] ^ 1);
			int k = K[v] - num[dame[v]];
			for (int i = k - 1; i < K[v]; i++) {
				S1[v][i] = S1[v][i] * tmp % M;
			}
			S2[v][k - 1] = tmp;
			tmp = S2[v][K[v] - 1];
			for (int i = K[v] - 2; i >= 0; i--) {
				tmp = tmp * S2[v][i] % M;
				S2[v][i] = tmp;
			}
			dame[v] = -1;
		}

		ll ret = 1;
		if (prev >= 2) {
			int k = K[v] - num[prev];
			if (k >= 2) ret *= S1[v][k - 2];
			if (k < K[v]) ret *= S2[v][k];
			ret %= M;
		}
		else ret = S1[v].back();

		return ret + 1;
	}
	dame[v] = prev;
	ll ret = 1;
	int k = 0;
	for (int i = he[v]; i; i = ne[i]) {
		int tmp = 1;
		if (i != prev) {
			tmp = dfs(to[i], i ^ 1);
			ret = ret * tmp % M;
		}
		S1[v][k] = ret;
		S2[v][k++] = tmp;
	}
	if (prev == -1) {
		ll tmp2 = S2[v][K[v] - 1];
		for (int i = k - 2; i >= 0; i--) {
			tmp2 = tmp2 * S2[v][i] % M;
			S2[v][i] = tmp2;
		}
	}
	return ret + 1;
}

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


	N = getint();
	M = getint();

	int k = 2;
	rep1(i, N - 1) {
		int x = getint(), y = getint();

		num[k] = K[x]++;
		to[k] = y;
		ne[k] = he[x];
		he[x] = k++;
		num[k] = K[y]++;
		to[k] = x;
		ne[k] = he[y];
		he[y] = k++;
	}
	rep1(i, N) {
		S1[i].resize(K[i]);
		S2[i].resize(K[i]);
	}

	rep1(j, N) putint(dfs(j, -1) - 1);

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 22272
//सत्यान्न प्रमदितव्यम्  ||

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
// #define mp make_pair
#define nt _int128
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define inf 0x3f3f3f3f

const ll mod = 1000000007;
#define mx 1000005
const ll mxi = 4e4+5;
// ll ar[mx][mx] = {0};

int main()
{
    fast_as_levi;
    ll n,m,i;
    cin>>n>>m;
    if(n<m)
    {
        for(i=0;i<m;i++)
        {
            cout<<n;
        }
    }
    else
    for(i=0;i<n;i++)
    cout<<m;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;
using namespace atcoder;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << "\n"

void solve(){
    ll N,Q;
    cin >> N >> Q;
    dsu d(N+1);
    while(Q--){
        ll t,u,v;
        cin >> t >> u >> v;
        if(t == 0){
            d.merge(u,v);
        }else{
            print(d.same(u,v));
        }
    }



}

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

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

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d) {
		cout << "Left" << endl;
	}
	else if (a + b == c + d) {
		cout << "Balanced" << endl;
	}
	else {
		cout << "Right" << endl;
	}
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, N):
        self.N = N
        self.parents = [-1] * N

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def roots(self):
        return (i for i, x in enumerate(self.parents) if x < 0)

    def group_count(self):
        return len(list(self.roots()))

N,M=map(int, input().split())
XYZ=[tuple(map(int, input().split())) for _ in range(M)]
UF=UnionFind(N)
for x,y,_ in XYZ:
    UF.union(x-1,y-1)
print(UF.group_count())

Measured memory_bytes: 22140
#include <iostream>
using namespace std;
int main() {
    string s;
    getline(cin,s);
    bool flag = true;
    for(int i=0;i<s.size();i++){
        if(i%2==0&&(s[i]!='R'&&s[i]!='U'&&s[i]!='D'))
        flag = false;
        else if(i%2==1 && (s[i]!='L'&&s[i]!='U'&&s[i]!='D'))
        flag = false;
    }
    if(flag)cout<<"Yes"<<endl;
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        int[] list = new int[n + 1];
        int id = -1;
        int top = Integer.MIN_VALUE;
        for (int i = 0; i < q; i++) {
            int a = sc.nextInt();
            int v = sc.nextInt();

            list[a] += v;
            if (id == a) {
                top += v;
            }
            if (v < 0 && id == a) {
                for (int j = 1; j < n + 1; j++) {
                    if (list[j] > top || list[j] == top && j < id) {
                        top = list[j];
                        id = j;
                    }
                }
            }
            if (v > 0 && id != a && (list[a] > top || list[a] == top && a < id)) {
                top = list[a];
                id = a;
            }
            System.out.println(id + " " + top);
        }
    }

}


Measured memory_bytes: 107280
#include<stdio.h>
#include<stdlib.h>
 
int partition(int *, int, int);
 
int main(){
 
  int n,r,i,*A,p;
 
  scanf("%d",&n);
 
  A = malloc(sizeof(int)*n); 
 
  for(i = 0 ; i < n ; i++)
    scanf("%d",&A[i]);
 
  p = partition(A, 0, n-1);
 
  for(i = 0 ; i < n ; i++){
    if(i == p) printf("[%d] ",A[i]);
    else if(i == n-1) printf("%d\n",A[i]);
    else printf("%d ",A[i]);
  }
 
  return 0;
 
}
 
 
int partition(int *A, int p, int r){
 
  int x,i,j,tmp;
 
  x = A[r];
  i = p;
 
  for(j = p ; j <= r-1 ; j++){
    if(A[j] <= x){
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
      i++;
    }
  }
    tmp = A[i];
    A[i] = A[r];
    A[r] = tmp;
 
    return i;
 
}

Measured memory_bytes: 992
// abc159_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;

    int ans = N * (N-1) / 2 + M * (M-1) /2;
    print(ans);


    return 0;
}


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

int main(){
    int N;
    cin >>N;
    int i,tmp,W[100];
    for(i=0;i<N;i++){
        cin>>tmp;
        W[i]=tmp;
    }
    int j,min=999999;
    for(i=0;i<N;i++){
        int t = i,S1=0,S2=0,gap;
        for(j=0;j<=t;j++){
            S1 += W[j];
        }
        for(j=t+1;j<N;j++){
            S2 += W[j];
        }
        if(S1<=S2){
            gap = S2-S1;
        }
        else{
            gap = S1-S2;
        }

        if(gap<min){
            min=gap;
        }
    }
    cout<<min;
    return 0;
}

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

ll a, b, c, k;

void solve() {
    cin >> a >> b >> c >> k;
    int res = a - b;
    if(k & 1) cout << -res << "\n";
    else cout << res << "\n";
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    solve();

}

Measured memory_bytes: 3640
s = input()
t = input()

ans = len(t)
for i in range(len(s) - len(t) + 1):
    tmp = s[i:i+len(t)]
    count = 0
    for t1, t2 in zip(tmp, t):
        if t1 != t2:
            count += 1
    ans = min(ans, count)
print(ans)


Measured memory_bytes: 9080
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"
int main() {
	while (1) {

		int N; cin >> N;
		if (!N)break;
		vector<int>ps(N);
		for (int i = 0; i < N; ++i) {
			cin >> ps[i];
		}
		vector < vector<pair<int, int>>>dp(N + 1, vector<pair<int, int>>(50000,make_pair(-1000,0)));
		dp[0][0] = make_pair(0, 0);
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < 49500; ++j) {
				const int nc = dp[i][j].first;
				const int nmoney = -dp[i][j].second;
				dp[i + 1][j] = max(dp[i + 1][j], make_pair(nc, -nmoney));
				const int price = ps[i];
				const int amari = price % 1000;
				if (amari == 0) {
					int nextmoney = j;
					int plusc = 0;
					if (nextmoney >= 500) {
						plusc++;
						nextmoney -= 500;;
					}
					dp[i + 1][nextmoney] = max(dp[i + 1][nextmoney], make_pair(nc + plusc, -nmoney - price));

				}else
				if (amari <= 500) {
					int nextmoney = j + 500 - amari;
					int plusc = 1;
					
					dp[i + 1][nextmoney] = max(dp[i + 1][nextmoney], make_pair(nc + plusc, -nmoney-price));
				}
				else {
					int nextmoney =j + 1000 - amari;
					int plusc = 0;
					if (nextmoney >= 500) {
						plusc++;
						nextmoney -= 500;;
					}
					dp[i + 1][nextmoney] = max(dp[i + 1][nextmoney], make_pair(nc + plusc, -nmoney - price));
				}
			}
		}
		pair<int, int>ans = make_pair(0, 0);
		for (int i = 0; i < 50000; ++i) {
			ans = max(ans, dp[N][i]);
		}
		cout << ans.first << " " << -ans.second << endl;
	}
	return 0;
}

Measured memory_bytes: 42672
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int h,w;
    string s[52],ans="Yes";
    cin>>h>>w;
    s[0]=s[h+1]="....................................................";
    for(int i=1;i<=h;i++){
        cin>>s[i];
        s[i]="."+s[i]+".";
    }
    
    
    
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(s[i][j]=='#'&&s[i][j+1]=='.'&&s[i][j-1]=='.'&&s[i+1][j]=='.'&&s[i-1][j]=='.'){
                ans="No";
                i=j=51;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<vector>

using namespace std;

static const int MAX_N = 100;

int main() {
    int A, B, C, X;
    int n500, n100, n50;

    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;

    int tmp;
    int ans = 0;

    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k = 0; k <= C; k++) {
                tmp = i * 500 + j * 100 + k * 50;
                if (tmp == X) ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int  long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000000007
#define mod2 998244353

int fexp(int a, int b){int ans = 1;while(b){if(b&1) ans = ans*a%mod2; b/=2;a=a*a%mod2;}return ans;}
int inverse(int a, int p){return fexp(a, p-2);}


void solve(){
	int n;cin>>n;
	int h=(n/500)*1000;
	n=n%500;
	h=h+(n/5)*5;
	cout<<h;
	return;
} 
signed main(){
	// int n;  cin>>n;  rep(i,0,n){solve();cout<<endl;}
	solve();
	return 0;
}

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

int main(){
    int n, k; cin >> n >> k;
    string s; cin >> s;
    s[k-1] = s[k-1] - 'A' + 'a';
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
from collections import deque
def bfs(S,H,W,sh,sw):
    black,white=0,0
    d=deque()
    d.append([sh,sw])
    if S[sh][sw]=='#':
        black+=1
    elif S[sh][sw]=='.':
        white+=1
    seen[sh][sw]=1
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    while(len(d)!=0):
        h=d[0][0]
        w=d[0][1]
        d.popleft()
        for dir in range(4):
            nh=h+dx[dir]
            nw=w+dy[dir]
            if(nh>H-1 or nh<0 or nw>W-1 or nw<0):
                continue
            if(seen[nh][nw] or S[nh][nw]==S[h][w]):
                continue
            if S[nh][nw]=='#':
                black+=1
            else:
                white+=1
            seen[nh][nw]=1
            d.append([nh,nw])
    return white,black

H,W=map(int,input().split())
G=[list(input()) for i in range(H)]
seen=[[0]*W for i in range(H)]
ans=0

for i in range(H):
    for j in range(W):
        if not seen[i][j]:
            w,b=bfs(G,H,W,i,j)
            ans+=w*b
print(ans)

Measured memory_bytes: 83512
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int  X,Y,A,B,C;
    cin >> X >> Y >> A >> B >> C;
    vector<int>p(A);
    vector<int>q(B);
    for(int i = 0; i < A; i++) {
        cin >> p[i];
    }
    for(int i = 0; i < B; i++) {
        cin >> q[i];
    }
    sort(p.begin(),p.end());
    sort(q.begin(),q.end());
    vector<int>cnt;
    for(int i = 0; i < X; i++) {
        cnt.push_back(p[A-i-1]);
    }
    for(int i = 0; i < Y; i++) {
        cnt.push_back(q[B-i-1]);
    }
    int ans = 0;
    for(int i = 0; i < C; i++) {
        int r;
        cin >> r; 
        cnt.push_back(r);
    }
    sort(cnt.begin(),cnt.end());
    for(int i = 0; i < X+Y; i++) {
        ans+=cnt[cnt.size()-1-i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 7920
#include<stdio.h>
#include<string.h>
int main(){
	int i;
	char a[100],b[100];
	gets(a);
	gets(b);
	if(strlen(a)>strlen(b))
		printf("GREATER\n");
	else if(strlen(a)<strlen(b))
		printf("LESS\n");
	else if(strlen(a)==strlen(b)){
		for(i=0;i<strlen(a);i++){
			if(a[i]>b[i]){
				printf("GREATER\n");
				return 0;
			}
			else if(a[i]<b[i]){
				printf("LESS\n");
				return 0;
			}
		}
		printf("EQUAL\n");
	}
	return 0;
}

Measured memory_bytes: 128
MOD=1000000007
N=int(input())
A=sorted(list(map(int,input().split())))
m=N%2
if m==1 and A[0]!=0:
  print(0)
else:
  for i in range(N//2):
    if A[2*i+m]==A[2*i+1+m]==2*i+1+m:
      continue
    else:
      print(0)
      exit()
  print(2**(N//2)%MOD)

Measured memory_bytes: 14008
#include<bits/stdc++.h>
 
#define INF 1000000007
#define LINF 1000000000000000007
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;


string s[3];

int main(){
	for(int i = 0; i < 3; i++){
		cin >> s[i];
	}
	
	for(int i = 0; i < 3; i++){
		cout << s[i][0];
	}
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256