akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;

long long n, m;
int mod = 1e9 + 7;

int main() {
    cin >> n >> m;
    long long sumX = 0, sumY = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        sumX += (2 * i - n + 1) * x % mod;
        sumX %= mod;
    }
    
    for (int i = 0; i < m; i++) {
        int y;
        cin >> y;
        sumY += (2 * i - m + 1) * y % mod;
        sumY %= mod;
    }
    
    cout << sumX * sumY % mod << endl;
}

Measured memory_bytes: 256
A,B=raw_input,range;n,m,q=map(int,A().split());s=[map(int,A())for _ in[0]*n]
def f(a):
 z=[[x*y for(x,y)in zip(t,u)]+[0,0]for(t,u)in zip(s,a)]+[[0]*m,[0]*m]
 def g(p):
	for i in B(n):
	 for j in B(m):z[i][j]+=z[i-p][j-1+p]
 g(1);g(0);return z
a,b,c=f([[1]*m]*n),f(t[1:]for t in s),f(s[1:])
for _ in[0]*q:x,y,z,w=map(int,A().split());g=lambda d,p,q:d[x-2][y-2]+d[z-p][w-q]-d[x-2][w-q]-d[z-p][y-2];print g(a,1,1)-g(b,1,2)-g(c,2,1)

Measured memory_bytes: 188988
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;
ll mod;
vector<vector<ll>> to;
vector<ll> dp[100001];
ll ans[100001];

ll dfs(ll v,ll p=-1)
{
  ll m=to[v].size();
  dp[v].resize(m);
  ll res=1;
  rep(i,m)
  {
    ll u=to[v][i];
    if(u==p)continue;
    dp[v][i]=(dfs(u,v)+1)%mod;
    res=(ll)res*dp[v][i]%mod;
  }
  return res;
}
void efs(ll v,ll x,ll p=-1)
{
  ll m=to[v].size();
  rep(i,m)
  {
    ll u=to[v][i];
    if(p==u)dp[v][i]=(x+1)%mod;
  }
  vector<ll>l=dp[v],r=dp[v];
  rep(i,m-1)l[i+1]=((ll)l[i]*l[i+1])%mod;
  for(ll i=m-1;i>=1;i--)r[i-1]=(ll)r[i]*r[i-1]%mod;
  ans[v]=l.back();
  rep(i,m)
  {
    ll u=to[v][i];
    if(u==p)continue;
    x=1;
    if(i)x=(ll)x*l[i-1]%mod;
    if(i+1<m)x=(ll)x*r[i+1]%mod;
    efs(u,x,v);
  }

}


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin>>n>>mod;
  to.resize(n);
  if(n==1){cout<<1<<endl;return 0;}
  rep(i,n-1)
  {
    ll a,b;
    cin>>a>>b;
    a--;b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ll x=dfs(0);
  efs(0,x);
  rep(i,n)
  {
    cout<<ans[i]<<"\n";
  }
  cout<<flush;

  return 0;

}


Measured memory_bytes: 25472
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  $t = array_map("intval", explode(" ", trim(fgets(STDIN))));

  $sum = array_sum($t);

  list($m) = explode(" ", trim(fgets(STDIN)));

  for($i=0; $i<$m; $i++){
    list($p, $x) = explode(" ", trim(fgets(STDIN)));
    echo $sum + $x - $t[$p-1].PHP_EOL;
  }
  

Measured memory_bytes: 16252
#include <stdio.h>

#define MAN 10000
#define GOSEN 5000
#define SEN 1000

int main(){
    int N,Y;
    scanf("%d%d",&N,&Y);
    int x,y,z;
    int flag = 0;
    for(x=0;x<=N;x++){
        for(y=0;y+x<=N;y++){
            if(x*MAN+y*GOSEN+(N-x-y)*SEN==Y ){
                flag = 1;
                goto tag;
            }
        }
    }tag:
    if(flag == 1){
        printf("%d %d %d\n",x,y,N-x-y);
    }else printf("-1 -1 -1\n");
    return 0;
}

Measured memory_bytes: 128
# Date [ 2020-08-22 21:07:07 ]
# Problem [ d.py ]
# Author Koki_tkg

import sys;      from decimal import Decimal
import math;     from itertools import combinations, product
import bisect;   from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

import numpy as np
from numba import i8, njit, u1, b1
from heapq import heappop, heappush

#@njit(i8(b1[:,:], i8, i8, i8, i8), cache=True)
def solve(grid, ch, cw, dh, dw):
    h, w = grid.shape
    
    dist = np.full((h, w), INF, dtype=np.int64)
    dist[ch][cw] = 0

    que = [(0, ch, cw)]

    while que:
        cnt, y, x = heappop(que)

        if y == dh and x == dw:
            break

        for dy in range(-2, 3):
            for dx in range(-2, 3):
                if dx == 0 and dy == 0:
                    continue

                if abs(dx) == 2 or abs(dy) == 2 or (abs(dx) == 1 and abs(dy) == 1):
                    warp = 1
                else:
                    warp = 0

                nx, ny = x + dx, y + dy
                if nx < 0 or nx >= w or ny < 0 or ny >= h or grid[ny][nx]:
                    continue
                
                if dist[ny][nx] > cnt + warp:
                    dist[ny][nx] = cnt + warp
                    heappush(que, (cnt + warp, ny, nx))

    if dist[dh][dw] == INF:
        return - 1
    else:
        return dist[dh][dw]


