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

const int inf = 1<<29;

template<typename T>
class IdMap {
public:
    IdMap(int n = 0) : ridx(n) {;}

    void add(const T t) {
        _idx[t] = ridx.size();
        ridx.push_back(t);
    }

    int idx(const T &t) {
        if(_idx.find(t) == _idx.end()) add(t);
        return _idx[t];
    }
    T get(int i) { return ridx[i]; }

    int size() { return ridx.size(); }

private:
    map<T,int> _idx;
    vector<T> ridx;
};

struct Edge { int s,t,c,sw; };
bool operator<(const Edge &e,const Edge &f) {
    return e.c != f.c ? e.c > f.c : (e.sw != f.sw) ? e.sw > f.sw : e.s < f.s;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

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

vector<int> seg[100001];
vector<int> ridx;
int tr;

int spath(const Graph &g,int s,int t,IdMap<string> &id) {
    const int n = g.size();
    vector<int> dist(n, inf), prev(n, -1), sw(n, inf);

    priority_queue<Edge> q;
    for(int i=0; i<seg[s].size(); ++i) {
        q.push((Edge){-2,seg[s][i],0,0});
        dist[seg[s][i]] = 0;
        sw[seg[s][i]] = 0;
    }

    while(!q.empty()) {
        Edge e = q.top(); q.pop();

        if(prev[e.t] != -1) continue;
        prev[e.t] = e.s;

        rep(i,g[e.t].size()) {
            int v = g[e.t][i].t, c = g[e.t][i].c;
            if(prev[v] != -1) continue;
            if(dist[v] > e.c + c) {
                dist[v] = e.c + c;
                sw[v] = e.sw;
                q.push((Edge){e.t,v,c+e.c,e.sw+g[e.t][i].sw});
            }
        }
    }

    int ans = inf, aw = inf;
    for(int i=0; i<seg[t].size(); ++i) {
        if(ans > dist[seg[t][i]]) {
            ans = dist[seg[t][i]];
            aw = sw[seg[t][i]];
        }else if(ans == dist[seg[t][i]]) {
            aw = min(aw, sw[seg[t][i]]);
        }
    }
    if(ans == inf) {
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans/2<<" "<<aw<<endl;
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    int n,a;
    string A,B,in;

    rep(i,100001) seg[i] = vector<int>(0);

    cin>>n>>tr>>A>>B;
    Graph g;
    IdMap<string> id;

    int cnt = 0;
    for(int i=0; i<n; ++i) {
        cin>>a;
        vector<int> s(a),time(a);
        for(int j=0; j<a; ++j) {
            cin>>in;
            s[j] = id.idx(in);
            ridx.push_back(s[j]);
        }

        seg[s[0]].push_back(cnt);
        g.push_back(Edges(0));
        cnt++;

        for(int j=0; j<a-1; ++j) {
            cin>>time[j+1];
            seg[s[j+1]].push_back(cnt);
            g.push_back(Edges(0));
            g[cnt-1].push_back((Edge){cnt-1,cnt,time[j+1]*2,0});
            g[cnt].push_back((Edge){cnt,cnt-1,time[j+1]*2,0});
            cnt++;
        }
    }

    for(int i=0; i<id.size(); ++i) {
        g.push_back(Edges(0));
        for(int j=0; j<seg[i].size(); ++j) {
            g[seg[i][j]].push_back((Edge){seg[i][j],cnt,tr,0});
            g[cnt].push_back((Edge){cnt,seg[i][j],tr,1});
        }
        cnt++;
    }

    spath(g,id.idx(A),id.idx(B),id);
}

Measured memory_bytes: 24000
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};


int main()
{
    int n,k;cin>>n>>k;
    int s=(n-1)*(n-2)/2;
    if(k>s){cout<<-1<<endl;return 0;}
    s+=n-1-k;
    cout<<s<<endl;
    for(int i=0;i<n-1&&s>0;i++)
    {
        for(int j=i+1;j<n&&s>0;j++,s--)
        {
            cout<<i+1<<" "<<j+1<<endl;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for(int i = (s); i < (e); i++)
#define FOE(i, s, e) for(int i = (s); i <= (e); i++)
#define FOD(i, s, e) for(int i = (s); i >= (e); i--)
#define ll long long

int a, b;
char s[10];

int main ()
{
	scanf("%d %s %d", &a, s, &b);
	if (s[0] == '+') printf("%d\n", a + b);
	else printf("%d\n", a - b);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

		while (true) {
			String s = sc.next();
			char type = sc.next().charAt(0);
			if (type == 'X') {
				break;
			}

			String[] words;

			if (s.indexOf('_') > -1) {
				words = s.split("_");
			}
			else {
				int start = 0;
				List<String> wordsTemp = new ArrayList<String>();
				for (int i = 1; i < s.length(); i++) {
					if (Character.isUpperCase(s.charAt(i))) {
						wordsTemp.add(s.substring(start, i));
						start = i;
					}
				}
				wordsTemp.add(s.substring(start));
				words = wordsTemp.toArray(new String[wordsTemp.size()]);
			}

			StringBuilder sb = new StringBuilder(s.length() + words.length);

			if (type == 'D') {
				sb.append(words[0].toLowerCase());
				for (int i = 1; i < words.length; i++) {
					sb.append('_').append(words[i].toLowerCase());
				}
			}
			else {
				if (type == 'L') {
					sb.append(words[0].toLowerCase());
				}
				for (int i = (type == 'L' ? 1 : 0); i < words.length; i++) {
					sb.append(Character.toUpperCase(words[i].charAt(0)));
					if (words[i].length() > 1)
						sb.append(words[i].substring(1));
				}
			}
			System.out.println(sb);

		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll;
typedef double dd;
#define pb push_back
#define mp make_pair
#define endl "\n"
#define M 1000000007
#define pi acos(-1)
/*ll power(ll a,ll b)
{
    ll res = 1;
    while(b > 0)
    {
        if(b & 1)
            res = (res*a)%M;
        a = (a*a)%M;
        b = b >> 1;
    }
    return res;
}*/
/*ll modinv(ll a)
{
   return power(a,M - 2); 
}*/
/*vector<ll> primes(ll n)
{
    bool *sieve = new bool[n + 1];
    ll i,j;
    vector<ll> v;
    for(i = 3; i <= n; i+=2)
        sieve[i] = true;
    sieve[2] = true;
    for(i = 3; i*i <= n; i+=2)
    {
        if(sieve[i])
            for(j = i*i; j <= n; j+=i)
                sieve[j] = false;
    }
    if(n >= 2)
    {
        v.pb(2);
        for(i = 3; i <= n; i+=2)
        {
            if(sieve[i])
                v.pb(i);
        }
    }
    return v;
}*/

/*class graph{
public:
    vector<ll> *g;
    ll n;
    graph(ll v)
    {
        n = v + 1;
        g = new vector<ll> [n];
    }
    void addegde(ll f,ll s)
    {
        g[f].pb(s);
        g[s].pb(f);
    }
    void dfs(bool *visited,ll sv)
    {
        visited[sv] = true;
        for(auto x: g[sv])
        {
            if(!visited[x])
            {
                dfs(visited,x);
            }
        }
    }
    void bfs(ll sv){
       queue<ll> q;
       bool visited[n] = {};
       q.push(sv);
       visited[sv] = true;
       while(!q.empty())
       {
           ll node = q.front();
           q.pop();
           for(auto x : g[node])
           {
               if(!visited[x])
               {
                   visited[x] = true;
                   q.push(x);
               }
           }
       }
    }
};*/
int main()
{
    ll i,j,t;
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5])
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
constexpr int B = 10;

int main() {
    int n;
    long long p;
    string s;
    cin >> n >> p >> s;

    if (p == 2 || p == 5) {
        long long ans = 0;
        for (int i = 0; i < n; i++) {
            const int d = s[i] - '0';
            if (d % p == 0) ans += i+1;
        }
        cout << ans << endl;
        return 0;
    }
    
    long long t = 1;
    reverse(s.begin(), s.end());
    vector<long long> d(n+1, 0);
    for (int i = 0; i < n; i++) {
        d[i+1] = (d[i] + (s[i]-'0') * t) % p;
        t = t * B % p;
    }
    
    long long ans = 0;
    map<long long, long long> mp;
    for (int i = 0; i <= n; i++) ans += mp[d[i]]++;
    
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int H, W;
  cin >> H >> W;
  
  string board[50];
  for (int i = 0; i < H; ++i)
    cin >> board[i];
  
  const int dx[4] = {1, 0, -1, 0};
  const int dy[4] = {0, 1, 0, -1};
  
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (board[i][j] == '.') continue;
      
      int numBlacks = 0;
      for (int d = 0; d < 4; ++d) {
        const int neighbor_i = i + dy[d];
        const int neighbor_j = j + dx[d];
        
        if (neighbor_i < 0 or H <= neighbor_i) continue;
        if (neighbor_j < 0 or W <= neighbor_j) continue;
        if (board[neighbor_i][neighbor_j] == '#') ++numBlacks;
      }
      
      if (numBlacks == 0) {
        cout << "No";
        return 0;
      }
    }
  }
  
  cout << "Yes";
}

Measured memory_bytes: 888
n, k = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i)

res = 0
exp = []

$factorials = []


def calc_exp(i)
  # num = [*1..i].inject(:+).to_f
  num = (i * i + i).to_f / 2.0
  num / i.to_f
end

nums.each do |i|
  exp << calc_exp(i)
end

current = 0
current_added = 0
exp.each_with_index do |e, idx|
  if current_added < k
    current += e
    current_added += 1
    res = current
    next
  end
  current -= exp[idx - k]
  current += e
  res = [current, res].max
end

puts res

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

int main() {
  string n, m;
  cin >> n >> m;
  int c = 0;
  for(int i = 0;i < n.size();++i) {
    if(n.at(i) != m.at(i)) {
      ++c;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 3848
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

vector<vector<int>> G;
vector<int> ans;

void dfs(int cur, int pre) {
	for (auto to : G[cur]) {
		if (to != pre) {
			ans[to] += ans[cur];
			dfs(to, cur);
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n, q;
	cin >> n >> q;
	
	G.resize(n);
	ans.resize(n, 0);
	
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	rep(i, q) {
		int p, x;
		cin >> p >> x;
		p--;
		ans[p] += x;
	}

	dfs(0, -1);

	for (auto a : ans) {
		cout << a << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 23552
S = input()
L = [-1 for i in range(len(S))]	# L[i]-> iから最も近い右にあるLの位置
R = [-1 for i in range(len(S))]	# R[i]-> iから最も近い左にあるRの位置

for i, s in enumerate(S):
  if s == 'L':
    L[i] = i
  else:
    R[i] = i

for i in range(len(S) - 1):
  if R[i + 1] == -1:
    R[i + 1] = R[i]
  if L[len(S) - i - 2] == -1:
    L[len(S) - i - 2] = L[len(S) - i - 1]

ans = [0 for i in range(len(S))]
for i in range(len(S)):
  if S[i] == 'L':
    if (i - R[i]) % 2 == 0:
      ans[R[i]] += 1
    else:
      ans[R[i] + 1] += 1
  else:
    if (L[i] - i) % 2 == 0:
      ans[L[i]] += 1
    else:
      ans[L[i] - 1] += 1

print(' '.join([str(a) for a in ans]))

Measured memory_bytes: 15228
#include <bits/stdc++.h>
#include<iostream>
#include<vector>
#include<string>
#include <sstream>
using namespace std;

int main(){
  int K, A, B, x;
  int j = 0;
  cin >> K >> A >> B;
  
  for(int i = A; i < B+1; i++){
     x = i % K;
    
     if(x == 0){
       j++;
     }
  }
    
  if(j > 0){
    cout << "OK" << endl;
  }    
  else{
    cout << "NG" << endl;
  }
  return 0;
}

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

int main() {
    int n, vi;
    cin >> n;
    map<int, int> even, odd;
    for (int i = 1; i <= n; i++) {
        cin >> vi;
        (i & 1 ? odd[vi] : even[vi])++;
    }

    int key_odd_first, key_odd_second, key_even_first, key_even_second;
    for (auto oddi : odd) {
        if (oddi.second > odd[key_odd_first]) key_odd_first = oddi.first;
    }
    for (auto oddi : odd) {
        if (oddi.second > odd[key_odd_second] && oddi.first != key_odd_first) key_odd_second = oddi.first;
    }
    for (auto eveni : even) {
        if (eveni.second > even[key_even_first]) key_even_first = eveni.first;
    }
    for (auto eveni : even) {
        if (eveni.second > even[key_even_second] && eveni.first != key_even_first) key_even_second = eveni.first;
    }

    int ans_odd = n / 2, ans_even = n / 2;
    if (key_odd_first != key_even_first) {
        ans_odd -= odd[key_odd_first];
        ans_even -= even[key_even_first];
    } else {
        if (odd[key_odd_second] > even[key_even_second]) {
            ans_odd -= odd[key_odd_second];
            ans_even -= even[key_even_first];
        } else {
            ans_odd -= odd[key_odd_first];
            ans_even -= even[key_even_second];
        }
    }

    cout << (ans_odd + ans_even) << endl;
}

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

public class Main {

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

        final int N = sc.nextInt();

        final Map<Integer, Map<Integer, Integer>> testimonies = new HashMap<>();
        for (int i = 0; i < N; i++) {
            final int A = sc.nextInt();
            testimonies.put(i, new HashMap<>());
            for (int j = 0; j < A; j++) {
                final int X = sc.nextInt();
                final int Y = sc.nextInt();
                testimonies.get(i).put(X-1, Y);
            }
        }

        int max = 0;
        for (int bit = 0; bit < (1<<N); bit++) {
            if (judge(N, bit, testimonies)) {
                int count = 0;
                for (int i = 0; i < N; i++) {
                    if ((bit & (1<<i)) != 0) {
                        count++;
                    }
                }
                max = Math.max(max, count);
            }
        }

        System.out.println(max);
    }

    private static boolean judge(int N, int bit, Map<Integer, Map<Integer, Integer>> testimonies) {
        // i 人目の証言を検証する
        for (int i = 0; i < N; i++) {
            // i 人目が「不親切」だったら、証言はすべて無意味
            if ((bit & (1<<i)) == 0) {
                continue;
            }

            // 証言を検証
            for (Map.Entry<Integer, Integer> testimony : testimonies.get(i).entrySet()) {
                final int k = testimony.getKey();
                final int v = testimony.getValue();

                // 証言が「親切」なのに実際は「不親切」ならダメ
                if (v == 1 && (bit & (1<<k)) == 0) {
                    return false;
                }
                // 証言が「不親切」なのに実際は「親切」ならダメ
                if (v == 0 && (bit & (1<<k)) != 0) {
                    return false;
                }
            }
        }
        // 証言がすべて一致していれば true
        return true;
    }
}


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

using namespace std;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int X[100009];

int main() {

    int n, x;

    scanf("%d%d", &n, &x);

    for (int i=0; i<n; i++) {
        int xi;
        scanf("%d", &xi);
        X[i] = abs(xi - x);
    }

    int ret = X[0];


    for (int i=1; i<n; i++) {
        ret = gcd(ret, X[i]);
    }

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

    //printf("%lld\n", gcd(24, 48));

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define INF ((int)1e9)
#define EPS (1e-9)
#define MOD (1000000007)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}
template<class S,class T>ostream& operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	map<int,int> mp;
	int n,t;
	cin>>n;
	vi a(n),b(n),c(n);
	rep(i,n) {
		cin>>t;
		a[t-1]=t*40000+i, b[t-1]=(n-t+1)*40000;
	}
	puti(a);
	puti(b);
	
	return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;

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

int main()
{
    int h, w;
    scanf("%d %d\n", &h, &w);
    queue<ii> bfs;
    for (int i = 0; i != h; ++i)
    {
        for (int j = 0; j != w; ++j)
        {
            char c = getchar();
            if (c == '#') bfs.push({i, j});
            else dist[i][j] = 1000000000;
        }
        getchar();
    }
    int ans = 0;
    while (!bfs.empty())
    {
        ii tmp = bfs.front();
        bfs.pop();
        
        int x, y;
        x = tmp.first;
        y = tmp.second;
        ans = max(ans, dist[x][y]);
        
        for (int i = 0; i != 4; ++i)
        {
            if (x + dx[i] >= 0 && x + dx[i] < h && y + dy[i] >= 0 && y + dy[i] < w && dist[x + dx[i]][y + dy[i]] == 1000000000)
            {
                dist[x + dx[i]][y + dy[i]] = 1 + dist[x][y];
                bfs.push({x + dx[i], y + dy[i]});
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9088
import math
N, K, S = map(int,input().split())

if S % 2 == 1:
  big = math.ceil(S/2)
  small = math.floor(S/2)
else:
  big = int(S/2)
  small = big

ans = list()
if N == K:
  for i,j in enumerate(range(N)):
    ans.append(S)
elif S == 1:
  for i,j in enumerate(range(N)):
    if i < K:
      ans.append(1)
    else:
      ans.append(2)
else:
  for i,j in enumerate(range(N)):
    if i <= K:
      if i % 2 == 0:
        ans.append(small)
      else:
        ans.append(big)
    else:
      if S != 10**9:
        ans.append(S+1)
      else:
        ans.append(S-1)
print(" ".join(map(str,ans)))
    

Measured memory_bytes: 15128
#include<cstdio>
inline int in();
inline void wr(int);
int main(int argc,char**argv){
	register int a=in(),b=in();
	wr((a+b-3)/(a-1)),putchar('\n');
}
inline int in(){
	register char c=getchar();
	register int x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())
		if(c=='-')f=-1;
	for(;c>='0'&&c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c&15);
	return x*f;
}
inline void wr(int x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)wr(x/10);
	putchar(x%10+'0');
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define RFOR(i,a,b) for(long long i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int main() {
	int N;
	cin >> N;
	cout << fixed << 800*N-N/15*200 << endl;
	
	return 0;
}

Measured memory_bytes: 256
<?php
$input_line = explode(' ', trim(fgets(STDIN)));
$N = $input_line[0]; $K = $input_line[1];
$s = 0; $t = 1; $res = 0;
while(1) {
    if ($t+$s > $N) { break; }
    else if ($t*$K >= $s) { $res++; $s += $t; }
    else { $t++; }
}
echo $res;
?>



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

using namespace std;

typedef long long  ll;
typedef vector<ll> VL;
typedef pair<ll,ll> PLL;
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define inf 1000*1000*1000+5
const ll mod=998244353;


int main()
{
	ll n;
	cin>>n;
	VL arr(n);
	ll low=INT_MAX,ct=0,sum=0;
	fr(i,0,n)
	{
		cin>>arr[i];
		if(arr[i]<0)
		{
			ct++;
			low=min(-1*arr[i],low);
			//sum+=arr[i];
		}
		else
		{
			low=min(arr[i],low);
			
		}
		sum+=abs(arr[i]);
	}
	if(ct%2==0)
	{
		cout<<sum<<endl;
	}
	else
	{
		cout<<sum-2*low<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
	int a, b;
	char op;
	while(1){
		int pin = 0;
		scanf("%d %c %d\n",&a,&op,&b);
		switch(op){
			case '?':
				pin = 1;
				break;
			case '+':
				printf("%d\n",a+b);
				break;
			case '-':
				printf("%d\n",a-b);
				break;
			case '*':
				printf("%d\n",a*b);
				break;
			case '/':
				printf("%d\n",a/b);
				break;
		}
		if(pin==1) break;
	}
	return 0;
}


Measured memory_bytes: 2100
n,m = map(int, input().split())
ng = False
b = [False] * n
ans = [0] * n
for i in range(m):
    s,c = map(int, input().split())
    s -= 1
    if not b[s]:
        ans[s] = c
        b[s] = True
    else:
        if ans[s] != c:
            ng = True

if n == 1:
    if ng:
        print(-1)
    else:
        print(*ans,sep="")
else:
    if ng:
        print(-1)
    else:
        if (not b[0]) and (ans[0] == 0):
            ans[0] = 1
            print(*ans,sep="")
        elif (b[0]) and (ans[0] == 0):
            print(-1)
        else:
            print(*ans,sep="")


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

const int mod = 1e9 + 7;

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

    vector<int> A(N), B(M);
    for (int& x : A) cin >> x;
    for (int& x : B) cin >> x;

    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    A.push_back(-1);
    B.push_back(-1);

    int ans = 1, cnt = 0, r = 0, c = 0;
    for (int x = N * M; x > 0; x--, cnt++) {
        if (A[r] == x && B[c] == x) {
            r++, c++;
        }
        else if (A[r] == x) {
            ans = ans * c % mod;
            r++;
        }
        else if (B[c] == x) {
            ans = ans * r % mod;
            c++;
        }
        else {
            ans *= r * c - cnt;
            ans %= mod;
        }
    }
    cout << ans << endl;

    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n; cin>>n;
    vi A(n);
    rep(i, n) cin>>A[i];
    int ans=0;
    rep(i, n){
        int b; cin>>b;
        ans += b;
    }
    vi C(n-1);
    rep(i, n-1) cin>>C[i];
    rep(i, n-1){
        if (A[i]+1 == A[i+1]){
            ans += C[A[i]-1];
        }
    }
    cout << ans << "\n";
	return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,Q;
string S;
string A[202020],B[202020];

int outL(int cur) {
	if(cur>=N) return 0;
	int i;
	FOR(i,Q) {
		if(S[cur]==A[i][0]) {
			if(B[i]=="L") cur--;
			if(B[i]=="R") cur++;
		}
		if(cur<0) return 1;
		if(cur>=N) return 0;
	}
	return 0;
}

int outR(int cur) {
	if(cur<0) return 0;
	int i;
	FOR(i,Q) {
		if(S[cur]==A[i][0]) {
			if(B[i]=="L") cur--;
			if(B[i]=="R") cur++;
		}
		if(cur<0) return 0;
		if(cur>=N) return 1;
	}
	return 0;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>Q>>S;
	FOR(i,Q) cin>>A[i]>>B[i];
	
	int L=-1;
	for(i=20;i>=0;i--) if(outL(L+(1<<i))) L+=1<<i;
	int R=N;
	for(i=20;i>=0;i--) if(outR(R-(1<<i))) R-=1<<i;
	
	int ret=N;
	FOR(i,N) if(i<=L || i>=R) ret--;
	
	cout<<ret<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 22452
import math
abc = [int(input()) for _ in range(5)]
tmp = 9
ans = 0
ii = 0
for i in range(5):
    tmpp = min(tmp, (abc[i]-1)%10)
    if tmp != tmpp:
        tmp = tmpp
        ii = i
for i in range(5):
    if i == ii:
        ans += abc[i]
    else:
        ans += (math.ceil(abc[i]/10))*10
print(ans)

Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
#define endl "\n"
typedef long long ll;
const long long INF=1e9;
int ci;

int main(){
    int k;
    int n=1e7+1;
    cin >> k;
    if(k%7==0) k/=7;
    if(k==1){
        cout << 1 << endl;
        return 0;
    }
    int ans=1;
    int r,a=10;
    r = a%(9*k);
    rep(i, n){
        if(r==1){
            cout << ans << endl;
            cin >> ci;
            return 0;
        }
        else r=(10*r)%(9*k);
        ++ans;
    }
    cout << -1 << endl;
    cin >> ci;
}

Measured memory_bytes: 3636
S = input()
x, y = int(S[:2]),int(S[2:])

yymm = (1<=y<=12)
mmyy = (1<=x<=12)

if yymm and mmyy:
    answer = 'AMBIGUOUS'
elif yymm and not(mmyy):
    answer = 'YYMM'
elif mmyy and not(yymm):
    answer = 'MMYY'
else:
    answer = 'NA'
print(answer)

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

n,k = map(int, input().split())
As = [int(input()) for i in range(n)]

# N: 処理する区間の長さ

INF = 0

mx = 300001
LV = (mx-1).bit_length()
N0 = 2**LV
data = [INF]*(2*N0)
lazy = [None]*(2*N0)

# 伝搬対象の区間を求める
def gindex(l, r):
    L = (l + N0) >> 1; R = (r + N0) >> 1
    lc = 0 if l & 1 else (L & -L).bit_length()
    rc = 0 if r & 1 else (R & -R).bit_length()
    for i in range(LV):
        if rc <= i:
            yield R
        if L < R and lc <= i:
            yield L
        L >>= 1; R >>= 1

# 遅延伝搬処理
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v
        lazy[i-1] = None

# 区間[l, r)をxで更新
def update(l, r, x):
    *ids, = gindex(l, r)
    propagates(*ids)

    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = x
        if L & 1:
            lazy[L-1] = data[L-1] = x
            L += 1
        L >>= 1; R >>= 1
    for i in ids:
        data[i-1] = max(data[2*i-1], data[2*i])

# 区間[l, r)内の最小値を求める
def query(l, r):
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = max(s, data[R-1])
        if L & 1:
            s = max(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s

update(As[0],As[0]+1,1)
for i, a in enumerate(As[1:]):
    l = max(0,a-k)
    r = min(mx,a+k)
    upd = query(l,r+1)
    if upd == -1:continue
    # print("i",i,"a",a,"upd",upd,"l",l,"r",r)
    update(a, a+1, upd+1)

ans = 0
for a in set(As):
    ans = max(ans,query(a,a+1))
print(ans)

Measured memory_bytes: 141700
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int N;
vector<P> p;
int G[101][101];

void connect(P p1, P p2){
    G[p1.first][p2.first]=1;
    G[p1.first][p2.second]=1;
    G[p1.second][p2.first]=1;
    G[p1.second][p2.second]=1;
}

int main(){
    cin>>N;
    if(N&1){
        rep(i,N/2){
            p.push_back(P(i+1,N-i-1));
        }
        p.push_back(P(N,N));
    }else{
        rep(i,N/2){
            p.push_back(P(i+1,N-i));
        }
    }

    for(int i=0;i<p.size()-1;i++){
        for(int j=i+1;j<p.size();j++){
            connect(p[i],p[j]);
        }
    }

    int M=0;
    repn(i,N){
        repn(j,N){
            if(G[i][j]==1){
                M++;
            }
        }
    }
    cout<<M<<endl;
    repn(i,N){
        repn(j,N){
            if(G[i][j]==1){
                cout<<i<<' '<<j<<endl;
            }
        }
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC127D34
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            long N = long.Parse(str[0]);//カードの枚数
            long M = long.Parse(str[1]);//操作の回数
            long[] A = new long[N];
            string[] str2 = Console.ReadLine().Split();
            for (int i = 0; i < N; i++)
            {
                A[i] = long.Parse(str2[i]);//カードの値
            }
            //Console.WriteLine(N+" "+M);
            //Array.Sort(A, (x, y) => x.CompareTo(y));
            Array.Sort(A);
            long[][] B = new long[M][];
            for (int i = 0; i < M; i++)
            {
                string[] str3 = Console.ReadLine().Split();
                B[i] = new long[2];
                B[i][0] = long.Parse(str3[0]);//B枚
                B[i][1] = long.Parse(str3[1]);//置き換える値
            }
            Array.Sort(B, (x, y) => y[1].CompareTo(x[1]));//置き換える値の大きい順にソート
            /*
            for (int i = 0; i < M; i++)
            {
                Console.WriteLine(B[i][0]+" "+B[i][1]);
            }
            */
            var list = new List<long> ();
            int ct = 0;
            for (int i = 0; i < M; i++)
            {
                for (long j = 0; j < B[i][0]; j++)
                {
                    list.Add(B[i][1]);
                    ct++;
                    if (ct > N)
                    {
                        break;
                    }
                }
            }
            long ans = 0;
            for (int i = 0; i < Math.Min(N,list.Count); i++)
            {
                ans += Math.Max(A[i], list[i]);
            }
            for (long i = Math.Min(N,list.Count); i < N; i++)
            {
                ans += A[i];
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 33952
H,N = map(int,input().split())
l = []
for i in range(N):
  l.append( list(map(int,input().split())) )

#dp[i][h]:i番目の魔法まで見てhのダメージを与えるときの最小魔力
dp = [[10**8+1 for j in range(H+1)] for i in range(N+1)]
dp[0][0] = 0

#配るdpで考える
for i in range(N):
  for h in range(H+1):
    #i番目の魔法を使わないとき
    dp[i+1][h] =  min(dp[i][h], dp[i+1][h])
    #i番目の魔法を一個使うとき
    dp[i+1][ min(h+l[i][0],H) ]  = min(dp[i+1][min(h+l[i][0],H)],dp[i+1][h]+l[i][1] )   
print(dp[N][H])

Measured memory_bytes: 125276
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[1010];
		for(int i = 2 ; i <= 1000 ; i++) {
			boolean isPrime = true;
			for(int j = 2 ; j * j <= i ; j++) {
				if(i % j == 0) isPrime = false;
			}
			if(isPrime) {
				int v = i;
				while(v <= 1000) {
					a[i] += n / v;
					v *= i;
				}
			}
		}
		long ans = 1;
		for(int i = 0 ; i <= 1000 ; i++) {
			ans = ans * (a[i] + 1) % 1000000007;
		}
		System.out.println(ans);
	}
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

const int N = 1e4;

void solve() {
  string s; cin >> s;
  if (s.back() == 's') s += "es"; else s += "s";
  cout << s;
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES (n == 1)

int main() {
  ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
  cout.setf(ios::fixed), cout.precision(2);
  //cout << 1.0 * clock() / CLOCKS_PER_SEC << endl;
  solve();
}


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

int main(){
    int n;
    double a, mn, mx, sum = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(i == 0) mn = mx = a;
        sum += a;
        if(mn > a) mn = a;
        if(mx < a) mx = a;
    }
    printf("%.0f %.0f %.0f\n", mn, mx, sum);
    return 0;
}



Measured memory_bytes: 3292
n, m = map(int, input().split())
k = [0] * m
s = [[] for _ in range(m)]
for i in range(m):
    l = list(map(int, input().split()))
    k[i] = l[0]
    s[i] = l[1:]
p = list(map(int, input().split()))

ans = 0
for i in range(1 << n):
    s_num = [0] * m
    for j in range(n):
        if i >> j & 1:
            for k in range(m):
                if j + 1 in s[k]:
                    s_num[k] += 1
    s_num = [x % 2 for x in s_num]
    if s_num == p:
        ans += 1
print(ans)

Measured memory_bytes: 42988
#include<bits/stdc++.h>
#define int long long int  //comment for large arrays
#define pll pair<int,int>
#define dbl long double
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define eps 0.00000001
#define INF 10000000000000001
#define all(x) (x).begin(),(x).end()
#define LB(v,x) (lower_bound(all(v),x) - v.begin()) 
#define UB(v,x) (upper_bound(all(v),x) - v.begin())
#define size(x) (int)(x).size()
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define popb() pop_back()
#define popf() pop_front()
#define mp(x,y) make_pair((x),(y))
#define vec(dt) vector<dt>
#define vv(dt) vector<vector<dt>>
#define fastio(x) ios_base::sync_with_stdio(x); cin.tie(NULL)
#define init(v,s) memset(v,s,sizeof(v)) 
#define bug(x) cerr<<"LINE: "<<__LINE__<<" || click to see test details "<<#x<<" = "<<x<<endl
#define loop(i,s,n) for(int i=s;i<n;i++)
#define bugprint(v) for(auto it:v) cout<<it<<" "; cout<<endl 
using namespace std;

int n,m,vis[100001];
vec(int) adj[100001],topological;

void dfs(int node)
{
	vis[node] = 1;
	for(auto it:adj[node])
		if(!vis[it])
			dfs(it);
	topological.pb(node);
}


signed main()
{
	fastio(0);
	cin>>n>>m;
	loop(i,0,m)
	{
		int x,y;
		cin>>x>>y;
		adj[x].pb(y);
	}
	loop(i,1,n+1) if(!vis[i]) dfs(i);
	int dp[n+1];
	init(dp,0);
	for(auto node:topological)
		for(auto it:adj[node])
			dp[node] = max(dp[node],dp[it]+1);
	int ans = 0;
	loop(i,1,n+1) ans = max(ans,dp[i]);
	cout<<ans<<endl;
	return 0;		
}

Measured memory_bytes: 9720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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

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

template<class T> inline auto __lcm(T& a, T& b) 
{ return a * b / __gcd(a, b); }

template<typename T> void remove(std::vector<T>& vector, unsigned int index)
{ vector.erase(vector.begin() + index); }


int main() {
  static const double pi = 3.141592653589793;
  double a, b, x;  cin >> a >> b >> x;

  double V = pow(a, 2) * b;
  if (V / 2 > x) {
    double A = a * pow(b, 2);
    double B = -2 * x;
    double cos_alpha = A / sqrt(pow(A, 2) + pow(B, 2));
    double alpha = acos(cos_alpha) * 180 / pi;

    cout << fixed << setprecision(8) << 90 - alpha;
  } else {
    double A = 2 * (b - x / pow(a, 2));
    double B = a;
    double sin_alpha = B / sqrt(pow(A, 2) + pow(B, 2));
    double alpha = asin(sin_alpha) * 180 / pi;

    cout << fixed << setprecision(8) << 90 - alpha;
  }

  return 0;
}

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

typedef long long ll;

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

    int N, W;
    cin>>N>>W;

    int weight, value;

    vector<ll> dp(W+1, 0);
    for (int i=0;i<N;++i){
        cin>>weight>>value;
        vector<ll> memo(W+1);
        
        for (int w=0;w<=W;++w){
            if (w>=weight) memo[w] = max(dp[w], dp[w-weight] + value);
            else memo[w] = dp[w];
        }
        dp = memo;
    }

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

Measured memory_bytes: 1804
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;

int main(){
	int num[12][12]={};
	int N,x;
int a;
while(1)
{cin>>N;
if(N==0)break;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++)
{cin>>num[i][j];num[i][N]+=num[i][j];}
}
for(int i=0;i<N;i++)
num[N][N]+=num[i][N];
for(int i=0;i<N;i++)
	for(int j=0;j<N;j++)
num[N][i]+=num[j][i];

for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++)
{

	
/*if(num[i][j]==0)a==4;
else if(num[i][j]>0)a =5-( (int)log10((double)(num[i][j]) )+ 1);
else if(num[i][j]<0)a =4-( (int)log10((double)(-num[i][j]) )+ 1);
for(int k=0;k<a;k++)
{cout<<" ";}
*/
printf("%5d",num[i][j]);}
cout<<endl;


}

for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++){
num[i][j]=0;
}
}


}

return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int K, N;
  cin >> K >> N;
  vector <int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  
  int longest = (K-A[N-1]+A[0]);
  for (int i = 1; i < N; i++) {
    longest = max(longest, A[i]-A[i-1]);
  }
  cout << K-longest << endl;
  return 0;
}


Measured memory_bytes: 1024
def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    routes = []
    routes.append(list(map(lambda x: int(x), inputs[0].split())))
    routes.append(list(map(lambda x: int(x), inputs[1].split())))
    N = len(routes[0])
    sums = []
    for down_point in range(0, N):
        sum = 0
        for j in range(0, down_point + 1):
            sum += routes[0][j]
        for j in range(down_point, N):
            sum += routes[1][j]
        sums.append(sum)

    max = 0
    for i in sums:
        max = i if i > max else max
    return max


if __name__ == "__main__":
    input()
    ret = solve(inputs(2))
    print(ret)


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

using namespace std;

const int MAX_V = 10010;

class UnionFindTree {
public:
  vector<int> par;
  UnionFindTree(int V=0){
    par.clear(); par.resize(V);
    for(int i=0;i<V;i++) par[i] = i;
  }

  int find(int x) {
    if( x == par[x] ) return x;
    return par[x] = find(par[x]);
  }

  void unit(int x,int y) {
    x = find(x), y = find(y);
    if( x != y ) par[x] = y;
  }

};

struct Edge {
  int src,dst,weight;
  bool operator < ( const Edge &edge ) const {
    if( weight != edge.weight ) return weight < edge.weight;
    return ( ( src != edge.src ) ? src < edge.src : dst < edge.dst );
  }
};

int V,E;

int kruskal(vector<Edge> edges){
  int ret = 0;
  sort(edges.begin(),edges.end());
  UnionFindTree uf(V);
  for(int i=0;i<edges.size();i++){
    int p1 = edges[i].src, p2 = edges[i].dst;
    if( uf.find(p1) != uf.find(p2) ) {
      uf.unit(p1,p2);
      ret += edges[i].weight;
    }
  }
  return ret;
}

int main(){
  cin >> V >> E;
  vector<Edge> edges;
  for(int i=0;i<E;i++) {
    int src,dst,weight;
    cin >> src >> dst >> weight;
    edges.push_back((Edge){src,dst,weight});
  }
  printf("%d\n",kruskal(edges));
  return 0;
}

Measured memory_bytes: 3636
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {
        var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var E = input[0];
        var Y = input[1];
        switch (E)
        {
            case 0:
                if (Y <= 1911)
                {
                    Console.WriteLine("M{0}", Y - 1867);
                }
                else if (Y <= 1925)
                {
                    Console.WriteLine("T{0}", Y - 1911);
                }
                else if (Y <= 1988)
                {
                    Console.WriteLine("S{0}", Y - 1925);
                }
                else
                {
                    Console.WriteLine("H{0}", Y - 1988);
                }
                break;
            case 1:
                Console.WriteLine(Y + 1867);
                break;
            case 2:
                Console.WriteLine(Y + 1911);
                break;
            case 3:
                Console.WriteLine(Y + 1925);
                break;
            case 4:
                Console.WriteLine(Y + 1988);
                break;
            default:
                break;
        }
    }
}


Measured memory_bytes: 18376
#include<iostream>
using namespace std;
char fg[101][101];
int H,W;
int a[4]={-1,0,0,1};
int b[4]={0,-1,1,0};
char nowfruit;
int cnt=0;
void func(int x,int y);
main(){
  while(1){
    cnt=0;
    cin>> H>> W;
    if(H==0&&W==0) break;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	cin>> fg[i][j];
      }
    }
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	if(fg[i][j]!='.'){
	  nowfruit=fg[i][j];
	  func(i,j);
	  cnt++;
	}
      }
    }
    cout<< cnt<< endl;
  }
}
void func(int x,int y){
  fg[x][y]='.';
  for(int vh=0;vh<4;vh++){
    int nx=x+a[vh];
    int ny=y+b[vh];
    if(nx>=0 && nx<H && ny>=0 && ny<W && fg[nx][ny]==nowfruit){
      func(nx,ny);
    }
  }
}

Measured memory_bytes: 1476
def factorial(number)
  number = 0 if number.nil?
  (1..number).inject(1,:*)
end

n = gets.to_i
P = gets.chomp.split(" ").map(&:to_i);
Q = gets.chomp.split(" ").map(&:to_i);
na = [*1..n]
nb = [*1..n]

a=0
b=0
for i in 0..(n-1)
    fc=factorial(n-i-1)
    
    a = a + (na.index(P[i])+1) * fc
    na.delete(P[i])
    b = b + (nb.index(Q[i])+1) * fc
    nb.delete(Q[i])
end

p (a-b).abs

Measured memory_bytes: 1788
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
N = int(input())
K = 10**5+1
P = [i for i in range(K)]

def par(a):
    if P[a] == a:
        return a
    t = par(P[a])
    P[a] = t
    return t
def cb(a, b):
    P[par(b)] = par(a)

X = [[] for _ in range(K)]
Y = [[] for _ in range(K)]
for _ in range(N):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    Y[y-1].append(x-1)
for i in range(K):
    for j in range(len(Y[i])-1):
        cb(Y[i][j], Y[i][j+1])

M = [[] for _ in range(K)]
for i in range(K):
    M[par(i)].append(i)
ans = -N
for i in range(K):
    S = []
    for j in M[i]:
        for k in X[j]:
            S.append(k)
    S = list(set(S))
    ans += len(S)*len(M[i])
print(ans)


Measured memory_bytes: 117296
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 0;
string s;
ll curr=0;

int main(){
	IOS
	cin >> s;
	ll ans=0;
	ll n=s.length();
	for(int i=0;i<n;i++){
		if(s[i]=='W'){
			ans+=abs(curr-i);
			curr++;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 3712
from collections import deque

n = int(input())
lst = deque()

for i in range (n):
    com = input().split()

    if com[0] == "insert":
        lst.appendleft(com[1])

    elif com[0] == "delete":
        try:
            lst.remove(com[1])
        except ValueError:
            continue

    elif com[0] == "deleteFirst":
        lst.popleft()

    else:
        lst.pop()

print(*lst)


Measured memory_bytes: 69736
//**************************
//*** writer  :  Alan Hu **
//************************

//傅思程你敢抄我程序？？？
//傅思程你敢抄我程序？？？
//傅思程你敢抄我程序？？？

#include<bits/stdc++.h>

using namespace std;

#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mkp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int a,b;

int main()
{
	cin>>a>>b;
	for (int i=1;i<=3;i++)
	{
		if (a*b*i%2==1)
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {


        Scanner sc = new Scanner(System.in);
        long X = sc.nextLong();
        long C = 100;
        int ans =0;
        while(C<X){
            C = cal(C);
            ans++;
        }
        System.out.println(ans);

    }
    private static long cal(long x){

        long amp = x + (x/100);
        return amp;
    }
}


Measured memory_bytes: 35808
n,h=map(int,input().split())
ab=sorted([list(map(int,input().split())) for _ in range(n)],key=lambda x:x[1],reverse=True)
m=max([i[0] for i in ab])
ans=0
for i in ab:
  if i[1]>m:
    h-=i[1]
    ans+=1
    if h<=0:
      print(ans)
      exit()
if h%m==0:
  print(ans+h//m)
else:
  print(ans+h//m+1)

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

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

	string s, ans;
	cin >> s;

	for (int i = 0; i < s.length(); i++)
	{
		ans.insert(0, "x");
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
lst = [None]*(M+1)
pre_count = 1
pre_current = ''
lst[0] = ['000000',0,0]
for i in range(1,M+1):
  lst[i] = list(map(int,input().split()))
  lst[i].append(i)
for k in range(1,M+1):
  lst[k][0] = str(lst[k][0])
  lst[k][0] = lst[k][0].zfill(6)
lst.sort(key = lambda x:x[1])
lst.sort(key = lambda x:x[0])
for j in range(1,M+1):
  if lst[j][0] == lst[j-1][0]:
    pre_count += 1
    lst[j].append(str(pre_count).zfill(6))
  else:
    pre_count = 1
    lst[j].append(str(pre_count).zfill(6))
lst.sort(key = lambda x:x[2])
for x in range(1,M+1):
  print(lst[x][0]+lst[x][3])

Measured memory_bytes: 43280
#include <stdio.h>

int main(){
  int n,k;
  scanf("%d%d",&n,&k);
  int i = 0;
  long long int ans=0;
  for(i=1;i<=k;i++){
    if((i+i)%k == 0 && i <= n){
      long long int num = (n-i)/k+1;
      ans = ans + num*num*num;
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
    int e[4];
    for(int i=0;i<4;++i) cin>>e[i];
    sort(e,e+4);
    cout<<((e[0]==e[1]&&e[2]==e[3])?"yes":"no")<<endl;
    return 0;
}


Measured memory_bytes: 3156
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<tuple>
#include<utility>
#include<cctype>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define enter "\n"

typedef long long ll;


int abc104_c(){
    //入力
    int d,g;
    ll p[11],c[11];
    cin >> d >> g;
    REP(i,d){
        cin >> p[i] >> c[i];
    }
    ll ans = 1e9;

    //処理
    for(int mask=0 ; mask < (1<<d) ; ++mask){
        ll score=0 , tmp=0 , restmax=-1;
        REP(i,d){
            if((mask>>i) & 1){
                score += p[i]*(i+1)*100 + c[i];
                tmp += p[i];
            }else{
                restmax = i;
            }
        }
        if(score<g){
            if(score + p[restmax]*(restmax+1)*100 >= g){
                ll need = ((g - score -1) / ((restmax+1)*100)) + 1;
                if(need<=p[restmax]) tmp += need;
            }else{
                continue;
            }
        }
        ans = min(ans, tmp);
    }

    //出力
    cout << ans <<enter;
    return 0;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int A, B;
    cin >> A >> B;

    if (A >= 10 || B >= 10) cout << -1 << endl;
    else cout << A * B << endl;
    return 0;
}

Measured memory_bytes: 256