akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<functional>

using namespace std;

int main() {
   int N, K;
   cin >> N >> K;
   int choice[ N ];
   for( int i = 0; i < N; i++ ) {
      cin >> choice[ i ];
   }
   int** dp = ( int ** ) malloc( sizeof( int * ) * 2 ) ;
   for( int i = 0; i < 2; i++ ) {
      dp[ i ] = ( int * ) malloc( sizeof( int ) * ( K + 1 ) );
      for( int k = 0; k < K + 1; k++ ) {
         dp[ i ][ k ] = -1;
      }
   }

   function< bool( int, int ) > getDp;
   getDp = [ & ] ( int t, int s ) -> bool {
      if( s <= 0 ) {
         return false;
      }
      if( dp[ t ][ s ] != -1 ) {
         return dp[ t ][ s ] == 1;
      }

      bool outcome = false;
      for( int i = 0; i < N; i++ ) {
         if( choice[ i ] <= s ) {
            outcome = !getDp( 1 - t, s - choice[ i ] );
            if( outcome ) {
               break;
            }
         }
      }
      dp[ t ][ s ] = outcome? 1 : 0;
      return outcome;
   };

   // Tackling the recursion depth
   for( int i = 0; i <= K; i ++ ) {
      getDp( 0, i );
      getDp( 1, i );
   }
   cout << ( getDp( 0, K )? "First" : "Second" );

   return 0;
}


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

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

  priority_queue<ll> a;
  rep(i, n) {
    ll ai;
    cin>>ai;
    a.push(ai);
  }

  rep(i, m) {
    ll t=a.top();
    a.pop();
    a.push(t/2);
  }

  ll sum=0;
  rep(i, n) {
    sum+=a.top();
    a.pop();
  }

  cout << sum << endl;
}


Measured memory_bytes: 1400
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 10005
#define inf 0x3f3f3f3f
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int m,n,k,w[10005],lst[10005];
vector <int> a;
struct edge{
	int to,cap,cst,rev;
};
vector <edge> adj[maxn];
int dis[maxn],h[maxn];
int V,prvv[maxn],prve[maxn],que[maxn],he,ta;
bool inque[maxn];
void addedge(int u,int v,int c,int d){
	adj[u].push_back((edge){v,c,d,(int)adj[v].size()});
	adj[v].push_back((edge){u,0,-d,(int)adj[u].size() - 1});
}
int min_cost_flow(int s,int t,int f){
	memset(h,0,sizeof(h));
	int res = 0;
	bool fir = true;
	while(f > 0){
		memset(dis,0x3f,sizeof(dis));
		dis[s] = 0;
		if(fir){
			memset(inque,0,sizeof(inque));
			he = ta = 0;
			inque[s] = true;
			que[ta++] = s;
			while(he != ta){
				int u = que[he++];
				if(he == V+2) he = 0;
				inque[u] = false;
				for(int i=0;i<adj[u].size();i++){
					edge &e = adj[u][i];
					if(e.cap && dis[u] + h[u] + e.cst - h[e.to] < dis[e.to]){
						dis[e.to] = dis[u] + h[u] + e.cst - h[e.to];
						prvv[e.to] = u;
						prve[e.to] = i;
						if(!inque[e.to]){
							inque[e.to] = true;
							que[ta++] = e.to;
							if(ta == V+2) ta = 0;
						}
					}
				}
			}
			fir = false;
		}else{
			priority_queue <P,vector<P>,greater<P> > que;
			que.push(mp(0,s));
			while(!que.empty()){
				P p = que.top();que.pop();
				int u = p.second;
				if(p.first != dis[u]) continue;
				for(int i=0;i<adj[u].size();i++){
					edge &e = adj[u][i];
					if(e.cap && dis[u] + h[u] - h[e.to] + e.cst < dis[e.to]){
						dis[e.to] = dis[u] + h[u] - h[e.to] + e.cst;
						prvv[e.to] = u;
						prve[e.to] = i;
						que.push(mp(dis[e.to],e.to));
					}
				}
			}
		}
		for(int i=0;i<=V;i++) h[i] += dis[i];
		int flow = f;
		for(int i=t;i!=s;i=prvv[i]){
			flow = min(flow,adj[prvv[i]][prve[i]].cap);
		}
		f -= flow;
		res += flow * h[t];
		for(int i=t;i!=s;i=prvv[i]){
			edge &e = adj[prvv[i]][prve[i]];
			e.cap -= flow;
			adj[e.to][e.rev].cap += flow;
		}
	}
	return res;
}
int main(){
	memset(lst,-1,sizeof(lst));
	scanf("%d%d%d",&m,&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&w[i]);
	}
	for(int i=1;i<=k;i++){
		int x;
		scanf("%d",&x);
		a.push_back(x);
	}
	int sum = 0;
	a.erase(unique(a.begin(),a.end()),a.end());
	k = a.size();
	for(int i=0;i<k-1;i++){
		addedge(i,i+1,m,0);
	}
	for(int i=0;i<k;i++){
		sum += w[a[i]];
		if(lst[a[i]] != -1) addedge(lst[a[i]],i-1,1,-w[a[i]]);
		lst[a[i]] = i;
	}
	V = k-1;
	printf("%d\n",sum + min_cost_flow(0,k-1,m-1));
	return 0;
}


Measured memory_bytes: 4464
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <queue>
#include <array>
#include <random>
#include <chrono>