def Main():
    H, W = read_ints()
    ch, cw = read_ints(); ch -= 1; cw -= 1
    dh, dw = read_ints(); dh -= 1; dw -= 1

    grid = np.array([[g == '#' for g in read_str()] for _ in range(H)])
    
    print(solve(grid, ch, cw, dh, dw))

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve','(b1[:,:], i8, i8, i8, i8,)')(solve)
    cc.compile()

if __name__ == '__main__':
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit()
    from my_module import solve
    Main()


Measured memory_bytes: 108676
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
using namespace std;
#define REP(i,a,n) for(int i = a ; i < n ; i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

void solve(){
}

int main(){
  vector<int> a(10);
  vector<int> b(10);
  rep(i,10) cin>>a[i];
  rep(i,10) cin>>b[i];
  sort(a.rbegin(),a.rend());
  sort(b.rbegin(),b.rend());
  cout<<a[0]+a[1]+a[2]<<" "<<b[0]+b[1]+b[2]<<endl;
}

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

int main() {
  int N;
  long long K;
  cin >> N >> K;
  vector<pair<int, int>> AB(N);
  for (int i = 0, a, b; i < N && cin >> a >> b; i++) AB.at(i) = {a, b};
  sort(AB.begin(), AB.end());

  int ans = 0;
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    sum += AB.at(i).second;
    if (sum >= K) {
      cout << AB.at(i).first << "\n";
      break;
    }
  }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll long long
#define lld long double
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
const int N = 101000,mod = 998244353;
ll p[N];
int n;
struct graph{
	int hsh[N],f[N],m,n;
	ll h[N];
	vector<int> e[N];
	void init(int S){
		n=S;
		read(m);
		for(int i=1;i<=m;i++){
			int x,y;read(x);read(y);
			if(x>y) swap(x,y);
			e[x].push_back(y);
		}
		for(int i=n;i;i--){
			for(int v:e[i]) hsh[f[v]]++;
			while(hsh[f[i]]) f[i]++;
			h[f[i]]=(h[f[i]]+p[i])%mod;
			for(int v:e[i]) hsh[f[v]]--;
		}
	}
}Gx,Gy,Gz;
int main(){
	read(n);
	p[0]=1;p[1]=1000000000000000000ll%mod;
	for(int i=2;i<=n;i++) p[i]=p[i-1]*p[1]%mod;
	Gx.init(n);
	Gy.init(n);
	Gz.init(n);
	int K=500;
	ll ans=0;
	for(int i=0;i<=K;i++)
		for(int j=0;j<=K;j++)
			ans=(ans+Gx.h[i]*Gy.h[j]%mod*Gz.h[i^j])%mod;
	cout<<ans<<'\n';
	return 0;
}



Measured memory_bytes: 17024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n; cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end(), [](int a, int b) {return a>b;});
  int ans=0;
 rep(i,n) {
    if(!(i&1)) ans+=a[i];
    else ans -= a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		if(a*b%2==0){
			System.out.println("Even");
		}
		else{
			System.out.println("Odd");
		}}}

Measured memory_bytes: 35784
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
using namespace std; 
 
const int N = 5e5 + 1000, OO = 1e9, M = 998244353, P = 6151, SQ = 1000, lg = 12;
typedef pair <int, int> pii;
bool b[N];

int32_t main() {
    use_fast;
    int n = 5e5;
    b[1] = true;
    for(int i = 2; i <= n; i++) {
    	if(b[i])
    		continue;
		for(int j = i * i; j <= n; j += i)
			b[j] = true;
	}
	int x;
	cin >> x;
	for(int i = x; i <= n; i++) 
		if(b[i] == false)
			return cout << i, 0;
	return 0; 
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/	

Measured memory_bytes: 768
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int c = s.nextInt();
		if(a >=0 && a <=100 && b >=0 && b <=100 && c >=0 && c <=100){
			if(a<b && b<c){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}

	}

}

Measured memory_bytes: 26284
s = list(input())
n = len(s) - 1

wa = 0
for i in range(2**n):
    lst = [""]*n
    for j in range(n):
        if i&(1<<j):
            lst[j] = "+"
    lst_s = [0]*(len(s) + n)
    lst_s[::2] = s
    lst_s[1::2] = lst
    #print(eval("".join(lst_s)))
    wa += eval("".join(lst_s))
print(wa)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <map>

using namespace std;

map<int, int> hit;

#define POS(value, i) ((value>>(i+(i<<1)))&7)

inline int swap_pos(int value, int i, int j)
{
	int vi, vj;
	i*=3; j*=3;
	vi = (value>>i) & 7;
	vj = (value>>j) & 7;

	value = (value & ~(7<<i)) | (vj<<i);
	value = (value & ~(7<<j)) | (vi<<j);
	return value;

}

