akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
int main(){
  int n; cin >> n;
  string s; cin >> s;
  ll count = 0;
  vector<int> red;
  vector<int> green;
  vector<int> blue;
  for(int i = 0; i < n; i++){
      if(s[i] == 'R')red.push_back(i);
      if(s[i] == 'G')green.push_back(i);
      if(s[i] == 'B')blue.push_back(i);
  }
  for(int i = 0; i < red.size(); ++i) {
      for(int j = 0; j < green.size(); ++j) {
          if((red[i] + green[j]) % 2 == 0) {
              if (binary_search(blue.begin(), blue.end(), (red[i] + green[j]) / 2)) {
                  count++;
              }
          }
      }
  }
    for(int i = 0; i < red.size(); ++i) {
        for(int j = 0; j < blue.size(); ++j) {
            if((red[i] + blue[j]) % 2 == 0) {
                if (binary_search(green.begin(), green.end(), (red[i] + blue[j]) / 2)) {
                    count++;
                }
            }
        }
    }
    for(int i = 0; i < blue.size(); ++i) {
        for(int j = 0; j < green.size(); ++j) {
            if((blue[i] + green[j]) % 2 == 0) {
                if (binary_search(red.begin(), red.end(), (blue[i] + green[j]) / 2)) {
                    count++;
                }
            }
        }
    }
  ll MAX = red.size() * blue.size() * green.size();
  cout << MAX - count << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	int K, N;
	cin >> K >> N;
	vector<int>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	int ans = 0;
	for (int i = 1; i < N; i++) {
		ans = max(ans, A[i] - A[i - 1]);
	}
	ans = max(ans, A[0] + (K - A[N - 1]));
	cout << K - ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k, a, b;
	cin >> k >> a >> b;
	int temp = (a/k)*k;
	while(temp <= b){
		if(temp >= a && temp <= b){
			cout << "OK" << endl;
			return 0;
		}
		temp += k;
	}
	cout << "NG" << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <set>
#include <map>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int N, K;
    cin >> N >> K;
    const int len = 200010;
    vector<int> ball(N), num(len, 0);
    REP(i, N) cin >> ball[i];
    
    REP(i, N) {
        num[ball[i]]++;
    }
    
    // calculation
    int color = 0;
    REP(i, len) {
        if (num[i] != 0) color++;
    }
    
    if (color <= K) {
        cout << 0 << "\n";
    } else {
        int diff = color - K, res = 0, idx = 0;
        sort(num.begin(), num.end());  // down
        REP(i, len) {
            if (num[i] != 0) {
                idx = i;
                break;
            }
        }
    
        for (int j = idx; j < idx + diff; ++j) {
            res += num[j];
        }
        cout << res << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 1792
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007
ll fac[1000000];
ll finv[1000000];
ll inv[1000000];

void comb_init(){
  fac[0] = 1;
  fac[1] = 1;
  for(int i=2;i<1000000;i++){
    fac[i] = i*fac[i-1];
    fac[i] %= MOD;
  }
  inv[1] = 1;
  for(int i=2;i<1000000;i++){
    inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
  }
  finv[0] = 1;
  finv[1] = 1;
  for(int i=2;i<1000000;i++){
    finv[i] = inv[i]*finv[i-1];
    finv[i] %= MOD;
  }
}

ll comb(ll n,ll k){
  ll c;
  c = fac[n];
  c *= finv[k];
  c %= MOD;
  c *= finv[n-k];
  c %= MOD;
  return c;
}

int main(){
  ll n,m,k;
  cin >> n >> m >> k;
  ll ans = 0;
  ll x = 0;
  comb_init();
  ll c = comb(n*m-2,k-2);
  //cout << c << endl;
  for(int d=1;d<m;d++){
    x = 1;
    x *= n%MOD;
    x %= MOD;
    x *= n%MOD;
    x %= MOD;
    x *= d%MOD;
    x %= MOD;
    x *= (m-d)%MOD;
    x %= MOD;
    ans += x;
    ans %= MOD;
  }
  ll y = 0;
  for(int d=1;d<n;d++){
    y = 1;
    y *= m%MOD;
    y %= MOD;
    y *= m%MOD;
    y %= MOD;
    y *= d%MOD;
    y %= MOD;
    y *= (n-d)%MOD;
    y %= MOD;
    ans += y;
    ans %= MOD;
  }
  ans *= c;
  cout << ans%MOD << endl;

  return 0;
}


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


using namespace std;


//最大公約数があればそれが答え。互いに素であれば、１

int gcd(int a, int b);

int main(){

	int num_i;
	std::cin >> num_i;

	std::vector<int> input(num_i);
	for (int i = 0; i < num_i; i++){
		std::cin >> input[i]; 
	}


	std::sort(input.begin(),input.end()); //昇順ソート		

	int ans=input[0];
	for (int i = 1; i < num_i ; i++)
	{
		ans = gcd(input[i],ans);
	}

	std::cout << ans << "\n";
	return 0;
}


int gcd(int a, int b){ //a>b
	int c =1;
	while(c!=0){
		c=a%b;
		a=b;
		b=c;
	}
	return a;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(){
	char a[123], b[123], c[123];
	scanf("%s %s %s", a, b, c);
	int chain = 1;
	int i = 0;
	while(a[i] != '\0') ++i;
	chain = a[--i] == b[0];
	if(chain){
		i = 0;
		while(b[i] != '\0') ++i;
		chain = b[--i] == c[0];
	}
	if(chain){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	return 0;
}


Measured memory_bytes: 128
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int x; readV(x);
  writeln(x == 3 || x == 5 || x == 7 ? "YES" : "NO");
}


Measured memory_bytes: 256
import sys
import math
from collections import deque
import heapq
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()
b = []
for i in range(N):
  b.append((a[i], i))
b.sort(reverse=True)

dp = [[0]*(N+1) for i in range(N+1)] # dp[i番目まで][左からj番目]

for i in range(N):
  happy, ID = b[i]
  #print(b[i])
  for l in range(i+1):
    lcnt = l
    rcnt = i - lcnt
    r = N-1 - rcnt
    if i > l-1:
      dp[i+1][l+1] = max(dp[i+1][l+1], dp[i][l] + happy*abs(ID - l))
      dp[i+1][l] = max(dp[i+1][l], dp[i][l] + happy*abs(ID - r))
    else:
      break
    #print(l,r)
    #print(dp)
  #print("---")
print(max(dp[-1]))

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

int main(){
    int n; cin>>n;
    map<string, int> mp;
    int mx=0;
    for(int i=0;i<n;++i){
        string s;cin>>s;
        ++mp[s];
        if(mp[s]>mx)mx=mp[s];
    }

    for(map<string, int>::iterator it=mp.begin();it!=mp.end();++it){
        if(it->second==mx) cout<<it->first<<endl;
    }

    return 0;
}


Measured memory_bytes: 25216
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] l = new int[n];
        long sum = 0;
        for (int i=0; i<n; i++) {
            l[i] = in.nextInt();
            sum += l[i];
        }

        Arrays.sort(l);
        int max = l[n-1];

        sum -= max;

        String ans = "No";
        if (max < sum) ans = "Yes";

        System.out.println(ans);

        in.close();
    }
}

