akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,K;
int A[100010];
int C[100010];
int num[100010];
int S[100010];
int L[100010];

void add(int &a,int b){
	a+=b;
	a%=MOD;
}

void seki(int &a,int b){
	a*=b;
	a%=MOD;
}

int extgcd(int a,int b,int &x,int &y){
	int g=a;
	x=1,y=0;
	if(b!=0){
		g=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}
	return g;
}
 
// 逆元
int mod_inverse(int a,int m){
	int x, y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}
 
// 階乗
std::vector<int>fact;
void mod_fact(int n, int m){
	fact.resize(n+1);
	fact[0]=1;
	for(int i=1;i<=n;i++){
		fact[i]=fact[i-1]*i%m;
	}
}
 
// nCk mod p
int mod_nCr(int n, int k, int m){
	if(n<k)return 0;
	return fact[n]*mod_inverse(fact[k]*fact[n-k]%m,m)%m;
}

signed main(){
	cin>>N>>K;
	mod_fact(100010,MOD);
	REP(i,N){
		cin>>A[i];
	}
	sort(A,A+N);
	REP(i,N){
		num[i+1]=num[i]+A[i];
	}
	for(int i=0;i<=N-2;i++){
		L[i]=(num[N]-num[i+1]);
		L[i]-=num[N-i-1];
		DEB(L[i])END
	}
	int ans=0;
	for(int i=0;i<=N-2;i++){
		int R=1;
		seki(R,L[i]);
		seki(R,mod_nCr(i,K-2,MOD));
		add(ans,R);
	}
	cout<<ans<<endl;
	return 0;
}
/*
4 3
1 2 3 4
*/

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
  int n;
  cin>>n;
  list<int> a(n);
  for(auto i=a.begin();i!=a.end();++i){
    cin>>*i;
  }
  a.sort();
  int cnt=0;
  for(int sh=31;sh>0;sh--){
    auto i=a.begin();
    auto j=prev(a.end());
    while(i!=j){
      if(*i + *j == 1 << sh){
        cnt++;
        ++i;
        a.erase(prev(i));
        if(i==j){
          a.erase(j);
          break;
        }else{
          --j;
          a.erase(next(j));
        }
      }else if(*i + *j < 1 << sh){
        ++i;
      }else{
        --j;
      }
    }
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N,H;
	int a;
	int b[100010]={};
	int amax=0;
	
	cin >> N >> H;
	for(int i=0;i<N;i++)
	{
		cin >> a >> b[i];
		amax=max(amax,a);
	}
	
	sort(b,b+N,greater<int>());
	
	int ans=0;
	for(int i=0;i<N && H>0;i++)
	{
		if(b[i]>amax)
		{
			H-=b[i];
			ans++;
		}
		else
			break;
	}
	
	if(H>0)
	{
		ans+=H/amax;
		if(H%amax!=0)
			ans++;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

int main()
{
	int n;
	cin >> n;
	vector<vector<int>> a(n, vector<int>(n - 1));
	vector<bool> done(n, false);

	int cnt = 0;
	rep(i, n) rep(j, n - 1)
	{
		int tmp;
		scanf("%d", &tmp);
		tmp--;
		a[i][j] = tmp;
	}
	map<int, int> ite;
	bool yet = true;
	bool fail = false;
	vector<vector<bool>> today(n, vector<bool>(n * n, true));
	//vector<bool>today(n,true);
	int day = 0;
	bool dec = false;
	deque<int> ydy;
	rep(i, n)
	{
		ydy.pb(i);
	}
	while (yet)
	{
		int t=ydy.size();
		rep(i, t)
		{
			int k=ydy.front();
			ydy.pop_front();
			if (ite[k] != n - 1 && today[k][day])
			{
				int j = a[k][ite[k]];
				if (ite[j] != n - 1 && today[j][day])
				{
					if (a[j][ite[j]] == k)
					{
						//cout<<k<<" "<<j<<endl;
						dec = true;
						ite[k]++;
						ite[j]++;
						ydy.pb(j);
						today[k][day] = false;
						today[j][day] = false;
						if (ite[k] == n - 1 && !done[k])
						{
							done[k] = true;
							//cout << k << "done" << endl;
							cnt++;
						}else{
							ydy.pb(k);
						}
						if (ite[j] == n - 1 && !done[j])
						{
							done[j] = true;
							//cout << j << "done" << endl;
							cnt++;
						}else{
							ydy.pb(j);
						}
					}
				}
			}
		}
		day++;
	//	cout << day << endl;

		if (cnt == n)
		{
			yet = false;
			break;
		}
		if (!dec)
		{
			fail = true;
			yet = false;
			break;
		}
		dec = false;
	}
	if (!fail)
	{
		cout << day << endl;
	}
	else
	{
		cout << -1 << endl;
	}
}


Measured memory_bytes: 126464
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define ll          unsigned long long int

#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000000001
#define all(a)      (a).begin(),(a).end()
#define ordered_set     tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> 
 
const long long INF = (long long) 1e11+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0){
    if(y%2) res=(x*res);
    x=(x*x);    
    y=y/2;
  }
  
  return res%mod;
}
 
ll modinv(ll x){
  return power(x,hell-2);
}

ll gcd(ll a,ll b)
{
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}

void fastIO() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int n,m;
vi gr[100005];
int par[100005];

