akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MAX_V 55
int INF = 1 << 28;
struct edge{
  int to,cap,rev;
  edge(){}
  edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
};
vector<edge> G[MAX_V*2+2];
bool used[MAX_V*2+2];
void add_edge(int from,int to,int cap){
  G[from].push_back(edge(to,cap,G[to].size()));
  // undirected
  //G[to].push_back(edge(from,cap,G[from].size()-1));
  // directed
  G[to].push_back(edge(from,0,G[from].size()-1));
}
 
int dfs(int v,int t,int f){
  if(v==t) return f;
  used[v]=true;
  for(int i=0;i<(int)G[v].size();i++){
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0 ){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    } 
  }
  return 0;
}
 
int max_flow(int s,int t){
  int flow=0;
  for(;;){
    memset(used,0,sizeof(used));
    int f=dfs(s,t,INF);
    if(f==0) return flow;
    flow+=f;
  }
}
 
signed main(){
  int V,E;
  cin>>V>>E;
  for(int i=0;i<E;i++){
    int u,v,c;
    cin>>u>>v>>c;
    add_edge(u,v,c);
  }
  cout<<max_flow(0,V-1)<<endl;
  return 0;
}

/*
verified on 2017/04/22
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A&lang=jp
*/

Measured memory_bytes: 3196
# https://atcoder.jp/contests/abc046/tasks/arc062_a
# 条件を考えよう
# iのときの割合の人数n[i],m[i]を考えると
# n[i]=p*A[i], m[i]=p*B[i] かつ n[i]>=n[i-1], m[i]>=m[i-1] を満たす最小のn[i], m[i]
# このような条件を満たすpを探すのは容易だ
# n[i-1]//A[i] がn[i]をギリギリ超えないpなのだから、ギリギリ超えるpはn[i-1]//A[i] + 1 (ぴったり割り切れるときは注意)
# nについてもmについてもギリギリ越したいのだから大きい方を採用する。(小さい方では片方が超えなくなる)


N = int(input())
ans = 1


def ret_nm(t, a, n, m):
    times_t = (n - 1) // t + 1
    times_a = (m - 1) // a + 1
    times = max(times_t, times_a)
    return times * t, times * a


n = m = 1
for _ in range(N):
    t, a = map(int, input().split())
    n, m = ret_nm(t, a, n, m)


print(n + m)


Measured memory_bytes: 38768
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    int N;
    string S;
    cin >> N >> S;
    int maxi = 0;
    for (int i = 1; i < N; i++)
    {
        int cnt = 0;
        vector<int> before(26, 0), after(26, 0);
        for (int j = 0; j <= i; j++)
        {
            before[S[j] - 'a']++;
        }
        for (int j = i + 1; j < N; j++)
        {
            after[S[j] - 'a']++;
        }
        for (int i = 0; i < 26; i++)
        {
            if (before[i] != 0 && after[i] != 0)
            {
                cnt++;
            }
        }
        maxi = max(maxi, cnt);
    }
    cout << maxi << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b<=a+c&&a+b<=b+c){
        cout<<a+b<<endl;
    }else if(b+c<=a+b&&b+c<=a+c){
        cout<<b+c<<endl;
    }else if(a+c<=a+b&&a+c<=b+c){
        cout<<a+c<<endl;
    }
    return 0;
}

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

using namespace std;

int main(void){
  char data[128];
  while(1){
    int n;
    char before, after;
    cin >> n;
    if(n == 0) break;
    //初期化
    for(int i = 0; i< 128; i++){
      data[i] = i;
    }

    //条件の代入
    for(int i = 0; i< n; i++){
      cin >> before;
      cin >> data[before];
      //    printf("%d\n",data[before]);
    }
    
    int num;
    cin >> num;
    char figure;
    for(int i = 0; i< num ; i++){
      cin >> figure;
      cout << data[figure];
    }
    cout << "\n";
  }
}