void init_map(int target)
{

	queue<int> q1, q2, *q, *nq, *qtmp;
	q = &q1; nq = &q2;
	q1.push(target);
	
	hit[target]=1;

	while (!q->empty()) {
		while (!nq->empty()) nq->pop();
		
		while (!q->empty()) {
			int value = q->front(); q->pop();
			int step = hit[value];
			int next_value;
			int i;
			for (i=0; i<=7; i++) {
				if (POS(value, i)!=0) continue;

				if (i<4) {
					next_value = swap_pos(value, i, i+4);
					if (hit[next_value]==0) {
						hit[next_value] = step+1;
						nq->push(next_value);
					}
				}
				else {
					next_value = swap_pos(value, i, i-4);
					if (hit[next_value]==0) {
						hit[next_value] = step+1;
						nq->push(next_value);
					}
				}

				if (i!=0 && i!=4) {
					next_value = swap_pos(value, i, i-1);
					if (hit[next_value]==0) {
						hit[next_value] = step+1;
						nq->push(next_value);
					}
				}

				if (i!=3 && i!=7) {
					next_value = swap_pos(value, i, i+1);
					if (hit[next_value]==0) {
						hit[next_value] = step+1;
						nq->push(next_value);
					}
				}
			}
				
		}

		qtmp = q; q = nq; nq = qtmp;

	}

}


int main()
{
	//freopen("in.txt", "r", stdin);

	int target, src;
	int i, j;

	target=0;
	for (i=0; i<=7; i++) {
		target = (target<<3)|i;
	}

	init_map(target);

	//printf("MAX_HIT=0x%x\n", MAX_HIT);

	while (scanf("%d", &src)==1) {
		for (i=1; i<=7; i++) {
			int tmp;
			scanf("%d", &tmp);
			src = (src<<3) | tmp;
		}

		printf("%d\n", hit[src]-1);

	}

	return 0;
}

