akhauriyash/Code-Regression huggingface dataset:
def main():
    H, W = map(int, input().split())
    S = []
    for _ in range(H):
        t = input()
        S.append(t)
    l = [[0] * W for _ in range(H)]
    r = [[0] * W for _ in range(H)]
    u = [[0] * W for _ in range(H)]
    d = [[0] * W for _ in range(H)]
    for i in range(H):
        t = -1
        for j in range(W):
            if S[i][j] == '#':
                t = j
                continue
            l[i][j] = t
    for i in range(H):
        t = W
        for j in range(W-1, -1, -1):
            if S[i][j] == '#':
                t = j
                continue
            r[i][j] = t
    for i in range(W):
        t = -1
        for j in range(H):
            if S[j][i] == '#':
                t = j
                continue
            u[j][i] = t
    for i in range(W):
        t = H
        for j in range(H-1, -1, -1):
            if S[j][i] == '#':
                t = j
                continue
            d[j][i] = t
    m = 0
    for i in range(H):
        for j in range(W):
            m = max(m, r[i][j] - l[i][j] + d[i][j] - u[i][j] - 3)
    return m
print(main())


Measured memory_bytes: 180740
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
string s;

int main(){
	cin >> s;
	ll ans = 0;
	ll ca = 0;
	ll state = 0;
	for(ll i = 0; i < s.size(); i++){
		if(s[i] == 'A'){
			if(state == 1){ca++;}
			else{ca = 1; state = 1;}
		}
		if(s[i] == 'B'){
			if(state == 1){state++;}
			else{ca = 0; state = 0;}
		}
		if(s[i] == 'C'){
			if(state == 2){
				ans += ca;
				state = 1;	
			}
			else{ca = 0; state = 0;}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
void test(vector<int> &a, int k){
	bool dp[k+1];
	memset(dp, 0, sizeof(dp));
	int n = a.size();
	for(int j = 1; j <= k; j++){
		for(int i = 0; i < a.size(); i++){
			if(j >= a[i]){
				dp[j] = dp[j] || !dp[j-a[i]];
			}
		}
	}
	if(dp[k]) cout << "First" << endl;
	else cout << "Second" << endl;
	return;
}
 
int main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i =0 ; i < n; i++){
		cin >> a[i];
	}
	test(a, k);
	return 0;
}


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

int num[100005] = {114514};
int n6[] = {1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
int func(int x) {
	if (x == 0) return 0;
	if (num[x] != 114514) return num[x];
	int res = x;
	for (int i = 0;i < 12;i++) {
		if (x >= n6[i]) {
			res = min(res,func(x-n6[i])+1);
		}
	}
	return num[x] = res;
}

int main() {
	int N;
	cin >> N;
	for (int i = 0;i < 100005;i++) {num[i] = 114514;}
	cout << func(N);
}

Measured memory_bytes: 3712
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,m;
    cin>>n>>m;
    vi c(m);
    rep(i,m)cin>>c[i];
    int dp[100000]={};
    REP(i,1,n)dp[i]=inf;
    rep(i,n){
        if(dp[i]!=inf){
            rep(j,m){
                dp[i+c[j]]=min(dp[i+c[j]],dp[i]+1);
            }
        }
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
const ll mod = 1e9 + 7;
ll powmod(ll a, ll b) { ll res=1; a%=mod; assert(b>=0); for(;b;b>>=1) { if(b&1) res=res*a%mod; a=a*a%mod; } return res; }
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a,b)) * b; }
ll extended_gcd(ll a, ll b, ll &x, ll &y) {
    if (b == 0) { x = 1; y = 0; return a; }
    ll xx, yy;
    ll res = extended_gcd(b, a%b, xx, yy); x = yy; y = xx - yy * (a / b);
    return res;
}

const ll sz = 1e4 + 5;
vector<ll> fac(sz, 1);

// ll nCr(ll n, ll r) {
//     return ( ( ( (fac[n] * powmod(fac[n-r], mod-2)) % mod ) * powmod(fac[r], mod-2) ) % mod );
// }

// * ALways PASS arrays, strings etc to functions BY REFERENCE

// const ll sz = 1e6 + 6;
// vector<bool> p(sz, true);

ll res;

// void func(ll sm, ll st, map<ll,ll> &mpp, ll tot) {
//     if (sm < 0)
//         return;
//     if (sm == 0) {
//         ll ans = fac[tot];
//         for (auto it: mpp)
//             ans = (ans * powmod(fac[it.se], mod-2)) % mod;
//         res = (res + ans) % mod;
//         return;
//     }
    