Measured memory_bytes: 1120
#include<iostream>
using namespace std;
int main () {
  int T, X;
  cin >> T >> X;
  int ans = T / X;
  int sho[] = {0, 0, 0, 0, 0};
  for ( int i = 0; i < 5; i ++) {
    T = T % X;
    T *= 10;
    sho[i] = T / X;
  }
  cout << ans << ".";
  for ( int i = 0; i < 5; i ++) {
    cout << sho[i];
  }
  cout << endl;
}
  

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int N = ni();
        int W = ni();

        ArrayList<Integer> vlist = new ArrayList<>();
        ArrayList<Integer> wlist = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            int v = ni();
            int w = ni();
            int m = ni();
            int p = 1;
            int tv = v;
            int tw = w;
            while (true) {
                if (m > p) {
                    m -= p;
                } else {
                    vlist.add(m * v);
                    wlist.add(m * w);
                    break;
                }
                vlist.add(tv);
                wlist.add(tw);
                tv *= 2;
                tw *= 2;
                p *= 2;
            }
        }

        int n = vlist.size();

        int[][] dp = new int[n + 1][W + 1];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <= W; j++) {
                if (j < wlist.get(i)) {
                    dp[i + 1][j] = dp[i][j];
                } else {
                    dp[i + 1][j] = Math.max(dp[i][j], dp[i][j - wlist.get(i)] + vlist.get(i));
                }
            }
        }

        out.println(dp[n][W]);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 87856
n = int(input())
ans = "No"

if n > 81 or n == 0:
    print(ans)
    exit()
else:
    for i in range(1, 10)[::-1]:
        x = n/i
        #print(x)
        if x.is_integer() == True:
            if len(str(int(x))) == 1:
                ans = "Yes"
    print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

