akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
    
typedef struct{
    int key;
    int left;
    int right;
} Node;
    
void insert(Node*, int, int);
void print1(Node*, int);
void print2(Node*, int);
    
int main()
{
    char s[10];
    Node *t;
    int m;
    int a;
    int i;
    int cnt=0;   
 
    scanf("%d", &m);
 
    t=(Node*)malloc(sizeof(Node)*m);
    
    for(i=0; i<m; i++)
    {
        scanf("%s", &s);
 
        if(s[0]=='i'){scanf("%d", &a);insert(t, cnt, a);cnt++;}
        if(s[0]=='p')
        {
            if(cnt>0) print1(t, 0);
            printf("\n");
            if(cnt>0) print2(t, 0);
            printf("\n");
        }
    }
        
    return 0;
    
}
    
void print1(Node *t, int p)
{
    if(t[p].left>=0)print1(t, t[p].left);
    printf(" %d", t[p].key);
    if(t[p].right>=0)print1(t, t[p].right);
}
    
void print2(Node *t, int p)
{
    printf(" %d",t[p].key);
    if(t[p].left>=0)print2(t,t[p].left);
    if(t[p].right>=0)print2(t,t[p].right);
}
    
void insert(Node *t, int cnt, int z)
{
    int x=0, y;
    if(cnt<1) x=-1;
    
    t[cnt].key = z;
    t[cnt].left = -1;
    t[cnt].right= -1;
    
    while(x>=0){
        y = x; 
        if(z < t[x].key)
            x = t[x].left; 
        else
            x = t[x].right; 
    }
    
    if(cnt<1){}
    else if(z < t[y].key)
    {
        t[y].left = cnt; 
    }
    else {
        t[y].right = cnt;
    }
}

Measured memory_bytes: 7568
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,count=0;
    cin>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        b[i]=a[i];
    }
    sort(b,b+n);
    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i])
        {
            count++;
        }
    }
    if(count==2 || count==0)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define in_range(x,l,r) (l<=x && x<r)
using namespace std;
typedef vector<int> vi;

int main(){
  int t;
  cin >> t;
  while(t--){
    int n,k;
    cin >> n >> k;
    vi x(n);
    rep(i,n)cin >> x[i];

    if(n<=k)cout << 0 << endl;
    else{
      vi dif(n-1);
      rep(i,n-1)dif[i] = x[i+1]-x[i];
      sort(dif.begin(),dif.end());
      
      cout << accumulate(dif.begin(),dif.begin()+n-k,0) << endl;
    }
  }
}

Measured memory_bytes: 1860
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<ll,int>
#define ll __int64
//#define ll long long
int n,m;
int a[310][310];
int pos[310];
int cnt[310];
bool u[310];
void che(){
	rep(i,n)cnt[i]=0;
	rep(i,n)cnt[pos[i]]++;
}