Measured memory_bytes: 2000
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    /**
     * @param args
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int P = sc.nextInt();
        int[] A = new int[N];
        for (int i=0; i<N; i++) {
            A[i] = sc.nextInt();
        }

        System.out.println(solve(N, P, A));
    }

    private static long solve(int N, int P, int[] A) {
        long sum = 0;

        int numEven = 0;
        int numOdd = 0;

        for (int i=0; i<N; i++) {
            if (A[i]%2 == 0) {
                numEven++;
            } else {
                numOdd++;
            }
        }

        if (P == 0) {

            if (numOdd >= 2) {
                BigInteger subtotal;
                for (int i = 0; i <= numOdd; i += 2) {
                    subtotal = BigInteger.ONE;

                    for (int k=0; k<i; k++) {
                        subtotal = subtotal.multiply(BigInteger.valueOf(numOdd-k));
//                        System.out.println("debug(multiply): k=" + k + ", subtotal=" + subtotal + ", value=" + (numOdd-k));
                    }
                    for (int k=i; k>0; k--) {
                        subtotal = subtotal.divide(BigInteger.valueOf(k));
//                        System.out.println("debug(divide): k=" + k + ", subtotal=" + subtotal + ", value=" + k);
                    }
  //                  System.out.println("debug: i=" + i + ", subtotal=" + subtotal);
                    sum += subtotal.longValue();
                }
            }
        } else {
            if (numOdd == 0) {
                return 0;
            } else {
                BigInteger subtotal;
                for (int i = 1; i <= numOdd; i += 2) {
                    subtotal = BigInteger.ONE;

                    for (int k=0; k<i; k++) {
                        subtotal = subtotal.multiply(BigInteger.valueOf(numOdd-k));
//                        System.out.println("debug(multiply): k=" + k + ", subtotal=" + subtotal + ", value=" + (numOdd-k));
                    }
                    for (int k=i; k>0; k--) {
                        subtotal = subtotal.divide(BigInteger.valueOf(k));
//                        System.out.println("debug(divide): k=" + k + ", subtotal=" + subtotal + ", value=" + k);
                    }

//                    System.out.println("debug: i=" + i + ", subtotal=" + subtotal);
                    sum += subtotal.longValue();
                }
            }
        }

//        System.out.println("debug: even=" + numEven + ", odd=" + numOdd);
        if (numEven != 0) {
            if (sum == 0) sum = 1;
            sum *= Math.pow(2, numEven);
//            System.out.println("debug: sum=" + sum);
        }

        return sum;
    }
}


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

int main() 
{
    long long n,x;
    cin>>n>>x;
    unordered_map<int,int> m;
    int a[n+1];
    vector<int> v;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int i=1,j=0;
    while(m.find(i)==m.end())
    {
        v.push_back(i);
        m.insert({i,j++});
        i=a[i];
    }
    //for(auto p:v)cout<<p<<" ";
    int k=v.size();
    if(x<k)cout<<v[x]<<endl;
    else
    {
        int loop=m[i];
        x-=loop;
        int z=x%(k-loop);
        cout<<v[loop+z]<<endl;
    }
    
}

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

int main() {
  int n,m,c,a,b[25],sum=0,res=0;
  cin >> n >> m >> c;
  for(int i=0;i<m;i++){
    cin >> b[i];
  }
  for(int j=0;j<n;j++){
      for(int i=0;i<m;i++){
            cin >> a;
            sum+=a*b[i];
      }
      if(sum+c>0)res++;
      sum=0;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

#if __has_include("debug.hpp")
#include "debug.hpp"
#else
template<typename T>
void debug(T& obj) {}
#endif

template<typename T>
T in(){
	T val;
	cin >> val;
	return val;
}

template<typename T>
vector<T> inv(ll num) {
	vector<T> val(num);
	rep(i,num) cin >> val[i];
	return val;
}

bool isPrime(ll num) {

	bool flag = true;
	for (int i = 2; i <= sqrt(num); i++) {
		if (num%i == 0) {
			flag = false;
			break;
		}
	}

	return flag;
}

//----------------------------------------------------------------------
void solve() {

	ll x;
	cin >> x;
	while(1) {
		if (isPrime(x)){
			cout << x;
			return;
		} else {
			x++;
		}
	}

}
//----------------------------------------------------------------------

int main(int argc, char* argv[]) {
	solve();
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  cin>>n;
  vector<int> as(n);
  for(int i=0;i<n;i++) cin>>as[i];

  long long ans=0;
  // a_i + a_j = i - j
  // <=> a_i - i = - a_j - j
  {
    map<int, int> cnt;
    for(int i=0;i<n;i++){
      ans+=cnt[-as[i]-i];
      cnt[as[i]-i]++;
    }
  }
  // a_i + a_j = -(i - j)
  // <=> a_i + i = - a_j + j
  {
    map<int, int> cnt;
    for(int i=0;i<n;i++){
      ans+=cnt[-as[i]+i];
      cnt[as[i]+i]++;
    }
  }
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 20976
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  string S; cin >> S;
  cout << S[0] << S[1] << S[2] << endl;
  

}

Measured memory_bytes: 3592
#include<iostream>
#include <stdio.h>
using namespace std;
  
int main(){
	int a,b,c,d,e,f,g,h;
	cin>>a>>b>>c>>d>>e>>f>>g>>h;
	int i=a+b+c+d;
	int j=e+f+g+h;
	if(i>j){
		cout<<i<<endl;}else{
		cout<<j<<endl;}
    return 0;
    }


Measured memory_bytes: 1160
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
const ll BIGMOD = 1e9 + 7;
using namespace std;

// 組み合わせ
ll Combination(ll n, ll r) {
  if (n < r) return 0;
  ll ans = 1;
  for (ll i = n; i > n - r; --i) ans *= i;
  for (ll i = 1; i <= r; ++i) ans /= i;
  return ans;
}  // End_Func

int main() {
  int n;
  cin >> n;
  vector<int> arr(n + 1, 0);
  vector<int> input(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &input[i]);
    arr[input[i]] += 1;
  }

  ll sum = 0;
  for (int i = 1; i <= n; ++i) {
    sum += Combination(arr[i], 2);
  }

  for (int i = 1; i <= n; ++i) {
    printf("%lld\n", sum - Combination(arr[input[i]], 2) +
                         Combination(arr[input[i]] - 1, 2));
  }

  return 0;
}

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

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N;
	int MARCH[5] = { 0, 0, 0, 0, 0 };
	ll ans = 0;
	string S;

	cin >> N;
	rep(i, N) {
		cin >> S;
		if (S[0] == 'M') MARCH[0]++;
		else if (S[0] == 'A') MARCH[1]++;
		else if (S[0] == 'R') MARCH[2]++;
		else if (S[0] == 'C') MARCH[3]++;
		else if (S[0] == 'H') MARCH[4]++;
	}

	repc(i, 0, 4) {
		repc(j, i + 1, 4) {
			repc(k, j + 1, 4) {
				ans += (ll)MARCH[i] * (ll)MARCH[j] * (ll)MARCH[k];
			}
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
n,k,q = (int(i) for i in input().split())
a = [k]*n
d = [0] + [a[i] - a[i-1] for i in range(1,n)]+[0]
for i in range(q):
  x = int(input())-1
  d[0]-=1
  d[x]+=1
  d[x+1]-=1
  d[n]+=1
a[0]+=d[0]
for i in range(1,n): a[i] = a[i-1]+d[i]
for i in range(n): print("Yes" if a[i]>0 else "No")

Measured memory_bytes: 8648
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <string> 
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 100005
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
template<class T> inline void read(T &f){
	f=0;
    T x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
ll a[55];
int main(){
	ll n;
	read(n);
	for(ll i=1;i<=n;i++){
		read(a[i]);
	}
	ll ans=0;
	for(ll i=1;i<=n;i++){
		for(ll j=i+1;j<=n;j++){
			ans+=a[i]*a[j];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int count = 0;
    for (int i = 1; i <= N; i++) {
      int tmp = scan.nextInt();
      if (tmp != i) {
        count++;
      }
    }


    if (count <= 2) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }

}


Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int H = sc.nextInt();
			int W = sc.nextInt();
		
			if(H == 0 && W == 0)
				break;
			
			for(int i = 0;i < H;i++){
				for(int j = 0;j < W;j++){
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 26872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int n;
	cin >> n;
	
	int ten = 1;

	vector<int> a(n),b(n-1);
	rep(i,n-1) cin >> b[i];

	a[0] = b[0];
	a[n-1] = b[n-2];
	FOR(i,1,n-1){
		a[i] = min(b[i], b[i-1]);
	}

	int ans = 0;
	rep(i,n) ans += a[i];
	cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e9;
multimap<string, ll> mp;
int main(){
    int n, m;
    cin >> n;
    set<ll> a;
    rep(i,n){
        ll an; cin >> an;
        a.insert(an);
    }
    cin >> m;
    set<ll> b;
    rep(i,m){
        ll bn; cin >> bn;
        b.insert(bn);
    }

    vector<ll> c;
    set_union(all(a), all(b), back_inserter(c));
    rep(i,c.size())cout << c[i] << endl;
    return 0;
}


Measured memory_bytes: 25804
N = int(input())
count = 0
b = 0
for _ in range(N):
    d1, d2 = map(int, input().split())
    if d1==d2:
        count+=1
    else:
        count=0
    if count==3:
        b=1
if b:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 62320
#include<bits/stdc++.h>
using namespace std;
#define M_PI  3.1415926535
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
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 ; }
ll inf = 1e9 + 7;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }
int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin ) ;
  ll t = 1;
  //cin>>t;
  while(t--)
  {
     ll n;
     cin>>n ;
     vector<ll> a(n) ;
     for( ll i = 0 ; i<n ; i++ ) cin>>a[i] ;

     vector<ll> pref_sum(n,0) ;
     pref_sum[0] = a[0]%inf ;
     for( ll i = 1 ; i<n ; i++ ) pref_sum[i] = (pref_sum[i-1]%inf + a[i]%inf)%inf ;
     ll ans = 0 ;
     for( ll i = n-1 ; i>=1 ; i-- ){
        ans = (ans%inf + (a[i]%inf*pref_sum[i-1]%inf)%inf)%inf ;
     }
     cout<<ans%inf;
  }
return 0;


}


Measured memory_bytes: 6348
#include<stdio.h>

void euclid(int a,int b);

int main(void){
  int x,y;
  int kari;
  int z;

  
  scanf("%d%d",&x,&y);
 
  euclid(x,y);

  return 0;

}


void euclid(int a,int b){
  int kari;
  int c;

  
if(b>a){
    kari=a;
    a=b;
    b=kari;
  }

  
 c=a%b;

 while(c!=0){
   
    a=b;
    b=c;
    c=a%b;

  }
  


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

}



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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

signed main(){
    string a, b, c;
    cin >> a >> b >> c;
    bool ans = a.back() == b.front() && b.back() == c.front();
    cout << (ans ? "YES" : "NO") << endl;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	ll n, k;
	cin >>n >>k;
	
	VL z(n+1), zsm(n+2);
	rep(i, n+1) z[i]=i;
	rep(i, n+1) zsm[i+1] = zsm[i] + z[i];
	//for(auto x :z) cerr<<x<<" "; dbg();
	//for(auto x :zsm) cerr<<x<<" "; dbg();
	ll ans = 0;
	rep2(i, k, n+2){
		ll mnp = zsm[i];
		ll mxp = zsm[n+1] - zsm[n+1-i];
		//dbg(i, mnp, mxp);
		ll df = mxp + 1 - mnp;
		if(mnp>mxp) df = 1;
		(ans += df)%=MD;
	}
	cout << ans <<"\n";
	
	return 0;
}


Measured memory_bytes: 6364
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>


using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  int A[N],B[M];
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=0;i<M;i++)cin>>B[i];
  sort(A,A+N);
  reverse(A,A+N);
  sort(B,B+M);
  reverse(B,B+M);
  int ai=0;
  int bi=0;
  long long ans =1;
  int mod = 1000000007;
  for(int x = N*M; x > 0; x--){
     if(ai < N && bi < M && A[ai]==x && B[bi]==x){
        ai++;
        bi++;
     }
     else if(ai < N &&A[ai]==x){
        ans *= bi;
        ai++;
     }
     else if(bi < M && B[bi]==x){
        ans *= ai;
        bi++;
     }
     else{
        //cout <<"*="<< ai<<"*"<<bi<<"-"<<(N*M-x)<<endl;
        ans *= ai*bi-(N*M-x);
     }
     ans %= mod;
  }
  cout << ans << endl;
  
  
  

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
      int h,w;
      cin>>h>>w;
      bool fld[w][h];
      int ans[w][h];
      char c;
      REP(i,h)REP(j,w){
            cin>>c;
            if(c=='c')fld[j][i]=true;
            else fld[j][i]=false;
      }
      int cnt=-1;
      REP(i,h){
            cnt=-1;
            REP(j,w){
                  if(fld[j][i]){
                        ans[j][i]=0;
                        cnt=0;
                  }else{
                        ans[j][i]=cnt==-1?-1:++cnt;
                  }
            }
      }
      REP(i,h){
            REP(j,w){
                  printf("%d%c",ans[j][i],j==w-1?'\n':' ');
            }
      }
}

Measured memory_bytes: 1192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static long Solve(int N, int M, long[] X, long[] Y, long[] Z)
        {
            long max = 0;
            foreach (int x in new[] { -1, 1 })
            {
                foreach (int y in new[] { -1, 1 })
                {
                    foreach (int z in new[] { -1, 1 })
                    {
                        var values = Enumerable.Range(0, N).Select(i => X[i] * x + Y[i] * y + Z[i] * z).OrderByDescending(value => value).Take(M).Sum();
                        max = Math.Max(values, max);
                    }
                }
            }
            return max;
        }
        static void Main(string[] args)
        {
            int[] V1 = ReadInts();
            int N = V1[0];
            int M = V1[1];
            var X = new long[N];
            var Y = new long[N];
            var Z = new long[N];
            for (int i = 0; i < N; ++i)
            {
                long[] V2 = ReadLongs();
                X[i] = V2[0];
                Y[i] = V2[1];
                Z[i] = V2[2];
            }
            Console.WriteLine(Solve(N, M, X, Y, Z));
        }
    }
}


Measured memory_bytes: 13536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

const long long INF = 1LL<<40;

int main(void){
    ll n, k;
    cin >> n >> k;

    vector<vector<ll>> s(n);
    rep(i, 0, n){
        ll t, d;
        cin >> t >> d;
        --t;
        s[t].push_back(d);
    }

    for(auto &v: s){
        sort(v.begin(), v.end(), greater<ll>());
        if(v.empty()) v.push_back(-INF);
    }

    sort(s.begin(), s.end(), [&](vector<ll> a, vector<ll> b){return a[0] > b[0];});

    ll cur = 0;
    priority_queue<ll> que;
    rep(i, 0, k){
        cur += s[i][0];
        rep(j, 1, s[i].size())
            que.push(s[i][j]);
    }

    rep(i, k, n){
        rep(j, 0, s[i].size()) que.push(s[i][j]);
    }

    ll res =  cur + k * k;
    rrep(x, k-1, 1){
        ll v = s[x][0];
        ll w = que.top();
        if(v < w){
            que.pop();
            cur += w;
            que.push(v);
            cur -= v;
        }
        res = max(res, cur + x*x);
    }
    cout << res << endl;
}


Measured memory_bytes: 8696
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <utility>

using namespace std;

int main() {
  int n, q;
  queue<pair<string, int> > p;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    string namei;
    int timei;
    cin >> namei >> timei;
    p.push(make_pair(namei, timei));
  }

  int elaps = 0, a;

  while (!p.empty()) {
    pair<string, int> u = p.front();
    p.pop();
    a = min(u.second, q);
    u.second -= a;
    elaps += a;
    if (u.second > 0) {
      p.push(u);
    } else {
      cout << u.first << " " << elaps << endl;
    }
  }
}

Measured memory_bytes: 6232
#include <stdio.h>

int main(void){
	int n, d;
	scanf("%d %d", &n, &d);
	if(n%(2*d+1)==0)	printf("%d", n / (2*d+1));
	else	printf("%d", n / (2*d+1) + 1);
	
	
	
	return 0;
}

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

int main(){
  ll N,M;
  cin >> N >> M;
  vector<ll> vec(N);
  for(ll i=0;i<N;i++){
    cin >> vec[i];
  }
  sort(vec.begin(),vec.end());
  
  vector<pair<ll,ll>> card(M);
  for(ll i=0;i<M;i++){
    ll b,c;
    cin >> b >> c;
    card[i]=make_pair(c,b);
  }
  sort(card.begin(),card.end());
  
  ll now =M-1;
  for(ll i=0;i<N;i++){
    if(card[now].second<=0){
      now--;
    }
    if(vec[i]<card[now].first){
      vec[i]=card[now].first;
      card[now].second--;
    }
  }
  
  ll ans=0;
  for(ll i=0;i<N;i++){
    ans +=vec[i];
  }
  cout << ans <<endl;
}

  

Measured memory_bytes: 2560
n, c = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(n)]
T = 10**5+1
record = [[0]*(T+3) for _ in range(c+1)]
channel = [[] for _ in range(c+1)]
stc.sort()

for s, t, c in stc:
    if not channel[c]:
        channel[c].append([s - 1, t])
        continue
    if channel[c][-1][1] == s:
        channel[c][-1][1] = t
    else:
        channel[c].append([s-1, t])

for i, v in enumerate(channel):
    for s, t in v:
        record[i][s] += 1
        record[i][t] -= 1

for i in record:
    for j in range(T+2):
        i[j+1] += i[j]

ans = 0
for i in range(T+2):
    y = 0
    for r in record:
        y += r[i]
    ans = max(ans, y)
print(ans)

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

#define fi first
#define se second
#define pb push_back

typedef long long LL;
typedef long double LD;

const LL INF = (1LL << 60);

typedef pair<LL,int> PLL;
void dijkstra(int n, vector<PLL> adjList[], int source, vector<LL>& dist);

int main() {

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

  vector<PLL> adjList[100005];

  int n, m, r;
  cin >> n >> m >> r;

  for (int i = 0; i < m; i++) {
    int s, t; LL d;
    cin >> s >> t >> d;

    adjList[s].pb({d, t});
  }

  vector<LL> dist;

  dijkstra(n, adjList, r, dist);

  for (int i = 0; i < n; i++) {
    if (dist[i] == INF)
      cout << "INF" << endl;
    else
      cout << dist[i] << endl;
  }

  return 0;
}

/*
 * @param n: number of nodes
 * @param adjList: adjacency list representation of the graph
 * @param source: source for shortest path
 *
 * @return dist[i]: shortest distance from source to node i, INF if unreachable
 */