using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define per(i, a, n) for (int i = n - 1; i >= a; --i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef int64_t i64;
typedef uint64_t ui64;
typedef pair<int, int> pi;

struct custom_hash {
    static ui64 splitmix64(ui64 x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(ui64 x) const {
        static const ui64 FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

template <class T, class U>
inline ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <class T, class U>
inline istream& operator>>(istream& os, pair<T, U>& p) {
    os >> p.first >> p.second;
    return os;
}
template <class T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
    if (v.empty())
        return os;
    if (v.begin() != v.end())
        os << v.front();
    for (auto it = ++v.begin(); it != v.end(); ++it)
        os << ' ' << *it;
    return os;
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
    for (auto& i : v)
        is >> i;
    return is;
}

template <class T, size_t N>
inline istream& operator>>(istream& is, array<T, N>& a) {
    for (auto& i : a)
        is >> i;
    return is;
}

inline void Solve(istream& is, ostream& os) {
    array<string, 4> candidates = {
        "dream",
        "dreamer",
        "erase",
        "eraser",
    };
    string s;
    is >> s;
    vector<int> dp(sz(s) + 1, 0);
    dp.front() = 1;
    rep(i, 0, sz(s)) {
        if (dp[i] == 0) {
            continue;
        }
        for (const auto& t : candidates) {
            if (i + sz(t) <= sz(s) && s.substr(i, sz(t)) == t) {
                dp[i + sz(t)] = 1;
            }
        }
    }
    os << (dp.back() ? "YES" : "NO") << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << setprecision(20) << fixed;
    Solve(cin, cout);
    return 0;
}


Measured memory_bytes: 848
n = int(input())
pp = list(input())
cnt = 0
lis = [0]*n
w = [0]*n
e = [0]*n
if pp[0] =="W":
    w[0] =1
else:
    e[0] =1
for i in range(1,n):
    if pp[i] == "W":
        w[i] = w[i-1]+1
        e[i] = e[i-1]

    else:
        e[i] = e[i-1]+1
        w[i] = w[i-1]
for i in range(1,n):
    lis[i] = w[i-1]+e[n-1]-e[i]
lis[0] = e[n-1]-e[0]

print(min(lis))


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

int n, x, cnt = 0, now = 0;
vector<int> l;

int main() {
  cin >> n >> x;
  l.resize(n);
  for(int i = 0; i < n; ++i) cin >> l[i];
  for(int i = 0; i < n; ++i) {
    now += l[i];
    if(now <= x) ++cnt;
  }
  cout << cnt + 1 << endl;
  return 0;
}

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

int main() {
  int A, B, C;
  scanf("%d%d%d", &A, &B, &C);

  int ans = C - (A - B);
  if (ans >= 0) {
    printf("%d", ans);
  } else {
    printf("0");
  }
  return 0;
}


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

#define log(x) cout << (x) << endl
#define rep(i, n) for (int i = 0; i < (int)n; ++i)

int main() {
    int n, y, a=0, b=0, c=0;
    cin >> n >> y;

    for (int j=0; j<=2000; ++j) {
        a = 10000*j;
        if (a > y) break;
        for (int k=0,l; k<=4000; ++k) {
            b = 5000*k;
            c = y - (a + b);
            if (c%1000||c<0) continue;
            l = c / 1000;
            if (j+k+l == n) {
                printf("%d %d %d\n", j, k, l);
                return 0;
            }
        }
    }

    printf("%d %d %d\n", -1,-1,-1);

    return 0;
}



Measured memory_bytes: 256
x = int(input())
sosu = [int(i) for i in range(2*x)]
sosu[1] = 0
for i in range(2,x):
    if sosu[i]!=0:
        j = 2
        while i * j < 2*x:
            sosu[i*j]=0
            j += 1
#print(sosu[x])
while sosu[x]==0:
    x += 1
print(x)


Measured memory_bytes: 16796
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const ll maxValue = 1e5 + 5 , INF = 1e9 + 7;

int main(){
	ll n , totalW;
	cin>>n>>totalW;
	ll w[n + 1] , v[n + 1] , dp[2][maxValue];
	for(int i = 0; i < n; i++){
	    cin>>w[i]>>v[i];
	}
// 	for(int i = 0; i < n; i++){
// 	    cin>>v[i];
// 	}
	for(int i = 0; i < 2; i++){
	    for(int j = 0; j < maxValue; j++){
	        dp[i][j] = INF;
	    }
	}
	bool in = 0;
	dp[0][0] = 0 , dp[1][0] = 0;
	for(int i = 0; i < n; i++){
	   // cout<<w[i]<<" "<<v[i]<<endl;
	    in = !in;
	   // cout<<in<<" ";
	    for(int j = 1; j < maxValue; j++){
	        if(j >= v[i]){
	           // if(j == v[i]) cout<<i<<" "<<v[i]<<" "<<j<<endl;
	            dp[in][j] = min(dp[!in][j - v[i]] + w[i] , dp[!in][j]);
	        }
	        else{
	            dp[in][j] = dp[!in][j];
	        }
	    }
	   // for(int j = 0; j <= 11; j++){
	   //     (dp[in][j] == INF)?(cout<<"INF "):(cout<<dp[in][j]<<" ");
	   // }
	   // cout<<endl;
	}
	ll ans = 0;
// 	cout<<in<<endl;
	for(int i = 0; i < maxValue; i++){
	   // cout<<dp[0][i]<<" "<<dp[1][i]<<endl;
	    if(dp[in][i] <= totalW){
	        ans = i;
	    }
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5184
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long intS
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    
    int a,b;
    
    cin >> a >> b;
    
    
    if ((a*b)%2 == 1){
    
    cout << "Yes" << endl;
    
    }else{
    
    cout << "No" << endl;
    
    }
    
    
    
    
//////////////////////////////////////////////////////
return 0;}

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

int main(void) {

	int n;
	int x[100];
	int sum = 0;
	int min = 1000000000;

	scanf("%d", &n);

	for (int i = 1; i <= n; i++)scanf("%d", &x[i]);

	for (int i = 0; i <= 100; i++) {
		for (int j = 1; j <= n; j++) {
			sum += pow(x[j] - i, 2);
		}
		if (sum < min)min = sum;
		sum = 0;
	}

	printf("%d\n", min);

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef double db;
const int mod = 1e9 + 7;
const int N = 1e6 + 5;
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll qsm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
int n,m,k,rt;
int isp[N], num[N],cnt;
ll a[N], b[N];
ll inv[N];
void prime(){
    isp[cnt++]=2;
    for(int i=2;i<1000;i++){
        int flag=0;
        for(int j=2;j<=sqrt(i*1.0)+1;j++){
            if(i%j==0){
                flag=1;
                break;
            }
        }
        if(!flag)
            isp[cnt++]=i;
    }
}

int main(){
    prime();
    inv[1]=1;
    rep(i,2,1000000) inv[i]=inv[mod%i]*(mod-mod/i)%mod;
    scanf("%d",&n);
    int bitgest;
    rep(i,1,n){
        scanf("%lld",&a[i]);
        b[i]=a[i];
        int tot;
        rep(j,0,cnt-1){
            tot=0;
            while(a[i]%isp[j]==0){
                a[i]/=isp[j];
                tot++;
            }
            if(tot>num[j]) num[j]=tot;
        }
        if(a[i]>1){
            num[cnt]=1;
            isp[cnt]=a[i];
            ++cnt;
        }
    }
    ll res=1;
    rep(i,0,cnt-1){
        if(num[i]){
            rep(j,1,num[i]) res=res*isp[i]%mod;
        }
    }
    ll ans=0;
    rep(i,1,n) ans = (ans+res%mod*inv[b[i]]%mod)%mod;
    printf("%lld\n",ans);
    return 0;
}
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
int n;
double dp[3000], h, sum;
int main(){
    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("", "r", stdin); freopen("", "w", stdout);
    cin >> n;
    dp[0] = 1;
    for (int i = 1; i <= n; i++){
        cin >> h;
        for (int j = i; j > 0; j--){
            dp[j] = dp[j - 1] * h + dp[j] * (1 - h);
        }
        dp[0] *= (1 - h);
    }
    for (int i = 1; i <= n; i++){
        if (i > n / 2) sum += dp[i];
    }
    printf("%.10lf", sum);
    return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=1e6+10;
const int mod7=1e9+7;
const int mod=1e9+7;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
int main()
{
    int n;read(n);
    string s;cin>>s;
    if(n>=s.size()) cout<<s<<endl;
    else
    {
        for(re int i=0;i<n;i++) putchar(s[i]);
        puts("...");
    }
}

Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner  in= new Scanner(System.in);
		double[] a = new double [6];
		while(true){
			try{
				for(int i = 0;i < 6;i++){
					a[i] = in.nextDouble();
				}
				double x = (a[2]*a[4]-a[5]*a[1])/(a[0]*a[4]-a[3]*a[1]);
				double y = (a[2]-a[0]*x)/a[1];
				double x2 = x*10000;
				double y2 = y*10000;
				if(x2 % 10 >= 5){
		            x2 = x2 + 1;
		        }
		        if(y2 % 10 >= 5){
		            y2 = y2 + 1;
		        }
		        x = x2 / 10000.0;
		        y = y2 / 10000.0;
		        if(x == 0.0){
		        	x = 0.0;
		        }if(y == 0.0){
		        	y = 0.0;
		        }
		        System.out.printf("%1.3f %1.3f\n",x,y);
			}catch(Exception e){
				System.exit(0);
			}
		}
	}
}

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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

#include <boost/operators.hpp>

class modint : private boost::operators<modint>, private boost::equivalent<modint> {
  modint(const long long x, const bool y)
      : x(x) {}

 public:
  static long long M;
  long long x;
  modint(const long long x = 0)
      : x((x % M + M) % M) {}
  modint operator-() const { return modint(x ? M - x : 0, true); }
  modint& operator+=(const modint& b) { return ((x += b.x) >= M ? x -= M : 0), *this; }
  modint& operator++() { return (++x >= M ? x -= M : 0), *this; }
  modint& operator-=(const modint& b) { return ((x -= b.x) < 0 ? x += M : 0), *this; }
  modint& operator--() { return (--x < 0 ? x += M : 0), *this; }
  modint& operator*=(const modint& b) { return x = x * b.x % M, *this; }
  modint& operator/=(const modint& b) { return *this *= b.pow(-1); }
  modint pow(long long b) const {
    long long r = 1, a = x;
    b = (b % (M - 1) + (M - 1)) % (M - 1);
    while (b) {
      if (b & 1) r = r * a % M;
      b = b >> 1;
      a = a * a % M;
    }
    return modint(r, true);
  }
  friend bool operator<(const modint& a, const modint& b) { return a.x < b.x; }
  friend std::istream& operator>>(std::istream& s, modint& a) { return s >> a.x, a = a.x, s; }
  friend std::ostream& operator<<(std::ostream& s, const modint& a) { return s << a.x; }
};
long long modint::M = 1e9 + 7;

map<ll, int>& dl(ll n, map<ll, int>& m) {
  if (n <= 1) return m;
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      ++m[i];
      return dl(n / i, m);
    }
  }
  ++m[n];
  return m;
}

ll a[10000];
int main() {
  int n;
  cin >> n;
  repi(n) cin >> a[i];
  map<ll, int> m;
  repi(n) {
    map<ll, int> m0;
    dl(a[i], m0);
    itr(m0) updatemax(m[v.first], v.second);
  }
  modint lcm(1);
  itr(m) lcm *= modint(v.first).pow(v.second);
  modint res(0);
  repi(n) res += lcm / a[i];
  cout << res << endl;
}


Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const int N=500005;
int n; 
int pos[N];
char ss[N];
int f[N];
int main()
{
	scanf("%d",&n);
	scanf("%s",ss+1);
	for (int u=1;u<=n;u++)
	{
		if (ss[u]=='1')	pos[u]=pos[u-1];
		else pos[u]=u;
	}
	for (int u=1;u<=n;u++)
	{
		f[u]=f[u-1];
		if (ss[u]=='1')
		{
			if (ss[u-1]=='0'&&ss[u-2]=='1')
			{
				f[u]=max(f[u],f[pos[u-2]]+(u-2)-pos[u-2]);
				f[u]=max(f[u],f[pos[u-2]+1]+(u-2)-(pos[u-2]+1));
			}
			else if (pos[u]>1&&ss[pos[u]-1]=='1') f[u]=max(f[u],f[pos[u]-2]+u-pos[u]);
		}
	}
	printf("%d\n",f[n]);
	return 0;
}

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

int main(void){
	std::array<std::array<int,3>,3> grid;
	
	for(int i=0;i<3;i++){
		std::cin>>grid.at(i)[0]>>grid.at(i)[1]>>grid.at(i)[2];
	}

	int jor = grid.at(0)[0] + grid.at(1)[1] + grid.at(2)[2];
	int sub = grid.at(1)[0] + grid.at(2)[0] + grid.at(0)[1] + grid.at(2)[1] + grid.at(0)[2] + grid.at(1)[2];

	if(jor * 2 == sub){
		std::cout<<"Yes"<<std::endl;
	}else{
		std::cout<<"No"<<std::endl;
	}
	return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main(){
	int n;
	cin>>n;
	string s;
	int ac=0,wa=0,tle=0,re=0;
	rep(i,n){
		cin>>s;
		if(s[0]=='A')ac++;
		else if(s[0]=='W')wa++;
		else if(s[0]=='T')tle++;
		else if(s[0]=='R')re++;
	}
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<re<<endl;
	return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  for(int N; cin >> N && N;) {
    int cnt[41];
    rep(i, N) {
      string s; cin >> s;
      cnt[i] = s.size();
    }
    const array<int, 5> arr{{5,7,5,7,7}};
    rep(st, N) {
      int sum = 0;
      int curr = 0;
      bool ok = 0;
      REP(i, st, N) {
        sum += cnt[i];
        if(sum == arr[curr]) {
          curr++;
          sum = 0;
          if(curr >= arr.size()) {
            ok = 1;
            break;
          }
        }
        if(sum > arr[curr]) {
          break;
        }
      }
      if(ok) {
        cout << st + 1 << endl;
        break;
      }
    }

  }
  
  return 0;
}

Measured memory_bytes: 3084
#include <stdio.h>
#include <algorithm>
#include <string.h>

using namespace std;
int a[200005],b[100005];

int main()
{
    int n;
    int m;
    while(~scanf("%d%d",&n,&m))
    {
        memset(a,0,sizeof(a));
        int len=0;
        while(m--)
        {
            int x;
            scanf("%d",&x);
                b[len++]=x;
        }
        for(int i=len-1;i>=0;i--)
        {
            if(a[b[i]]==0)
            {
                printf("%d\n",b[i]);
                a[b[i]]=1;
            }
        }
        for(int i=1;i<=n;i++)
            if(a[i]==0)printf("%d\n",i);

    }

    return 0;
}

Measured memory_bytes: 3920
#include <iostream>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  int ans = 0;
  if (a == 1) ans += 3e5;
  else if (a == 2) ans += 2e5;
  else if (a == 3) ans += 1e5;
  if (b == 1) ans += 3e5;
  else if (b == 2) ans += 2e5;
  else if (b == 3) ans += 1e5;
  cout << ((ans == 6e5) ? (int)(10e5) : ans) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;

const int N=100007;
int ARR[N],b[N],t,k; 
long long ans;
int main()  
{  
    int n;
    while(~scanf("%d",&n))
    {
    	for(int i = 0;i < n; i++)
    	{
    		scanf("%d",&ARR[i]);
    	}
    	sort(ARR,ARR+n);
    	int s=ARR[0];
    	t=0;
    	for(int i = 1;i < n; i++)
    	{
    		if(ARR[i]==s)
    		{
    			k=t;
    			b[t++]=s;
    		}
    		else
    		{
    			s=ARR[i];
    		}
    	}
    	if(t<2)
    	{
    		ans=0;
    	}
    	else
    	{
    		ans=b[t-1];
			if(b[t-1]==b[t-2])
			{
				ans*=b[t-3];
			}
			else
			{
				ans*=b[t-2];
			}
    	}
    	printf("%lld\n",ans);
    	
    }
     
}  



Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;

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

    vector<int>oks(N+1,true);
    for(int i=0;i<M;++i){
        int a;
        cin>>a;
        oks[a]=false;
    }

    vector<long long int>dp(N+1);
    dp[0]=1;
    for(int now=0;now<N;++now){
        for(int next=now+1;next<=min(N,now+2);++next){
            if(oks[next]){
                dp[next]+=dp[now];
                dp[next]%=mod;
            }
        }
    }

    cout<<dp[N]<<endl;
    return 0;
}

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

int main() {
    string s, t; cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());//, greater<string>());
    string t2 = "";
    for (int i = t.size()-1; i >= 0; i--) {
        t2.push_back(t[i]);
    }
    
    if (s < t2) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
        int a, b, c, d, e, f;
        double y;
        std::cout.precision(3);
        std::cout.setf(std::ios::fixed);
        while(std::cin >> a >> b >> c >> d >> e >> f)
        {
                if(a != 0)
                {
                        y = (f - d*c/(double)a)/(e - d*b/(double)a);
                        std::cout << (c - b*y)/a << " " << y << std::endl;
                }
                else
                {
                        y = c/(double)b;
                        std::cout << (f - e*y)/d << " " << y << std::endl;
                }
        }
        return 0;
}

Measured memory_bytes: 1236
import java.util.*;

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        for (int i = 0; i < 100000; i++) {
            if ((int)(i * 0.08) == a && (int)(i * 0.1) == b) {
                System.out.println(i);
                return;
            }
        }
        System.out.println("-1");

    }

}