int main(){
	cin>>n>>m;
	rep(i,n)rep(j,m){cin>>a[i][j];a[i][j]--;}
	int ans=5000;


	rep(i,m){
		int ret=0,in=0;
		rep(j,m)cnt[j]=0;

		rep(j,n)cnt[a[j][pos[j]]]++;
		rep(j,m){
			if(ret<cnt[j]){
				ret=cnt[j];
				in=j;
			}
		}

		u[in]=1;
		//cout<<in+1<<endl;
		//rep(j,n)cout<<pos[j]<<" ";cout<<endl;
		//rep(j,m)cout<<cnt[j]<<" ";cout<<endl;
		rep(j,n){
			while(u[a[j][pos[j]]]==1)
			{
				pos[j]++;
				if(pos[j]>=m)break;
			}
		}	



		ans=min(ans,ret);
	}

		//rep(j,n)cout<<pos[j]<<" ";cout<<endl;
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
        #define F first
        #define S second
        using ll = long long;
        const ll mod = 1000000007;
        const ll infi = 1000000000000000;
        const ll md = 998244353;
        using namespace std;
        using vl = vector<ll>;
        using pll =  pair<ll,ll>;
        
        ll power(ll x,ll y){
            ll res = 1;
            while(y){
                if(y&1) res = (res*x)%mod;
                x = (x*x)%mod; 
                y= y/2;
            }
            return res;
        }
      
        void  solve(){
           int n,k;
           cin>>n>>k;
           vl a(n),comb(n+1),fact(n+1);
           fact[0] = 1,fact[1] = 1;
           for(int i=2;i<=n;i++){
               fact[i] = (i*fact[i-1])%mod;
           }
           for(int i=k-1;i<=n;i++){
               comb[i] = (fact[i] * power(fact[i - k + 1],mod-2))%mod;
               comb[i] = (comb[i]*power(fact[k-1],mod-2))%mod;
           }
           for(int i=0;i<n;i++){
               cin>>a[i];
           }
           sort(a.begin(),a.end());
           ll mas=0,mis=0;
           for(int i=k;i<=n;i++){
               ll pans;
               pans = (a[i-1]*comb[i-1])%mod;
               mas = (mas + pans)%mod;
           }
           for(int i=1;i<=n-k+1;i++){
               ll pans;
               pans = (a[i-1] *comb[n - i])%mod;
               mis = (mis + pans)%mod;
           }
           ll ans  = (mas - mis +mod)%mod;
           cout<<ans<<endl;
           
        }
        
      
        int main() {
            ios_base::sync_with_stdio(false);
            cin.tie(NULL);
           // int n; cin>>n; for(int i=0;i<n;i++)
            solve();
            return 0;
        }

Measured memory_bytes: 2560
#include<stdio.h>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<climits>
#include<string>
using namespace std;
#define lli long long int
#define f first
#define s second
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define pr(n) printf("%d",n);
#define prl(n) printf("%lld",n);
#define nl printf("\n");
#define all(c) (c).begin(), (c).end()
#define sz(a) int((a).size())
#define FN(i,n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++))
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
			cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
			const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
void optimizeIO()
{
	        ios_base:: sync_with_stdio(false);
		        cin.tie(NULL);
}

int main()
{
	int n;
	cin >> n;
	int arr[111111];
	int cost[111111];
	for(int i=1;i<=n;i++)
		cin >> arr[i];
	cost[1]=0;
	cost[2]=abs(arr[2]-arr[1]);
	for(int i=3;i<=n;i++)
	{
		cost[i] = min(cost[i-1]+abs(arr[i]-arr[i-1]),cost[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout << cost[n] << endl;
}


Measured memory_bytes: 1024
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,m;
bool vis[10][10];
char s[10][10];
void dfs(int x,int y)
{
	vis[x][y]=1;
	if(s[x][y+1]=='#'&&!vis[x][y+1])
		dfs(x,y+1);
	else if(s[x+1][y]=='#'&&!vis[x+1][y])
		dfs(x+1,y);
}
int main()
{
	get2(n,m);
	for(int i=1;i<=n;i++)
		scanf("%s",s[i]+1);
	dfs(1,1);
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(s[i][j]=='#'&&!vis[i][j])
	{
		puts("Impossible");
		return 0;
	}
	puts("Possible");
	return 0;
}

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

int main() {
 
  int n;
  cin >> n;
  vector<int> d(n);

  for (int i = 0; i < n; i++) { cin >> d.at(i); }

  int ans = 0;

  for (int i = 0; i < n; i++) {
    for (int j = 1; j < n; j++) {
      if (i < j) {
        ans = ans + (d.at(i) * d.at(j));
      }
    }
  }
  cout << ans << endl;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
bool possible[100001]; vector<ll> a(100001,0);
int main()
{
    fast
    ll n,W; cin>>n>>W;
    ll w[n],v[n];
    for(ll i=0;i<n;i++) cin>>w[i]>>v[i];
    possible[0]=true;
    for(ll k=0;k<n;k++)
    {
        for(ll x=W;x>=0;x--)
        {
            if(possible[x])
            {
                if(x+w[k]<=W)
                {
                    possible[x+w[k]]=true;
                    a[x+w[k]]=max(a[x+w[k]],a[x]+v[k]);
                }
            }
        }
    }
    ll maxx=0;
    for(ll i=0;i<=W;i++)
    {
        maxx=max(maxx,a[i]);
    }
    cout<<maxx;

    return 0;
}


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

#define int long long
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}

int N,R,T;
int p[111];

int a[1111],b[1111];
int cnt[1111];
signed main(){
    cin>>N>>R>>T;
    rep(i,N)cin>>p[i];

    rep(t,T){
        rep(i,R)a[i]+=b[i],b[i]=0;
        rep(i,N){
            int np=p[i]*(t+1)%R;
            if(t)b[np]++;
            if(a[np])a[np]--;
            else cnt[np]++;
        }
    }

    cout<<accumulate(cnt,cnt+R,0ll)<<endl;
    return 0;
}

Measured memory_bytes: 1184
MOD = 10**9+7
h, w, k = map(int, input().split())
ans = 0
dp = [ [0]*w for _ in range(h+1)]
dp[0][0] = 1
for i in range(h):
  for j in range(2**(w-1)):
    s = bin(j)[2:]
    s = "0"*(w-1-len(s)) + s
    for t in range(w-2):
      if s[t] == s[t+1] == "1":
        break
    else:
      s = "0" + s + "0"
      for t in range(w):
        if s[t] == "0" and s[t+1] == "0":
          dp[i+1][t] += dp[i][t]
        else:
          if s[t] == "1":
            dp[i+1][t] += dp[i][t-1]
          else:
            dp[i+1][t] += dp[i][t+1]
        dp[i+1][t] %= MOD
print(dp[h][k-1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define x first
#define y second
#pragma GCC optimize(2)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize(3)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target("sse3","sse2","sse")
#pragma GCC target("avx","sse4","sse4.1","sse4.2","ssse3")
#pragma GCC target("f16c")
#pragma GCC optimize("inline","fast-math","unroll-loops","no-stack-protector")
#pragma GCC diagnostic error "-fwhole-program"
#pragma GCC diagnostic error "-fcse-skip-blocks"
#pragma GCC diagnostic error "-funsafe-loop-optimizations"
#pragma GCC diagnostic error "-std=c++14"
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<long,long> PLL;
typedef pair<char,char> PCC;
typedef long long LL;
const int N=8005;
const int M=1e6;
const int INF=0x3f3f3f3f;
const int MOD=1000000007;
int n,m;
int cnt1[26],cnt2[26];
int main()
{
    IOS;
    string s;cin>>s;
    string t;cin>>t;
    int fg=1;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]){
            fg=0;
            break;
        }
    }
    fg ? cout<<"Yes"<<endl : cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(abs(b-a)<=(v-w)*t) cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 3660
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    std::string s;
    std::cin>>s;

    std::replace(s.begin(), s.end(), ',', ' ');
    std::cout<<s<<std::endl;
    return 0;
}

Measured memory_bytes: 256
##入力は以下の形式で標準入力から与えられる。
##N L
##S1
##S2
##:
##SN
n, l = gets.chomp.split(" ").map(&:to_i)
a_s = []
n.times do
  a_s << gets.chomp
end

##長さ Lの文字列を N個持っており、それぞれ S1, S2, ... , SN です。
##それらの文字列を好きな順番で全て結合してできる文字列のうち、
##もっとも辞書順で小さいものを求めてください。

##与えられる文字列を好きな順番で全て結合してできる文字列のうち、
##もっとも辞書順で小さいものを出力せよ。

##与えられた文字列を 昇順に並び替えてから結合することで、辞書順最小を達成できます。
# p n
# p l
puts "#{a_s.sort.join}"

Measured memory_bytes: 1788
/* Aditya0412 */
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;
#define pb push_back 
#define ve vector
#define vii vector < int >
#define vll vector < ll > 
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define all(a)      (a).begin(),(a).end()
#define si(x)       (int)((x).size())
#define debug(x)    cout<<#x<<" is "<<(x)<<endl;cout.flush();  
#define se second 
#define endl        '\n'
#define f(i,a,b)    for(int i=a;i<b;i++)
#define mem(a,x)          memset(a,x,sizeof(a))

// === Debug macro starts here ===

int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
    os<<"[";
    for(auto& x:v){os<<x<<", ";}
    return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
    return os<<"{"<<p.first<<", "<<p.second<<"}";
}

// === Debug macro ends here ===


// const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=1000000+6;
#define M_PI           3.14159265358979323846
void inp(ll *arr,ll n)
{
  for(int i=0;i<n;i++)
    cin>>arr[i];
}
void inp_mat(ll *arr,ll n,ll m)
{
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
        {
          ll x;cin>>x;
          *((arr+i*m) + j)=x;
        }
}
// syntax for inp_mat inp_mat((ll *)arr,n,m);
// int x2[]={+1,-1,+0,+0};
// int y2[]={+0,+0,+1,-1};
int main() 
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //  #ifndef ONLINE_JUDGEc
    //   freopen ("INPUT.txt" , "r" , stdin);
    //   freopen ("OUTPUT.txt", "w" , stdout);
    // #endif 
    int t=1;
    // cin>>t;
    while(t--)
    {
      ll n;cin>>n;ll arr[n];inp(arr,n);sort(arr,arr+n);
      ll ans=0;
      ans+=arr[n-1];
      ll x=n-2;
      ll j=n-2;int c=0;
      while(x--)
      {
        if(c==0)
        {
          ans+=arr[j];c++;
        }
        else
        {
          ans+=arr[j];c++;c%=2;j--;
        }
        
      }
      cout<<ans;
    }    
} 

Measured memory_bytes: 5220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		int ans = 1;
		for(int i=1; i<s.length(); i++) {
			if(s[i] != s[i-1]) ans++;
		}
		cout<<ans<<"\n";
 	}
 	return 0;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