Measured memory_bytes: 23764
from fractions import gcd
N,M=map(int,input().split())
S=input()
T=input()
g=gcd(N,M)
n=N//g
m=M//g
s=[]
t=[]
for i in range(N):
    if i%n==0:
        s.append(S[i])
for j in range(M):
    if j%m==0:
        t.append(T[j])
for x,y in zip(s,t):
    if x!=y:
        print(-1)
        exit()
print(M*N//g)

Measured memory_bytes: 67180
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int now,n,la,pr,tot,a[500001],b[500001];
char s[500001];
void build(int x,int y){
	tot++;
	a[tot]=x;b[tot]=y;
}
int main(){
	int i,j;
	scanf("%s",s+1);
	n=strlen(s+1);
	if(s[1]=='0'||s[n]=='1')return puts("-1"),0;
	for(i=1;i<=n/2;i++)if(s[i]!=s[n-i])return puts("-1"),0;
	la=1;pr=1;now=2;
	build(la,la+1);
	la=2;
	for(i=2;i<=n/2;i++)if(s[i]=='1'){
		now=la;
		for(j=pr+1;j<i;j++)now++,build(la,now);
		build(la,now+1);
		la=now+1;
		pr=i;
	}
	for(i=la+1;i<=n;i++)build(la,i);
	for(i=1;i<n;i++)printf("%d %d\n",a[i],b[i]);
}

Measured memory_bytes: 3968
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    A, V, B, W, T = next(it),next(it),next(it),next(it),next(it)

    y, n = "YES", "NO"
    if A == B:
        print(y)
        return
    if V <= W:
        print(n)
        return
    print(y if (A-B)**2  <= (T*(W-V))**2 else n)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9136
a, b = map(int, input().split())

if (a >= 1 and a <= 1000000000) and (b >= 1 and b <= 1000000000):
    d = int(a / b)
    r = int(a % b)
    f = float(a / b)

    print("{0:d} {1:d} {2:f}".format(d, r, f))
else:
    pass

Measured memory_bytes: 7668
#include <stdio.h>
#define MAX 20
#define N 2001

int a[MAX], n;
int solve(int, int);

int main() {

    int i, m;
    int q[N];

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    scanf("%d", &m);
    for (i = 0; i < m; i++) {
        scanf("%d", &q[i]);
        if(solve(0, q[i])) printf("yes\n");
        else printf("no\n");
    }
    return 0;

}

int solve(int p, int t) {
    if(t == 0) return 1;
    if(p == n) return 0;
    if(solve(p+1, t)) return 1;
    if(solve(p+1, t-a[p])) return 1;
    return 0;
}

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

using namespace std;

int main(){
    string S;
    long K=0;
    int count=0,i=0;
    cin >> S >> K;
    while(true){
        if(S[i]=='1'){count++;i++;}
        else break;
    }
    if(count>=K){cout << 1 << endl;}
    else cout << S[count] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		int H1 = input.nextInt();
		int M1 = input.nextInt();
		int H2 = input.nextInt();
		int M2 = input.nextInt();
		int K = input.nextInt();
		int H = H2-H1;
		int M = M2-M1;
		int mins = H*60+M;
		System.out.println(mins-K);
	}	
}

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