signed main(){
	int Q,H,S,D,N;
	int ans=0;
	cin>>Q>>H>>S>>D>>N;
	pair<int,double> F[5]={};
	F[0]=make_pair(Q*8,0.25);
	F[1]=make_pair(H*4,0.5);
	F[2]=make_pair(S*2,1.0);
	F[3]=make_pair(D,2.0);
	sort(F,F+4);
	REP(i,4){
		if(F[i].second==2.0){
			ans+=(N/2)*D;
			N=N%2;
		}
		else{
			int t;
			if(F[i].second==1.0){
				t=S;
			}
			else if(F[i].second==0.5){
				t=H;
			}
			else{
				t=Q;
			}
			DEB(t)DEB((double)N/F[i].second)END
			ans+=(int)((double)N/F[i].second)*t;
			break;
		}
		DEB(N)DEB(F[i].first)END
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

void Output(vector<int> A)
{
	for (int i = 0;i < A.size();i++)
	{
		cout << A[i];
		if (i != A.size() - 1)
			cout << " ";
	}
	cout << endl;
}

int main()
{
	int N;

	cin >> N;

	vector<int> A(N);

	for (int i = 0;i < N;i++)
		cin >> A[i];

	Output(A);
	for (int i = 1;i < N;i++)
	{
		int v = A[i];

		int j = i - 1;
		while (j >= 0 && A[j] > v)
		{
			A[j + 1] = A[j];
			j--;
		}

		A[j + 1] = v;

		Output(A);
	}


	return 0;
}

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

using namespace std;
#define ff first
#define ss second
#define pb push_back
#define quicker ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;

vector<int> parent, size; //Both of size n where n is the number of nodes

void make_set(int v) {
    parent[v] = v;
    size[v] = 1;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (size[a] < size[b])
            swap(a, b);
        parent[b] = a;
        size[a] += size[b];
    }
}

int main()
{
    quicker
    int n, m, k, a, b;
    cin >> n >> m >> k;
    vector<vector<int>> adj(n + 1);
    vector<vector<int>> nadj(n + 1);
    parent.resize(n + 1, -1);
    size.resize(n + 1, 0);
    for (int i = 1; i <= n; i++) make_set(i);
    for (int i = 0; i < m; i++){
      cin >> a >> b;
      adj[a].pb(b);
      adj[b].pb(a);
      union_sets(a, b);
    }
    for (int i = 0; i < k; i++){
      cin >> a >> b;
      nadj[a].pb(b);
      nadj[b].pb(a);
    }
    vector<int> ans(n + 1, 0);
    for (int i = 1; i <= n; i++){
      ans[i] = size[find_set(i)] - 1;
      for (auto u: adj[i]) --ans[i];
      for (auto u: nadj[i]) if (find_set(i) == find_set(u)) --ans[i];
    }
    for (int i = 1; i <= n; i++) cout << ans[i] << " ";
    return 0;
}


Measured memory_bytes: 13048
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc093/tasks/abc093_b

int main() {
    int A, B, K; cin >> A >> B >> K;

    set<ll>st;
    for (int i = A; i < A+K; i++) {
        if (i > B) continue;
        st.insert(i);
    }
    for (int i = B; i > B-K; i--) {
        if (i < A) continue;
        st.insert(i);
    }

    for (ll t : st) {
        cout << t << "\n";
    }

    return 0;
}


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

using namespace std;

int main(){
	double x1,y1,x2,y2;
	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    printf("%.8lf\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}



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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;
ll h;

ll a[MAX_N], b[MAX_N];

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &h);

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

  ll max_a = -1LL;

  for (int i = 0; i < n; ++i) {
    max_a = max(max_a, a[i]);
  }

  sort(b, b + n, greater<ll>());

  ll cnt = 0LL;
  ll dmg = 0LL;

  for (int i = 0; i < n; ++i) {
    if (b[i] <= max_a) break;

    cnt += 1LL;

    dmg += b[i];

    if (dmg >= h) break;
  }

  ll ans;
  if (dmg >= h) {
    ans = cnt;
  } else {
    ll remain = h - dmg;

    cnt += (remain - 1LL + max_a) / max_a;

    ans = cnt;
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>

using namespace std;

int main(){

    int N; cin >> N;

    vector <int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];

    sort(a.begin(), a.end(), greater<int>());

    int num = a[0], count = 0;
    while(num > 0){
        num = num / 2;
        count ++;
    }


    vector <int> b(count);
    for (int i = 0; i < N; i++){
        num = a[i];
        for (int j = 0; j < count; j++){
            b[j] += num % 2;
            num = num / 2;
        }
    }

    bool flag = true;
    for (int i = 0; i < count; i++){
        if (b[i] % 2 != 0){
            flag = false;
            break;
        }
    }
    
    if (flag == true) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    


    return 0;
}

Measured memory_bytes: 640
a = gets.to_i
b = gets.to_i
c = gets.to_i
x = gets.to_i

cnt = 0
0.upto(a) do |i|
  0.upto(b) do |j|
    0.upto(c) do |k|
      cnt += 1 if 500 * i + 100 * j + 50 * k == x
    end
  end
end
puts cnt


Measured memory_bytes: 1788
/*input
2
ip cc
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}


int main(){
	IOS;
	string s;
	cin>>s;
	bool f=1;
	REP(i,SZ(s)){
		if(i&1){
			if(s[i]=='R') f=0;
		}
		else{
			if(s[i]=='L') f=0;
		}
	}
	if(f) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
A,B,K=map(int,input().split())


def yaku(num):
    yaku_num=[num]
    for i in range(1,num):
        if num % i == 0:
            yaku_num.append(i)
    return yaku_num

A_yaku=set(yaku(A))
B_yaku=set(yaku(B))
# print(A_yaku)
# print(B_yaku)

yakusu=list(A_yaku & B_yaku)
# print(yakusu[K-1])
yakusu.sort(reverse=True)
print(yakusu[K-1])

Measured memory_bytes: 3064
//
// Created by Myabu on 2020/01/21.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int M;
    cin>>M;
    cout<<48-M<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define ll long long
using namespace std;

ll n,s,len;
bool check(ll x, ll tmp) {
	if (tmp == 1)
		return true;
	ll cnt = 0;
	while (x) {
		cnt += x % tmp;
		x /= tmp;
	}
	return cnt == s;
}

int main() {
	cin>>n>>s;
	len = (ll)sqrt(n) + 1;
	for (ll i = 2; i <= len; i++)
		if (check(n, i)) {
			cout<<i<<endl;
			return 0;
		}
	if (n <= s) {
		cout<< (n < s ? -1 : n + 1) <<endl;
		return 0;
	}
	ll tmp = n - s, ttmp = tmp / len + 1;
	for (int i = ttmp; i; i--)
		if (tmp % i == 0 && s >= i && s - i <= tmp / i && i <= tmp / i) {
			cout<< (tmp / i + 1) <<endl;
			return 0;
		}
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    N=ii()
    d = [0] * 10**5 * 2
    ans = 0
    for a in mis():
        d[a] += 1
        ans += a
    Q=ii()
    for _ in range(Q):
        b, c = mis()
        d[c] += d[b]
        ans -= d[b]*b
        ans += d[b]*c
        d[b] = 0
        print(ans)


main()



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

int main() {
    int n, a;
    int max, min;
    max = -10000000;
    min = 10000000;
    long long sum = 0;

    cin >> n;
    for (int i=0; i < n; i++) {
        cin >> a;
        if (max < a) max = a;
        if (a < min) min = a;
        sum += a;
    }

    cout << min << " " << max << " " << sum << "\n";
    return 0;
}

Measured memory_bytes: 1168
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var s = Console.ReadLine();
        var ans = "Yes";
        foreach (var c in s.Where((c, i) => i % 2 == 0))
        {
            if (!(c == 'R' || c == 'U' || c == 'D')) ans = "No";
        }
        foreach (var c in s.Where((c, i) => i % 2 == 1))
        {
            if (!(c == 'L' || c == 'U' || c == 'D')) ans = "No";
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13268
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

const int N = 100005;
map<string, int> ms;
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	while(n --){
		string s;
		cin >> s;
		sort(s.begin(), s.end());
		ms[s] ++;
	}
	int ans = 0;
	for(auto x: ms)
		ans += x.second*(x.second - 1)/2;
	cout << ans;
}

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

#define REP(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ALL(c) c.begin(), c.end()
#define SZ(c) (int) c.size()
#define DBG1(x) cout<<#x<<" = "<<x<<"\n"
#if USE_CP_REDIR
#define CP \
    freopen("input.txt","r", stdin); \
    freopen("output.txt","w", stdout);
#endif

using ll = long long;
const ll MOD = 1'000'000'007;

ll add(ll a, ll b){
    return (a % MOD + b % MOD) % MOD;
}
ll mult(ll a, ll b){
    return (a % MOD * b % MOD) % MOD;
}


int main()
{
ios::sync_with_stdio(false);
#ifdef CP
    CP;
#endif
    int n;
    cin >> n;
    vector<int> a(n), suff(n+1);
    REP(i, 0, n) cin >> a[i];
    suff[n] = 0;
    for (int i = n-1; i >= 0; i--){
        suff[i] = add(suff[i+1], a[i]);
    }
    ll ans = 0;
    REP(i, 0, n){
        ans = add(ans, mult(a[i], suff[i+1]));
    }
    cout << ans << endl;
}

Measured memory_bytes: 4840
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"math"
	"os"
	"strconv"
)

func main() {
	n := readFloat64()

	fmt.Println(math.Ceil(n / 2))
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readInt() int {
	return int(readInt64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
n, k = map(int, input().split())
a = list(map(int, input().split()))
visited = []
visited_index = [-1] * n
pre = 0

while visited_index[pre] == -1:
    now = a[pre]
    visited.append(pre)
    visited_index[pre] = len(visited)
    pre = now - 1

loop = len(visited) - visited_index[pre] + 1
head = visited_index[pre] - 1

if k < head:
    print(visited[k] + 1)
else:
    k -= head
    k %= loop
    print(visited[head + k] + 1)

Measured memory_bytes: 95120
#if defined(LOCAL)
#define PROBLEM_NAME "c"
const double _max_double_error = 1e-9;
#include "testutils.h"
#define L(x...) debug(x)
#else
#define L(x, ...) (x)
#include <bits/stdc++.h>
#endif

using namespace std;
using vi = vector<int>; using vvi = vector<vi>;
using ii = pair<int,int>; using vii = vector<ii>;
using l = long long; using vl = vector<l>; using vvl = vector<vl>;
using ll = pair<l,l>; using vll = vector<ll>; using vvll = vector<vll>;
using lu = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vd = vector<double>; using vvd = vector<vd>;
using mll = unordered_map<l, l>;
const l INF = numeric_limits<l>::max();
const double EPS = 1e-10; static constexpr auto PI = acos(-1);
const l e0=1, e3=1000, e5=100000, e6=10*e5, e7=10*e6, e8=10*e7, e9=10*e8;
const char lf = '\n';
#define all(x) begin(x), end(x)
#define F(a,b,c) for (l a = l(b); a < l(c); a++)
#define B(a,b,c) for (l a = l(c) - 1; a >= l(b); a--)

#if defined(LOCAL)
#define L(x...) debug(x)
#else
#define L(x, ...) (x)
#endif

void solve(istream& cin, ostream& cout) {
  l n;
  while (cin >> n) {
    vl v(n);
    F(i, 0, n) cin >> v[i];
    l answer = 0;
    sort(all(v));
    while (v.back() >= n) {
      l x = v.back() / n;
      v.back() -= x * n;
      answer += x;
      F(i, 0, n - 1) v[i] += x;
      sort(all(v));
    }
    cout << answer << lf;
  }
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(15);
#if defined(LOCAL)
  maybe_run_tests(cin, cout);
  // _generate_random_test = generate_random;
  // _solve_brute = solve_brute;
  // _player_b = player_b;
  // _custom_solution_checker = solution_checker;
#else
  solve(cin, cout);
#endif
}


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

int main() {
	long long n, a, aa[100000] = {}, b[100000], c[100000], q;
	long long sum = 0;
	scanf("%lld", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a);
		a--;
		aa[a]++;
	}
	for(long long i=0;i<100000;i++){
		sum += (i + 1ll) * aa[i];
	}
	scanf("%lld", &q);
	for (int i = 0; i < q; i++) {
		scanf("%lld%lld", &b[i], &c[i]);
	}
	for (int i = 0; i < q; i++) {
		sum += (c[i] - b[i]) * aa[b[i] - 1];
		printf("%lld\n", sum );
		aa[c[i] - 1] += aa[b[i] - 1];
		aa[b[i] - 1] = 0;
	}

	return 0;
}


Measured memory_bytes: 4076
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        a[i] -= i + 1;
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    int b = a[n / 2];
    for(int i = 0; i < n; ++i)  ans += abs(a[i] - b);
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int d[200005];
int a[200005];
vector<int> vv;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) {
    cin >> a[i + 1];
  }

  fill(d, d+n, 0);
  for(int i=n; i>0; i--) {
    int sum = 0;
    for(int j=i; j<=n; j+=i) {
      sum += d[j];
    }
    if((sum % 2) != a[i]) {
      d[i]++;
      vv.push_back(i);
    }
  }

  cout << vv.size() << endl;
  REP(i, vv.size()) {
    cout << vv[i] << " ";
  }

  cout << endl;
}


Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <array>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
struct fix_point: private T {
  explicit constexpr fix_point(T &&func): T(std::forward<T>(func)) { }
  template <class... Args>
  constexpr decltype(auto) operator () (Args &&... args) const {
    return T::operator()(*this, std::forward<Args>(args)...);
  }
};

template <class T>
constexpr decltype(auto) make_fix_point(T &&func) {
  return fix_point<T>{std::forward<T>(func)};
}

std::array<long long, 19> calc_pow10() {
  std::array<long long, 19> res{};
  res[0] = 1;
  for (int i: range(1, 19)) {
    res[i] = res[i - 1] * 10;
  }
  return res;
}

auto pow10 = calc_pow10();

std::array<std::array<long long, 19>, 19> calc_sum_max() {
  std::array<std::array<long long, 19>, 19> res{};
  for (int i: range(0, 19)) {
    for (int j: revrange(0, i / 2)) {
      res[i][j] += pow10[i - j - 1] - pow10[j];
      res[i][j] += res[i][j + 1];
    }
  }
  return res;
}

auto sum_max = calc_sum_max();

int main() {
  int D;
  std::cin >> D;
  long long ans = 0;
  for (int digit: range(2, 19)) {
    ans += make_fix_point([&](auto dfs, long long cur, int d) -> long long {
      int e = digit - d - 1;
      if (d > e) {
        return (cur == 0 ? 1 : 0);
      }
      if (d == e) {
        return (cur == 0 ? 10 : 0);
      }
      if (std::abs(cur) > 9 * sum_max[digit][d]) {
        return 0;
      }
      long long base = pow10[e] - pow10[d];
      long long res = 0;
      auto coeff = [&](int i) { return (d == 0 ? 9 - std::abs(i) : 10 - std::abs(i)); };
      for (int i: range(-9, 10)) {
        res += dfs(cur - base * i, d + 1) * coeff(i);
      }
      return res;
    })(D, 0);
  }
  std::cout << ans << '\n';
  return 0;
}


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

int main(){
  ll n, ans=0;
  cin >> n;
  vector<int> a(n);

  rep(i, n){
    if((i+1)%3==0){
      continue;
    }
    else{
      if((i+1)%5==0){
        continue;
      }
      else{
        a[i]=i+1;
      }
    }
  }

  rep(i, n){
    ans+=a[i];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 7044
import java.util.*;

public class Main {
	public static void main(String[] args) {
    	Scanner input = new Scanner(System.in);
      	int N = input.nextInt();
      	int T = input.nextInt();
      	int A = input.nextInt();
      	double minGap = 5000;
      	int ans = 0;
      
      	for (int i = 0; i < N; i++) {
          	double avg = (double)T - 0.006 * input.nextInt();
          	if (Math.abs(A - avg) < minGap) {
            	minGap = Math.abs(A - avg);
              	ans = i + 1;
            }
        }
		
      	System.out.print(ans);
    } 	
}


Measured memory_bytes: 22996
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

min_y = min(y)
if (max(x) < min_y) and (X < min_y) and (min_y <= Y):
    print('No War')
else:
    print('War')


Measured memory_bytes: 2940
use proconio::input;
use std::collections::HashMap;

fn main() {
    input! {
        mut n: usize,
        a: [u64; n-1],
    }

    let mut res = HashMap::new();
    for aa in a {
        let count = res.entry(aa).or_insert(0);
        *count += 1;
    }

    for nn in 1..=n as u64 {
        println!("{}", res.entry(nn).or_default());
    }
}

Measured memory_bytes: 11412
#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;



int main() {
	int a;
	string  s;
	cin >> a >> s;

	if (a < 3200) {
		cout << "red" << endl;
	}
	else {
		cout << s << endl;
	}

	
}


Measured memory_bytes: 3592
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

ll expo(ll a, ll b){
    ll ex = 1;
    rep(i, b){
        ex *= a;
    }
    return ex;
}

ll fact(ll a){
    ll fc = 1;
    REP(i, 1, a+1){
        fc *= i;
    }
    return fc;
}

int main() {
    ll n, k;
    cin >> n >> k;
    if(n%k==0) {
        cout << 0 << endl;
    }
    else {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef double db;
typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MOD = 1e9+7;
const double PI  = 3.14159265358;
const double EPS = 1e-8;

#define INT_MX 2147483647
#define INF ((int)1e9)
#define LLINF ((ll)1e18)
#define F first
#define S second
#define MP(x,y) make_pair(x,y)
#define siz(v) ((int)v.size())
#define rs(n) resize(n)
#define ALL(v) v.begin(),v.end()
#define reset(v) memset((v),0,sizeof(v))
#define EB emplace_back
#define PB push_back
#define PF push_front
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,a,b) for(int i=(a);i<(b);i++) 
#define vec vector
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

void solve(){
	int n, r;
	
	cin >> r >> n ;
	
	if(r >= 10)	cout << n ;
	else cout << n + 100 * (10 - r); 
	
	
}

int main(){
	int T = 1;
	
	while(T--){
		solve();
	}
}




Measured memory_bytes: 256
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::cmp::Ordering;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_cols<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let mut yen = read::<i32>();
    let a_price = read::<i32>();
    let b_price = read::<i32>();

    yen -= a_price;
    yen %= b_price;

    println!("{}", yen);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
#define MAX_N 1000
#define MAX_W 10000

int n, A[MAX_N], s, B[MAX_N], T[MAX_W];

int solve()
{
	int ans = 0, count = 0;
	bool V[MAX_N];
    memset(V, false, sizeof(V));
    memcpy(B, A, sizeof(int) * n);
    sort(B, B + n);
    for (int i = 0; i < n; i++) T[B[i]] = i;
    for (int i = 0; i < n; i++) {
        if (V[i]) continue;
        int cur = i;
        int S = 0;
        int m = MAX_W;
        int an = 0;
        while (1) {
            V[cur] = true;
            an++;
            int v = A[cur];
            m = min(m, v);
            S += v;
            cur = T[v];
            if (V[cur]) break;
        }
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
    }
    return ans;
}

int main()
{
    cin >> n;
    s = MAX_W;
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        s = min(s, A[i]);
    }
    int ans = solve();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3168
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		String[] Ws = W.split(" ");
		int N = Integer.parseInt(Ws[0]);
		int R = Integer.parseInt(Ws[1]);

		int ans =  R+(100*(10-Math.min(10, N)));


		System.out.println(ans);

	}

}


Measured memory_bytes: 21972
N, M, X, Y = map(int,input().split())
x = [int(x) for x in input().split()]
y = [int(y) for y in input().split()]
x.append(X)
y.append(Y)
x_max = max(x)
y_min = min(y)
if x_max < y_min:
    print('No War')
else:
    print('War')

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
#debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = II()
    a_list = LI()
    b_list = LI()
    c_list = LI()

    base = 0
    add = 0
    past = -10
    for i in range(N):
        a = a_list[i]
        base += b_list[a-1]
        if a == past + 1:
            add += c_list[past-1]
        past = a
    print(add+base)
solve()

Measured memory_bytes: 3064
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=100005;
int n,ans,mx1,mx2,id;
int a[maxn],cnt[3][maxn];

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d",&n);
	REP(i,n)scanf("%d",&a[i]);
	REP(i,2){
		for(int j=i;j<=n;j+=2)cnt[i][a[j]]++;
	} 
//	REP(i,2)REP(j,10)cout<<i<<" "<<j<<" "<<cnt[i][j]<<endl;
	REP(i,100000){
		if(cnt[2][i]>=mx1)mx2=mx1,mx1=cnt[2][i],id=i;
		else if(cnt[2][i]>=mx2)mx2=cnt[2][i];
	}
//	cout<<mx1<<" "<<mx2<<" "<<id<<endl;
	ans=INF;
	REP(i,100000){
		int cur=n/2-cnt[1][i];
		if(i==id)cur+=n/2-mx2;
		else cur+=n/2-mx1;
		ans=min(ans,cur);
	}
	printf("%d",ans);
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  rep(i, m){
    cin >> s[i] >> c[i];
  }
  bool zero=true;
    rep(i, m){
      if(c[i]!=0){
        zero=false;
        break;
      }
    }

  if(zero && n==1){
    cout << "0" << endl;
    return 0;
  }
  repo(i, 999){
    int i2=i;
    bool nflag=true;
    rep(j, n){
      if(i2==0){
        nflag=false;
        break;
      }
      i2/=10;
    }
    if(i2!=0){
      nflag=false;
    }
    if(!nflag){
      continue;
    }
    bool scflag=true;
    rep(j, m){
      int i3=i;
      int sn=n-s[j];
      rep(k, sn){
        i3/=10;
      }
      i3%=10;
      if(i3!=c[j]){
        scflag=false;
        break;
      }
    }
    if(scflag){
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 3604
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {
	
	long long int n, d;
	cin >> n >> d;
	vector<long long int>p;
	for (int i = 0; i < n; i++) {
		long long int x;
		cin >> x;
		p.push_back(abs(x-d));
	}
	long long int r = p[0];
	for (int i = 1; i < n ; i++) {
		long long int t = p[i];
		if (r > t)swap(r, t);
		while (r) {
			long long int a = r;
			r = t%r;
			t = a;

		}
		r = t;
	}


	cout << r << endl;
	return 0;

}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h, w;
    scanf ("%d %d", &h, &w);
    int cnt = 0;
    for (int i = 1; i <= h; ++i) {
        getchar ();
        for (int j = 1; j <= w; ++j) {
            char ch=getchar ();
            if (ch=='#') ++cnt;
        }
    }
    puts((cnt==h+w-1)?"Possible":"Impossible");
    return 0;
}

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

template<typename F, typename T>
struct segment_tree {
        F merge;
        T identity;
        vector<T> data;
        int n;
        segment_tree(int len, F _merge, T _identity) : merge(_merge), identity(_identity) {
                n = pow(2, ceil(log2(len)));
                data.resize(2 * n - 1, identity); 
        }
        void update(int k, T p) { //update k-th value to p
                k += n - 1;
                data[k] = p;
                while (k > 0) {
                        k = (k - 1) / 2;
                        data[k] = merge(data[k * 2 + 1], data[k * 2 + 2]);
                }
        }
        // [l, r)
        T query(int a, int b) { return query(a, b, 0, 0, n); }
        T query(int a, int b, int k, int l, int r) {
                if (r <= a || b <= l) return identity; //initial value
                if (a <= l && r <= b) return data[k];
                int m = (l + r) / 2;
                return merge(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
        }
};

int main() {
        int n;
        scanf("%d", &n);
        vector<int> a(n);
        rep(i, n) {
                scanf("%d", &a[i]);
        }
        auto f = [&](long long a, long long b) {
                while (b) {
                        a %= b;
                        swap(a, b);
                }
                return a;
        };
        segment_tree<decltype(f), long long> segtree(n, f, 0);
        rep(i, n) segtree.update(i, a[i]);
        long long ans = 0;
        rep(i, n) {
                ans = max(ans, f(segtree.query(0, i), segtree.query(i + 1, n)));
        }
        printf("%lld\n", ans);
        return 0;
}


Measured memory_bytes: 2816
import java.util.Scanner;
import java.util.Arrays;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
int m=scan.nextInt();

if(n<=m){
System.out.println("unsafe");
}else{
System.out.println("safe");
}

}
}

Measured memory_bytes: 35764
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>
#include <math.h>

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  vector<int> nums(5);
  for (int i=0; i<5; ++i) {
    cin >> nums[i];
    if (nums[i] == 0) {
      cout << i+1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, K, Q;
  cin >> N >> K >> Q;
  ll a;
  map<ll, ll> m;
  ll total = 0;
  for (int i = 0; i < Q; i++) {
    cin >> a;
    a--;
    m[a]++;
    total++;
  }
  for (int i = 0; i < N; i++) {
    if (0 < K - total + m[i]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 9880
#include<stdio.h>
#include<string.h>
#define N 100

int main(){
  int i,j,len;
  char S[N];
  char T[N];
  char tmp;

  scanf("%s",S);
  scanf("%s",T);

  len = strlen(S);

  for(i=0;i<len;i++){
    tmp = S[0];
    for(j=0;j<len;j++)
      S[j] = S[j+1];
    S[len-1] = tmp;
    if(strcmp(S,T) == 0){
      printf("Yes\n");
      return 0;
    }
  }

  printf("No\n");

  return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#include<functional>
#define _USE_MATH_DEFINES

#include<math.h>
#include<map>

#define SENTINEL 1000000001

#define min(a,b) ((a)>(b)?(b):(a))
#define max(a,b) ((a)>(b)?(a):(b))

#define INF 200000000

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

vector<int> G[100000];
int ord[100000], low[100000];
bool checked[100000];
int S[100000];
int cmp[100000];
int k;
int s;
int idx;

void dfs(int v)
{
	checked[v] = true;
	ord[v] = k++;
	low[v] = ord[v];
	S[s++] = v;

	for (int i = 0; i != G[v].size(); i++)
	{
		if (ord[G[v][i]] == -1)
		{
			dfs(G[v][i]);
			low[v] = min(low[v], low[G[v][i]]);
		}
		else if (checked[G[v][i]])
		{
			low[v] = min(low[v], ord[G[v][i]]);
		}
	}
	if (low[v] == ord[v])
	{
		while (true)
		{
			int w = S[--s];
			checked[w] = false;
			cmp[w] = idx;
			if (w == v)break;
		}
		idx++;
	}
}

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

	int V, E;
	scanf("%d %d", &V, &E);

	for (int i = 0; i < V; i++)
	{
		ord[i] = -1;
	}

	for (int i = 0; i < E; i++)
	{
		int u, v;
		scanf("%d %d", &u, &v);

		G[u].push_back(v);
	}

	for (int i = 0; i < V; i++)
	{
		if (ord[i] == -1)
		{
			dfs(i);
		}
	}
	
	int Q;
	scanf("%d", &Q);

	for (int i = 0; i < Q; i++)
	{
		int u, v;
		scanf("%d %d", &u, &v);

		printf(cmp[u] == cmp[v] ? "1\n" : "0\n");
	}

	return 0;
}


Measured memory_bytes: 6572
n = int(input())
s = list(input().rstrip('\n'))
cumsum = [[0, 0] for i in range(n)]
cnt_1 = 0
cnt_2 = 0
cnt = [-1] * n
for i in range(n):
    if s[i] == 'E':
        cnt_1 += 1
    else:
        cnt_2 += 1
    cumsum[i][0] = cnt_1
    cumsum[i][1] = cnt_2
for i in range(n):
    if s[i] == 'E':
        cnt[i] += 1
    cnt[i] += cumsum[n - 1][0] - cumsum[i][0] + cumsum[i][1]
print(min(cnt))


Measured memory_bytes: 57656