int main(){
    int n,k;
    cin>>n>>k;
    int p[n];
    rep(i,n) cin>>p[i];
    //範囲を選ぶの全パターンはn-k+1通りある

    vector<bool> X(n-k+1,true);

    int ans=0;
    set<int> st;
    rep(i,k) st.insert(p[i]);
    for(int i=0;i<n-k;i++){
        st.insert(p[i+k]);
        if(p[i]==*st.begin()&&p[i+k]==*prev(st.end())) X[i+1]=false;
        //O(logN)
        st.erase(p[i]);
    }

    //初期盤面とのダブリをimos法を用いて調べる
    /*
    p[j]>p[j+1]となっている部分があればそこが含まれるような
    範囲の選び方をする部分は初期盤面とは一致しない
    */
    vector<int> imos(n,0);
    for(int j=0;j<n-1;j++){
        if(p[j]>p[j+1]){
            imos[max(0,j-(k-2))]++;
            imos[j+1]--;
        }
    }
    vector<int> sm(n,0);
    sm[0]=imos[0];
    for(int i=1;i<n;i++){
        sm[i]=sm[i-1]+imos[i];
    }
    int cnt=0;
    for(int i=0;i<n-k+1;i++){
        if(sm[i]<=0){
            cnt++;
            X[i]=false;
        }
    }
    rep(i,X.size()){
        if(X[i]) ans++;
    }
    cout<<(ans+bool(cnt))<<endl;
    return 0;
}


Measured memory_bytes: 12032
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class28
    {
        static void Main()
        {
            int N = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ans = a[0];
            for(int i = 0; i < N; i++)
            {
                ans = gcd(ans, a[i]);
            }
            Console.WriteLine(ans);
        }
        static int gcd(int a,int b)
        {
            return a == 0 ? b : gcd(b%a,a);
        }
    }
}


Measured memory_bytes: 19936
#include <stdio.h>