Measured memory_bytes: 23636
package main

import (
	"fmt"
)

func main() {
	var n, m, q int
	fmt.Scan(&n, &m, &q)

	L, R := make([]int, m), make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&L[i], &R[i])
	}

	P, Q := make([]int, q), make([]int, q)
	for i := 0; i < q; i++ {
		fmt.Scan(&P[i], &Q[i])
	}

	T := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		T[i] = make([]int, n+1)
	}
	for i := 0; i < m; i++ {
		T[L[i]][R[i]]++
	}

	for i := 0; i <= n; i++ {
		sum := 0
		for j := 0; j <= n; j++ {
			sum += T[i][j]
			T[i][j] = sum
		}
	}

	for i := 0; i < q; i++ {
		l, r := P[i], Q[i]
		num := 0
		for j := l; j <= r; j++ {
			num += T[j][r] - T[j][l-1]
		}
		fmt.Println(num)
	}
}


Measured memory_bytes: 11520
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
int l[100000], r[100000], s[100000] = { 0 };
int main()
{
	int N, Q;
	char S[100000];
	scanf("%d%d%s", &N, &Q, S);
	for (int i = 0; i < Q; i++) {
		scanf("%d%d", &l[i], &r[i]);
	}
	s[0] = 0;
	int i = 1;
	while (S[i] != '\0') {
		s[i] = s[i - 1];
		if (S[i] == 'C' && S[i - 1] == 'A') {
			s[i]++;
		}
		//printf("%d\n", s[i]);
		i++;
	}
	for (int i = 0; i < Q; i++) {
		printf("%d\n", s[r[i] - 1] - s[l[i] - 1]);
	}
	return 0;
}