int main(){

    int x, y;
    std::cin >> x >> y;

    std::vector<size_t> ans;

    if(x  <= y)  ans.emplace_back(y - x);
    if(-x <= y)  ans.emplace_back(y + x + 1);
    if(x  <= -y) ans.emplace_back(-y - x + 1);
    if(-x <= -y) ans.emplace_back(-y + x + 2);

    std::cout << *std::min_element(ans.begin(), ans.end()) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#define INF 2000000000
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define PL pair<long long, long long>
#define P pair<int,int>
#define mk make_pair
#define en endl;
#define WHITE 0
#define BLACK 2
#define GRAY 1
#define RE return 0;

#define MAX 30

int h,w,a[MAX][MAX];
int main(){
  cin>>h>>w;
  for(int i=1; i<=h; i++){
    for(int j=1; j<=w; j++){
      cin>>a[i][j];
    }
  }
  
  int minl=INF;
  for(int i=1; i<=h; i++){
    for(int j=1; j<=w; j++){
      int min_sum=0;
      for(int k=1; k<=h; k++){
        for(int l=1; l<=w; l++){
          if(k==i||l==j) continue;
          int dist=min(abs(k-i),abs(l-j));
          min_sum+=dist*a[k][l];
        }
      }
      minl=min(min_sum,minl);
    }
  }
  
  cout<<minl<<en
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int H, W;
  cin >> H >> W;
  vector<int> M(H, 0), m(H, 0);
  for (int i = 0; i < H; i++)
  {
    string S;
    cin >> S;
    bool flg = false;
    for (int j = 0; j < W; j++)
    {
      if (S.at(j) == '#')
      {
        if (!flg)
        {
          m.at(i) = j;
          flg = true;
        }
        M.at(i) = j;
      }
    }
  }
  
  string ans = "Possible";
  for (int i = 1; i < H; i++)
  {
    if (M.at(i - 1) != m.at(i))
    {
      ans = "Impossible";
      break;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;


int main() {
    int x, y;
    while ( cin >> x >> y ) {
        if ( x == 0 && y == 0 ) break;
        int min = x < y ? x : y;
        int max = x > y ? x : y;
        cout << min << " " << max << endl;
    }
}

Measured memory_bytes: 3056
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	vector<int> h(n);

	int mx = -1;
	for (int i = 0; i < n; i++) {
		cin >> h[i];

		mx = max(mx, h[i]);
	}

	int ans = 0;
	for (int y = 1; y <= mx; y++) {
		
		bool f = true;

		if (h[0]>= y) {
			ans++;
		}
		else {
			f = false;
		}

		for (int j = 1; j < n; j++) {
			
			if (f == true) {
				if (h[j] < y) {
					
					f = false;
				}
			}
			else {
				if (h[j] >= y) {
					ans++;
					f = true;
				}
			}
			
		}

	}

	cout << ans << endl;


	return 0;
}

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

int main(int argc, char const *argv[]) {
    int N, D, ans=0;
    cin >> N >> D;

    vector<vector<int>> points(N, vector<int> (D));

    for (int i=0; i<N; i++) {
        for (int j=0; j<D; j++) {
            cin >> points.at(i).at(j);
        }
    }

    for (int i=0; i<N; i++) {    
        for (int j=i+1; j<N; j++) {
            int num = 0;
            for (int k=0; k<D; k++) {
                int dist = points.at(i).at(k) - points.at(j).at(k);
                num += dist * dist;
            }

            double real = sqrt(num);
            bool judge =  false;

            for (int p=0; p<=real; p++) {
                if (p*p == num) {
                    judge = true;
                    break;
                }
            }

            if (judge) {
                ans++;
            }

        }

    }

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


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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

void solve(){
	ll n;
	cin >> n;
	map < pll, ll > mpp, mp;
	fo(i, 1, n){
		string s = to_string(i);
		ll a, b;
		a = s[0] - '0';
		b = s[sz(s)-1] - '0';
		if(!b)continue;
		mpp[{a, b}]++;
		mp[{b, a}]++;
	}
	ll ans = 0;
	
    for(auto it : mpp){
    	ans += (it.ss*mp[{it.ff.ff, it.ff.ss}]);
    }
    cout << ans << endl;
}

int main(){
    IOS;
    //io_set();
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        solve();
    }
    return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;
 
//Flying Jenny
public class Main{
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] c = {4,1,4,1,2,1,2,1};
        while(sc.hasNext()){
            int[] a = new int[8];
            for(int i=0;i<8;i++)a[i]=sc.nextInt();
            int min = Integer.MAX_VALUE;
            String v = "";
            for(int top=0;top<8;top++){
                int r = 0;
                String m = "";
                for(int j=0;j<8;j++){
                    r += Math.max(0, a[j]-c[(top+j)%8]);
                    m += c[(top+j)%8];
                }
                if(r<min){
                    min = r;
                    v = m;
                }
                else if(r==min&&m.compareTo(v)<0)v = m;
            }
            System.out.print(v.charAt(0));
            for(int i=1;i<8;i++)System.out.print(" "+v.charAt(i));
            System.out.println();
        }
    }
}


Measured memory_bytes: 31344
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	return (!b ? a : gcd(b, a % b));
}

void solve(int x)
{
	vector<int> ret;
	for (int i = 1; i * i <= x; i++){
		if (x % i == 0){
			ret.push_back(i);
			if (i != x / i) ret.push_back(x / i);
		}
	}
	sort(ret.begin(), ret.end());
	
	for (int i = 0; i < ret.size(); i++) printf("%d\n", ret[i]);
}

int main()
{
	int n;
	int x;
	
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++){
		int t;
		scanf("%d", &t);
		if (!i) x = gcd(t, t);
		else x = gcd(x, t);
	}
	
	solve(x);
	
	return (0);
}