//     for (ll i = st; i <= sm; i++) {
//         mpp[i] += 1;
//         func(sm-i, i, mpp, tot+1);
//         mpp[i] -= 1;
//     }
// }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    // for (int i = 1; i < sz; i++)
    //     fac[i] = (fac[i-1] * i) % mod;
    
    // p[0] = p[1] = false;
    // for (ll i = 2; i*i <= sz; i++) if (p[i]) {
    //     for (ll j = i*i; j <= sz; j += i)
    //         p[j] = false;
    // }
    
    int t = 1;
    // cin >> t;

    while(t--) {
        ll sm;
        cin >> sm;
        
        // res = 0;
        // map<ll,ll> mpp;
        // func(sm, 3ll, mpp, 0ll);
        
        if (sm <= 2) {
            cout << 0 << endl;
            return 0;
        }
        else if (sm <= 5) {
            cout << 1 << endl;
            return 0;
        }
        
        vector<ll> dp(sm+1, 1);
        dp[0] = dp[1] = dp[2] = 0;
        
        for (int i = 6; i <= sm; i++) {
            for (int j = i-3; j >= 0; j--)
            dp[i] = (dp[i] + dp[j]) % mod;
        }
        
        cout << dp[sm] << endl;
    }
    
	return 0;
}


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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> edges(N, vector<int>());
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  for (auto e : edges[0]) {
    for (auto f : edges[e]) {
      if (f == N - 1) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;

  return 0;
}
/* vim:set fdm=marker: */


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

bool kaibun(string S) {
    string rev = S;
    reverse(rev.begin(), rev.end());
    return S == rev;
}

int main() {
    string S;
    cin >> S;
    int N = S.size();

    bool ans = true;
    if (!kaibun(S)) {
        ans = false;
    }
    if (!kaibun(S.substr(0, (N - 1) / 2))) {
        ans = false;
    }
    if (!kaibun(S.substr((N + 3) / 2 - 1, N - ((N + 3) / 2 - 1)))) {
        ans = false;
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
while 1:
        e=map(int,raw_input().split())
        m=e[0]
        f=e[1]
        r=e[2]
        if m==f==r==-1:
                break
        elif m==-1 or f==-1 or m+f<30:
                print "F"
        elif m+f<50 and r<50:
                print "D"
        elif m+f<65:
                print "C"
        elif m+f<80:
                print "B"
        else:
                print "A"

Measured memory_bytes: 4228
import java.util.Scanner;

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

        int x = sc.nextInt();
        if (x == 3 || x == 5 || x == 7)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define For(i, s, e) for(int i = s;i <= e;i++)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;



int main() {
    ll x;cin >> x;
    int i = 0;
    ll m = 100;
    while(1){
        i++;
        m = m*1.01;
        if(m>=x) {
            cout << i;
            return 0;
        }
    }
}


Measured memory_bytes: 3636
def inpl():
    return list(map(int, input().split()))


N = int(input())
A = [int(input()) for i in range(N)]
A.append(-1)
ma = N
na = N
for i in range(N):
    if A[i] > A[ma]:
        na = ma
        ma = i
    elif A[i] > A[na]:
        na = i

for i in range(N):
    if i == ma:
        print(A[na])
    else:
        print(A[ma])


Measured memory_bytes: 12632
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int a, b;
    cin >> a >> b;

    int ans = 0;
    for(int i = a; i <= b; i++){
        if(i % 10 == i / 10000 && i % 100 / 10 == i / 1000 % 10){
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    int n; cin >> n;
    vector<int> h(n);
    int mx = 0;
    int cnt = 0;
    rep(i, n) {
        cin >> h[i];
        mx = max(h[i], mx);
        if(mx<=h[i]) cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 256
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right

# import numpy as np
# from scipy.special import perm
# from scipy.special import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

########

P, Q, R = l_inpl()

print(sum([P, Q, R]) - max([P, Q, R]))

Measured memory_bytes: 3796
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int x = N * 800;
	int y = 200 * (x / 12000);
	int ans = x - y;
	System.out.println(ans);
}
}

Measured memory_bytes: 21972
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

class Dice
{
private:
  int surf[6];
public:
  void set_surf(int* input);
  void roll(char orient);
  void disp_top();
  void disp_right(int tp, int fw);
};

void Dice::set_surf(int* input)
{
  memcpy(surf, input, 6*sizeof(int));
}

void Dice::roll(char orient){
  int temp[6];
  
  switch(orient){
  case 'S':
    temp[0]=surf[4];
    temp[1]=surf[0];
    temp[2]=surf[2];
    temp[3]=surf[3];
    temp[4]=surf[5];
    temp[5]=surf[1];
    break;
  case 'N':
    temp[0]=surf[1];
    temp[1]=surf[5];
    temp[2]=surf[2];
    temp[3]=surf[3];
    temp[4]=surf[0];
    temp[5]=surf[4];
    break;
  case 'W':
    temp[0]=surf[2];
    temp[1]=surf[1];
    temp[2]=surf[5];
    temp[3]=surf[0];
    temp[4]=surf[4];
    temp[5]=surf[3];
    break;
  case 'E':
    temp[0]=surf[3];
    temp[1]=surf[1];
    temp[2]=surf[0];
    temp[3]=surf[5];
    temp[4]=surf[4];
    temp[5]=surf[2];
    break;
  }

  memcpy(surf, temp, 6*sizeof(int));
  
}

void Dice::disp_top(){
  cout << surf[0] << endl;
}

void Dice::disp_right(int tp, int fw){
  int index_tp, index_fw;
  int right[6][4][2] = {
    { {1, 2}, {2, 4}, {4, 3}, {3, 1} },
    { {0, 3}, {3, 5}, {5, 2}, {2, 0} },
    { {0, 1}, {1, 5}, {5, 4}, {4, 0} },
    { {0, 4}, {4, 5}, {5, 1}, {1, 0} },
    { {0, 2}, {2, 5}, {5, 3}, {3, 0} },
    { {1, 3}, {3, 4}, {4, 2}, {2, 1} }
  };
  
  for(int i=0; i<6; i++){
    if(surf[i] == tp){
      index_tp = i;
    }
    if(surf[i] == fw){
      index_fw = i;
    }
  }
  
  for(int i=0; i<4; i++){
    if(right[index_tp][i][0] == index_fw){
      cout << surf[right[index_tp][i][1]] << endl;
    }
  }


}

int main()
{
  int input[6], n;
  Dice dice;
  string order;
  
  for(int i=0; i<6; i++){
    cin >> input[i];
  }
  dice.set_surf(input);
  
  cin >> n;

  for(int i=0; i<n; i++){
    int tp, fw;
    cin >> tp >> fw;
    dice.disp_right(tp, fw);
  }
  
  return(0);
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      	
        // 入力
        int n = sc.nextInt();
      	
      if(n==1){
      	System.out.println(0);
      }
      if(n==0){
      	System.out.println(1);
      }

    }
}

Measured memory_bytes: 35656
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define clr(s, x) memset(s, x, sizeof(s))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
inline int read(){int r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll readll(){ll r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
inline ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const double eps = 1e-8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 1e5+1000;
const int MAXM = 1e5;
char s[MAXN],t[MAXN];
map<ll,char> x;
ll n,m;
map<ll,int> vis;
int main(){
	cin>>n>>m>>s>>t;
	x[1]=s[0];
	ll l=n/gcd(n,m)*m;
	if(s[0]!=t[0]){
		puts("-1");
		return 0;
	}
	for(int i=1;i<n;i++){
		if((i)*(l/n)+1>l){
			puts("-1");
			return 0;
		}
		x[(i)*(l/n)+1]=s[i];
		vis[(i)*(l/n)+1]=1;
	}
	for(int i=1;i<m;i++){
		if((i)*(l/m)+1>l){
			puts("-1");
			return 0;
		}
		if(!vis[(i)*(l/m)+1]){
			x[(i)*(l/m)+1]=t[i];
			vis[(i)*(l/m)+1]=1;
		}
		else if(vis[(i)*(l/m)+1]){
			if(t[i]!=x[(i)*(l/m)+1]){
				puts("-1");
				return 0;
			}
		}
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 21248
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

const ll MOD = 1e9+7;
long long modpow(long long a, long long n) {
      long long res = 1;
      while (n > 0) {
          if (n & 1) res = res * a % MOD;
          a = a * a % MOD;
          n >>= 1;
      }
      return res;
  }
int main() {
    ll n;
    std::cin >> n;
    map<pair<ll,ll>,ll> cnt1;
    map<pair<ll,ll>,ll> cnt2;
    for (int i = 0; i < n; i++) {
        ll a,b;
        std::cin >> a>>b;
        if(a!=0&&b!=0){
            ll g = gcd(a,b);
            a = a/g;
            b = b/g;
            if(b<0){
                a*=-1;
                b*=-1;
            }
            cnt1[{a,b}]++;
        }else{
            if(a==0&&b==0){
                cnt2[{a,b}]++;    
            }else{
                if(a==0){
                    cnt2[{0,1}]++;    
                }else{
                    cnt2[{1,0}]++;
                }
            }
        }
    }
    
    ll ans = 1;
    map<pair<ll,ll>,bool> done;
    for (auto e : cnt1) {
        if(e.second==0)continue;
        
        ll ta,tb;
        ta = e.first.first;
        tb = e.first.second;
        if(done[{ta,tb}])continue;
        if(ta<0){
            ta*=-1;
            tb*=-1;
        }
        if(e.first.first!=0&&e.first.second!=0){
            ans *= (modpow(2,e.second)+modpow(2,cnt1[{-tb,ta}])-1)%MOD;
            ans %= MOD;
            done[{-tb,ta}]=true;
        }
    }
    
    ans *= (modpow(2,cnt2[{1,0}])+modpow(2,cnt2[{0,1}])-1)%MOD;
    ans -= 1;
    ans += MOD;
    ans += cnt2[{0,0}];
    ans %= MOD;
    std::cout << ans << std::endl;
}


Measured memory_bytes: 53604
import numpy as np
N , M = map(int,input().split())
A = list(map(int,input().split()))
B_C = []
C = []
for i in range(M):
	B_C.append(list(map(int,input().split())))
B_C =np.array(B_C,dtype = np.int64)
B_C = B_C[np.argsort(B_C[:,1])]
not_change = N
A.sort()
A = np.array(A,dtype = np.int64)
k = M - 1
sum_num = 0
judge = 0 
while judge == 0:
	if not_change > B_C[k][0]:
		if A[N - not_change] < B_C[k][1]:
			if A[N - not_change  + B_C[k][0]] < B_C[k][1]:
				sum_num += B_C[k][1] * B_C[k][0]
				not_change -= B_C[k][0]
				if not_change == 0:
					judge = 1
			else:
				while A[N - not_change] < B_C[k][1]:
					sum_num += B_C[k][1]
					not_change -= 1
				judge = 1
		else:
			judge = 1
	else:
		if A[N - not_change] < B_C[k][1]:
			if A[N-1] < B_C[k][1]:
				sum_num += B_C[k][1] * not_change
				not_change = 0
				judge = 1
			else:
				while A[N - not_change] < B_C[k][1]:
					sum_num += B_C[k][1]
					not_change -= 1
				judge = 1
		else:
			judge = 1
	k -= 1
	if k == -1:
		judge = 1


if not_change == 0:
	print(sum_num)
else:
	print(A[N-not_change:N].sum() + sum_num)
	
	


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

int main() {
  int k;
  int a, b;
  cin >> k >> a >> b;
  bool cond = false;
  for (int i = a; i <= b; i++){
    if(i % k == 0){
      cond = true;
      break;
    }
  }
  cout << (cond ? "OK" : "NG") << endl;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

const ll INF = LONG_LONG_MAX / 2;

int N;
vector<ll> as;
vector<ll> bs;

int main(void) {
    cin >> N;

    ll sum = 0;

    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
        as[i] -= (i + 1);
        sum += as[i];
    }

    // printf("sum: %lld\n", sum);

    bs = as;
    sort(bs.begin(), bs.end());

    if (N % 2 == 0) {
        vector<ll> cand_b = {bs[N / 2], bs[N / 2 - 1]};
        ll ans = INF;
        for (auto b : cand_b) {
            // printf("b: %lld\n", b);
            ll acc = 0;
            for (int i = 0; i < N; i++) {
                acc += abs(bs[i] - b);
            }
            chmin(ans, acc);
        }
        cout << ans << endl;
    } else {
        ll b = bs[N / 2];
        // printf("b: %lld\n", b);
        ll ans = 0;
        for (int i = 0; i < N; i++) {
            ans += abs(bs[i] - b);
        }
        cout << ans << endl;
    }


    return 0;
}


Measured memory_bytes: 3328
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector< std::vector<T> > &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

struct Node{
	int parents, slibing, degree, depth, height, left, right;
	Node(){
		parents = -1;
		slibing = -1;
		degree = -1;
		depth = 0;
		height = 0;
	}
};

struct Tree{
	int size;
	vector<Node> da;
	Tree() {}
	Tree(int _size) : size(_size){
		da = vector<Node>(size);
	}
	void construct_parents(){
		rip(i,size,0){
			da[da[i].left].parents = i;
			da[da[i].right].parents = i;
		}
	}
	void construct_sibling(){
		rip(i,size,0) if(da[i].parents == -1) continue; else da[i].slibing = da[da[i].parents].left + da[da[i].parents].right - i;
	}
	void construct_degree(){
		rip(i,size,0) da[i].degree = min(da[i].left,0) + min(da[i].right,0) + 2;
	}
	Node *find_root(){
		rip(i,size,0) if(da[i].parents == -1) return &(*this).da[i];
	}
	void output(){
		rip(i,size,0){
			string state;
			if(da[i].parents == -1) state = "root";
			else if(da[i].degree == 0) state = "leaf";
			else state = "internal node";
			printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",
			i, da[i].parents, da[i].slibing, da[i].degree, da[i].depth, da[i].height, state.c_str());
		}
	}
};

void dfs(Tree *tr, Node *now){
	if(now->left >= 0){
		Node *next = &tr->da[now->left];
		next -> depth = now->depth + 1;
		dfs(tr, next);
		chmax(now -> height, next -> height + 1);
	}
	if(now->right >= 0){
		Node *next = &tr->da[now->right];
		next -> depth = now->depth + 1;
		dfs(tr, next);
		chmax(now -> height, next -> height + 1);
	}
}

int main(){
	int n; cin >> n;
	Tree tr(n);
	rip(i,n,0){
		int id, left, right; cin >> id >> left >> right;
		tr.da[id].left = left;
		tr.da[id].right = right;
	}
	tr.construct_parents();
	tr.construct_sibling();
	tr.construct_degree();
	dfs(&tr, tr.find_root());
	tr.output();
}


Measured memory_bytes: 3340
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

#define ll long long
using vt = int; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define MOD 1000000007

int main() {
	int n;
	cin >> n;
	vector<int> p(n), q(n), r(n);
	rep(i, n) cin >> p.at(i);
	rep(i, n) cin >> q.at(i);
	rep(i, n) r.at(i) = i + 1;
	int N = 1;
	map <vector<int>, int> mp;
	do {
		mp[r] = mp.size();
	} while (next_permutation(r.begin(), r.end()));
	int ans = abs(mp[p] - mp[q]);
	cout << ans << endl;
	return 0;
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl '\n'
#define int long long

int factors[1000005];

void pre()
{
    ffor(i,1,1000005)
    {
        for(int j=i; j<1000005; j+=i) factors[j]++;
    }
}

signed main()
{
    

    pre();

    int n;
    cin>>n;

    int ans=0;

    ffor(i,1,n)
    {
        ans+=factors[n-i];
    }
    cout<<ans;
    
    return 0;
}



Measured memory_bytes: 11444
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstdio>

using namespace std;

struct Node {
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key)x = x->left;
		else x = x -> right;
	}
	z->parent = y;
	if (y == NIL)root = z;
	else {
		if (y->key > z->key)y->left = z;
		else y->right = z;
	}
}

void inorder(Node *u) {
	if (u == NIL)return;
	inorder(u->left);
	cout << " " << u->key;
	inorder(u->right);
}

void preorder(Node *u) {
	if (u == NIL)return;
	cout << " " << u -> key;
	preorder(u -> left);
	preorder(u->right);
}

Node *find(Node *u,int k) {
		while (u != NIL && k!=u->key) {
		if (u->key > k)u = u->left;
		else u = u->right;
	}return u;
}

int main() {
	int m,x;
	cin >> m;
	string s;
	for (int i = 0;i < m;++i) {
		cin >> s;
		if (s == "insert") {
			cin >> x;
			insert(x);
		}
		else if (s == "find") {
			cin >> x;
			if (find(root, x) == NIL)cout << "no" << endl;
			else cout << "yes" << endl;
		}
		else {
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 21896
class BITmax:
    def __init__(self, N, init=0):
        self.init = init
        self.tree = [self.init] * (N+1)
    
    def set(self, x, value):
        while x < N + 1:
            old = self.tree[x]
            if value <= old:
                break
            self.tree[x] = value
            x += x & -x
    
    def find_max_to(self, x):
        result = self.init
        while x > 0:
            result = max(result, self.tree[x])
            x -= x & -x
        return result

N = int(input())
dpt = BITmax(N)

h_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

for h, b in zip(h_list, b_list):
    dpt.set(h, dpt.find_max_to(h-1) + b)

print(max(dpt.tree))


Measured memory_bytes: 42524
def main():
  n,q=map(int,input().split())
  a=[0]*(n-1)
  c=[0 for i in range(n)]
  for i in range(n-1):
    a[i]=list(map(int,input().split()))

  a.sort()

  for i in range(q):
    x,y=map(int,input().split())
    c[x-1]+=y
  for i in range(n-1):
    c[a[i][1]-1]+=c[a[i][0]-1]
  print(*c)
if __name__ == "__main__":
    main()

Measured memory_bytes: 66640
s = io.read('l')

ans1 = #s + 1

for i = 1, #s do
    if s:byte(i) == 49 then
        ans1 = math.min(ans1, math.max(i, #s - i + 1))
    end
end

ans2 = #s + 1

for i = 1, #s do
    if s:byte(i) == 48 then
        ans2 = math.min(ans2, math.max(i, #s - i + 1))
    end
end

print(math.max(ans1, ans2) - 1)


Measured memory_bytes: 1136
N, X, Y = map(int, input().split())
retlist = [0]*N
for i in range(1, N):
    for j in range(i + 1, N + 1):
        num = min(abs(j - i), abs(X - i) + 1 + abs(Y - j), abs(X - j) + 1 + abs(Y - i))
        retlist[num - 1] += 1
for i in range(N-1):
    print(retlist[i])


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)(x).size())
#define mset(a,v) memset(a,v,sizeof(a))
#define mcpy(a,b) memcpy(a,b,sizeof(a))
using namespace std;
typedef long long ll;


int main(){
	string s;
	cin>>s;
	ll t=0,r=0;
	for(char c:s){
		if(c=='B')t++;
		else r+=t;
	}
	cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main() {
	int n;
	long long x;
	long long int ans = 0;
	cin >> n >> x;
	long long int a, b;
	long long int y;
	for (int i = 0;i < n;i++) {
		if (i == 0) {
			cin >> a;
			continue;
		}
		cin >> b;
		if (a < 0) {
			a = 0;
		}
		if (a + b > x) {
			y = a + b - x;
			b -= y;
			ans += y;
		}
		a = b;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int i, j, m, n;
  char c1[100000], c2[100000], s1[100000], s2[100000];

  while(1){
    cin >> m;
    if (m == 0) break;
    for (i=0; i<m; i++){
      cin >> c1[i] >> c2[i];
    }

    cin >> n;
    for (i=0; i<n; i++){
      cin >> s1[i];
      for (j=0; j<m; j++){
	if (s1[i] == c1[j]){
	  s2[i]=c2[j];
	  break;
	}
	s2[i]=s1[i];
      }
    }

    for (i=0; i<n; i++){
      cout << s2[i];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3280
#include <cstdio>
using namespace std;
const int N=200010;
int n,a[N];
long long s,d,ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	int j=1;
	for(int i=1;i<=n;i++){
		while(j<=n&&(d^a[j])==(s+a[j])){
			d^=a[j];
			s+=a[j];
			j++;
		}
		ans+=j-i;
		d^=a[i];
		s-=a[i];
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 896
import sys

# 再帰回数の制限
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7

def input():
    return sys.stdin.readline().strip()


import numpy as np

def main():
    A = []
    for i in range(3):
        A.extend(list(map(int, input().split())))

    N = int(input())
    for j in range(N):
        b = int(input())
        if b in A:
            bi = A.index(b)
            A[bi] = 0

    arr = np.array(A).reshape(3,3)

    row = arr.sum(axis=0)
    col = arr.sum(axis=1)
    diag = sum(arr.diagonal())
    diag_rev = arr[0, 2] + arr[1, 1] + arr[2, 0]

    for r, c in zip(row, col):
        if r == 0 or c == 0:
            print("Yes")
            return 0
    
    if diag == 0 or diag_rev == 0:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n;
	ll a[114514];
	cin>>n;
	int zero=0, minus=0;
	ll mi=1e9;
	ll sum=0;
	REP(i, n){
		cin>>a[i];
		if(a[i]==0){
			++zero;
		}
		if(a[i]<0){
			++minus;
		}
		sum+=abs(a[i]);
		CHMIN(mi, abs(a[i]));
	}
	cout<<((zero>0 || (minus&1)==0) ? sum : sum-2*mi)<<'\n';
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;


int main(void){
  int n,i,x[105],p,s,ans=1e9;
  
  cin >> n;
  for (i=0;i<n;i++) cin >> x[i];
  
  for (p=1;p<=100;p++){
    s=0;
    for (i=0;i<n;i++) s+=(x[i]-p)*(x[i]-p);
    ans=min(ans,s);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
char a[16], b[16] = {'C', 'O', 'D', 'E', 'F', 'E', 'S', 'T', 'I', 'V', 'A', 'L', '2', '0', '1', '6'};
int ans;
int main()
{
	cin >> a;
	for(int i = 0; i < 16; i ++){
		if(a[i] != b[i]) ans ++;
	}
	cout << ans;
	return 0;
}

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

  //input X
  cin >> X;
  vector <bool > expo(X+1);
  //i = 1 expo[1] = 1;
  expo[1] = 1;
  // X>=i>=2 : X 以下の　べき乗数の計算　
  for(int i = 2;i<=X;i++){
    int a = i * i;
    while(a<=X){
      expo[a] = 1;
      a *= i;
    }
  }

  //output
  for(int i=X;i >=1; i--)
    if(expo[i]) {
      cout << i << endl;
      return 0;
    }
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
vector<string> str(50);
int h,w;
bool check(int i,int j){
  if(str[i][j]=='.') return true;
  bool flag=false;
  if(i>0){
    flag|=(str[i-1][j]=='#');
  }
  if(j>0){
    flag|=(str[i][j-1]=='#');
  }
  if(i<h-1){
    flag|=(str[i+1][j]=='#');
  }
  if(j<w-1){
    flag|=(str[i][j+1]=='#');
  }
  return flag;
}
int main(){
  cin>>h>>w;
  for(int i=0;i<h;i++) cin>>str[i];
  bool flag=true;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      flag&=check(i,j);
    }
  }
  cout<<(flag?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;
typedef pair<int, int> pii;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const ll INF = 1e9 + 7;


int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

struct node {

	ll to;
	ll cost;

};

vector<node> G[ARRAY_MAX];
int n;
bool used[ARRAY_MAX];
int co[ARRAY_MAX];

void dfs(int now, int color)
{

	//cout << "now = " << now << "color = " << color << endl;
	used[now] = 1;
	co[now] = color;

	bool all_visited = true;

	for (int i = 0; i < n; i++)
	{
		if (used[i] == false)
		{
			all_visited = false;
			break;
		}
	}

	//cout << "a" << endl;
	if (all_visited)
	{
		return;
	}

	//cout << "b" << endl;
	for (int i = 0;i < G[now].size();i++)
	{
		if (used[G[now][i].to] == true)
		{
			continue;
		}

		//cout << "cost = " << G[now][i].cost << endl;
		if (G[now][i].cost % 2)
		{
			//cout << "c" << endl;
			dfs(G[now][i].to, 1 - color);
		}
		else
		{
			dfs(G[now][i].to, color);
		}
	}
}

int main() {

	cin >> n;
	for (int i = 0; i < n-1; i++)
	{
		ll a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		G[a].push_back(node{ b,c });
		G[b].push_back(node{ a,c });
	}


	/*for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < G[i].size(); j++)
		{
			cout << G[i][j].to << " ";
		}
		cout << endl;
	}*/

	dfs(0,0);

	for (int i = 0; i < n; i++)
	{
		cout << co[i] << endl;
	}

	return 0;
}



Measured memory_bytes: 9856
import itertools

n = int(input())

p = list(input().split())
q = list(input().split())

x = sorted(p)

xx = list(itertools.permutations(x))

tp = tuple(p)
tq = tuple(q)

a = xx.index(tp)
b = xx.index(tq)

ans = abs(a - b)

print(ans)

Measured memory_bytes: 8052
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 

const int MOD = 1000000007;

int dp[100005];

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

    vector<int> h(N);
    rep(i, N) cin >> h[i];
    
    dp[0] = 0;
    dp[1] = abs(h[0]-h[1]);
    for (int i = 2; i < N; ++i) {
        dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]), dp[i-1] + abs(h[i]-h[i-1]));
    }

    cout << dp[N-1] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
#define file "orz"
const int mxN=1e5+5;
int pref[mxN], pref2[mxN];
int main()
{
    //freopen(file".inp","r",stdin);
    //freopen(file".out","w",stdout);
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    string s,t;
    cin>>s>>t;
    for(int i=0;i<s.length();i++)
    {
    	if(s[i]=='A')
    		pref[i+1]=pref[i]+1;
    	else
    		pref[i+1]=pref[i]-1;
	}
	for(int i=0;i<t.length();i++)
    {
    	if(t[i]=='A')
    		pref2[i+1]=pref2[i]+1;
    	else
    		pref2[i+1]=pref2[i]-1;
	}
	int q;
	cin>>q;
	for(int i=0,a,b,c,d;i<q;i++)
	{
		cin>>a>>b>>c>>d;
		int x=pref[b]-pref[a-1];
		int y=pref2[d]-pref2[c-1];
//		cout<<x<<" "<<y<<endl;
		x=(x+mxN)%3;
		y=(y+mxN)%3;
//		cout<<x<<" "<<y<<endl;
		if(x==y)
			cout<<"YES\n";
		else
			cout<<"NO\n";
	}
}


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

struct dish
{
	int a, b, s;

	bool operator>(const dish& right) const
	{
		return s > right.s;
	}
};

int main()
{
	int n;
	long long m = 0;

	cin >> n;

	vector<dish> d(n);

	for (int i = 0; i < n; i++) {
		cin >> d[i].a >> d[i].b;
		d[i].s = d[i].a + d[i].b;
	}

	sort(d.begin(), d.end(), greater<dish>());

	for (int i = 0; i < n; i++) {
		if (i % 2 == 0)
			m += d[i].a;
		else
			m -= d[i].b;
	}

	cout << m << endl;

	return 0;
}


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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int X;
    cin >> X;
    reps(i, 360) {
        if (X * i % 360 == 0) { fin(i); }
    }
}


Measured memory_bytes: 3588
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

double x[100],y[100];

double dist(int n, int p) {
  int i;
  double d=0;
  for(i=0;i<n;i++) {
    d+=pow(abs(x[i]-y[i]),p);
  }
  double pp=1.0/p;
  d=pow(d, pp);
  return d;
}

int main(){
  int n,i;
  cin >> n;
  for(i=0;i<n;i++) {
    cin >> x[i];
  }
  for(i=0;i<n;i++) {
    cin >> y[i];
  }
  double d1=dist(n, 1),d2=dist(n, 2),d3=dist(n, 3);
  double d4=0;
  for (i=0;i<n;i++) {
    if (abs(x[i]-y[i]) > d4) {
      d4 = abs(x[i]-y[i]);
    }
  }
  cout << fixed;
  cout << std::setprecision(5) << d1 << endl << d2 << endl << d3 << endl << d4 << endl;
  return 0;
}



Measured memory_bytes: 3412
#include <bits/stdc++.h>
#define mk make_pair
#define ll long long
using namespace std;
const int N = 3e5 + 5;
const int mod = 1e9 + 7;
int n, m, a[N], p, mx;
int main() {
	cin >> n;
	mx = -1e9;
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		if (abs(a[i]) > mx) {
			mx = abs(a[i]);
			p = i;
		}
	}
	cout << 2 * (n - 1) << endl;
	if (a[p] < 0) {
		for (int i = 1; i <= n; i++) {
			if (i == p) continue;
			printf("%d %d\n", p, i);
		}
		for (int i = n - 1; i >= 1; i--) {
			printf("%d %d\n", i + 1, i);
		}
	} else {
		for (int i = 1; i <= n; i++) {
			if (i == p) continue;
			printf("%d %d\n", p, i);
		}
		for (int i = 1; i < n; i++) {
			printf("%d %d\n", i, i + 1);
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
#include<functional>
#include<cassert>
using namespace std;
#define ll long long
int main(){
    ll N;
    cin >> N;
    ll i;
    ll A[N];
    for(i=0;i<N;i++){
        cin >> A[i];
        A[i]-=i+1;
    }
    sort(A,A+N);
    ll sum=0;
    for(i=0;i<N;i++){
        sum+=abs(A[i]-A[N/2]);
    }
    cout << sum << endl;
    return 0;
}

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

int main() {
  string S, s1, s2, s3;
  cin >> S;
  
  s1 = S[0];
  s2 = S[1];
  s3 = S[2];
  
  if (s1 == s2 && s1 == s3){
  	cout << "No" << endl;
  }
  else {
  	cout << "Yes" << endl;
  } 
}


Measured memory_bytes: 256
N=int(input())
answer=[]

for i in range(N):
    answer.append(input())
    
if(len(set(answer))!=len(answer)):
    print("No")
else:
    for j in range(N-1):
        if(answer[j][-1]==answer[j+1][0]):
            if(j==N-2):
                print("Yes")
            else:
                continue
        else:
            print("No")
            break

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
	int i,n,cnt=0,min;
	char ss[300001];
	scanf("%d",&n);
	scanf("%s",ss);

	for(i=1;i<n;i++){
		if(ss[i]=='E')cnt++;
	}

	min=cnt;

	for(i=1;i<n;i++){
		if(ss[i]=='E')cnt--;
		if(ss[i-1]=='W')cnt++;
		if(min>cnt)min=cnt;
	}

	printf("%d\n",min);
	return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 3223372036854775807
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
//#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
//#define leng length()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<Pll,ll> a,pair<Pll,ll> b){
        return a.fi.se>b.fi.se;
}
ll cmp2(pair<Pll,ll> a,pair<Pll,ll> b){
        return a.se<b.se;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //------------------------------
    string s;cin>>s;
    int x=0;
    for(int i=0;i<6;i++){
        if(s[i]=='1')x++;
    }
    cout<<x<<endl;
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //------------------------------- 
    return 0;
}
//----------------------------------------------------------------------


















































Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// to container
template <class C>
void input(C &c)
{
    for_each(c.begin(), c.end(), [](auto &i) { cin >> i; });
}

// to number, string
template <class T>
T input()
{
    T data;
    cin >> data;
    return data;
}

int main()
{
    ll N = input<ll>();
    ll num_2 = 0, num_4 = 0;
    for (ll i = 0; i < N; i++)
    {
        ll a = input<ll>();
        if (a % 4 == 0)
        {
            num_4++;
        }
        else if (a % 2 == 0)
        {
            num_2++;
        }
    }

    if (num_2 % 2 != 0)
    {
        num_2 -= 1;
    }

    if (num_4 >= (N - num_2) / 2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

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

int main() {
	int N;
	cin >> N;	
	int Na = N % 1000;
	int Nb = N % 1110;

	if (N % 1111 == 0 || Na % 111 == 0 || Nb < 10) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  deque<char> dq;
  for (int i = 0; i < S.size(); i++) {
    dq.push_back(S.at(i));
  }
  bool b = 1;
  while (!dq.empty()) {
    if (dq.size()>= 5 && dq.at(0)=='d' && dq.at(1)=='r' && dq.at(2)=='e' && dq.at(3)=='a' && dq.at(4)=='m') {
      for (int i = 0; i < 5; i++) {
        dq.pop_front();
      }
      if (!dq.empty() && dq.at(0)=='e' && dq.at(1)=='r' && (dq.size()==2 || (dq.size()>2 && dq.at(2)!='a'))) {
        for (int i = 0; i < 2; i++) {
          dq.pop_front();
        }
      }
    }
    else if (dq.size()>=5 && dq.at(0)=='e' && dq.at(1)=='r' && dq.at(2)=='a' && dq.at(3)=='s' && dq.at(4)=='e') {
      for (int i = 0; i < 5; i++) {
        dq.pop_front();
      }
      if (!dq.empty() && dq.at(0)=='r') {
        dq.pop_front();
      }
    }
    else {
      b = 0;
      break;
    }
  }
  if (b == 0) {
    cout << "NO" << endl;
  }
  if (b == 1) {
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 512