Measured memory_bytes: 2048
N = int(input())
A = list(map(int,input().split()))
# ((A合計**2)-ΣAそれぞれ**2)//2
mod = 10**9+7
AA = sum(A)
ans = (AA%mod)**2
ans %= mod
for a in A:
    ans -= a**2
    ans %= mod
ans %= mod
print(ans*pow(2,mod-2,mod)%mod)

Measured memory_bytes: 105148
#include<stdio.h>
int main(void)
{
  int n,i,count=0,hight=0,h;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d ",&h);
    if(hight<=h){
      hight=h;
      count++;
    }
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{//2<3<4<5<6<7<8<9<10<11<12<13<1
   int a,b;
   cin>>a>>b;
   if(a>b&&b!=1)
   {
       cout<<"Alice";
   }
   else if(a>b&&b==1)
   {
       cout<<"Bob";
   }
   else if(a<b&&a!=1)
   {
      cout<<"Bob"; 
   }
   else if(a<b&&a==1)
   {
      cout<<"Alice"; 
   }
   else if(a==b)
   {
       cout<<"Draw";
   }
   
   
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
#define vv(a,b) vector< vector<int> > v(a,vector<int>(b,0));
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int mod =1e9+1;
vector<int>c;
vector< vector<int> >dat;
int n,m,x;
ll anscost=1e7;



void bfs(int a,vector<int> b,ll cost)
{
    bool flag=true;
    rep(i,m)
    {
        if(b[i]<x)flag=false;
    }
    if(flag)
    {
        anscost=min(anscost,cost);
        return;
    }
    if(a<n-1)
    {
        bfs(a+1,b,cost);
        rep(i,m)
        {
            b[i]+=dat[a+1][i];
        }
        bfs(a+1,b,cost+c[a+1]);

    }
    return;

}

int main()
{
    cin>>n>>m>>x;
    c=vector<int>(n);
    dat=vector< vector<int>>(n,vector<int>(m,0));
    rep(i,n)
    {
        cin>>c[i];
        rep(j,m)
        {
            cin>>dat[i][j];
        }
    }
    vector<int> know(m,0);
    bfs(-1,know,0);
    if(anscost!=1e7)
    {
        cout<<anscost<<endl;
    }
    else
    {
        cout<<-1<<endl;
    }
    


}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <iomanip>
 
using namespace std;
 
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLDLD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VB;
 
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define endl "\n"
 
const LD eps=1e-10;
const long long INFLL=(LL)(1e9)*(LL)(1e9);
const int INF=1e9;
 
template<class T>
void chmin(T& a, const T b)
{
	if(a>b)
		a=b;
}
template<class T>
void chmax(T& a, const T b)
{
	if(a<b)
		a=b;
}
 
const LL pow(const LL p, const LL q)
{
	LL t=1;
	for(int i=0;i<q;i++)
		t*=p;
	return t;
}

template <typename T>
struct has_iter
{
	private:
		template <typename U>
		static constexpr true_type check(typename U::iterator*);
		template <typename U>
		static constexpr false_type check(...);

	public:
		static constexpr bool value = decltype(check<T>(nullptr))::value;
};


template<typename T, typename U = typename T::iterator>
void print(const T& container)
{
		auto&& first=begin(container), last=end(container);
		auto&& back=prev(last);
		for(auto e=first; e!=last; e=next(e))
			cout<<*e<<" \n"[e==back];
}


extern void* enabler;
template<typename Head, typename enable_if<!has_iter<Head>::value>::type*& = enabler>
void print(const Head& head)
{
	cout<<head<<endl;
}

template<> void print<string>(const string& container)
{
	cout<<container<<endl;
}

template<typename Head, typename... Tail>
void print(const Head& head, const Tail&... tail)
{
	cout<<head<<" ";
	print(tail...);
}

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

template<typename T>
istream& operator >> (istream& is, vector<T>& vec)
{
	for(T& x: vec) is >> x;
	return is;
}


template<typename T, typename U>
ostream& operator << (ostream& os, const pair<T, U>& p)
{
	os<<'('<<p.first<<", "<<p.second<<')';
	return os;
}

template<typename T>
vector<T> read(int n)
{
	vector<T> t(n);
	cin>>t;
	return t;
}

template<typename T>
T read()
{
	T t;
	cin>>t;
	return t;
}

template<typename Head, typename... Tail>
struct vector_demensions
{
	using type=vector<typename vector_demensions<Tail...>::type>;
};

template<typename Head>
struct vector_demensions<Head> { using type=Head; };

template<typename T>
vector<T> make_vectors(int size, T val)
{
	return vector<T>(size, val);
}

template<typename T=int, typename... Args>
auto make_vectors(int size, Args... tail)
	-> typename vector_demensions<Args..., T>::type
{
	auto val=make_vectors<T>(forward<Args>(tail)...);
	return vector<decltype(val)>(size, val);
}



int main()
{
	LL a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k%2==0)
		print(a-b);
	else
		print(b-a);
}


Measured memory_bytes: 764
#include <stdio.h>

int main(void) {
	int r, g, b, number;
	scanf("%d %d %d", &r, &g, &b);
	number = 100 * r + 10 * g + b;
	if (number % 4 == 0) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}
	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, x, t;
  cin >> n >> x >> t;
  int g = n/x;
  if(x*g!=n) g++;
  cout<<g*t<<endl;
  return 0;
}


