akhauriyash/Code-Regression huggingface dataset:
from operator import itemgetter

N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = []
for i in range(M):
    B,C = map(int,input().split())
    BC.append([B,C])

BC.sort(key = itemgetter(1),reverse=True)

change = []
for b,c in BC:
    change += [c] * b
    if len(change) > N:
        break
A += change
A.sort(reverse=True)
answer = sum(A[:N])
print(answer)

Measured memory_bytes: 32960
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 1000
int n,m,a,b;
int read(){
	int x=0,F=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*F;
}
int main()
{
	n=read(),m=read(),a=read(),b=read();
	for(int i=1;i<=n;i++,puts(""))
		for(int j=1;j<=m;j++)
		printf("%d",(i>b)^(j>a));
}

Measured memory_bytes: 1280
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;



int MOD=1000000007;
int main(void){
	int N,M;
	cin >> N >> M;
	if(N==M) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

namespace ABC137
{
    class C
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            Dictionary<string, long> dic = new Dictionary<string, long>();
            string[] ss = new string[N];

            for (int i = 0; i < N; i++)
            {
                string s = Console.ReadLine();
                ss[i] = String.Concat(s.OrderBy(a => a));
            }

            for (int i = 0; i < N; i++)
            {
                if (dic.ContainsKey(ss[i]))
                {
                    dic[ss[i]]++;
                }
                else
                {
                    dic.Add(ss[i], 0);
                }
            }

            long res = 0;
            foreach (int i in dic.Values)
            {
                long temp = i;
                while (1 <= temp)
                {
                    res += temp;
                    temp--;
                }
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 30992
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#define INF 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
signed main(){
    int n;
    cin>>n;
    int m,l;
    cin>>m>>l;
    cout<<l-(min(n,m+l)-m)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> s;
    ll ans = 0;
    int n = (int)s.size();
    rep(bit, 0, 1 << (n - 1)) {
        ll sum = 0;
        rep(i, 0, n) {
            sum = sum * 10 + (s[i] - '0');
            if ((bit >> i) & 1) {
                ans += sum;
                sum = 0;
            }
        }
        // sum += sum * 10 + (s[n - 1] - '0');
        ans += sum;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)

signed main(){

	int N, M, R;
	cin >> N >> M >> R;
	vector<int> r(R);
	for (int i = 0; i < R; i++){
		cin >> r[i];
		r[i]--;
	}
	int d[200][200];
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			d[i][j] = INF;

	for (int i = 0; i < M; i++){
		int a, b, c;
		cin >> a >> b >> c;
		d[a - 1][b - 1] = c;
		d[b - 1][a - 1] = c;
	}

	for (int k = 0; k < N; k++){
		for (int i = 0; i < N; i++){
			if (d[i][k] == INF) continue;
			for (int j = 0; j < N; j++){
				if (d[k][j] == INF) continue;
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}

	int ans = INF;
	vector<int> perm;
	for (int i = 0; i < R; i++) perm.push_back(i);
	do{
		int dist = 0;
		for (int i = 0; i < R-1; i++){
			dist += d[r[perm[i]]][r[perm[i + 1]]];
		}
		ans = min(ans, dist);

		for (int i = 0; i < R; i++) cerr << r[perm[i]]+1;
		cerr << " " << dist << endl;

	} while (next_permutation(perm.begin(), perm.end()));

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

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int n;
vector <string> str;
string mem[15][15];

string con(string a,string b){
  int K=0;
  for(int i=0;i<a.size();i++){
    int j=i,k=0;
    while(a[j]&&b[k]&&a[j]==b[k]) j++,k++;
    if(!a[j]||!b[k])K=max(K,k);
  }
  return b.substr(K,b.size());
}

string solve(){
  string dp[1<<14][14];
  for(int i=0;i<n;i++) dp[1<<i][i]=str[i];
  
  for(int i=0;i<(1<<n);i++)
    for(int k=0;k<n;k++){
      if(dp[i][k]=="")continue;
      for(int j=0;j<n;j++){
	if((i&(1<<j)))continue;
	string nx=dp[i][k]+mem[k][j],&ndp=dp[i|1<<j][j];
	if(!ndp.size()||nx.size()<ndp.size()||(nx.size()==ndp.size()&&ndp>nx))ndp=nx;
      }
    }

  string res=dp[(1<<n)-1][0];
  for(int i=1;i<n;i++) {
    string a=dp[(1<<n)-1][i];
    if(res.size()>a.size()||(a.size()==res.size()&&res>a)) res=a;
  }
  return res;
}

int main(){
  
  while(cin>>n,n){
    str.resize(n);
    for(int i=0;i<n;i++)cin>>str[i];

    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	if(i!=j&&con(str[i],str[j])=="") str.erase(str.begin()+j),j=-1,i=0,n--;

    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++) mem[i][j]=con(str[i],str[j]);

    cout<<solve().size()<<endl;
  }
  return 0;
}

Measured memory_bytes: 30792
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

struct Edge {
	int from;
	int to;
	int id;
	long long int cost;
};

void dfs(const int now,const int from,const vector<vector<int>>&edges, const vector<int>&types,
	vector<int>&nums) {
	for (auto e : edges[now]) {
		if(e==from)continue;
		{
			const int nt=types[e];
			if (nt == 0) {
				nums[e]=nums[now]&0b110;
			}
			else if (nt == 1) {
				nums[e]=nums[now]&0b101;
			}
			else if (nt == 2) {
				nums[e]=nums[now]|0b110;
			}
			else if (nt == 3) {
				nums[e]=nums[now]|0b101;
			}
			else if (nt == 4) {
				nums[e]=nums[now]^0b110;
			}
			else if (nt == 5) {
				nums[e]=nums[now]^0b101;
			}
		}
		dfs(e,now,edges,types,nums);
	}
}

int dfs2(const int now, const int from, const vector<vector<int>>&edges,const vector<int>&types,
	bool is_a,vector<int>&perms) {

	if (edges[now].size() == 1&&from!=-1)return perms[types[now]];
	int ans;
	if (is_a) {
		ans=-1;
	}
	else {
		ans=100;
	}

	for (auto e : edges[now]) {
		if(e==from)continue;
		if (is_a) {
			ans=max(ans,dfs2(e,now,edges,types,!is_a,perms));
		}
		else {
			ans=min(ans,dfs2(e,now,edges,types,!is_a,perms));
		}
	}
	return ans;
}

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

	map<vector<int>, int>ans_mp;
	
		vector<int>types(N,-1);
		vector<string>name_sts{
			"T=T&X"	 ,
			"T=T&Y" ,
			"T=T|X",
			"T=T|Y",
			"T=T^X",
			"T=T^Y",
		};

		for (int i = 1; i < N; ++i) {
			string st; cin >> st;
			types[i] = find(name_sts.begin(), name_sts.end(), st) - name_sts.begin();
		}

		vector<vector<int>>edges(N);
		for (int i = 0; i < N-1; ++i) {
			int a, b; cin >> a >> b;
			edges[a].push_back(b);
			edges[b].push_back(a);
		}
		vector<int>nums(N);
		dfs(0, -1, edges, types, nums);

		/*vector<int>perms(8);
		iota(perms.begin(),perms.end(),0);
		do {
			bool ok=true;
			for (int i = 1; i < 8; ++i) {
				for (int j = 1; j < 8; ++j) {
					if ((i|j) == j) {
						if (perms[i] > perms[j]) {
							ok = false;
						}
					}
				}
			}
			if(perms[0]<perms[2])
			if(!ok)continue;
			auto num = dfs2(0, -1, edges, nums, true, perms);
			ans_mp[perms] =find(perms.begin(),perms.end(),num)-perms.begin();
		} while (next_permutation(perms.begin() + 1, perms.end() - 1));
*/
	
	
	while (M--) {
		int X,Y;cin>>X>>Y;
		int onlyX=((X|Y)^Y);
		int onlyY=((X|Y)^X);
		vector<pair<int,int>>ps;
		vector<int>anums{
			0,
			onlyY,
			onlyX,
			onlyX|onlyY,
			X&Y,
			Y,
			X,
			X|Y,
		};
		for (int i = 0; i < 8; ++i) {
			ps.emplace_back(anums[i],i);
		}
		sort(ps.begin(),ps.end());
		vector<int>perms(8);
		for (int i = 0; i < 8; ++i) {
			perms[ps[i].second]=i;
		}
		if (ans_mp.find(perms) == ans_mp.end()) {
			auto num= dfs2(0, -1, edges, nums, true, perms);
			ans_mp[perms] =find(perms.begin(),perms.end(),num)-perms.begin();
		}
		int ans_id=ans_mp[perms];
		int ans=anums[ans_id];
		cout<<anums[ans_id]<<endl;
	}
	return 0;
}


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

using namespace std;

int main()
{

	int n, k;
	cin>>n>>k;
	vector< int > w;
	int num, P;
	for( int i=0; i<n; i++ ) {
		cin>>num;
		w.push_back( num );
		P = max( P, num );
	}
	
	int truckCnt, lr, i;
	int left = P;
	
	int right = 100000*10000;
	while( left < right ) {
		P = (left+right)/2;		
		truckCnt = k-1;
		lr = 0;
		for( i=0; i<n; i++ ) {
			if( P < lr+w.at(i) ) {
				truckCnt--;
				if( truckCnt < 0 ) { break; }
				lr = 0;
			}
			lr += w.at(i);
		}
		if( 0 <= truckCnt ) {
			right = P;
		} else {
			left = P+1;
		}
	}
	
	cout<<left<<'\n';
    return 0;
}

Measured memory_bytes: 1672
N = int(input())
S = input()

x = 0
x_max = 0

for i in range(N):
  
  if S[i] == "I":
    x += 1
  elif S[i] == "D":
    x -= 1
  
  if x_max < x:
    x_max = x
    
print(x_max)

      

Measured memory_bytes: 9140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  ll n; cin >> n;
  vector<ll> a(n);
  for (int i=0; i<n; i++){
    cin >> a[i];
  }
  ll ans = 0;
  ll t = n-1;
  sort(a.rbegin(),a.rend());
  for (int i=0; i<n; i++) {
    if (t <= 0) break;
    if (i == 0) {
      ans += a[i]; t--;
      continue;
    }
    ans += a[i]; t--;
    if (t <= 0) break;
    ans += a[i]; t--;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4840
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){
    int N;
    bool tmp;
    cin >> N;
    vector<bool> arr;
    for (int i=0; i<N; i++){
        cin >> tmp;
        arr.push_back(tmp);
    }
    map<int, bool> table;
    vector<int> ans;
    for (int i=N - 1; i>=0; i--){
        bool prev_i = false;
        for (int j=2; j<=N / (i + 1); j++){
            prev_i ^= table[(i + 1)*j];
        }
        prev_i ^= arr[i];
        table[i + 1] = (int)prev_i;
        if (prev_i){
            ans.push_back(i + 1);
        }
    }
    cout << ans.size() << endl;
    for (int i : ans){
        cout << i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 10616
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n,k=gsmi
d=gets.chomp.split

while true do
  bin=n.to_s.chars.uniq
  if (bin & d).empty?
    break
  else
    n+=1
  end
end

puts n

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int w, h, n; cin >> w >> h >> n;
    map<int, int> m;
    for(int i = 0; i < n; i++){
        int x, y, a; cin >> x >> y >> a;
        if(a == 1){
            m[a] = max(m[a], x);
        }else if(a == 2){
            int t = w - x;
            m[a] = max(m[a], t);
        }else if(a == 3){
            m[a] = max(m[a], y);
        }else{
            int t = h - y;
            m[a] = max(m[a], t);
        }
    }
    w -= (m[1] + m[2]);
    h -= (m[3] + m[4]);
    if(0 < w && 0 < h) cout << w * h << endl;
    else cout << 0 << endl;
}


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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var q = int.Parse(Console.ReadLine());
        var seqQuery = Console.In.ReadToEnd()
            .Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

        var ts = new char[s.Length + seqQuery.Length * 2];
        int head = seqQuery.Length;
        int last = head + s.Length;
        var reverse = false;
        Array.Copy(s.ToCharArray(), 0, ts, head, s.Length);
        for (int i = 0; i < seqQuery.Length; ++i)
        {
            if (seqQuery[i][0] == '1')
            {
                reverse = !reverse;
                continue;
            }

            var f = seqQuery[i][2];
            var c = seqQuery[i][4];
            if (f == '1' && !reverse || f == '2' && reverse)
            {
                --head;
                ts[head] = c;
            }
            else
            {
                ts[last] = c;
                ++last;
            }
        }

        var final = new char[last - head];
        Array.Copy(ts, head, final, 0, final.Length);
        if (reverse)
        {
            Array.Reverse(final);
        }
        
        Console.WriteLine(new string(final));
    }
}


Measured memory_bytes: 34396
#include <iostream>
#include <algorithm>
using namespace std;
long long n,ans,l[100005],r[100005];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie();
	cin>>n;
	for (int i=1;i<=n;++i) cin>>l[i]>>r[i];
	sort(l,l+n+1,greater <long long>());
	sort(r,r+n+1);
	for (int i=0;i<=n;i++) if (l[i]>r[i]) ans+=l[i]-r[i];
	cout<<2*ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

signed main(){
    FASTER;
    int a,b;cin>>a>>b;
    cout<<(a*b)/__gcd(a,b);
}

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

ll f(ll n){
    if(n%4==0) return n;
    if(n%4==1) return 1;
    if(n%4==2) return n^1;
    return 0;
}


int main(){
    ll a, b;
    cin >> a >> b;
    cout << (f(b)^f(a-1)) << endl;
    return 0;
    // ll a, b;
    // cin >> a >> b;
    // ll num = b-a+1;

    // if(a==b){
    //     cout << a << endl;
    //     return 0;
    // }

    // ll out = 0;
    // rep(i, 41){
    //     // cout << out << endl;
    //     ll tmp1 = num / pow(2, i+1);
    //     ll rem = num - tmp1 * pow(2, i+1);
    //     // cout << rem << endl;
    //     if(rem!=0){
    //         ll tmp2 = a / pow(2, i+1);
    //         ll rem2 = a - tmp2 * pow(2, i+1);
    //         int tmp=0;
    //         if(rem2 >= pow(2, i)){
    //             if(rem2+rem-1 <= pow(2, i+1)-1){
    //                 tmp = rem;
    //             }else{
    //                 tmp = (pow(2, i+1)-rem2);
    //             }
    //         }else{
    //             if(rem2+rem-1-pow(2, i)>0){
    //                 tmp = rem2+rem-pow(2, i);
    //             }
    //         }
    //         cout << tmp << endl;
    //         tmp = tmp%2;
    //         out += pow(2, i)*tmp;
    //     }    
    // } 
    // cout << out << endl;
    // return 0;

}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		
		String line = scan.nextLine();
		StringBuffer sb = new StringBuffer();
		for(int i = 0; i < line.length(); i++){
			char ch = line.charAt(i);
			if(Character.isLowerCase(ch)){
				ch = Character.toUpperCase(ch);
			}
			sb.append(ch);
		}
		String out = sb.toString();
		System.out.printf("%s\n", out);
	}
}

Measured memory_bytes: 25956
import math
a,b,h,m = map(int,input().split())
def l(x,y,th):
    return math.sqrt(x*x+y*y - 2*x*y*math.cos(math.radians(th)))
def sita(h,m):
    a = 30*h+0.5*m
    b = 6*m
    if a > 180 and b < 180:
        a =360-a
        return a + b
    elif a < 180 and b > 180:
        b = 360-b
        return a + b
    else:
        if a > b:
            return a-b
        else:
            return b-a
print(l(a,b,sita(h,m)))

Measured memory_bytes: 9536
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

ll pow_mod(ll a, ll p) {
    ll res = 1;
    while(p) {
        if (p & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        p >>= 1;
    }

    return res;
}


ll mod_inv(ll a, ll m) {
    ll b = m, u = 0, v = 1;
    while(a) {
        ll t = b / a;
        swap(b -= t * a, a);
        swap(u -= t * v, v);
    }

    return (u % m + m) % m;
}

ll gcd(ll a, ll b) {
    if(b == 0) return a;
    return gcd(b, a%b);
}


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    ll H, N;
    cin >> H >> N;

    ll s = 0;
    REP(i, N) {
        ll a;
        cin >> a;
        s += a;
    }

    if (s >= H) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
//    cout << fixed << setprecision(20);

}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	char s[15],s2[15];
	scanf("%s",s);
	scanf("%s",s2);
	int len=strlen(s2);
	s2[len-1]='\0';
	if(strcmp(s,s2)==0) printf("Yes\n");
	else printf("No\n");
} 

Measured memory_bytes: 1656
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n = int(input())
  A = readInts()
  l = 0
  r = sum(A)
  LIST = []
  for i in range(n-1):
    l += A[i]
    r -= A[i]
    LIST.append(abs(l-r))
  print(min(LIST))
  # 全部足してから、左から消していく感じ
if __name__ == '__main__':
  main()

Measured memory_bytes: 24820
a=input()
if a=='SUN':
  print(7)
elif a=='MON':
  print(6)
elif a=='TUE':
  print(5)
elif a=='WED':
  print(4)
elif a=='THU':
  print(3)
elif a=='FRI':
  print(2)
elif a=='SAT':
  print(1)

Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
struct Main {}

#[allow(dead_code)]
impl Main {}

fn main() {
    let a = read::<i32>();
    let b = read::<i32>();
    println!("{}", a * b);
}


Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll a[1010],sum[1010];
int main(){
	ll n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
	}
	vector<ll>v;
	for(int i=1;i<=n;i++)for(int j=i+1;j<=n;j++)v.push_back(sum[j]-sum[i-1]);
	ll ans=0;
	for(int i=40;i>=0;i--){
		ll cnt=0,t=(1ll<<i);
		for(ll x:v){
			if((x&(ans+t))==ans+t)cnt++;
		}
		if(cnt>=k)ans+=t;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 7480
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define cin_desync()                                                           \
    do {                                                                       \
        ios_base::sync_with_stdio(false);                                      \
        cin.tie(0);                                                            \
    } while (0)

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}

#else
#define trace(...)
#endif // ifndef ONLINE_JUDGE

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int max_N = 2e5 + 10;
int A[max_N];

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

    map<ll, int, greater<ll>> cnt;
    for (int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        cnt[x]++;
    }

    vector<ll> p2 = {1};
    while(p2.back() < 2e9) {
        p2.push_back(2 * p2.back());
    }
    reverse(p2.begin(), p2.end());

    int ans = 0;
    for (auto &c : cnt) {
        int v = c.first;
        while(c.second > 0) {
            c.second--;
            for (auto &p : p2) {
                if (cnt.find(p - v) == cnt.end()) {
                    continue;
                }
                if (cnt[p - v] > 0) {
                    cnt[p - v]--;
                    ++ans;
                    break;
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 12800
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <functional>
#include <cstdlib>
#include <iomanip>
#include <climits>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 2e9 + 1e8;
const ll INF = 2e18 + 1e17;
const int mod = 998244353;
const int MOD = 1e9 + 7;
 
ll gcd(ll a, ll b) {
	return (b == 0 ? a : gcd(b, a % b));
}
bool is_prime(ll x) {
	if (x == 1 || (x % 2 == 0 && x > 2))     return false;
	for (int i = 3; i*i <= x; i += 2) {
		if (!(x % i)) {
			return false;
		}
	}
	return true;
}
 
/**************************************************************************************
***************************************************************************************/
const int MAXN = 100010;

int a, b;

int main (){
    ios_base::sync_with_stdio(false);   cin.tie(false);
    cin>>a>>b;
    string aa, bb;
    for (int i = 0; i<b; i++){
        aa+=(a +' 0');
    }
    for (int i = 0; i<a; i++){
        bb+=(b + '0');
    }
    if (aa < bb){
        cout<<aa<<endl;
    }
    else {
        cout<<bb<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    for k in range(j+1,n):
      if l[i]==l[j] or l[i]==l[k] or l[j]==l[k]:continue
      if l[i]+l[j]>l[k]:
        ans+=1
print(ans)

Measured memory_bytes: 73344
N=int(input())

a = list(map(int,input().split()))

from collections import defaultdict

A=defaultdict(int)
zero_count=0
for aa in a:
    A[aa]+=1
    if aa==0:
        zero_count+=1

if zero_count==N:
    print("Yes")
else:
    if N%3!=0:
        print("No")
    else:
        if len(list(A.keys()))>3:
            print("No")
        else:
            a_list=list(A.keys())
            a_list.sort()
            if len(a_list)==1:
                print("No")
            elif len(a_list)==2:
                if a_list[0]!=0:
                    print("No")
                else:
                    if A[0]==N//3:
                        print("Yes")
                    else:
                        print("No")
            else:
                if A[a_list[0]]==A[a_list[1]] and A[a_list[1]]==A[a_list[2]]:
                    if a_list[0]^a_list[1]==a_list[2]:
                        print("Yes")
                    else:
                        print("No")
                else:
                    print("No")


Measured memory_bytes: 60784
import numpy as np
n=int(input())
x=list(map(int,input().split()))
s=int(sum(x)/n)
t=s+1
X=np.array(x)
P=np.ones(n)*s
Q=P+np.ones(n)
ans=min(sum((X-Q)**2),sum((X-P)**2))
print(int(ans))

Measured memory_bytes: 12500
def func(nums, oprs, x):
    if len(nums) == 0:
        return [oprs, x]
    oprs1, x1 = func(nums[1:], oprs+'+', x+int(nums[0]))
    if x1 == 7:
        return [oprs1, x1]
    oprs2, x2 = func(nums[1:], oprs+'-', x-int(nums[0]))
    return [oprs2, x2]


S = input()
oprs, x = func(S[1:], '', int(S[0]))
print('{}{}{}{}{}{}{}=7'.format(S[0], oprs[0], S[1], oprs[1], S[2], oprs[2], S[3]))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main (void){
	int n,i,x,y,z,a[2000001];
	cin >> n;
	for(i=0;i<n;i++) cin >> a[i];
	sort(a,a+n);
	x=a[n-1];
	y=a[0];
	z=abs(2*a[i]-x);
	for(i=1;i<n-1;i++){
		if(abs(2*a[i]-x)<z){
			z=abs(2*a[i]-x);
			y=a[i];
		}
	}
	cout << x << " " << y << endl;
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <vector>
#include <math.h>

using namespace std;
 int main(){

  long long  x,y;
  cin>>x>>y;


  if(x*y < 0) cout<<abs(abs(x) - abs(y))+1<<endl;
  else if(x*y == 0){

   if(x<y) cout<<y-x<<endl;
   else cout<<x-y+1<<endl;
  }
  else {
     if(x<y) cout<<y-x<<endl;
     else
        cout<<x-y+2<<endl;

  }


 return 0;
 }


Measured memory_bytes: 384
'use strict'
function main(input) {
  input = input.trim().replace(/(0+)/, '0').split('')
  if (input[input.length - 1] === '0') {
    console.log(Number(input.join('')))
  } else {
    console.log(input.reduce((r, c) => Number(r) + Number(c), 0))
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 11468
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll n; cin >> n;
  for(ll i=1;i<=3500;i++){
    for(ll j=1;j<=3500;j++){
      if(4*i*j-n*j-n*i==0) continue;
      if((n*i*j)%(4*i*j-n*j-n*i)!=0) continue;
      ll k=n*i*j/(4*i*j-n*j-n*i);
      if(k>=1&&k<=3500){
        cout <<i<<" "<<j<<" "<<k<< endl;
        return 0;
      }
    }
  }
  
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



const int MAX = 5100;
vint num[MAX];

int N, M, a, b, x;

int main() {
    while (cin >> N >> M) {
        for (int i = 0; i <= N+5; ++i) num[i].resize(i+10, 0);
        
        for (int i = 0; i < M; ++i) {
            cin >> a >> b >> x;
            num[a][b]++;
            num[a][b+1]--;
            num[a+x+1][b]--;
            num[a+x+2][b+1]++;
            num[a+x+1][b+x+2]++;
            num[a+x+2][b+x+2]--;
        }
        
        for (int i = 0; i <= N+2; ++i)
            for (int j = 0; j <= i+1; ++j)
                num[i][j+1] += num[i][j];
        
        for (int i = 0; i <= N+2; ++i)
            for (int j = 0; j <= i+1; ++j)
                num[i+1][j] += num[i][j];
        
        for (int i = 0; i <= N+2; ++i)
            for (int j = 0; j <= i+1; ++j)
                num[i+1][j+1] += num[i][j];
                
        int res = 0;
        for (int i = 1; i <= N+1; ++i) {
            for (int j = 1; j <= i; ++j) {
                //cout << num[i][j] << " ";
                if (num[i][j] > 0) ++res;
            }
            //cout << endl;
        }
        
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 50504
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())

const int INF = 1e9;


// code
// ------------------------------------------------
int main() {
  int n,x;
  cin >> n >> x;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  vsort(a);
  bool flg = false;
  int ans = 0;
  rep(i,n)
  {
    if(x >= a[i])
    {
      x -= a[i];
      ans++;
    }
    else
    {
      flg = true;
      break;
    }
  }

  if((x != 0) && (flg == false))
    ans--;

  cout << ans ;

  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

Measured memory_bytes: 256
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int sum,matrix[20][20],n,m,dp[20][1<<15],num[1<<15];
int main(){
	fastio;
	cin>>n>>m;
	rb(i,1,m){
		int u,v,c;
		cin>>u>>v>>c;
		u--;
		v--;
		matrix[u][v]=matrix[v][u]=c;
		sum+=c;
	}
//	cout<<sum<<endl;
	rep(i,1<<n){
		if(i==0) continue;
		int las=i&(i-1);
		num[i]=num[las];
		int now;
		rep(j,n)
		{
			if(i&(1<<j)){
				now=j;
				break;
			} 
		}
//		cout<<i<<" "<<now<<endl;
		rep(j,n)
			if(las&(1<<j)){
				num[i]+=matrix[now][j];
			}
	}
	memset(dp,-0x3f,sizeof(dp));
	rep(i,1<<n)
		if(i&1){
			dp[0][i]=num[i];
		} 
	rep(mask,1<<n){
		rep(i,n)
		{
			if(dp[i][mask]>=0){
				int x=~mask;
				x&=(1<<(n))-1;
				for(int maskn=x;maskn;maskn=x&(maskn-1)){
					rep(j,n){
						if(maskn&(1<<j)){
							if(matrix[i][j])
							dp[j][maskn+mask]=max(dp[j][maskn+mask],dp[i][mask]+matrix[i][j]+num[maskn]);
						}
					} 
				}
			}
		}
	}
	cout<<sum-dp[n-1][(1<<n)-1]<<endl;
	return 0;
}


Measured memory_bytes: 2944
/**
*
* Author: MARS
* Lang: GNU C++14
*
**/

#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair<int,int>

typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl pi = acos(-1);
const ll inf = 1LL<<30;
const dbl eps = 1e-9;
const ll mod = 1e9+7;

/** /////////// ** Code ** /////////// **/

const int N=200200;
int a[N];

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

    ll sum=0;
    for(int i=1 ; i<n ; i++){
        if(a[i] < a[i-1]){
            sum+=(a[i-1]-a[i]);
            a[i]=a[i-1];
        }
    }

    printf("%lld\n",sum);
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MOD 1000000007
int N, K;
vector<int> edge[100000];

int used[100000];
LL dfs(int n, int p, int c){
	if(n == 0) used[n] = 0;
	else if(p == 0) used[n] = 1 + c;
	else used[n] = 2 + c;
	int tmp = 0;
	LL ans = K - used[n];
	for(int i=0; i<edge[n].size(); i++){
		if(edge[n][i] == p) continue;
		ans *= dfs(edge[n][i], n, tmp);
		ans %= MOD;
		tmp++;
	}
	return ans;
}

int main(){
	cin >> N >> K;
	for(int i=0; i<N-1; i++){
		int a,b;
		cin >> a >> b;
		a--; b--;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}
	cout << dfs(0, -1, -2) << endl;
}


Measured memory_bytes: 12032
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <set>
#include <string>
using namespace std;

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

    int max_cnt = 0;
    for ( int i = 0 ; i < n-1 ; i++ ){
        string a,b;
        a = s.substr(0,i+1);
        b = s.substr(i+1);
        int cnt = 0;
        for ( int j = 97 ; j <= 122 ; j++ ){
            if ( a.find(j) != -1 && b.find(j) != -1 ) cnt++;
        }
        if ( cnt > max_cnt) max_cnt = cnt;
    }
    cout << max_cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;

int n, a[200010];
int w[200010];

ll merge_cnt(int l, int r)
{
	if(l+1>=r) return 0;
	else if(l+2==r)
	{
		if(a[l]<a[l+1]) return 0;
		else
		{
			swap(a[l], a[l+1]);
			return 1;
		}
	}
	else
	{
		int m=(l+r)/2;
		ll cl=merge_cnt(l, m);
		ll cr=merge_cnt(m, r);
		ll c=0;
		int i=l, j=m;
		int k=l;
		while(i<m && j<r)
		{
			if(a[i]<a[j]) w[k++]=a[i++];
			else
			{
				w[k++]=a[j++];
				c+=m-i;
			}
		}
		while(i<m) w[k++]=a[i++];
		while(j<r) w[k++]=a[j++];
		assert(k==r);
		copy(w+l, w+r, a+l);
		return cl+cr+c;
	}
}

int main()
{
	cin >> n;
	rep(i, n)
	{
		cin >> a[i];
	}
	cout << merge_cnt(0, n) <<endl;
	return 0;
}

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

using namespace std;

int main(){
    char c;
    cin>>c;
    switch (c){
        case 'A':cout<<'T'<<endl;
        break;
        case 'T':cout<<'A'<<endl;
            break;
        case 'C':cout<<'G'<<endl;
            break;
        case 'G':cout<<'C'<<endl;
            break;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string.h>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>
#include <regex>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

template <typename T> ostream& operator<<(ostream& out, vector<T> &v){
  for (int i = 0; i < (int)v.size(); i++) {
    out<<v[i]<<' ';
  }
  return out;
}

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

  int a; cin >> a;
  cout << a + a * a + a * a * a << endl;


  return 0;
}


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

int main()
{
  int n, x;
  cin >> n >> x;
  vector<int> v(n);
  for (auto&& e : v) cin >> e;
  int ans = 1;
  int d = 0;
  for (int i = 0; i < n; i++) {
    d += v[i];
    if (d > x) break;
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int N, M, K, Q, W, H, R, C;
string S;

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

    cin >> N >> M;
    vector<int> s(M);
    vector<char> c(M);
    REP(i, M) {
        cin >> s.at(i) >> c.at(i);
        s[i]--;
    }

    string str;
    REP(i, N) { str.push_back('.'); }

    REP(i, M) {
        if (str[s[i]] == '.') {
            str[s[i]] = c[i];
        } else {
            if (str[s[i]] != c[i]) {
                cout << -1 << endl;
                return 0;
            }
        }
        if (s[i] == 0 && c[i] == '0' && N > 1) {
            cout << -1 << endl;
            return 0;
        }
    }

    if (str[0] == '.') {
        if (N != 1) {
            str[0] = '1';
        } else {
            str[0] = '0';
        }
    }

    FOR(i, 1, N) {
        if (str[i] == '.') {
            str[i] = '0';
        }
    }

    int ans = stoi(str);
    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) ++)
using namespace std;

int main() {
        int n, m;
        scanf("%d%d", &n, &m);
        vector<vector<int>> tmp(n);
        rep(i, n - 1) {
                int a, b;
                scanf("%d%d", &a, &b);
                a --, b --;
                tmp[a].push_back(b);
                tmp[b].push_back(a);
        }
        vector<vector<int>> g(n);
        function<void (int, int)> modify = [&](int u, int prev) {
                for (auto v : tmp[u]) if (v != prev) {
                        g[u].push_back(v);
                        modify(v, u);
                }
        };
        modify(0, -1);

        vector<long long> dp(n);
        vector<vector<long long>> left(n), right(n);
        function<void (int)> dfs = [&](int u) {
                for (auto v : g[u]) {
                        dfs(v);
                }
                if (g[u].size() == 0) {
                        dp[u] = 1;
                        return;
                }
                dp[u] = 1;
                for (auto v : g[u]) {
                        (dp[u] *= dp[v] + 1) %= m;
                }
                left[u].resize(g[u].size());
                right[u].resize(g[u].size());
                left[u][0] = dp[g[u][0]] + 1;
                right[u][g[u].size() - 1] = dp[g[u].back()] + 1;
                for (int i = 1; i < g[u].size(); i ++) {
                        left[u][i] = left[u][i - 1] * (dp[g[u][i]] + 1) % m;
                }
                for (int i = (int) g[u].size() - 2; i >= 0; i --) {
                        right[u][i] = right[u][i + 1] * (dp[g[u][i]] + 1) % m;
                }
        };
        dfs(0);
        vector<long long> ans(n);
        function<void (int, long long)> dfs2 = [&](int u, long long r) {
                ans[u] = dp[u] * (r + 1) % m;
                for (int i = 0; i < g[u].size(); i ++) {
                        long long nxt = (i > 0 ? left[u][i - 1] : 1) * (i < (int) g[u].size() - 1 ? right[u][i + 1] : 1) % m;
                        dfs2(g[u][i], nxt * (r + 1) % m);
                }
        };
        dfs2(0, 0);
        rep(i, n) {
                printf("%lld\n", ans[i]);
        }
        return 0;
}


Measured memory_bytes: 28928
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e6+1;
int d[MAXN];
bool prime[MAXN];
int n;

void sieve(){
    memset(prime,true,sizeof(prime));
    for(int p=2; p*p<=MAXN; p++){
        if(prime[p]){
            for(int i=p*p; i<=MAXN; i+=p){
                prime[i] = false;
                d[i] = p;
            }
        }
    }
    d[1]=1;
    for(int i=2; i<=MAXN; i++) if(prime[i]) d[i] = i;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    int a[n]; for(int i=0; i<n; i++) cin >> a[i];
    int b[n]; for(int i=0; i<n; i++) b[i] = a[i];
    sieve();
    bool pairwise = true;
    map<int,int> m;
    for(int i=0; i<n; i++){
        set<int> s;
        while(a[i]>1){
            s.insert(d[a[i]]);
            a[i]/=d[a[i]];
        }
        for(auto& a : s){
            m[a]++;
            if(m[a]>1){
                pairwise = false;
                break;
            }
        }
        if(!pairwise) break;
    }
    if(pairwise) cout << "pairwise coprime" << endl;
    else{
        int curr = gcd(b[0],b[1]);
        for(int i=2; i<n; i++){
            curr = gcd(curr,b[i]);
        }
        if(curr==1) cout << "setwise coprime" << endl;
        else cout << "not coprime" << endl;
    }
}

Measured memory_bytes: 16284
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
using ll=long long;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a+b+c>=22) cout << "bust" << endl;
  else cout << "win" << endl;
  
  
}

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

int main(){
    char ch;
    int ct[26] = {};

    while(cin >> ch){
        ch = tolower(ch);
        if(isalpha(ch)){
            ct[ch-'a']++;
        }
     
    }

    for(int i=0;i<26;i++){
        printf("%c : %d\n",i+'a',ct[i]);
    }
    return 0;

}


Measured memory_bytes: 3116
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc := newScanner()
	var s = sc.readString()
	var t = sc.readString()

	sr := []rune(s)
	st := []rune(t)
	var max = 0
	for i := 0; i < len(sr)-len(st)+1; i++ {
		var cnt = 0
		for j := 0; j < len(st); j++ {
			if sr[i+j] == st[j] {
				cnt++
			}
		}
		if cnt > max {
			max = cnt
		}
	}
	fmt.Println(len(st) - max)

}

//////////////////
//////////////////
//////////////////

func abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}

	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func pow(base, exponent int) int {
	if exponent < 0 {
		panic(fmt.Sprintf("exponent (%d) should not be a minus", exponent))
	}

	answer := 1
	for i := 0; i < exponent; i++ {
		answer *= base
	}
	return answer
}

func ceil(divident, dividor int) int {
	if dividor == 0 {
		panic("dividor should not be 0")
	}

	quo := divident / dividor
	rem := divident % dividor

	if rem != 0 {
		if (divident > 0 && dividor > 0) ||
			(divident < 0 && dividor < 0) {
			return quo + 1
		}
	}
	return quo
}

// -   sortutil

func reverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func reverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// -   io

type scanner struct {
	bufScanner *bufio.Scanner
}

func newScanner() *scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &scanner{bufSc}
}

func (sc *scanner) readString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *scanner) readInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}

func (sc *scanner) readInt64() int64 {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.ParseInt(text, 10, 64)
	if err != nil {
		panic(err)
	}
	return num
}


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

int main(int argc, char* argv[]) {
  string s;
  cin >> s;
  for (int i = 1; i < s.size(); i++) {
    if (s[i] == s[i - 1]) {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;
  return 0;
}

Measured memory_bytes: 256