void dijkstra(int n, vector<PLL> adjList[], int source, vector<LL>& dist) {
  dist.assign(n, INF); dist[source] = 0;
  priority_queue<PLL,vector<PLL>,greater<PLL>> pq; pq.push({0LL, source});
  while (!pq.empty()) {
    LL cost; int u;
    tie(cost, u) = pq.top(); pq.pop();

    if (cost > dist[u]) continue;

    for (PLL neighbor : adjList[u]) {
      LL w; int v;
      tie(w, v) = neighbor;
      if (dist[v] > dist[u] + w) {
        dist[v] = dist[u] + w;
        pq.push({dist[v], v});
      }
    }
  }
}


Measured memory_bytes: 19340
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7; 
const int MINF = -1050000000;


int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
		cout << 0 << endl;
		return 0;
	}

	else {
		cout << min({ a*b,b*c,a*c }) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  while(1){
    int n,x;
    scanf("%d",&n);
    scanf("%d",&x);
    if(n == 0 && x == 0) break;
    int count = 0;
    for(int i=1;i<=n-2;i++) for(int j=i+1;j<=n-1;j++) for(int k=j+1;k<=n;k++) if(i+j+k==x) count++;
    printf("%d\n", count);
  }
}


Measured memory_bytes: 2692
#include<stdio.h>
#define N 36