Measured memory_bytes: 3640
from collections import Counter

while 1:
    try:
        puzzle = map(int, raw_input())
    except EOFError:
        break
    ret = []
    for i in xrange(1, 10):
        cnt = Counter(puzzle + [i])
        if cnt[i] > 4:
            continue
        for j in xrange(1, 10):
            if cnt[j] < 2:
                continue
            tmp = Counter(puzzle + [i])
            tmp[j] -= 2
            for k in xrange(1, 10):
                if not tmp[k]:
                    continue
                if tmp[k] >= 3:
                    tmp[k] -= 3

                while tmp[k] and tmp[k + 1] and tmp[k + 2]:
                    tmp[k] -= 1
                    tmp[k + 1] -= 1
                    tmp[k + 2] -= 1
                if tmp[k]:
                    break
            else:
                ret.append(i)
                break
    if ret:
        print ' '.join(map(str, ret))
    else:
        print 0

Measured memory_bytes: 4592
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX_SIZE 1000

int main(){

  char data[MAX_SIZE];
  int i;

  //??????????????\???
  fgets(data, sizeof(data), stdin);

  //apple???peach?????????
  for(i=0;i<MAX_SIZE;i++){

    if( data[i] == 'a' && data[i+1] == 'p' && data[i+2] == 'p' &&
        data[i+3] == 'l' && data[i+4] == 'e'){

      data[i]   = 'p';
      data[i+1] = 'e';
      data[i+2] = 'a';
      data[i+3] = 'c';
      data[i+4] = 'h';


    }

    //peach???apple?????????
    else if( data[i] == 'p' && data[i+1] == 'e' && data[i+2] == 'a' &&
             data[i+3] == 'c' && data[i+4] == 'h'){

      data[i]   = 'a';
      data[i+1] = 'p';
      data[i+2] = 'p';
      data[i+3] = 'l';
      data[i+4] = 'e';

    }

  }

  printf("%s",data);

  return 0;

}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A1, A2, A3;
  cin >> A1 >> A2 >> A3;
  printf("%s\n", (A1+A2+A3)>=22?"bust":"win");
}