Measured memory_bytes: 1052
import numpy as np

N, M = map(int, input().split())


fav_list = np.arange(1, M + 1)

for i in range(N):
    result_list = list(map(int,input().split()))
    del result_list[0]
    fav_list = np.intersect1d(fav_list, result_list)
    
print(fav_list.size)


Measured memory_bytes: 20924
S = input()

front = int(S[:2])
back = int(S[2:])

checkMY = 0
checkYM = 0
if front >= 1 and front <= 12:
    checkMY = 1

if back >= 1 and back <= 12:
    checkYM = 1


if checkMY == 1:
    if checkYM == 1:
        print('AMBIGUOUS')
    else:
        print('MMYY')

else:
    if checkYM == 1:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 38384
from heapq import *
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    def update(j, min_w, sum_w, wn):
        j = ia[j][0]
        fin[j] = True
        w = ia[j][1]
        if w < min_w: min_w = w
        return j, min_w, sum_w + w, wn + 1

    inf = 10 ** 16
    n = int(input())
    aa = list(map(int, input().split()))
    ia = [[i, a] for i, a in enumerate(aa)]
    ia.sort(key=lambda x: x[1])
    #print(ia)
    fin = [False] * n
    min_a = ia[0][1]
    ans = 0
    for i in range(n):
        if fin[i]: continue
        min_w = inf
        sum_w = 0
        wn = 0

        j, min_w, sum_w, wn = update(i, min_w, sum_w, wn)
        if i == j: continue

        while j != i:
            j, min_w, sum_w, wn = update(j, min_w, sum_w, wn)

        ans += min(sum_w + min_w * (wn - 2), sum_w + min_a * (wn + 1) + min_w)
    print(ans)

main()



Measured memory_bytes: 5840
#include <iostream>
#include <cassert>

#define MAX_N (100000000)

bool is_prime(int n)
{
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0)
            return false;
    }
    return true;
}


int main(void)
{
    int N;
    std::cin >> N;
    int *a;
    a = new int[N];
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
    }

    int num_of_prime = 0;
    for (int i = 0; i < N; i++) {
        if (is_prime(a[i])) ++num_of_prime;
    }
    
    std::cout << num_of_prime << std::endl;

    return 0;
}



Measured memory_bytes: 3136
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
using namespace std;
#define IOS {ios :: sync_with_stdio(false); cin.tie(0);cout.tie(0); }
#define F first
#define S second
#define pb push_back
typedef long double ld;
#define deci(n) cout << fixed << setprecision(n);
typedef long long ll;

#define mem0(x)  memset(x,0,sizeof(x));
#define mem1(x)  memset(x,1,sizeof(x));
#define memm1(x) memset(x,-1,sizeof(x));
#define all(a) a.begin(), a.end()
#define pll pair<ll, ll>
#define bits(x) __builtin_popcount(x)
#define fori(n)  for (ll i = 0; i < n; i++)
#define fori2(n) for(ll i=1;i<=n;i++)
#define forj(n)  for (ll j = 0; j < n; j++)
#define forj2(n) for(ll j=1;j<=n;j++)
#define fork(n)  for (ll k = 0; k < n; k++)
#define fork2(n) for(ll k=1;k<=n;k++)
#define vll vector <ll>
#define mll map <ll, ll>
#define vpll vector <pll>
const ll md = 1e9 + 7;

#define BSET(a, p) ((a) | (1ll << (p)))
#define BCHK(a, p) ((a) & (1ll << (p)))
#define BXOR(a, p) ((a) ^ (1ll << (p)));
#define BREM(a, p) (BCHK(a, p)?(BXOR(a, p)):(a))
#define BSHO(a, N) (bitset<N>(a))
// const ll N = 100005;
// ll fac[N] = {1};
// #define calfac for(ll i=1  ;i<N;i++) fac[i] = (fac[i-1]*i)%md;
// ll C[N+1][M+1]; 
// void  ncr(){
//     ll n = N,k = M; 
//     for (ll i = 0; i <= n; i++) { 
//         for (ll j = 0; j <= min(i, k); j++) { 
//             if (j == 0 || j == i)  C[i][j] = 1; 
//             else C[i][j] = C[i - 1][j - 1] +  C[i - 1][j]; 
//         } 
//     } 
// } 