typedef struct{
	char mark;
	int num;
}card_t;

void copy_cards(card_t* copy, card_t* original,int n){
	for(int i=0;i<n;i++){
		copy[i].mark=original[i].mark;
		copy[i].num=original[i].num;
	}
}

void card_change(card_t* a,card_t* b){
	char tmp_m;
	int tmp_n;
	
	tmp_m=a->mark;
	a->mark=b->mark;
	b->mark=tmp_m;
	
	tmp_n=a->num;
	a->num=b->num;
	b->num=tmp_n;
}

void card_print(card_t* card,int n){
	for(int i=0;i<n;i++){
		printf("%c",card[i].mark);
		printf("%d",card[i].num);
		if(i!=n-1)printf(" ");
	}
	printf("\n");
}

int main(void){
	int n;
	int c_num[10]={};
	
	scanf("%d ",&n);
	
	card_t original[N];
	card_t bubble[N];
	card_t selection[N];
	
	for(int i=0;i<n;i++){
		scanf("%c",&original[i].mark);
		scanf("%d ",&original[i].num);
	}
	copy_cards(bubble,original,n);
	copy_cards(selection,original,n);
	
	int flag=1;
	
	while(flag){
		flag=0;
		for(int j=n-1;j>=1;j--){
			if(bubble[j].num<bubble[j-1].num){
				card_change(bubble+j,bubble+j-1);
				flag=1;
			}
		}
	}
	
	card_print(bubble,n);
	
	int aim,stable_flag=1;
	for(int i=0;i<n;i++){
		aim=original[i].num;
		for(int j=0;j<n;j++){
			if(bubble[j].num==aim){
				if(bubble[j+c_num[aim]].mark==original[i].mark){
					c_num[aim]++;//ok
				}else{
					stable_flag=0;
				}
				break;
			}
		}
	}
	
	if(stable_flag){
		printf("Stable\n");
	}else{
		printf("Not stable\n");
	}
	
	//選択ソート
	int minj;
	
	for(int i=0;i<n;i++){
        minj=i;
        for(int j=i;j<n;j++){
            if(selection[j].num<selection[minj].num){
                minj=j;
            }
        }
		card_change(selection+i,selection+minj);
    	
    }
	
	card_print(selection,n);
	
	for(int i=0;i<10;i++)c_num[i]=0;
	
	stable_flag=1;
	for(int i=0;i<n;i++){
		aim=original[i].num;
		for(int j=0;j<n;j++){
			if(selection[j].num==aim){
				if(selection[j+c_num[aim]].mark==original[i].mark){
					c_num[aim]++;//ok
				}else{
					stable_flag=0;
				}
				break;
			}
		}
	}
	
	if(stable_flag){
		printf("Stable\n");
	}else{
		printf("Not stable\n");
	}
	
	return 0;
}