Measured memory_bytes: 256
def main():
    n = int(input())
    flg = 0
    val=0
    ans=0
    ns = str(n)
    nl = len(ns)
    tmp = [[0]*10 for i in range(11)]
    for i in range(1,n+1):
        s = str(i)
        top = int(s[0])
        btm = int(s[-1])
        tmp[top][btm] += 1

    for i,a in enumerate(tmp):
        for j,b in enumerate(a):
            if b != 0:
                ans += b*tmp[j][i]
    print(ans)





if __name__=='__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int MOD = 1000000007;

vector<pair<ll,ll>> factorization(ll a){
    vector<pair<ll, ll>> factorize;
    for(int i = 2; i * i <= a; i++){
        if (a % i != 0) continue;
        ll cnt = 0;
        while(a % i == 0){
            a /= i;
            cnt++;
        }
        factorize.push_back({i, cnt});
    }
    if (a != 1) factorize.push_back({a, 1});
    return factorize;
}



int main(void){
    int A, B, C, D; cin >> A >> B >> C >> D;
    
    int cnt = 0;
    while(A > 0 && C > 0){
        if (cnt % 2 == 0){
            C -= B;
        }else{
            A -= D;
        }
        cnt++;
    }
    if (A <= 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main()
{
    int n,k,minn,maxn;
    scanf("%d",&n);
    scanf("%d",&k);
    minn=maxn=k;
    for (int i=1;i<n;i++)
    {
        scanf("%d",&k);
        if (k<minn) minn=k;
        if (k>maxn) maxn=k;
    }
    printf("%d\n",maxn-minn);
    return 0;
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct BIT{
  int n;
  vector<ll> bit;
  BIT(int size):n(size),bit(size+1,0){}

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

  void add(int i,ll v){
    if(i==0)return ;
    while(i<=n){
      bit[i]+=v;
      i+=i&-i;
    }
  }

  ll lower_bound(ll w){
    if(w<=0)return 0;
    ll x=0,r=1;
    while(r<n)r<<=1;
    for(ll k=r;k>0;k>>=1){
      if(x+k<=n&&bit[x+k]<w){
        w-=bit[x+k];
        x+=k;
      }
    }
    return x+1;
  }
};

ll n,m;
ll a[100010],b[100010],sum[100010];

bool ok(ll X){
  rep(i,n){
    if(a[i]<=X)b[i]=1;
    else b[i]=0;
  }
  rep(i,n){
    sum[i+1]=sum[i]+b[i];
  }
  const ll B=100010;
  BIT bit(2*B+10);
  ll cnt=0;
  rep(r,n+1){
    cnt+=bit.sum(2*sum[r]-r-1+B);
    bit.add(2*sum[r]-r+B,1);
  }
  return cnt>=m;
}

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

  cin>>n;
  rep(i,n)cin>>a[i];
  m=(n*(n+1)/2)/2+1;

  ll lb=0,ub=1e9;
  while(ub-lb>1){
    ll mid=(lb+ub)/2;
    if(ok(mid))ub=mid;
    else lb=mid;
  }
  cout<<ub<<endl;

  return 0;
}


Measured memory_bytes: 4224
N = int(input())
T = list(map(int, input().split()))
sumT = sum(T)
M = int(input())
PX = [list(map(int, input().split())) for _ in range(M)]
for i in range(M):
    p, x = PX[i]
    print(sumT-T[p-1]+x)

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <array>
#include <stack>
#include <queue>
#include <chrono>
#include <numeric>
#include <memory.h>
#include <map>
#include <math.h>
#include <utility>
#include <set>

#pragma warning(disable:4996)
using namespace std;
#define REP(i,n) for(int i = 0 ; i < n ; ++i)
typedef long long Int;
const double PI = 3.141592653589793238;
const Int INF = 999999999999;
typedef pair<int, int> P;

int S[3][3] = {
		{ 0, 1, 0 },
		{ 1, 1, 1 },
		{ 0, 1, 0 },
};
int M[3][3] = {
		{ 1, 1, 1 },
		{ 1, 1, 1 },
		{ 1, 1, 1 },
};
int L[5][5] = {
		{ 0, 0, 1, 0, 0 },
		{ 0, 1, 1, 1, 0 },
		{ 1, 1, 1, 1, 1 },
		{ 0, 1, 1, 1, 0 },
		{ 0, 0, 1, 0, 0 },
};

string week[7]{
		"Monday",
		"Tuesday",
		"Wednesday",
		"Thursday",
		"Friday",
		"Saturday",
		"Sunday"
};

int dd[11]{3,1,3,2,3,2,3,3,2,3,2};

int main()
{
	int m, d;
	while (cin >> m >> d, m&&d){
		int start = 3;
		int di(0);
		for (int i = 1; i < m; ++i){
			di += dd[i - 1];
		}
		di += (d - 1) % 7;
		di += start;
		di %= 7;
		cout << week[di] << endl;
	}
	return 0;

}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll H, W;
  cin >> H >> W;

  rep(i, W + 2) cout << "#";
  ENDL;

  rep(i, H) {
    cout << "#";
    string s;
    cin >> s;
    cout << s;
    cout << "#" << endl;
  }
  rep(i, W + 2) cout << "#";
  ENDL;
  return 0;
}

Measured memory_bytes: 3672
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right){
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for(i=0; i<n1; i++) L[i] = A[left + i];
    for(i=0; i<n2; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for(k=left; k<right; k++){
        if(L[i].value <= R[j].value){
            A[k] = L[i++];
        }else{
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right){
    int mid;
    if(left + 1 < right){
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r){
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p-1;
    for(j=p; j<r; j++){
        if(A[j].value <= x.value){
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i+1]; A[i+1] = A[r]; A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r){
    int q;
    if(p<r){
        q = partition(A, n, p, r);
        quickSort(A, n, p, q-1);
        quickSort(A, n, q+1, r);
    }
}

int main(){
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for(i=0; i<n; i++){
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n); //マージソートでは、rightの項を見ないので、ひとつ要素数が多くなっている
    quickSort(B, n, 0, n-1);

    for(i=0; i<n; i++){
        //マージソートとクイックソートの結果を比べる
        if(A[i].suit != B[i].suit) stable = 0;
    }

    if( stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for(i=0; i<n; i++){
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}


Measured memory_bytes: 5032
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://agc014.contest.atcoder.jp/tasks/agc014_a>
問題文============================================================
 高橋君と青木君とすぬけ君はそれぞれクッキーを A,B,C 個持っています。
 
 この 3 人はお互いにクッキーを交換することにしました。具体的には、以下の操作を繰り返します。
 
 3 人は同時に、各々が持っているクッキーを半分ずつに分けて、残りの 2 人にそれぞれ一方を渡す。
 ただし、誰かの持っているクッキーの個数が奇数個になったら、そこで操作を繰り返すのをやめます。
 
 さて、クッキーの交換は何回行うことができるでしょうか。 ただし、無限に続けられる場合もあることに注意してください。
=================================================================

解説=============================================================

 貪欲シミュレーションでok
 
================================================================
*/

bool check(ll A,ll B,ll C){
    return (A|B|C)&1;
}
void exchange(ll &A,ll& B,ll &C){
    ll tA = B/2 + C/2;
    ll tB = A/2 + C/2;
    ll tC = A/2 + B/2;
    A = tA;
    B = tB;
    C = tC;
}
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll A,B,C; cin >> A >> B >> C;
    for(int i = 0; i < 10000000;i++){
        if(check(A,B,C)){
            cout << i << endl;
            return 0;
        }
        exchange(A,B,C);
    }
    cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <map>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint l[100005], r[100005];
map<llint, llint> mp;
vector<P> vec;
P L[100005], R[100005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> l[i] >> r[i];
		if(mp.count(l[i]) == 0) mp[l[i]] = r[i];
		else mp[l[i]] = min(mp[l[i]], r[i]);
	}
	
	llint mn = inf;
	auto it = mp.end();
	do{
		it--;
		if(it->second < mn){
			vec.push_back(*it);
			mn = it->second;
		}
	}while(it != mp.begin());
	
	int m = vec.size();
	vec.push_back(make_pair(-inf, -inf));
	sort(vec.begin(), vec.end());
	
	llint ans = 0;
	L[0] = make_pair(-inf ,inf);
	for(int i = 1; i <= n; i++){
		L[i] = make_pair(max(L[i-1].first, l[i]), min(L[i-1].second, r[i]));
	}
	R[n+1] = make_pair(-inf ,inf);
	for(int i = n; i >= 1; i--){
		R[i] = make_pair(max(R[i+1].first, l[i]), min(R[i+1].second, r[i]));
	}
	for(int i = 1; i <= n; i++){
		llint ub = min(L[i].second, R[i+1].second), lb = max(L[i].first, R[i+1].first);
		ans = max(ans, r[i]-l[i]+1 + max(0LL, ub-lb+1));
	}
	
	
	L[0] = make_pair(-inf ,inf);
	for(int i = 1; i <= m; i++){
		L[i] = make_pair(max(L[i-1].first, vec[i].first), min(L[i-1].second, vec[i].second));
	}
	R[m+1] = make_pair(-inf ,inf);
	for(int i = m; i >= 1; i--){
		R[i] = make_pair(max(R[i+1].first, vec[i].first), min(R[i+1].second, vec[i].second));
	}
	
	llint mxlen = -inf, mnlen = inf;
	for(int i = 1; i <= n; i++){
		mxlen = max(mxlen, r[i]-l[i]+1);
		mnlen = min(mnlen, r[i]-l[i]+1);
	}
	ans = max(ans, mxlen);
	if(m == 1) ans = mxlen + mnlen;
	
	for(int i = 1; i < m; i++){
		ans = max(ans, max(0LL, L[i].second-L[i].first+1) + max(0LL, R[i+1].second-R[i+1].first+1));
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 12916
#include <stdio.h>
#include <stdlib.h>
typedef struct tuple{
    int n;
    int count;
}tuple;
int compare_descending(const void * a , const void * b){
    return ((tuple*)b)->count - ((tuple*)a)->count;
}

int N, K;
tuple tuples[200001]; //1-based

int main(void){
    scanf("%d %d",&N,&K);
    for(int i = 0; i <= N; i++){
        tuples[i].n = i;
        tuples[i].count = 0;
    }
    
    int A;
    for(int i = 0; i < N; i++){
        scanf("%d",&A);
        tuples[A].count++;
    }
    
    qsort(tuples,200001,sizeof(tuple),compare_descending);
    /*for(int i = 0; i <= N; i++){
        printf("%d",tuples[i].count);
    }puts("");
    for(int i = 0; i <= N; i++){
        printf("%d",tuples[i].n);
    }puts("");*/
    int ret = 0;
    for(int i = K ; i <= N; i++){
        ret += tuples[i].count;
    }
    printf("%d\n",ret);
}

Measured memory_bytes: 3324
from networkx import *
h,w=map(int,input().split())
G=DiGraph()
G.add_nodes_from(range(10))
C=[[*map(int,input().split())]for _ in "_"*10]
G.add_weighted_edges_from([(i,j,C[i][j])for i in range(10)for j in range(10)])
S=[single_source_dijkstra_path_length(G,i)[1]for i in range(10)]
A=[[*map(int,input().split())]for _ in "_"*h]
print(sum(S[abs(x)] for a in A for x in a))

Measured memory_bytes: 53804
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<functional>

#define REP(i,n) for(int i=0;i<n;i++)
#define ll long long int

using namespace std;

int to_int(string s) {
  return atoi(s.c_str());
}

//vector<ll> a;

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

 // a.reserve(n);
  int a[300000];
  for(int i=0;i<n;i++) {
    cin >> a[i];
    a[i] -= i+1;
  }

  sort(a, a+n);
  long long  b;
  if(n%2 == 0) {
    b = a[n/2 -1];
  } else {
    b = a[(n-1)/2];
  }

  long long  r = 0;

  for(int i=0;i<n;i++) {
    r += abs(a[i] - b);
  }

  cout << r << endl;
return 0;
}


Measured memory_bytes: 1024