#define RBTTYPE int
#define ordered_set tree<RBTTYPE, null_type, less<RBTTYPE>, rb_tree_tag,tree_order_statistics_node_update> 
// Ordered set docs:
// order_of_key (k) : Number of items strictly smaller than k .
// find_by_order(k) : K-th element in a set (counting from zero).
ll modexp(ll x, ll ex) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x) % md;
        ex >>= 1ll;
        x = (x * x) % md;
    }
    return ans;
}
ll modInv(ll a)
{
    return pow(a,md-2);
}
 
// ll nCr(ll n,ll r)
// {
//     return (fac[n]*modInv((fac[r]*fac[n-r])%md))%md;
// }

 
// ll po(ll x,ll n){
//     if(n==0) return 1;
//     if(n%2==1) return (x*po(x,n-1));
//     else {
//         ll k=po(x,n/2);
//         return (k*k);
//     }
// }
 
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
}
ll n,e[51][51]; 

void mul(ll a[51][51],ll b[51][51]){
    ll t[51][51];
    fori2(n){
        forj2(n){
            t[i][j] = 0;
            fork2(n){
                t[i][j] += (a[i][k]*b[k][j])%md ;
                t[i][j] %= md;
            }
        }
    }
    fori2(n) forj2(n) a[i][j] = t[i][j];
}


void po(ll a[51][51],ll k){
    if(k <= 1) return ;
    po(a,k/2);
    mul(a,a);
    if(k%2){
        mul(a,e);
    }
}


int32_t main(){
    IOS;
    ll a[51][51];
    ll i,j,k,p,m,q;
    cin >> n >> k;
    fori2(n) forj2(n) {cin >> a[i][j];e[i][j]=a[i][j];}
    po(a,k);
    ll sum =0 ;
    fori2(n) forj2(n) {
        sum += a[i][j];
        sum %= md;
    }
    cout << sum <<"\n";
} 

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

#define N 26
#define MAX_T 1.9
#define TRIAL 5
#define K 16

const long INF = 1L << 60;

int c[N];
int s[365][N];
int last[N];

std::chrono::time_point<std::chrono::steady_clock> start, endt;

random_device rd;
mt19937 generator(rd());
uniform_real_distribution<> dist_real(0.0, 1.0);
uniform_int_distribution<> dist_int(0, RAND_MAX);
uniform_int_distribution<> dist_int_k(0, K);

struct ContestInfo {
	int D;
	long score;
	long best_score;
	vector<int> t;
	vector<int> best_t;
	set<int> held[N];
	ContestInfo(int dd) : D(dd), score(0) {
		t.resize(D, -1);
		for (int i = 0; i < N; i++) {
			held[i].insert(-1);
			held[i].insert(D);
			score -= c[i] * D * (D + 1) / 2;
		}
	}

	void add(int dd, int qq) {
		if (t[dd] != -1) {
			cout << "Add faild!" << endl;
			exit(1);
		}

		t[dd] = qq;
		score += s[dd][qq];
		auto itr = held[qq].insert(dd).first;
		auto ritr = next(itr);
		auto litr = prev(itr);
		auto range = [](int l, int r) {
			int k = r - l - 1;
			return -k * (k + 1) / 2;
		};
		score -= c[qq] * range(*litr, *ritr);
		score += c[qq] * (range(*litr, *itr) + range(*itr, *ritr));
	}

	void erase(int dd) {
		if (t[dd] == -1) {
			cout << "Erase faild!" << endl;
			exit(1);
		}
		int qq = t[dd];
		t[dd] = -1;
		score -= s[dd][qq];
		auto itr = held[qq].find(dd);
		auto ritr = next(itr);
		auto litr = prev(itr);
		auto range = [](int l, int r) {
			int k = r - l - 1;
			return -k * (k + 1) / 2;
		};
		score += c[qq] * range(*litr, *ritr);
		score -= c[qq] * (range(*litr, *itr) + range(*itr, *ritr));
		held[qq].erase(itr);
	}

	void change(int dd, int qq) {
		erase(dd);
		add(dd, qq);
	}

	void swap(int d1, int q1, int d2, int q2) {
		change(d1, q2);
		change(d2, q1);
	}

	long calc_score(int dd) {
		long ret = 0;
		fill(last, last + N, -1);
		for (int i = 0; i <= dd; i++) {
			ret += s[i][t[i]];
			last[t[i]] = i;
			for (int j = 0; j < N; j++) {
				ret -= c[j] * (i - last[j]);
			}
		}
		return ret;
	}

	void save() {
		best_t = t;
		best_score = score;
	}

	void output(bool show = false) {
		for (int i = 0; i < D; i++)
			cout << best_t[i] + 1 << endl;
		if (show) cout << best_score << endl;
	}
};

double dice() {
	return dist_real(generator);
}

double prob(double rem) {
	return 1.0 - 1e-3;
	// return 1.0 / exp(rem);
	// return 1.0 / pow(8, rem);
	// return dist_real(generator);
}

void tic() {
	start = std::chrono::steady_clock::now();
}

double toc() {
	endt = std::chrono::steady_clock::now();
	std::chrono::duration<double> elapsed_seconds = endt - start;
	return elapsed_seconds.count();
}