void bfs(int v){
    queue<int> q;
    
    q.push(v);
    
    int dis[n+1];
    
    forn(i,1,n+1)
    dis[i]=1e7;
    
    dis[v]=0;
    
    memset(par,-1,sizeof(par));
    
    while(!q.empty()){
        v=q.front();
        q.pop();
        
        for(auto u:gr[v]){
            if(dis[u]>dis[v]+1){
                par[u]=v;
                dis[u]=dis[v]+1;
                q.push(u);
            }
        }
    }
}

void solve(){
    cin>>n>>m;
    
    forn(i,0,m){
        int u,v;
        cin>>u>>v;
        gr[u].pb(v);
        gr[v].pb(u);
    }
    
    bfs(1);
    
    forn(i,2,n+1){
        if(par[i]==-1){
            cout<<"No";
            return;
        }
    }
    
    cout<<"Yes\n";
    
    forn(i,2,n+1)
    cout<<par[i]<<"\n";
}

int main(){
   fastIO();
   int test;
   //cin>>test;
   test=1;    
   
   while(test--)
   solve();
}


Measured memory_bytes: 10896
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector <int> a(n);
	vector <int> b(n);
	vector <int> c(n - 1);
	int ans = 0, z;
	for (auto & u : a)
		cin >> u;
	for (int i = 0; i < n; i++)
	{
		cin >> z;
		ans += z;
	}
 	for (auto & u : c)
		cin >> u;
	for (int i = 0; i < n - 1; i++)
		if (a[i + 1] - a[i] == 1)
			ans += c[a[i] - 1];
	cout << ans;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
a = 0
list1 = []
for i in range(2):
  if i == 0:
    a = list(map(int,input().split()))[0]
  if i == 1:
    list1 = list(map(int,input().split()))
    
max = list1[0]
sum = 0
for i in list1:
  if (i >= max):
    sum += 1
    max = i