int main(){
  int hana[100],taro[100],i,j,n,m,sumh,sumt,tem[2];

  while(1){
    scanf("%d %d",&n,&m);
    if((n==0)&&(m==0)) break;
    for(sumt=0,i=0;i<n;i++){
      scanf("%d",&taro[i]);
      sumt+=taro[i];
    }
    for(sumh=0,i=0;i<m;i++){
      scanf("%d",&hana[i]);
      sumh+=hana[i];
    }
    for(i=0;i<2;i++) tem[i] = -1;
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
	if((sumh-hana[j]+taro[i])==(sumt-taro[i]+hana[j])){
	  tem[0] = taro[i];
	  tem[1] = hana[j];
	  break;
	}
      }
      if(tem[0]!=-1 && tem[1] != -1) break;
    }
    if(tem[0]!=-1 && tem[1] != -1) printf("%d %d\n",tem[0],tem[1]);
    else printf("-1\n");
  }


  return 0;
}

Measured memory_bytes: 608
#include<iostream>
#include<string>
using namespace std;
int main() {
    string str;
    getline(cin, str);
    for (int i = 0; i < (int)str.size(); i++) {
        if (str[i] >= 'a'&&str[i] <= 'z') {
            cout << (char)(str[i] - 32);
        }
        else if (str[i] >= 'A'&&str[i] <= 'Z') {
            cout << (char)(str[i] + 32);
        }
        else { cout <<  str[i]; }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3216
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		sc.close();

		int x=700;
		for(char c: line.toCharArray()) {
			if (c == 'o') x += 100;
		}
		System.out.println(x);
	}
}


Measured memory_bytes: 21844
//
#include <bits/stdc++.h>
using namespace std;
template<size_t SIZE, class T> inline size_t array_size(T (&arr)[SIZE]) {
    return SIZE;
}
int main() {
    string str;
    cin>>str;
    char c[]={'0','1'};
    int64_t c_a=0;
    int64_t c_b=0;
    for(int64_t i= 0;i<str.length();++i){
        //0101
        if (str[i] != c[i%2]) {
            ++c_a;
        }
        //1010
        if (str[i] != c[(i+1)%2]) {
            ++c_b;
        }
    }
    cout<<(c_a<c_b?c_a:c_b)<<endl;
    return 0;
}

Measured memory_bytes: 512
use whiteread::parse_line;

fn main() {
    let n: usize = parse_line().unwrap();
    let (s, t): (String, String) = parse_line().unwrap();

    let mut u: String = "".to_string();
    let mut i: usize = 0;

    while i < n {
        u = u + &s[i..i+1] + &t[i..i+1];
        i = i + 1;
    }

    println!("{}", u);
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int count=0;
  for(int i=0; i<n-1;i++){
    if (vec.at(i)==vec.at(i+1))count++;
  }
  cout << n-count <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

typedef vector<int> Edges;
typedef vector<Edges> Graph;

int n;
ll len[1200000];
bool root[1200000];
Graph g;
vector<int> order;

int main() {
  while (scanf("%d", &n) > 0) {
    MEMSET(root, false);
    g = Graph(n);
    REP(i, n) {
      int p;
      scanf("%lld %d", &len[i], &p);
      if (p != -1) {
        g[p].push_back(i);
      } else {
        root[i] = true;
      }
    }
    REP(i, n) {
      if (!root[i]) { continue; }
      queue<int> que;
      que.push(i);
      while (!que.empty()) {
        int from = que.front();
        que.pop();
        order.push_back(from);
        FORIT(it, g[from]) {
          int to = *it;
          que.push(to);
        }
      }
    }
    reverse(order.begin(), order.end());
    ll ans = 0;
    REP(i, n) {
      int from = order[i];
      vector<int> lens;
      FORIT(it, g[from]) {
        lens.push_back(len[*it]);
      }
      sort(lens.begin(), lens.end());
      ll sum = 0;
      FORIT(it, lens) {
        ans += sum;
        sum += *it;
      }
      len[from] += sum;
    }
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 74108
#include<iostream>
#include<climits>
#include<algorithm>
using namespace std;
int n,W;
int weight[110],value[110];
int dp[10010][10010];
int main() {
	cin >> n>>W;
	for (int i = 0; i < n; i++)cin >>value[i]>> weight[i];
	for (int x = 0; x <= W; x++)dp[0][x] = 0;
		for (int i = 0; i < n; i++) {
			for (int x = 0; x <= W; x++) {
				if (x >= weight[i])dp[i + 1][x] = max(dp[i][x - weight[i]] + value[i], dp[i][x]);
				else dp[i + 1][x] = dp[i][x];
			}
	}
	cout << dp[n][W] << endl;
}


Measured memory_bytes: 7044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, k;
  cin >> n >> k;
  vi x(n);
  rep(i, n) cin >> x[i];
  sort(all(x));
  int ans = 1e9;
  rep(l, n - k + 1) {
    int r = l + k - 1;
    int d = min(abs(x[l]), abs(x[r])) + abs(x[r] - x[l]);
    ans = min(ans, d);
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
w,h,x,y,r=gets.split.map(&:to_i)

points = [
  [x+r, y+r],
  [x+r,y-r],
  [x-r,y+r],
  [x-r,y-r],
]

def cover(w,h,px,py)
  px>=0&&px<=w&&py>=0&&py<=h
end

result = points.all?{|p|
px,py = p
cover(w,h,px, py)
}

puts result ? "Yes" : "No"


Measured memory_bytes: 6872
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int W, H;
  while (cin >> W >> H && W != 0) {
    static vector<pair<int,int> > ps[3000];
    for (int i = 0; i < 3000; i++) {
      ps[i].clear();
    }
    pair<int,int> g;
    int m = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        string s;
        cin >> s;
        istringstream iss(s);
        int n;
        if (s == "S") {
          ps[0].push_back(make_pair(i, j));
        } else if (s == "G") {
          g = make_pair(i, j);
        } else if (iss >> n) {
          ps[n].push_back(make_pair(i, j));
          m = max(m, n);
        }
      }
    }
    ps[++m].push_back(g);

    static int dp[3000][3000];
    for (int i = 1; i <= m; i++) {
      fill_n(dp[i], ps[i].size(), 10000000);
      for (int j = 0; j < ps[i-1].size(); j++) {
        for (int k = 0; k < ps[i].size(); k++) {
          const int l = abs(ps[i][k].first - ps[i-1][j].first) + abs(ps[i][k].second - ps[i-1][j].second);
          dp[i][k] = min(dp[i][k], dp[i-1][j] + l);
        }
      }
    }
    cout << dp[m][0] << endl;
  }
  return 0;
}

Measured memory_bytes: 1464
#include<iostream>
using namespace std;
int main(){
	int a, b, n, i, z = 0;
	int x[100], y[100];
	cin >> a >> b >> n;
	for (i = 0; i < n; i++){
		cin >> x[i] >> y[i];
		if (x[i] <= a&&y[i] > a){
			z = 1;
		}
		if (x[i] < b&&y[i] >= b){
			z = 1;
		}
		if (a <= x[i] && y[i] <= b){
			z = 1;
		}
	}
	cout << z << endl;
	return 0;
}


Measured memory_bytes: 3096
#include <stdio.h> 
 #include <math.h> 
 
 
 int main(){ 
     double x1, y1, x2, y2, distance; 
     scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2); 
     distance=sqrt((pow(x2-x1, 2)+pow(y2-y1, 2))); 
     printf("%f\n", distance); 
 
 
     return 0; 
 } 