Measured memory_bytes: 2092
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  string S,T;
  cin >> S >> T;
  string ans="No";
  
  for(int i=0;i<S.size();++i){
    string temp_S=S;
    char temp_c=*(S.end()-1);
    temp_S.pop_back();
    temp_S=temp_c+temp_S;
    if(temp_S==T){
      ans="Yes";
      break;
    }
    S=temp_S;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int a;
  cin >> a;
  
  
  if(a%(a%10+(a%100)/10+(a%1000)/100+(a%10000)/1000+(a%100000)/10000+(a%1000000)/100000+(a%10000000)/1000000+(a%100000000)/10000000+(a/100000000)) == 0){
    cout <<"Yes" << endl;
  }
    else{
      cout <<"No" <<endl;
    }
  }


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

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    string S; cin >> S;

    stack<char> st;
    for(auto c : S){
        if(!st.empty() && st.top()!=c) st.pop();
        else st.push(c);
    }

    cout << S.size() - st.size() << endl;
    return 0;
}

Measured memory_bytes: 512
class Dice
  attr_reader :current
  def initialize(current = 1, north = 5, east = 3)
    @current = current
    @north = north
    @east = east
  end

  def roll(direction)
    case direction
    when "N"
      @current, @north = 7 - @north, @current
    when "S"
      @current, @north = @north, 7 - @current
    when "E"
      @current, @east  = 7 - @east, @current
    when "W"
      @current, @east  = @east, 7 - @current
    end
    Dice.new(@current, @north, @east)
  end