print(sum)
  

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin >> N;
    vector<int> mountain(N);
    for (int i = 0; i < N; i++) cin >> mountain[i];
    int max = mountain[0];
    int ans = 1;
    for (int i = 1; i < N; i++){
        if (mountain[i] >= max){
            max = mountain[i];
            ans++;
        } 
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e5 + 5;
long long int DP[MAXN];
int N;
long long H[MAXN];
long long rec(int idx)
{
    if(idx == (N - 1))
    {
        return 0;
    }
    if(DP[idx] != -1)
        return DP[idx];
    if(idx == (N - 2))
        DP[idx] = rec(idx + 1) + abs(H[idx] - H[idx + 1]);
    else
        DP[idx] = min(rec(idx + 1) + abs(H[idx] - H[idx + 1]), rec(idx + 2) + abs(H[idx] - H[idx + 2]));
    return DP[idx];
}

int main()
{
    cin >> N;
    for(int i = 0; i < N; ++i)
        cin >> H[i];
    for(int i = 0; i < N; ++i)
        DP[i] = -1;
    cout << rec(0) << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());

using ll = long long int;

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

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

int main(){
    int a, b;
    cin >> a >> b;
    if((a + b) % 2 == 1) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << (a + b) / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

"""
・nCr(R+1, i)
　R+1箇所の赤の間のうち、どこに青のグループを置くか
・nCr(B+i-1-i, B-i)
　B個の玉をi個のグループに割り振る(ただし0個グループはダメ→n,r両方からグループ数iを引く)
"""

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def init_fact_inv(MAX: int) -> list:
    """ 階乗たくさん使う時用のテーブル準備

    Params
    ------
        MAX：階乗に使う数値の最大以上まで作る
    Returns
    -------
        List, List
    """
    MAX += 1
    # 階乗テーブル
    factorial = [1] * MAX
    factorial[0] = factorial[1] = 1
    for i in range(2, MAX):
        factorial[i] = factorial[i-1] * i % MOD
    # 階乗の逆元テーブル
    inverse = [1] * MAX
    # powに第三引数入れると冪乗のmod付計算を高速にやってくれる
    inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
    for i in range(MAX-2, 0, -1):
        # 最後から戻っていくこのループならMAX回powするより処理が速い
        inverse[i] = inverse[i+1] * (i+1) % MOD
    return factorial, inverse

def nCr(n, r, factorial, inverse):
    """ 組み合わせの数 (必要な階乗と逆元のテーブルを事前に作っておく) """
    if n < r: return 0
    # 10C7 = 10C3
    r = min(r, n-r)
    # 分子の計算
    numerator = factorial[n]
    # 分母の計算
    denominator = inverse[r] * inverse[n-r] % MOD
    return numerator * denominator % MOD

N,K=MAP()
R=N-K
B=K

fact, inv = init_fact_inv(N)

for i in range(1, K+1):
    print(nCr(R+1, i, fact, inv) * nCr(B-1, B-i, fact, inv) % MOD)


Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>
#include <functional>
#include <sstream>

using namespace std;

#define ERROR_ID		0

#define PROCESS_ERROR(Condition)    \
{                                   \
		if (!(Condition))           \
		{                           \
			goto Exit0;             \
		}                           \
}

typedef unsigned char       BYTE;
typedef int                 BOOL;
typedef unsigned long       DWORD;
typedef long long			LLONG;

int main(int argc, char* argv[])
{
	int			nStepCount;
	char		chWord;
	int			nMaxHeight			= 0;
	int			nStepHeight			= 0;

	cin >> nStepCount;

	for (int i = 1; i <= nStepCount; i++)
	{
		cin >> chWord;

		if (chWord == 'I')
		{
			nStepHeight += 1;
			nMaxHeight = max(nMaxHeight, nStepHeight);
		}
		if (chWord  == 'D')
		{
			nStepHeight -= 1;
			nMaxHeight = max(nMaxHeight, nStepHeight);
		}
	}
	cout << nMaxHeight << endl;	
	return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>){
    val s = readLine()!!
    var ok = true
    for(i in 0 until s.length step 2){
        if(s[i] == 'L') ok = false
    }
    for(i in 1 until s.length step 2){
        if(s[i] == 'R') ok = false
    }
    println(if(ok) "Yes" else "No")
}


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

def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

from collections import defaultdict


N,K = two_int()


query = []
for i in range(N):
    query.append(two_int() )

query = sorted(query, key=lambda x: x[0])

ans=0
sums=0
for q in query:
    if sums < K <= sums+q[1]:
        ans=q[0]
        break
    
    sums += q[1]

print(ans)


Measured memory_bytes: 52828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
int q[100009],w[100009];

int main(){
  int n,r;
  cin >> n >> r;
  if(n>=10){cout << r << endl;}
  else{cout << r+100*(10-n) << endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
const int MOD = 1e9+7;
int main() {
	string s;
	cin >> s;
	for(int i = 0; i < s.size();i++)
		cout<<"x";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

struct Dice {
  int top;
  int bottom;
  int front;
  int back;
  int left;
  int right;
  Dice() : top(1), bottom(6), front(2), back(5), left(4), right(3) {}
  void E() {
    int tmp = right;
    right = top; top = left; left = bottom; bottom = tmp;
  }
  void N() {
    int tmp = back;
    back = top; top = front; front = bottom; bottom = tmp;
  }
  void S() {
    int tmp = front;
    front = top; top = back; back = bottom; bottom = tmp;
  }
  void W() {
    int tmp = left;
    left = top; top = right; right = bottom; bottom = tmp;
  }
  void Fit(int t, int f) {
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 4; ++j) {
        if (f == front) break;
        N();
      }
      E();
    }
    if (f == front) {
      for (int i = 0; i < 4; ++i) {
        if (t == top) break;
        E();
      }
    }
  }
};

int main() {
  Dice d;
  cin >> d.top;
  cin >> d.front;
  cin >> d.right;
  cin >> d.left;
  cin >> d.back;
  cin >> d.bottom;
  
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int t, f;
    cin >> t >> f;
    d.Fit(t, f);
    cout << d.right << endl;
  }
  return 0;
}



Measured memory_bytes: 3088
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
int in(){int a;scanf("%d",&a);return a;}
ll lin(){ll a;scanf("%lld",&a);return a;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int n, m;
string s, t;
int dp[2][2002][2002];
bool S[2002], T[2002];

int rec(int I, int a, int b) // I := ???I????????????, a := s??????????????????, b := t??????????????????
{
    int &res = dp[I][a][b];

    if (~res) return res;

    res = 0;
    
    if (a < m && I != S[a]) {
        chmax(res, 1 + rec(S[a], a + 1, b));
    }

    if (b < n && I != T[b]) {
        chmax(res, 1 + rec(T[b], a, b + 1));
    }

    return res;
}

#define local 0

int main()
{
    if (!local) {
        m = in(), n = in();
        cin >> s >> t;
    } else {
        cin >> s >> t;
        m = s.size(), n = t.size();
    }

    rep(i, m) S[i] = s[i] == 'I';
    rep(i, n) T[i] = t[i] == 'I';

    memset(dp, -1, sizeof dp);

    int ma = 0;

    rep(i, m) rep(j, n) {
        chmax(ma, rec(S[i], i+1, j) + S[i]);
        chmax(ma, rec(T[j], i, j+1) + T[j]);
    }

    printf("%d\n", ma == 0 ? 0 : (ma - (ma % 2 == 0)));
}

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

using namespace std;

#define ll         long long int
#define ld          double
#define vi          vector <int>
#define vl          vector<ll>
#define vp          vector <pair<int,int>>
#define vvi         vector <vector <int>>
#define vpl         vector<pair<ll,ll>>
#define vvl         vector<vector<ll>>
#define pb          push_back
#define mp          make_pair
#define pi          pair<int,int>
#define all(a)      a.begin(),a.end()
#define tillN(a,n)  a.begin(),a.begin() + n
#define ff          first
#define ss          second
#define minel(a)	*min_element(all(a))
#define maxel(a)	*max_element(all(a))
#define minelN(a,n) *min_element(tillN(a,n))
#define maxelN(a,n) *max_element(tillN(a,n))
#define mod         1000000007

ll inf = 1e18;

ll expo(ll x,ll y)
{
        ll ans = 1;
        while(y!=0)
        {
                if(y%2)
                {
                        ans = ans*x;
                }

                y = y>>1;
                x = x*x;
        }

        return ans;
}

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

	 return gcd(b%a , a);
}

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

ll max(ll x,ll y)
{
    if(x > y)
        return x;
    return y;

}

ll min(ll x,ll y)
{
    if(x < y)
        return x;
    return y;

}

 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin >> h >> w;
    char grid[h+1][w+1];
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cin >> grid[i][j];
        }
    }

    /*cout << "the grid is " << endl;

    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cout << grid[i][j];
        }

        cout << endl;
    }*/


    int dp[h+1][w+1];
    dp[1][1] = 1;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(grid[i][j] == '#')
                dp[i][j] = 0;
            else
            {
                if(i==1 && j==1)
                    continue;
                else
                {
                    if(i==1)
                    {
                        dp[i][j] = dp[i][j-1];
                    }
                    else
                    {
                        if(j==1)
                        {
                            dp[i][j] = dp[i-1][j];
                        }
                        else
                        {
                            dp[i][j] = (dp[i-1][j]%mod + dp[i][j-1]%mod)%mod;
                        }
                    }
                }
            }
        }
    }



    // cout << "the dp look like " << endl;

    // for(int i=1;i<=h;i++)
    // {
    //     for(int j=1;j<=w;j++)
    //     {
    //         cout << dp[i][j] << "   ";
    //     }

    //     cout << endl;
    // }



    cout << dp[h][w] << endl;

}