int main() {
	int d;
	cin >> d;
	for (int i = 0; i < N; i++)
		cin >> c[i];
	for (int i = 0; i < d; i++) {
		for (int j = 0; j < N; j++) {
			cin >> s[i][j];
		}
	}

	ContestInfo ci(d);

	for (int i = 0; i < d; i++) {
		long max_score = -INF;
		int best_q = 0;
		for (int j = 0; j < N; j++) {
			ci.add(i, j);
			long new_score = ci.calc_score(i);
			if (max_score < new_score) {
				max_score = new_score;
				best_q = j;
			}
			ci.erase(i);
		}
		ci.add(i, best_q);
	}
	ci.save();
	ci.output();
}

Measured memory_bytes: 3696
n, t = gets.strip.split.map(&:to_i)
a = gets.strip.split.map(&:to_i)

min = a.first
checker = []
a.each do |e|
  checker << e-min
  min = e if min > e
end

#p checker.group_by(&:itself)
#p checker.group_by(&:itself)[checker.max]
p checker.group_by(&:itself)[checker.max].length




Measured memory_bytes: 20996
#include <algorithm>
#include <cstdio>
#include <vector>
#include <utility>

int main() {
    int n;
    int count = 1;
    while (scanf("%d", &n) != EOF) {
        if (n == 0)
            break;
        std::vector<std::vector<int>> ans;
        int value = 1;
        for (int i = 1; i <= n; ++i) {
            std::vector<int> v;
            for (int j = 0; j < i; ++j) {
                v.push_back(value++);
            }
            ans.push_back(v);
        }
        for (int i = n - 1; i > 0; --i) {
            std::vector<int> v;
            for (int j = 0; j < i; ++j) {
                v.push_back(value++);
            }
            ans.push_back(v);
        }
        for (unsigned int i = 1; i < ans.size(); i += 2) {
            std::reverse(ans[i].begin(), ans[i].end());
        }

        printf("Case %d:\n", count++);
        for (int j = 0; j < n; ++j) {
            for (int i = 0; i < n; ++i) {
                printf("%3d", ans[i + j].back());
                ans[i + j].pop_back();
                if (i + 1 == n) {
                    printf("\n");
                }
            }
        }
    }
}

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

int main(){
    string s;
    cin >> s;
    int x=0;
    rep(i,4){
        if(s[i]=='+'){
            x++;
        }else if(s[i]=='-'){
            x--;
        }
    }
    cout << x << endl;
}


Measured memory_bytes: 3616
s=input().rstrip().split(' ')
th=int(s[0])
tss=int(s[1])
ah=int(s[2])
ass=int(s[3])
I=0;
while(1):
    if ah>0 and th>0:
        if I%2==0:
            I+=1;
            ah-=tss;
        else:
            th-=ass
            I+=1;
    else:
        break;
if I%2==0:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long long a[100010][3];
long long dp[100010][3];

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

  for(long long i=0; i<n;i++){
    for(int j=0;j<3;j++){
      cin>>a[i][j];
    }
  }  

  
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(j==k) continue;
        chmax(dp[i+1][k],dp[i][j]+a[i][k]);
      }
    }
  }
  cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll inv[1000000];
ll FactorialInv[1000000];
ll Factorial[1000000];
ll beki(ll a, ll b){
    if(b == 0){
        return 1;
    }
    ll ans = beki(a, b / 2);
    ans = ans * ans % mod;
    if(b % 2 == 1){
        ans = ans * a % mod;
    }
    return ans;
}
void init_combination(){
    inv[1] = 1;
    FactorialInv[1] = 1;
    Factorial[1] = 1;
    for(int i = 2; i < 1000000; i++){
        inv[i] = beki(i, mod - 2);
        Factorial[i] = Factorial[i - 1] * i % mod;
        FactorialInv[i] = FactorialInv[i - 1] * inv[i] % mod;
    }
}
ll combination(ll a, ll b){
    if((a == b) || (b == 0)){
        return 1;
    }
    ll ans = Factorial[a] * FactorialInv[b] % mod;
    ans = ans * FactorialInv[a - b] % mod;
    return ans;
}
ll H, W, N;

auto c = [](l_l a, l_l b) {
    if(a.second != b.second) return a.second > b.second;
    return a.first > b.first;
};

priority_queue<l_l, vector<l_l>, decltype(c)> que(c);
struct grid {
    ll r;
    ll c;
    ll even;
    ll odd;
    grid(ll _r, ll _c, ll _even, ll _odd) {
        r = _r;
        c = _c;
        even = _even;
        odd = _odd;
    }
};

bool operator< (grid a, grid b) {
    if(a.r != b.r) return a.r < b.r;
    return a.c < b.c;
}

set<grid> searched;