Measured memory_bytes: 2124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		sc.close();

		int s = 0;
		while(true) {
			if(s == 0) {
				if (A.length() == 0) {
					System.out.println("A");
					return;
				}
				if(A.charAt(0) == 'a') {
					s = 0;
				}else if(A.charAt(0) == 'b') {
					s = 1;
				}else if(A.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				A = A.substring(1, A.length());
			}else if(s == 1) {
				if (B.length() == 0) {
					System.out.println("B");
					return;
				}
				if(B.charAt(0) == 'a') {
					s = 0;
				}else if(B.charAt(0) == 'b') {
					s = 1;
				}else if(B.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				B = B.substring(1, B.length());
			}else if(s == 2) {
				if (C.length() == 0) {
					System.out.println("C");
					return;
				}
				if(C.charAt(0) == 'a') {
					s = 0;
				}else if(C.charAt(0) == 'b') {
					s = 1;
				}else if(C.charAt(0) == 'c') {
					s = 2;
				}
				//先頭文字の除去
				C = C.substring(1, C.length());
			}
		}

	}
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}

int N,K;
int A[111];

int dp[111][111][256];

signed main(){
    cin>>N>>K;
    rep(i,N)cin>>A[i];

    dp[0][0][0]=1;
    for(int i=0;i<N;i++){
        for(int j=0;j<=i;j++){
            for(int k=0;k<256;k++){
                add(dp[i+1][j][k],dp[i][j][k]);
                add(dp[i+1][j+1][k^A[i]],dp[i][j][k]);
            }
        }
    }

    int ans=0;
    for(int i=0;i<=N;i++){
        int tmp=dp[N][i][K];
        for(int j=1;j<=i;j++)tmp=tmp*j%mod;
        add(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 20864
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.);
const long long mod = 1000000007;
typedef long long ll;
//printf("%.12lf\n",mid);
//const long long sze = 2*(2^(long long)(ceil(log(100000)/log(2))));
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
long long lcm(int a, int b){
  return ((long long)a*(long long)b)/gcd(a, b);
}
inline void prep()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
};
long long modpow(long long x, long long n) { 
  if (n == 0) return 1%mod; 
  long long u = modpow(x,n/2); 
  u = (u*u)%mod; 
  if (n%2 == 1) u = (u*x)%mod; 
  return u;
}
 
long long modpow2(long long x, long long n, long long modd) { 
  if (n == 0) return 1LL%modd; 
  long long u = modpow2(x,n/2LL, modd); 
 
  u = (long long)(u*u)%modd; 
  if (n%2LL == 1) u = (long long)(u*x)%modd; 
  return u;
}
 
bool chosen[1001]={false};

vector<int> permutation;
int arr[4];
bool mapp[501][501] = {{false}};
int maxxx = -1;
void search(int n) {
  if (permutation.size() == n) {
    
  } else {
    for (int i = 0; i < n; i++) {
      if (chosen[i]) continue;
      chosen[i] = true;
      permutation.push_back(i);
      search(n);
      chosen[i] = false;
      permutation.pop_back();
    }
  }
}

vector<long long> primeFactors(long long n)
{
    // Print the number of 2s that divide n
    vector<long long> res;
    bool found = false;
    while (n%2 == 0)
    {
      found = true;
        n = n/2;
    }
    if (found){
      res.push_back(2);
    }
    // n must be odd at this point.  So we can skip 
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
      
        // While i divides n, print i and divide n
        bool found2 = false;
        while (n%i == 0)
        { 
          found2 = true;
            n = n/i;
        }
        if (found2){
          res.push_back(i);
        }
    }

    // This condition is to handle the case when n 
    // is a prime number greater than 2
    if (n > 2)
        res.push_back(n);
    return res;
}