Measured memory_bytes: 5120
import sys
from collections import Counter


input = sys.stdin.readline


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    C = Counter(A)

    ans = 0
    for k in C.keys():
        if k > C[k]:
            ans += C[k]
        else:
            ans += C[k] - k
    print(ans)


    
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 18340
n,m,l=map(int,input().split())
a = [[0 for i in range(m)] for j in range(n)]
#print(a)
b = [[0 for i in range(1)] for j in range(m)]
#print(b)
A=[]
B=[]
for j in range (n):
    a = [int(x) for x in input().split()]
    A.append(a)
#print(A)
for i in range(m):
    b = [int(y) for y in input().split()]
    B.append(b)
#print(B)
#print(A[1][1])
for j in range (0,n):
        F=[]
        #print(j)
        for k in range (0,l):
            S=0
            for i in range (0,m):
                B1=B[i][k]
                A1=A[j][i]
        #print(A1)
                #print(A1,B1,sep=" ")
                S=S+int(A1)*int(B1)
            F.append(S)
            #print(S,end='')
            #rint('@',end='')
        print(*F)


Measured memory_bytes: 6572
import java.util.Scanner;
class Main{
    public static void main(String[] args){
		int a,b,c,cnt=0;
		Scanner sc=new Scanner(System.in);
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		for(int i=a;i<=b;i++){
			if(c%i==0){
				cnt++;
			}
		}
		System.out.println(cnt);
    }
}


Measured memory_bytes: 26376
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

vector<int> divisor(int n) {
    vector<int> ret;

    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != n / i) ret.push_back(n / i);
        }
    }

    return move(ret);
}

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

    auto d = divisor(N);

    int ret = INF;

    for (int v : d) {
        int sum = v + (N / v);
        ret = min(ret, sum);
    }
    cout << ret -2 << endl;

    return 0;
}

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

#define ll long long
#define nl '\n'
#define deb(x) cerr<<#x" = "<<x<<nl
#define in() ( { int a ; scanf("%d", &a); a; } )

const int N = 3e5 + 9;
const int mod = 1e9 + 7;

vector<int> g[N], b[N];
int vis[N];
set<int> cur;
void dfs(int u)
{
    vis[u] = 1;
    cur.insert(u);
    for(auto v: g[u]) if(!vis[v]) dfs(v);
}
int ans[N];
int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m, k; cin >> n >> m >> k;
    while(m--){
        int u, v; cin >> u >> v; g[u].emplace_back(v); g[v].emplace_back(u);
    }
    while(k--){
        int u, v; cin >> u >> v; b[u].emplace_back(v); b[v].emplace_back(u);
    }
    for(int i = 1; i <= n; i++) if(!vis[i]){
        dfs(i);
        for(auto u: cur){
            ans[u] = cur.size();
            ans[u] -= g[u].size();
            for(auto v: b[u]) ans[u] -= cur.find(v) != cur.end();
        }
        cur.clear();
    }
    for(int i = 1; i <= n; i++) cout << ans[i] - 1<< ' ';
    cout << nl;
    return 0;
}