end

dice = gets.split
puts dice[gets.chomp.chars.reduce(Dice.new) {|acc, x| acc.roll(x) }.current - 1]

Measured memory_bytes: 8684
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		int W = sc.nextInt();
		if(S <= W) {
			System.out.println("unsafe");
		} else {
			System.out.println("safe");
		}
	}
}


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










string S;
string T = "keyence";
int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S;
    N = S.length();

    if (S == T) {
        printf("YES\n");
        return;
    }

    rep(a, 0, N) rep(b, a, N) {
        string s = "";
        if (a) s += S.substr(0, a);
        if (b + 1 < N) s += S.substr(b + 1);
        if (s == T) {
            printf("YES\n");
            return;
        }
    }

    printf("NO\n");
}


Measured memory_bytes: 256
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  int INF=(1<<29);
  int n,p[5010],dp[5010][5],i,j,k;
  scanf("%d\n",&n);
  for(i=0;i<n;i++){
    scanf("%d ",&p[i]);
  }
  for(i=0;i<=n;i++){
    for(j=0;j<=3;j++){
      dp[i][j]=INF;
    }
  }
  for(i=0;i<=3;i++){
    dp[0][i]=i;
  }
  for(i=0;i<n;i++){
    if(i==n-1){
      for(j=0;j<=3;j++){
        for(k=0;k<=3;k++){
          if(j+k<p[i]){
            continue;
          }
          dp[i+1][k]=min(dp[i+1][k],dp[i][j]+k);
        }
      }
      continue;
    }
    for(j=0;j<=3;j++){
      for(k=0;k<=3;k++){
        if(j+k<p[i]){
          continue;
        }
        dp[i+1][k]=min(dp[i+1][k],dp[i][j]+2*k);
      }
    }
  }
  int min=INF;
  for(i=0;i<=3;i++){
    if(dp[n][i]<min){
      min=dp[n][i];
    }
  }
  printf("%d\n",min);
  return 0;
}


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

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;

/*
    if you have any question about any part of my code,
    please don't shy to ask anytime :)
*/



void solve()
{
    ll n,k;
    cin>>n>>k;
    vector<ll>x(n);
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
    }

    sort(x.begin(), x.end());
    ll ans=0;
    for(int i=0;i<k;i++)
    {
        ans+=x[i];
    }
    cout<<ans<<endl;
}

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

    // ll t;
    // cin >> t;

    // while (t--)
    // {
    //     solve();
    // }
    solve();
    return 0;
}

Measured memory_bytes: 3664
import heapq

N,M = map(int,input().split())
a = list(map(int,input().split()))
a = list(map(lambda x: x*(-1), a))
heapq.heapify(a)
for _ in range(M):
    heapq.heappush(a,((heapq.heappop(a)*(-1))//2)*(-1))
print(abs(sum(a)))


Measured memory_bytes: 20352
#include<bits/stdc++.h>
using namespace std;
int w[105],s1=0,s2,n,ans=1e9,s=0;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>w[i];
		s+=w[i];
	}
	for(int i=1;i<=n;i++){
		s1+=w[i];
		s2=s-s1;
		ans=min(ans,abs(s1-s2));
	}
	cout<<ans;
}

Measured memory_bytes: 256
N = int(input())
S = input()
T = input()
kaburi = 0
for i in range(N):
    #sの末尾とtの先頭を比べる
    #print("sの末尾"+str(i+1)+"文字目"+S[-(i+1):])
    #print("Tの先頭"+str(i+1)+"文字目"+T[0:i+1])
    if S[-(i+1):] == T[0:i+1]:
        kaburi = len(S[-(i+1):])
print(2*N-kaburi)

Measured memory_bytes: 3060