int main(){
  prep();
  int n, coord;
  cin >> n >> coord;
  if (n == 1){
    int num;
    cin >> num;
    cout << abs(coord-num);
    return 0;
  }
  
  int gcdd;
  cin >> gcdd;
  gcdd = abs(gcdd-coord);
  for (int i=0; i<n-1; i++){
    int num;
    cin >> num;
    gcdd = gcd(gcdd, abs(coord-num));
  }
  cout << gcdd;
  return 0;
}
// if TLE think about switching or removing loops & try not to use vector functions like size() or create new vector in a loop
// never use brackets with map when accessing value
// if the input/output is just a number see if it fits into a function (linearly, exponentially)
// if getting error for no reason check overflows
// if can't think of anything efficient try brute force
// look at solved problems of other ppl 2 see which is easiest
// if can precompute 
// if getting random error w/ loop check if boundaries are being changed during loop
// if you can't solve any more problems check for hacks in ur code then hack 
// in reversing problems if checking for a pattern use write down indices
// if already sure about wrong answers check TLE

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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N,K,S;
    cin >> N >> K >> S;

    if (S==1000000000) {
        rep(i,K) {
            cout << S << " ";
        }
        rep(i,N-K) {
            cout << 1 << " ";
        }
        cout << endl;
    }
    else {
        rep(i,K) {
            cout << S << " ";
        }
        rep(i,N-K) {
            cout << S+1 << " ";
        }
        cout << endl;
    }
}


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