Measured memory_bytes: 27000
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		Map<String, Integer> map = new HashMap<>();
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			if (map.containsKey(s)) {
				map.put(s, map.get(s) + 1);
			} else {
				map.put(s, 1);
			}
		}
		int m = sc.nextInt();
		for (int i = 0; i < m; i++) {
			String s = sc.next();
			if (map.containsKey(s)) {
				map.put(s, map.get(s) - 1);
			} else {
				map.put(s, -1);
			}
		}
		sc.close();

		int ans = 0;
		for (int v : map.values()) {
			ans = Math.max(ans, v);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
R = 10**9 + 7
DBG = True  and False
def ddprint(x):
  if DBG:
    print(x)

# extended gcd and modinv
# x = y*(x/y) + x%y
#   ->  g = ax+by = a(y*(x/y) + x%y) + by
#         = (a*(x/y) + b)*y + a*(x%y)
#
# while  g=ax+by, b==0  ->  g=x, a=1

def exgcd(x,y):
    if y == 0:
        return (x,1,0)
    else:
        g,b,a = exgcd(y, x%y)
        return (g, a, b-(x//y)*a)

# return y s.t. x*y mod p == 1
def modinv(x,p):
    g,a,b = exgcd(x,p)  # ax+bp = g, g=1 if mutually prime
    return a%p

def pw(x,e):
    if e==0:
        return 1
    elif e%2==0:
        return (pw(x,e//2)**2)%R
    else:
        return (x * pw(x,e//2)**2)%R

def rmod(i,qb,qw):
    global two2i, itwo2i
    numer = (two2i[i] - qb + qw)
    iden = itwo2i[i+1]
    ddprint("num {} idn {}".format(numer, iden))
    return (numer*iden)%R

b,w = inm()
ddprint("b {} w {}".format(b,w))

inv2 = modinv(2,R)
fact = [1] * (b+w+2)
for i in range(2,b+w+1):
    fact[i] = (i*fact[i-1])%R
ifact = [1] * (b+w+2)
ifact[b+w] = modinv(fact[b+w],R)
for i in range(b+w-1,0,-1):
    ifact[i] = ((i+1)*ifact[i+1])%R
two2i = [1] * (b+w+2)
itwo2i = [1] * (b+w+2)
itwo2i[1] = inv2
for i in range(1,b+w+1):
    x = (2*two2i[i-1])
    two2i[i] = x if x < R else x-R
    itwo2i[i] = (inv2*itwo2i[i-1]) % R
ddprint(fact[0:5])
ddprint(ifact[0:5])

cb = cw = 1
qb = qw = 0
print(500000004)
for i in range(1,b+w):
    qb = 0 if i<b else 1 if i==b else (2*qb+cb) % R
    qw = 0 if i<w else 1 if i==w else (2*qw+cw) % R
    cb = 1 if i<b else (fact[i]*ifact[b-1]*ifact[i-b+1]) % R
    cw = 1 if i<w else (fact[i]*ifact[w-1]*ifact[i-w+1]) % R
    ddprint("i {} cb {} cw {} qb {} qw {}".format(i,cb,cw,qb,qw))
    print(rmod(i,qb,qw))


Measured memory_bytes: 66520
#include<bits/stdc++.h>
#define ull unsigned long long int
using namespace std;

ull f(ull n){
  switch(n%4){
  case 0:
    return n;
  case 1:
    return 1;
  case 2:
    return n^1;
  default:
    return 0;
  }
}


int main(void) {
  ull a,b;
  cin >> a >> b;

  cout << (f(a-1)^f(b)) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream> 
#include<stdio.h>
using namespace std;
int main(){
    int n,m;
    cin >> n;
    int c[n],v[n];
    for(int j = 0; j < n;j++){
        cin >> c[j];
    }
for(int l = 0; l < n;l++){
        cin >> v[l];
    }
m = 0;

for(int i = 0;i < n;i++){
    if (c[i]-v[i]>0){
        m = m + (c[i]-v[i]);
        }
    }
cout << m << endl;
}

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    REP(i, n) cin >> v[i];
    ll ans = 0;
    vector<ll> a;
    for(ll i = 0; i <= min(n, k); i++){
        if(i != 0) a.PB(v[i-1]);
        vector<ll> b = a;
        for(ll j = 0; (i+j) <= min(n, k); j++){
            if(j != 0) b.PB(v[n-j]);
            sort(b.begin(), b.end());
            ll sum = 0;
            REP(l, SIZE(b)){
                if(b[l] < 0 && l < k - (i + j)) continue;
                sum += b[l];
            }
            ans = max(ans, sum);
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3636
package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanRunes() []rune { return []rune(scanString()) }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

func scanInts(n int) []int {
	res := make([]int, n); for i := 0; i < n; i++ { res[i] = scanInt() }; return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	a := scanInt()
	b := scanInt()
	m := scanInt()
	as := scanInts(a)
	bs := scanInts(b)

	ans := 1 << 31 -1

	for i := 0; i < m; i++ {
		x := scanInt()-1
		y := scanInt()-1
		c := scanInt()
		ans = min(ans, as[x]+bs[y]-c)
	}

	sort.Ints(as)
	sort.Ints(bs)

	fmt.Fprintln(wr, min(ans, as[0]+bs[0]))

}

type wa struct {
	x,y,c int
}


Measured memory_bytes: 4608
#include <stdio.h>
#include <math.h>

int get_uint() {
  int n = 0;
  int c = getchar_unlocked();
  if(c < 48 || 57 < c) return c;
  while(47 < c && c < 58) {
    n = 10 * n + (c & 0xf);
    c = getchar_unlocked();
  }
  return n;
}
typedef struct Point {
  double x;
  double y;
} Point;
void koch(int n, Point left, Point right) {
  if(!n) return;
  Point s, u, t;
  // MATH KNOWLEDGE
  const double THETA = M_PI / 3;
  s.x = (2 * left.x + right.x) / 3;
  s.y = (2 * left.y + right.y) / 3;
  t.x = (2 * right.x + left.x) / 3;
  t.y = (2 * right.y + left.y) / 3;
  u.x = (t.x - s.x) * cos(THETA) - (t.y - s.y) * sin(THETA) + s.x;
  u.y = (t.x - s.x) * sin(THETA) + (t.y - s.y) * cos(THETA) + s.y;
  koch(n-1, left, s);
  printf("%.5lf %.5lf\n", s.x, s.y);
  koch(n-1, s, u);
  printf("%.5lf %.5lf\n", u.x, u.y);
  koch(n-1, u, t);
  printf("%.5lf %.5lf\n", t.x, t.y);
  koch(n-1, t, right);
}
int main(int argc, char **argv) {
  int n = get_uint();
  printf("%.5lf %.5lf\n", 0.0, 0.0);
  koch(n, (Point){0, 0}, (Point){100, 0});
  printf("%.5lf %.5lf\n", 100.0, 0.0);
  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define endl '\n'
#define N 1000001
#define mod 1e9+7
using namespace std;
typedef long long ll;
vector<vector<ll> >v(100001);
ll dp[100001];
ll sol(ll a){
    if(dp[a]!=-1)return dp[a];
    ll res=0;
    for(ll i=0;i<v[a].size();i++){
        res=max(res,sol(v[a][i])+1);
    }
    return dp[a]=res;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,m;
	cin>>n>>m;
	ll x,y;
	for(ll i=0;i<m;i++){
	    cin>>x>>y;
	    v[x].push_back(y);
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)dp[i]=-1;
	for(ll i=1;i<=n;i++){
	    ans=max(ans,sol(i));
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 11568
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string S; cin >> S;
    S += 'R';
    queue<int> q;
    int begin = 0;
    for(int i = 1; i < S.size(); ++i) {
        if(S[i] != S[i-1]){
            q.push(i - begin);
            begin = i;
        }
    }
    vector<int> ans(S.size());
    for(int i = 1; i < S.size()-1; ++i) {
        if(S[i] == 'L' && S[i-1] == 'R'){
            int x = q.front(); q.pop();
            ans[i] += x/2;
            ans[i-1] += (x+1)/2;
            x = q.front(); q.pop();
            ans[i] += (x+1)/2;
            ans[i-1] += x/2;
        }
    }
    for(int i = 0; i < S.size() - 1; ++i){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4140
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

int main(void){
	ll k,a,b,c;
	cin >> a >> b >> c >> k;
	cout << ((k%2)?(b-a):(a-b)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define CTOI(x) (x - 'A') 
#define ctoi(x) (x - 'a')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;
}

LL exp(LL a, LL b){
    LL res = 1;
    LL sum = a;
    while(b){
        if(b&1)res = (res * sum) % MOD;
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int count(int x){
    int res = 0;
    while(x){
        res += x & 1;
        x>>=1;
    }
    return res;
}

int main(){
    string str;
    cin >> str;
    REP(i, 3){
        if(str[i] == str[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {
    int n, k;
    cin >> n >> k;
    string str;
    cin >> str;

    vector<LL> nums;
    if (str[0] == '0') nums.push_back(0);
    for (LL i = 0; i < (LL)str.size();) {
        LL j = i;
        while (j < (int)str.size() and str[j] == str[i]) {
            j++;
        }
        nums.push_back(j - i);
        i = j;
    }
    if (str.back() == '0') {
        nums.push_back(0);
    }

    vector<LL> sums((int)nums.size() + 1, 0);
    rep(i, nums.size()) {
        sums[i + 1] = sums[i] + nums[i];
    }

    LL res = 0;
    for (int left = 0; left < (int)sums.size(); left += 2) {
        int right = left + k * 2 + 1;

        if (right >= (int)sums.size()) {
            right = (int)sums.size() - 1;
        }
        res = max(res, sums[right] - sums[left]);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 2100
fun main(args: Array<String>) {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val grid = (0 until h).map { readLine()!!.toCharArray() }.toTypedArray()
    val dx = listOf(0, 1, 1, 1, 0, -1, -1, -1)
    val dy = listOf(-1, -1, 0, 1, 1, 1, 0, -1)
    for (i in 0 until h) {
        for (j in 0 until w) {
            if (grid[i][j] == '.') {
                var cnt = 0
                for (k in 0 until 8) {
                    val x = j + dx[k]
                    val y = i + dy[k]
                    if (x in 0 until w && y in 0 until h) {
                        if (grid[y][x] == '#') cnt++
                    }
                }
                grid[i][j] = '0' + cnt
            }
        }
    }
    println(grid.joinToString("\n") { String(it) })
}


Measured memory_bytes: 38128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int h,w,k;
	cin>>h>>w>>k;
	vector<vector<int>> mat(h,vector<int>(w,0));
	string s;
	for(int i=0; i<h; i++)
	{
		cin>>s;
		for(int j=0; j<(int)s.length(); j++)
			if(s[j]=='1')
				mat[i][j]=1;
	}
	int msC = h+w-2;
	int mhl = 1<<(h-1);
	for(int msk=0; msk<mhl; msk++)
	{
		int hl = __builtin_popcount(msk);
		int vl=0;
		bool poss=1;
		vector<int> hsc(hl+1,0);
		for(int j=0; (j<w) && poss; j++)
		{
			int segpos=0;
			vector<int> thsc(hl+1,0);
			for(int i=0; i<h; i++)
			{
				thsc[segpos]+=mat[i][j];
				if((1<<i)&msk)
					segpos++;
			}
			for(int i=0; i<=hl; i++)
			{
				if(thsc[i]>k)
				{
					poss=0;
					break;
				}
				if((hsc[i]+thsc[i])>k)
				{
					hsc=thsc;
					vl++;
					break;
				}
				hsc[i]+=thsc[i];
			}
		}
		if(poss)
			msC = min(msC,hl+vl);
	}
	cout<<msC<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <string>
#define int long long
#define pii pair<int, int>
using namespace std;

void fast() {
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
}

signed main() {
	fast();
	int a, b;
	cin >> a >> b;
	if (b % a == 0) {
		cout << b + a;
	} else {
		cout << b - a;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>

using namespace std;

int main(){
	double a,b,c,d;
	cin>>a>>b>>c>>d;

	double ans=sqrt(abs(c-a)*abs(c-a)+abs(d-b)*abs(d-b));
	printf("%.7f\n",ans);
	return 0;
}

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

int n, a[100050], l[100050], len = 1;

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

	l[1] = a[1];

	for (int i = 2; i <= n; i++)
	{
		if (a[i] > l[len])
			l[++len] = a[i];
		else
			*lower_bound(l + 1, l + len + 1, a[i]) = a[i];
	}

	cout << len << endl;
	return 0;
}


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

struct Card { char suit, value; };

void bubble(struct Card A[], int N){
    for(int i=0; i<N;i++){
        for(int j= N-1;j>=i; j--){
            if(A[j].value < A[j-1].value){
                Card t =A[j]; A[j]=A[j-1];A[j-1]=t; 
            }
        }
    }
}

void selection(struct Card A[], int N){
    for (int i = 0; i<N; i++){
        int minj = i;
        for(int j=i; j<N;j++){
            if(A[j].value < A[minj].value) minj=j;
        }
        Card t = A[i]; A[i]= A[minj]; A[minj] = t;
    }
}

void print(struct Card A[], int N){
    for(int i=0; i < N; i++){
        if(i>0 ) cout << " ";
        cout <<A[i].suit << A[i].value;
    }
    cout<<endl;
}

//バブルソートと選択ソートの結果を比較
bool isStable(struct Card C1[], struct Card C2[], int N){
    for(int i = 0; i < N; i++){
        if(C1[i].suit != C2[i].suit)return false;
    }
    return true;
}

int main(){
    Card C1[100], C2[100];
    int N;
    char ch;
    cin >>N;
    for(int i =0; i<N;i++){
        cin >>C1[i].suit >>C1[i].value;
    }

    for(int i=0; i<N; i++) C2[i] = C1[i];

    bubble(C1, N);
    selection(C2, N);

    print(C1, N);
    cout <<"Stable"<<endl;
    print(C2, N);
    if(isStable(C1, C2, N)){
        cout <<"Stable"<<endl;
    } else {
        cout << "Not stable" << endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>

using namespace std;

#define INF		(1000000000)
#define MAX_N	(100000+100+1)
#define ABS(val)	(val > 0 ? val : -(val))
int main(int argc,char **arv)
{
	int i,j;
	int N,K;
	int ary[MAX_N];
	long long dp[MAX_N];
	long long tmp;
	for (i = 0; i < MAX_N; i++) {
		dp[i] = INF;
	}

	cin >> N >> K;
	for (i = 0; i < N; i++) {
		cin >> ary[i];
	}

	dp[0] = 0;
	for (i = 0; i < N; i++) {
		for (j = 1; j <= K; j++) {
			tmp = ABS(ary[i+j] - ary[i]) + dp[i];
#if 0
			cout << "pos:" << (i+j) <<", tmp:" << tmp << ", dp[" << i << "]:" << dp[i] << endl;
#endif
			if (tmp < dp[i+j]) {
				dp[i+j] = tmp;
			}
		}
	}

#if 0
	for (i = 1; i < N; i++) {
		cout << "dp[" << i << "]:" << dp[i] << endl;
	}
#endif
	
	cout << dp[N-1] << endl;
	return 0;
}


Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
class Program
{
 
    static void Main()
    {
        int i=0;
        int K = int.Parse(Console.ReadLine());
        string[] AB = Console.ReadLine().Split(' ');
        int A = int.Parse(AB[0]);
        int B = int.Parse(AB[1]);
 
        
        while(true)
        {
            int L = K;
            i += 1;
            K *= i;
            if(K>B)
            {
                Console.WriteLine("NG");
                break;
            }
            if(K >= A && K<=B)
            {
                if (K >= A && K <= B)
                {
                    Console.WriteLine("OK");
                }
                else
                {
                    Console.WriteLine("NG");
                }
                break;
            }
            K = L;
        }
      
    }
}

Measured memory_bytes: 27404
n, y = map(int, input().split())
for a in range(n + 1):
    for b in range(n - a + 1):
        c = n - a - b
        if 10 * a + 5 * b + c == y // 1000:
            print(a, b, c)
            exit()
print(-1, -1, -1)

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

int main() {
  int k,s,count = 0;
  cin >> k >> s;
  for(int x = 0; x <= k; x++){
    for(int y = 0; y <= k; y++){
      if(s - x - y <= k && s - x - y >= 0){
        count++;
      }
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#始めの2匹が決まるとあとは自動的に決まるので矛盾していないかどうか判定

def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N = int(input())
    s = list(input())
    s += s[0]

    def check(p):
        for i in range(1, N+1):
            if s[i]=='o' and p[i]=='S':
                p += p[i-1]
            elif s[i]=='o' and p[i]=='W':
                if p[i-1]=='S':
                    p += 'W'
                else:
                    p += 'S'
            elif s[i]=='x' and p[i]=='S':
                if p[i-1]=='S':
                    p += 'W'
                else:
                    p += 'S'
            else:
                p += p[i-1]
        if p[0]==p[N] and p[1]==p[N+1]:
            print(p[:-2])
            exit()

    for i in ['SS', 'SW', 'WS', 'WW']:
        check(i)
    print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 4516
#include<stdio.h>
int main(void)
{
	int a,s,d[5],f,g,h,j,i,k;
	scanf("%d",&a);
	while(a!=0000){
		s=a;
		h=0;
		k=1;
		while(s!=6174){
			for(i=1;i<=4;i++){
				d[i]=s%10;
				s=s/10;
			}
			if(d[1]==d[2]&&d[2]==d[3]&&d[3]==d[4]){
				k=0;
				break;
			}
			for(i=1;i<=4;i++){
				for(j=i;j<=4;j++){
					if(d[i]<d[j]){
						g=d[i];
						d[i]=d[j];
						d[j]=g;
					}
				}
			}
			h++;
			s=(d[1]*1000+d[2]*100+d[3]*10+d[4])-(d[4]*1000+d[3]*100+d[2]*10+d[1]);
			//printf("%d\n",s);
		}
		if(k==1){
			printf("%d\n",h);
		}
		if(k==0){
			printf("NA\n");
		}
		scanf("%d",&a);
	}
	return 0;
}

Measured memory_bytes: 1036
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second


void solve() {
	char t; cin >> t;
	if (t == 'G')cout << "C" << endl;
	if (t == 'C')cout << "G" << endl;
	if (t == 'T')cout << "A" << endl;
	if (t == 'A')cout << "T" << endl;
}
int main() {
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long double x , y;
	cin>>x>>y;
	
	
	if(x>y){
		printf("GREATER");
		
	}else if(x==y){
		printf("EQUAL");
	}
	else{
		printf("LESS");
	}
	

}

Measured memory_bytes: 256
import copy
from collections import deque
h, w = map(int, input().split())
mapping = [0]*h
for i in range(h):
  mapping[i] = input()

  
already = [[False]*w for i in range(h)]
for i in range(h):
  for j in range(w):
    if mapping[i][j] == "#":
      already[i][j] = True


ans = 0

for i in range(h):
  for j in range(w):
    if already[i][j]:
      continue
    
    yet = copy.deepcopy(already)
    yet[i][j] = True
    not_yet = deque([])
    
    depth = [[0]*w for i in range(h)]
    
    if i != 0 and not yet[i-1][j]:
        not_yet.append([i-1, j])
        depth[i-1][j] = 1
        yet[i-1][j] = True
    if i != h-1 and not yet[i+1][j]:
        not_yet.append([i+1, j])
        depth[i+1][j] = 1
        yet[i+1][j] = True
    if j != 0 and not yet[i][j-1]:
        not_yet.append([i, j-1])
        depth[i][j-1] = 1
        yet[i][j-1] = True
    if j != w-1 and not yet[i][j+1]:
        not_yet.append([i, j+1])
        depth[i][j+1] = 1
        yet[i][j+1] = True
    
    while len(not_yet) > 0:
        key = not_yet.popleft()
        a, b = key[0], key[1]
        
        if a != 0 and not yet[a-1][b]:
            not_yet.append([a-1, b])
            yet[a-1][b] = True
            depth[a-1][b] = depth[a][b]+1
            
        if a != h-1 and not yet[a+1][b]:
            not_yet.append([a+1, b])
            yet[a+1][b] = True
            depth[a+1][b] = depth[a][b]+1
            
        if b != 0 and not yet[a][b-1]:
            not_yet.append([a, b-1])
            yet[a][b-1] = True
            depth[a][b-1] = depth[a][b]+1
            
        if b != w-1 and not yet[a][b+1]:
            not_yet.append([a, b+1])
            yet[a][b+1] = True
            depth[a][b+1] = depth[a][b]+1
            
    for x in range(h):
        for y in range(w):
            if ans < depth[x][y]:
                ans = depth[x][y]
print(ans)

Measured memory_bytes: 3564
"use strict";

var main = function main(input) {
  var S = input.trim();
  var N = S.split('').length;
  var list = [];
  list.push(S);

  for (var i = 0; i < N - 1; i++) {
    var list2 = [];

    for (var j = 0; j < list.length; j++) {
      var s = list[j]; // +入れない方

      list2.push(s); // +入れる方

      var pattern = /[0-9]/;
      var count = 0;
      var sAlter = "";

      for (var k = 0; k < s.split('').length; k++) {
        var c = s.split('')[k];

        if (pattern.test(c)) {
          count++;
        }

        if (count == i + 1) {
          sAlter = s.substring(0, k + 1) + '+' + s.substring(k + 1);
        }
      }

      list2.push(sAlter);
    }

    list = list2;
  }

  var result = 0;
  list.forEach(function (elem) {
    result += parseInt(elem.split('+').reduce(function (prev, current) {
      return parseInt(prev, 10) + parseInt(current, 10);
    }), 10);
  });
  console.log(result);
};

main(require('fs').readFileSync('/dev/stdin', 'utf-8'));

Measured memory_bytes: 23180