int main() {
    //cout.precision(10);
    init_combination();
    cin >> H >> W >> N;
    for(int i = 1; i <= N; i++) {
        ll r, c;
        cin >> r >> c;
        que.emplace(r, c);
        //searched.insert({r, c, 0, 0});
    }
    /*
    auto itr = searched.begin();
    cout << (*itr).r << " " << (*itr).c << endl;
    cout << que.top().first << " " << que.top().second << endl;
    */
    searched.insert({1, 1, 1, 0});
    while(!que.empty()) {
        ll r = que.top().first;
        ll c = que.top().second;
        que.pop();
        ll even = 0;
        ll odd = 0;
        for(auto itr = searched.begin(); itr != searched.end(); itr++) {
            if((*itr).r > r) break;
            //cerr << "FROM: " << (*itr).r << " " << (*itr).c << " " << (*itr).even << " " << (*itr).odd << " TO: " << r << " " << c << endl;
            ll dr = r - (*itr).r;
            ll dc = c - (*itr).c;
            even += (*itr).odd * combination(dr + dc, dr);
            even %= mod;
            odd += (*itr).even * combination(dr + dc, dr);
            odd %= mod;
        }
        //cerr << r << " " << c << " " << even << " " << odd << endl;
        searched.insert({r, c, even, odd});
    }
    ll ans = 0;
    for(auto itr = searched.begin(); itr != searched.end(); itr++) {
        //cerr << (*itr).r << " " << (*itr).c << " " << (*itr).even << " " << (*itr).odd << endl;
        ll dr = H - (*itr).r;
        ll dc = W - (*itr).c;
        ans += (*itr).even * combination(dr + dc, dr) % mod;
        ans -= (*itr).odd * combination(dr + dc, dr) % mod;
        ans = (ans + mod) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 23936
s = input()
x,y = map(int,input().split())

n = len(s)

temp = 0
xys = [[],[]]

xy = 0

first = True


for i in range(n):
    if(s[i] == 'F'):
        temp += 1
    else:
        if(temp!=0):
            if(first):
                x -= temp
            else:
                xys[xy].append(temp)
            temp = 0
        xy = (xy + 1) % 2
        first = False
        
if(temp!=0):
    if(first):
        x -= temp
    else:
        xys[xy].append(temp)
        temp = 0

for xy,target in zip([0,1], [x,y]):
    nums = xys[xy]
    len_ = len(nums)
    
    if(len_ == 0):
        if(target == 0):
            continue
        else:
            print('No')
            exit()
    
    target = abs(target)
    sum_ = sum(nums)
    
    if((sum_ - target) % 2 == 1) | (target > sum_):
        print('No')
        exit()
        
    max = 1 + (sum_ - target)//2
    
    dp = [[0] * max for _ in range(len_ + 1)]
    dp[0][0] = 1
    
    for i in range(1, len_ + 1):
        dp[i][0] = 1
        temp = nums[i-1]
        for j in range(temp, max):
            dp[i][j] = dp[i-1][j-temp] | dp[i-1][j]
        
        if(dp[i][-1] == 1):
            break
            
        if(i == len_):
            print('No')
            exit()
    

print('Yes')
    



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

static const int N = 1000;

int lcs(string X,string Y){
    int C[N+1][N+1];
    int m = X.size();
    int n = Y.size();
    int maxl = 0;
    X = ' ' + X;
    Y = ' ' + Y;
    for (int i = 1; i <= m ; ++i) {
        C[i][0] = 0;
    }
    for (int j = 1; j <= n ; ++j) {
        C[0][j] = 0;
    }

    for (int i = 1; i <= m ; ++i) {
        for (int j = 1; j <= n ; ++j) {
         if (X[i] == Y[j]){
             C[i][j] = C[i-1][j-1] + 1;
         }else{
             C[i][j] = max(C[i-1][j],C[i][j-1]);
         }
            maxl = max(maxl,C[i][j]);
        }
    }
    return maxl;
}


int main(){
    string s1,s2;
    int n;
    cin >> n;
    for (int i = 0; i < n ; ++i) {
        cin >> s1 >> s2;
        cout << lcs(s1,s2) << endl;
    }
    return 0;
}

Measured memory_bytes: 5128
#include<bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;// 任意長整数型
using bint = mp::cpp_int;// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;// ついでに有理数型
using rat = boost::rational<bint>;
*/
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()

struct dice {
  ll s[6];
  ll &top()   {return s[0];}
  ll &south() {return s[1];}
  ll &east()  {return s[2];}
  ll &west()  {return s[3];}
  ll &north() {return s[4];}
  ll &bottom(){return s[5];}
  void roll(char c){
    string b("EWNSRL");
    int v[6][4]={{0,3,5,2},
                 {0,2,5,3},
                 {0,1,5,4},
                 {0,4,5,1},
                 {1,2,4,3},
                 {1,3,4,2}};
    for(int k=0;k<6;k++){
      if(b[k]!=c) continue;
      int t=s[v[k][0]];
      s[v[k][0]]=s[v[k][1]];
      s[v[k][1]]=s[v[k][2]];
      s[v[k][2]]=s[v[k][3]];
      s[v[k][3]]=t;
    }
  }
};

int main(){ //srand((unsigned)time(NULL));
  dice x;
  for (int i = 0; i < 6; i++) {
    cin >> x.s[i];
  }
  string S;cin >> S;
  for (int i = 0; i < S.length(); i++) {
    x.roll(S[i]);
  }
  cout << x.top() << endl;
}



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

using namespace std;

int main()
{
    string instr;
    int joi,ioi;

    cin >> instr;
    while(!cin.eof()) {
        joi=0;
        ioi=0;
        for(int i=0; i<(int)instr.size()-2; ++i) {
            if(instr[i]=='J') {
                if(instr[i+1]=='O' && instr[i+2]=='I') ++joi;
            } else if(instr[i]=='I') {
                if(instr[i+1]=='O' && instr[i+2]=='I') ++ioi;
            }
        }
        cout << joi << endl;
        cout << ioi << endl;
        cin >> instr;
    }
    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n;
  vector<int> v(n + 1), w(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> v.at(i) >> w.at(i);
  }
  cin >> q;
  vector<int> u(q), l(q);
  for (int i = 0; i < q; i++) {
    cin >> u.at(i) >> l.at(i);
  }
  int d = 9;
  while ((1 << d) > n) d--;
  vector<vector<int>> dp(1 << d, vector<int>(100001));
  for (int i = 1; i < (1 << d); i++) {
    for (int j = 0; j <= 100000; j++) {
      dp[i][j] = dp[i / 2][j];
      if (j < w[i]) continue;
      dp[i][j] = max(dp[i][j], dp[i / 2][j - w[i]] + v[i]);
    }
    for (int j = 1; j <= 100000; j++) {
      dp[i][j] = max(dp[i][j], dp[i][j - 1]);
    }
  }
  for (int i = 0; i < q; i++) {
    if (u.at(i) < (1 << d)) {
      cout << dp[u[i]][l[i]] << "\n";
    } else {
      int dq = 0, ans = 0;
      while ((u[i] >> dq) >= (1 << d)) dq++;
      for (int j = 0; j < (1 << dq); j++) {
        int sv = 0, sw = 0;
        for (int k = 0; k < dq; k++) {
          if ((j >> k) & 1) continue;
          sv += v.at(u[i] >> k);
          sw += w.at(u[i] >> k);
        }
        if (sw > l[i]) continue;
        ans = max(ans, sv + dp[u[i] >> dq][l[i] - sw]);
      }
      cout << ans << "\n";
    }
  }
}


Measured memory_bytes: 207328
S=input()
# S=list(S)
def solve(S):
	while(S!=""):
		if len(S)>=7 and S[-7:]=="dreamer":
			S=S[:-7]
		elif len(S)>=6 and S[-6:]=="eraser":
			S=S[:-6]
		elif len(S)>=5 and S[-5:]=="dream" :
			S=S[:-5]
		elif len(S)>=5 and S[-5:]=="erase":
			S=S[:-5]
		else:
			return("NO")
	return("YES")

print(solve(S))


Measured memory_bytes: 3316
n, x, y = list(map(int,input().split()))
d = [0 for i in range(n-1)] 
for i in range(1,n+1):
  for j in range(i+1,n+1):
    d[min([j-i, abs(x-i) + 1 + abs(j-y), abs(y-i) + 1 + abs(j-x)])-1] += 1

for i in d:
  print(i)

Measured memory_bytes: 3444
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    inf=10**9
    h,n=MI()
    aa=[]
    bb=[]
    for _ in range(n):
        a,b=MI()
        aa.append(a)
        bb.append(b)
    dp=[inf]*(h+1)
    dp[0]=0
    for i in range(h):
        pre=dp[i]
        for a,b in zip(aa,bb):
            ni=h if i+a>h else i+a
            if pre+b<dp[ni]:dp[ni]=pre+b
    print(dp[h])

main()

Measured memory_bytes: 40832
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (int i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001007;

int main(){
    int h, w; cin >> h >> w;
    vector<vector<char>> maze(h, vector<char>(w));
    int siro = 0;
    rep(i,h){
        rep(j,w){
            cin >> maze[i][j];
            if (maze[i][j] == '.') siro++;
        }
    }
    vector<vector<int>> cost(h, vector<int>(w, INF));
    cost[0][0] = 1;
    queue<P> q; q.push(P(0,0));
    vector<int> dx = {0,1,0,-1};
    vector<int> dy = {1,0,-1,0};
    while (!q.empty()){
        P p = q.front(); q.pop();
        int x = p.first; int y = p.second;
        rep(i,4){
            if (0 <= x+dx[i] && x+dx[i] < h && 0 <= y+dy[i] && y+dy[i] < w && maze[x+dx[i]][y+dy[i]] == '.' && cost[x+dx[i]][y+dy[i]] > cost[x][y] + 1){
                cost[x+dx[i]][y+dy[i]] = cost[x][y] + 1;
                q.push(P(x+dx[i], y+dy[i]));
            }
        }
    }
    if (cost[h-1][w-1] != INF) cout << siro - cost[h-1][w-1] << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int an[SIZE];
int main(){
    int N,X,Y;
    R(N,X,Y);
    FOR(x,1,N)FOR(y,x+1,N){
        an[min(y-x,abs(x-X)+1+abs(y-Y))]++;
    }
    FOR(i,1,N-1)W(an[i]);
    return 0;
}


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

using namespace std;

int main()
{
    int n, tmp, ans = INT_MAX;
    vector<int> xs;

    cin >> n;
    for (size_t i = 0; i < n; ++i)
    {
        cin >> tmp;
        xs.push_back(tmp);
    }

    for (int p = 1; p <= 100; ++p)
    {
        int v = 0;
        for (auto x : xs)
        {
            v += (x - p) * (x - p);
        }
        ans = min(ans, v);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256