int main(){
	int x, a, b;
	cin >> x >> a >> b;
	if (a >= b)
	{
		cout << "delicious" << endl;
	}else if (a + x >= b)
	{
		cout << "safe" << endl;
	}else{
		cout << "dangerous" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>
#include <cmath>
#include <limits>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

//ll days = 5000000000000000;

int main() {
    string s;
    ll k;
    cin >> s >> k;
    int ans = 1;
    rep(i, s.size()) {
        if(s[i] != '1') {
            ans = s[i] - '0';
            break;
        }

        if(i + 1 >= k) break;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include<algorithm>
#include<vector>
#define PI (6.28318530717958623200/2)
using namespace std;

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

    int money =1000;


    while(N >money){
        money += 1000;
    }
    cout << money - N;

}
        
    


Measured memory_bytes: 3628
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
using namespace std;
#define REP(i,n); for(int i = 0;i < (int)(n);i++)

int main() {
	int r,d,x[11];
	cin >> r >> d >> x[0];
	for (int i = 1; i<11;i++){
		x[i] = r * x[i-1] - d;
	}
	for (int i = 1; i<11;i++){
		cout << x[i] << endl;
	}
	return(0);
}

Measured memory_bytes: 256
#include <iostream>
#define int long long
using namespace std;

int ai, ao, at, aj, al, as, az;

signed main() {
	cin >> ai >> ao >> at >> aj >> al >> as >> az;
	
	int ans = ao;
	
	//i, j, l
	int IJL = min(ai, min(aj, al));
	
	int remI = ai - IJL;
	int remJ = aj - IJL;
	int remL = al - IJL;

	int cst = 0;
	cst += (remI % 2 == 1 && ai >= 2);
	cst += (remJ % 2 == 1 && aj >= 2);
	cst += (remL % 2 == 1 && al >= 2);
	
	if (cst >= 2) {
		IJL--;
		remI++;
		remJ++;
		remL++;
	}
	
	ans += IJL * 3 + (remJ / 2) * 2 + (remL / 2) * 2 + (remI / 2) * 2;
	
	cout << ans << endl;
	return 0;
}

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

struct process{
    string name;
    int time;
}pro[100000];
int top = 0, bottom = 0;

int push(process x){
    if(bottom >= 100000) {
        return 1;
    }
    pro[bottom] = x;
    if((bottom + 1) == 100000) bottom = 0;
    else bottom++;
    return 0;
}

process pop(void){
    if(top == bottom){
        cout << "error" << endl;
    }
    process v;
    v = pro[top];
    if((top + 1) == 100000) top = 0;
    else top++;
    return v;
}

int main(void){
    int n, q, t = 0;
    process v;
    cin >> n >> q;

    for(int i = 0; i < n; i++){
        cin >> v.name >> v.time;
        push(v);
    }

    while(top != bottom){
        v = pop();
        if(v.time <= q){
            t += v.time;
            cout << v.name << ' ' << t << endl;
        }else {
            t += q;
            v.time -= q;
            push(v);
        }
    }
    return 0;
}


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

using namespace std;

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


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <queue>
#include <stack> 
#include <string>
#include <set>
#include <map>
#include <vector>
using namespace std;
typedef long long ll;
ll lc[88];
void init(){
	lc[0]=2,lc[1]=1;
	for(int i=2;i<=86;i++){
		lc[i]=lc[i-1]+lc[i-2];
	}
}
int main(void){
	int n;
	init();
	while(cin>>n){
		cout<<lc[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define N 36

typedef struct{
  char mark;
  int number;
  int order;
}trump;

int main()
{
  int i, j, num, mj, flag=1;
  trump array1[N], array2[N], tmp;

  scanf("%d", &num);

  for( i=0; i<num; i++){
    while(1){
      scanf("%c", &array1[i].mark);
      if( array1[i].mark != 'D' && array1[i].mark != 'C' && array1[i].mark != 'S' && array1[i].mark != 'H')continue;
      scanf("%d", &array1[i].number);
      break;
    }
    array1[i].order = i+1;
    array2[i] = array1[i];
  }

  for( i=0; i<num; i++){
    for( j=num-1; j>=i+1; j--){
      if( array1[j].number < array1[j-1].number ){
	tmp = array1[j];
	array1[j] = array1[j-1];
	array1[j-1] = tmp;
      }
    }
  }

  for( i=0; i<num-1; i++){
    printf("%c%d ", array1[i].mark, array1[i].number);
  }

  printf("%c%d\n", array1[i].mark, array1[i].number);

  for( i=1; i<num; i++){
    if( array1[i].number == array1[i-1].number && array1[i].order - array1[i-1].order < 0 )flag =0;
  }

  if( flag == 1 ) printf("Stable\n");
  else printf("Not stable\n");

  flag = 1;

  for( i=0; i<num; i++){
    mj = i;

    for( j=i; j<num; j++){
      if( array2[j].number < array2[mj].number )mj = j;
    }
      tmp = array2[i];
      array2[i] = array2[mj];
      array2[mj] = tmp;
    }

  for( i=0; i<num-1; i++){
    printf("%c%d ", array2[i].mark, array2[i].number);
  }

  printf("%c%d\n", array2[i].mark, array2[i].number);

  for( i=1; i<num; i++){
    if( array2[i].number == array2[i-1].number && array2[i].order - array2[i-1].order < 0 )flag =0;
  }

  if( flag == 1 ) printf("Stable\n");
  else printf("Not stable\n");
    
  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

bool b[102];
int main() {
  int x,n;
  cin >> x >> n;
  rep(i,n){
    int p;
    cin >> p;
    b[p] = true;
  }
  int ans = -1;
  rep(i,102){
    if(b[i])continue;
    if(abs(ans-x)>abs(i-x)){
      ans = i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3580
//????????????????????????????????????????????????????????????
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br =
				new BufferedReader(new InputStreamReader(System.in));
		
		String inputStr = br.readLine();			//??\??????????????????inputStr
		String searchStr = br.readLine();			//????´¢??????
		
		String ringInputStr = inputStr + inputStr;
		
		if(ringInputStr.contains(searchStr)) {
			System.out.println("Yes");
		}
		else
			System.out.println("No");
		
	}

}

Measured memory_bytes: 24436
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    int n;
    scanf("%d",&n);
    int a[110],i,j;
    for(i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int min=0;
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            if(abs(a[i]-a[j])>min)
                min=abs(a[i]-a[j]);
        }
    }
    printf("%d\n",min);
    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

typedef long long int64;
const int64 MOD = (int64)( 1e9 + 7 );

const int MAX_N = 200;
const int MAX_W = 10000;

int N, W;
int wes[MAX_N];
int64 ways[MAX_N + 1][MAX_W + 1];

void init() {
	scanf("%d%d", &N, &W);
	for (int i = 0; i < N; ++i) {
		scanf("%d", wes + i);
	}
}

int solve() {
	sort(wes, wes + N, greater<int>());
	ways[0][0] = 1;
	int res = accumulate(wes, wes + N, 0);
	for (int i = 0; i < N; ++i) {
		for (int w = 0; w <= W; ++w) {
			if (w + res > W) {
				ways[i+1][w] = (ways[i+1][w] + ways[i][w]) % MOD;
			}
			if (w + wes[i] <= W) {
				ways[i+1][w+wes[i]] = (ways[i+1][w+wes[i]] + ways[i][w]) % MOD;
			}
		}
		res -= wes[i];
	}

	int64 ans = 0;
	for (int w = 0; w <= W; ++w) {
		ans = (ans + ways[N][w]) % MOD;
	}
	return int(ans);
}

int main() {
	init();
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 16604
#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 all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

ll dp[2005][2005];
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int n;
   cin >> n;
   vector<P> p;
   rep(i, 0, n) {
      int a;
      cin >> a;
      p.emplace_back(a, i);
   }
   sort(p.rbegin(), p.rend());
   rep(i, 0, n) {
      int a = p[i].first;
      int ai = p[i].second;
      rep(l, 0, i + 1) {
         int r = i - l;
         chmax(dp[i + 1][l + 1], dp[i][l] + ll(ai - l) * a);
         chmax(dp[i + 1][l], dp[i][l] + ll((n - 1 - r) - ai) * a);
      }
   }
   ll ans = 0;
   rep(i, 0, n + 1) chmax(ans, dp[n][i]);
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 26288
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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;
}



int main(){
    ll a,b;
    cin >> a >> b;
    if(a>b){
        ll ctp = b;
        b = a;
        a = ctp;
    }
    ll m = b;
    ll n = a;

    while(n!=0){
        ll ctp = n;
        n = m%n;
        m = ctp;
    }

    cout << a * b /m << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define PI 3.1415926535897932385
#define forl(i,a,b) for (ll i = a; i < b; i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<int,int> pi;
int main() {
    ll n;
    cin>>n;
    map<int,int> m;
    forl(i,0,n-1)
    {
        ll x; cin>>x;
        m[x]++;
    }
    forl(i,1,n+1)
    {
        cout<<m[i]<<endl;
    }
	return 0;
}


Measured memory_bytes: 12976
#include <iostream>
using namespace std;
int a[7][2],c;
int f(int tc,int tp,int maxc,int maxp){
	if(tc == maxc) {
		if(maxp == tp) ++c;
	}
	else {
		for(int i = 0;i <= a[tc][1];++i){
			f(tc + 1,tp + (a[tc][0] * i),maxc,maxp);
		}
	}
	return 0;
}
int main(){
	int n,b,price;
	while(cin >> n,n){
		for(int i = 0;i < n;++i){
			cin >> a[i][0] >> a[i][1];
		}
		cin >> b;
		for(int i = 0;i < b;++i){
			c = 0;
			cin >> price;
			f(0,0,n,price);
			cout << c << endl;
		}
	}
	return 0;
}

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

const int N = 1e5 + 7;

vector <int> kid[N], ad[N];
int n, par[N], res[N], mx[N];
bool is[N];

void dfs(int p, int v) {
	int tmp = 0;
	for (auto u: ad[v]) 
		if (u != p) {
			kid[v].push_back(u);
			par[u] = v;
			dfs(v, u);
			tmp = max(tmp, mx[u]);
		}
	mx[v] = 1 + tmp;
}

void solve(int v) {
	for (auto u: kid[v])
		solve(u);
	vector <int> d;
	for (auto u: kid[v]) {
		if (res[u])
			res[v] += res[u];
		else
			d.push_back(u);
	}
	sort (d.begin(), d.end(), [](int x, int y) {
		return mx[x] < mx[y];		
	});
	for (int i = 1; i < d.size(); i++)
		is[d[i]] = 1, res[v]++;
}

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		x++, y++;
		ad[x].push_back(y);
		ad[y].push_back(x);
	}
	dfs(0, 1);
	solve(1);
	int t = 0;
	for (int i = 1; i <= n; i++) {
		if (!is[i] && par[par[i]] != 0 && !is[par[i]] && res[par[i]] == res[1])
			t = 1;
	}
	cout << max(1, t + res[1]);
	return 0;
}

Measured memory_bytes: 21248
#include <iostream>
#include <string>

using namespace std;

int main(){

  int A,B;
  string S,T,U;
  
  cin>>S>>T;
  cin>>A>>B;
  cin>>U;

  if(S==U){
    cout<<A-1<<" "<<B<<endl;
  }
  else{
    cout<<A<<" "<<B-1<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/
signed main(){
	int n;cin>>n;

	int ans=0;
	FOR(j,1,n){
		int a=n/j;
		ans+=a*(a+1)/2*j;

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


Measured memory_bytes: 3572
/**********************************************************************
   File hoge.cpp
   Author  harunaya
   Date   2020-04-29(Wed)
   note   
**********************************************************************/

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

int main() {
  int p, q, r; 
  cin >> p >> q >> r;
  int ans = min(min(p + q, q + r), p + r);
  cout << ans << endl;
  }


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

p = [0] * 62

def insert(x):
    for i in range(60, -1, -1):
        if x >> i & 1:
            if not p[i]:
                p[i] = x
                break
            x ^= p[i]

all = 0 
for x in a:
    all ^= x

for i in range(61):
    if all >> i & 1:
        for j in range(n):
            if a[j] >> i & 1:
                a[j] -= (1<<i)

for x in a:
    insert(x)
ans = 0
for i in range(60, -1, -1):
    if (p[i] ^ ans) > ans:
        ans = p[i] ^ ans
print(ans + (ans ^ all))


Measured memory_bytes: 77088
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7;
const int larg = 1e5;

typedef pair<int, int> P;
typedef long long ll;
ll N;

bool contnum(ll n){
	bool flag[10] = {false};
	while(n > 0){
		flag[n%10] = true;
		n /= 10;
	}
	return flag[3]&&flag[5]&&flag[7];
}

int dfs(ll n){
	if(n > N) return 0;
	if(contnum(n)) return dfs(n*10+3)+dfs(n*10+5)+dfs(n*10+7)+1;
	else return dfs(n*10+3)+dfs(n*10+5)+dfs(n*10+7);
}

int main() {
	cin >> N;
	cout << dfs(0);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n,x;
  int sum=0;
  scanf("%d",&n);
  scanf("%d",&x);
  int l[n];
  int j=0;
  for(int cnt=0;cnt<n;cnt++){
    scanf("%d",&l[cnt]);
  }
  for(j=0;j<n;j++){
    sum+=l[j];
    if(sum>x){
      break;
    }
  }
  printf("%d",j+1);
  return 0;
}

Measured memory_bytes: 128