akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// 1-indexed
template <class T, class E>
struct SegmentTreeLaze {
  // a,b:T c,d:E e:E(unit)
  // g(f(a,b),c) = f(g(a,c),g(b,c))
  // g(g(a,c),d) = g(a,h(c,d))
  // g(a,e) = a
  typedef function<T(T, T)> F;
  typedef function<T(T, E)> G;
  typedef function<E(E, E)> H;
  int n, height;
  F f;
  G g;
  H h;
  T tunit;
  E eunit;
  vector<T> dat;
  vector<E> laz;
  SegmentTreeLaze(){};
  SegmentTreeLaze(int newn, F f, G g, H h, T nt, E ne)
      : f(f), g(g), h(h), tunit(nt), eunit(ne) {
    init(newn);
  }
  void init(int newn) {
    n = 1, height = 0;
    while(n < newn) n <<= 1, ++height;
    dat.assign(n << 1, tunit);
    laz.assign(n << 1, eunit);
  }

  inline T reflect(int k) {
    return laz[k] == eunit ? dat[k] : g(dat[k], laz[k]);
  }

  inline void eval(int k) {
    if(laz[k] == eunit) return;
    laz[k << 1] = h(laz[k << 1], laz[k]);
    laz[(k << 1) | 1] = h(laz[(k << 1) | 1], laz[k]);
    dat[k] = reflect(k);
    laz[k] = eunit;
  }

  inline void thrust(int k) {
    for(int i = height; i; --i) eval(k >> i);
  }

  void recalc(int k) {
    while(k >>= 1)
      dat[k] = f(reflect(k << 1), reflect((k << 1) | 1));
  }
  // [a,b)
  void update(int a, int b, E newdata) {
    thrust(a += n);
    thrust(b += n - 1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) laz[l] = h(laz[l], newdata), l++;
      if(r & 1) --r, laz[r] = h(laz[r], newdata);
    }
    recalc(a);
    recalc(b);
  }

  void set_val(int k, T newdata) {
    thrust(k += n);
    dat[k] = newdata;
    laz[k] = eunit;
    recalc(k);
  }

  // [a,b)
  T query(int a, int b) {
    thrust(a += n);
    thrust(b += n - 1);
    T vl = tunit, vr = tunit;
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) vl = f(vl, reflect(l++));
      if(r & 1) vr = f(reflect(--r), vr);
    }
    return f(vl, vr);
  }
};

struct data {
  long long l, r, a;
};

long long n, m;
map<long long, vector<data>> mp;

long long solve();

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    long long l, r, a;
    cin >> l >> r >> a;
    mp[r].push_back({l, r, a});
  }

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

long long solve() {
  auto f = [](long long l, long long r) {
    return max(l, r);
  };
  auto g = [](long long l, long long r) { return l + r; };
  auto h = [](long long l, long long r) { return l + r; };
  SegmentTreeLaze<long long, long long> dp(n + 1, f, g, h,
                                           0, 0);
  for(int i = 1; i <= n; ++i) {
    dp.update(i, i + 1, dp.query(1, i + 1));
    long long mpsize = mp[i].size();
    for(int j = 0; j < mpsize; ++j)
      dp.update(mp[i][j].l, i + 1, mp[i][j].a);
  }
  return dp.query(1, n + 1);
}

Measured memory_bytes: 30592
//package hw9;
import java.util.Scanner;

 class Profit{
	 private int n;
	 private int[] rateArray;
	 
	 public Profit() {
		 n = 0;
		 
	 }
	 
	 public void buildArray() {
		 Scanner in = new Scanner(System.in);
		 n = in.nextInt();
		 rateArray = new int[n];
		 for (int i = 0; i < n; i++)
			 rateArray[i] = in.nextInt();
		 in.close();
		 System.out.println(computeMaxProfit(n, rateArray));
		 
		 //for (int i = 0; i < n; i++)
			// System.out.println(rateArray[i]);
	 }
	 
	 public int computeMaxProfit(int n, int[] array) {
		 int maxProfit = -999999999;
		 /*for (int i = 0 ; i < n -1; i ++) {
			 for (int j = i + 1; j < n; j++) {
				 if (array[j] - array[i] > maxProfit) {
					 maxProfit = array[j] - array[i];
					 //System.out.println("Max Profit as of time " + i + " : " + maxProfit);
				 }
			 }
		 }*/
		 
		 int currentMax = array[1] - array[0];
		 int currentMin = array[0];
		 for (int i = 1; i < n; i++) {
			 if (array[i] - currentMin > currentMax) {
				 currentMax = array[i] - currentMin;
			 }
			 if (array[i] < currentMin) {
				 currentMin = array[i];
			 }
		 }
		 
		 
		 return currentMax;
	 }
 }

public class Main {
	public static void main(String[] args) {
		Profit p = new Profit();
		p.buildArray();
		
		
	}

}



Measured memory_bytes: 102668
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 6000
int n;
vector<int> g[N];
bool used[N];
int t[N], w[N];
ll inv[N], fact[N], ifact[N];
ll dp[N], dp2[N];
 
void init_fact(ll n = N){
    inv[1] = 1;
    for(int i = 2; i < n; i++) inv[i] = inv[mod%i] * (mod - mod/i) % mod;
	fact[0] = ifact[0] = 1;
	for(int i = 1; i < n; i++){
		fact[i] = (fact[i-1]*i)%mod;
		ifact[i]=(ifact[i-1]*inv[i])%mod;
	}
}

void dfs(int u){
	used[u] = true;
	t[u] = 1;
	for(auto v: g[u]){
		if(used[v]) continue;
		dfs(v);
		t[u] += t[v];
		chmax(w[u], t[v]);
	}
	chmax(w[u], n-t[u]);
}

int main(){
	init_fact();
	cin>>n;
	rep(i, n-1){
		int x, y;
		cin>>x>>y;
		x--; y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(0);
	int wx = 0;
	rep(i, n) if(w[i]<w[wx]) wx = i;
	rep(i, n){
		if(w[i]==w[wx] && i!=wx){
			cerr<<"b"<<endl;
			cout<<fact[n/2]*fact[n/2]%mod<<endl;
			return 0;
		}
	}
	mset(used, 0);
	dfs(wx);
	dp[0] = 1;
	for(auto v: g[wx]){
		memcpy(dp2, dp, sizeof(dp));
		ll s = t[v], r = 1;
		for(ll i = 1; i <= s; i++){
			r = r*(s-i+1)%mod;
			ll r2 = fact[s]*ifact[i]%mod*ifact[s-i]%mod;
			for(ll j = n; j >= i; j--){
				(dp[j]+=dp2[j-i]*r%mod*r2%mod)%=mod;
			}
		}
	}
	ll res = 0;
	rep(i, n){
		(res+=dp[i]*fact[n-i]%mod*(i%2?-1:1))%=mod;
	}
	(res+=mod)%=mod;
	cout<<res<<endl;
	/*
	cerr<<"start debug"<<endl;
	cerr<<"c "<<wx<<endl;
	rep(i, n) cerr<<dp[i]<<endl;
	cerr<<"s "<<g[wx].size()<<endl;
	for(auto v: g[wx]) cerr<<t[v]<<endl;
	*/
	return 0;
}


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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> l(n);
  for(int i = 0; i < n; i++) cin >> l[i];
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  int ans = 0;
  for(int i = 0; i < k; i++){
    ans += l[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <cstdio>
#include <iostream>
#include <vector>
#include <climits>
#include <cstdlib>

using namespace std;

int main(void)
{
    int n, k;
    cin >>n >>k;

    vector<int> costs;
    for(int i = 0; i < n; i++){
        int h;
        cin >>h;
        costs.push_back(h);
    }

    vector<long long int> costSum(n, LLONG_MAX);
    costSum[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <=k; j++){
            if(i - j < 0){
                continue;
            }
            if( costSum[i] > costSum[i - j] + abs(costs[i-j] - costs[i])){
                costSum[i] = costSum[i - j] + abs(costs[i-j] - costs[i]);
            }
        }
    }
    printf("%lld\n", costSum[n-1]);
    return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define rFORq(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
const ll p = 1000000007;
int main(){
    int H,W,K; SCD3(H,W,K);
    static ll dp[102][10] = {};
    static ll F[9] = {1,1,2,3,5,8,13,21,34};

    dp[0][1] = 1;

    FORq(i,0,H){
        FORq(j,1,W){
            ll X,Y,Z;
            X=0;Y=0;Z=0;
            X = F[j-2] * F[W-j];
            Y = F[j-1] * F[W-j];
            Z = F[j-1] * F[W-j-1];

            //printf("(i,j) = (%d,%d) , X = %lld, Y = %lld, Z = %lld\n",i,j,X,Y,Z);

            dp[i+1][j-1] = (dp[i+1][j-1] + (X * dp[i][j]) % p) % p;
            dp[i+1][j] = (dp[i+1][j] + (Y * dp[i][j]) % p) % p;
            dp[i+1][j+1] = (dp[i+1][j+1] + (Z * dp[i][j]) % p) % p;

        }
    }

    PRINTLLD(dp[H][K]);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for((i)=1;(i)<=(n);(i)++)
using namespace std;
const int mod=998244353;
int n,m,i,j,ans,fac[1000005],inv[1000005],fiv[1000005];
int c(int x,int y){
	if(x<y||x<0||y<0) return 0;
	return 1ll*fac[x]*fiv[y]%mod*fiv[x-y]%mod; 
}
int main(){
	fac[0]=fac[1]=inv[1]=fiv[0]=fiv[1]=1;
	for(i=2;i<=1000000;i++){
		fac[i]=1ll*fac[i-1]*i%mod;
		inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
		fiv[i]=1ll*fiv[i-1]*inv[i]%mod;
	} 
	scanf("%d%d",&n,&m);
	for(i=n;i<=m;i++){
		//y-x <= i-n+1
		ans=(0ll+ans+c(m,i)-c(m,i*2-n+1)+mod)%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11904
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;






int main(){
    ll a,b;
    cin>>a>>b;
    ll ans=a*b-a-b+1;
    cout<<ans<<endl;
    
    
    return 0;
}

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



long double dis(long long int x, long long int y){
    long long int sum;
    long long int sq_x, sq_y;
    sq_x = x*x; sq_y = y*y;
    if(sq_x < 0){sq_x = (-1)*sq_x;}
    if(sq_y < 0){sq_y = (-1)*sq_y;}
    

    sum = sq_x + sq_y;
    return sqrt(sum);
}



int main(void){
    
    int N, D;
    long long int x, y;
    long double distance;
    int overD = 0;


    cin >> N; cin >> D;

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

        cin >> x;
        cin >> y;

    
        distance = dis(x, y);
    
        if(distance <= D){
            overD++;
        }

    }
    cout << overD;
    

    return 0;
}

Measured memory_bytes: 3680
#include <iostream>
#include <bits/stdc++.h>
#include <sstream>
#define PI 3.14159265358979323846264338327950L
#define ll long long
using namespace std;

int main()
{
    int a;
    cin >> a;
    int n[a];
    for(int i=0; i<a; i++){
        cin >> n[i];
    }
    int ans = 0;
    for(int i=0; i<a; i+=2){
        if(n[i] % 2 != 0){
            ans++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3576
def inputting():
    n=int(input())
    S=sorted(map(int,input().split()))
    q=int(input())
    T=list(map(int,input().split()))
    return n,S,q,T

def linearsearch(n,S,t):
    for s in S:
        if s==t:
            return 1
    return 0

def main():
    n,S,q,T=inputting()
    count=0
    for t in T:
        flag=linearsearch(n,S,t)
        if flag==1:
            count+=1
    print(count)
    

if __name__=='__main__':
    main()




Measured memory_bytes: 6548
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i;
    cin >> N;

    vector<pair<ll, ll>> AB(N);
    
    for(i=0; i<N; i++){
        cin >> AB[i].first >> AB[i].second;
    }

    sort(AB.begin(), AB.end());

    cout << AB[N-1].first+AB[N-1].second << endl;

    return 0;
}

Measured memory_bytes: 1920
k, n = map(int, input().split())
list = list(map(int, input().split()))
ans = 100000000
for i in range(n):
    list.append(list[i] + k)
for i in range(n):
    m = list[i + n - 1] - list[i]
    ans = min(ans, m)
print(ans)

Measured memory_bytes: 92620
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s; cin >> s;
    map<char,int> mp;
    for(int i=0;i<s.size();++i){
        mp[s[i]]++;
    }
    if(mp.size() == 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int N;
  int ans = 0;

  cin >> N;

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

  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      ans += d[i] * d[j];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

X = getN()

if X >= 30:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 78024
#include <stdio.h>
#include <stdlib.h>

int asc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main(){
   int i,n,m,a[100],s;
    
   scanf("%d %d",&n,&m);
   for (s=i=0;i<n;i++) {
      scanf("%d",&a[i]);
      s+=a[i];
   }
   qsort(a,n,sizeof(int),asc);
   if (s>a[m-1]*m*4) puts("No");
   else              puts("Yes");
   return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll int
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
const ll mod=998244353;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> data_struct;

int main()
{
	string a,b;
	cin>>a>>b;
	if(b.length() == a.length()+1)
	{
		if(a == b.substr(0,b.length()-1))
			cout<<"Yes";
		else
			cout<<"No";
		return 0;
	}
	cout<<"No";
}

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

using namespace std;

int dp[8][1001];

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

    while(true) {
        int M;
        cin >> M;
        if(!M) break;
        dp[0][0] = 1;
        for(int i = 1; i <= M; ++i) {
            int A, B;
            cin >> A >> B;
            for(int j = 0; j < 1001; ++j) dp[i][j] = 0;
            for(int j = 0; j < 1001; ++j) {
                if(dp[i-1][j]) {
                    for(int k = 0; k <= B; ++k) {
                        const int next = j + A*k;
                        if(next <= 1000) dp[i][next] += dp[i-1][j];
                    }
                }
            }
        }
        int N;
        cin >> N;
        while(N--) {
            int NG;
            cin >> NG;
            cout << dp[M][NG] << endl;
        }
    }
    return 0;
}

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

int main() {
  ll n;
  cin>>n;
  cout<<n*(n-1)/2<<endl;
  return 0;
}


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

cnt = 0

while True:
    x = str(N + cnt)
    if len(x) >= 4:
        if x[0] == x[1] and x[0] == x[2] and x[0] == x[3]:
            break
    else:
        if x[0] == x[1] and x[0] == x[2]:
            break
    cnt += 1
    
print(x)

Measured memory_bytes: 3060
from collections import deque


def bfs(start):
    Q = deque()
    Q.append(start)
    child = deque()
    dist[start[1]][start[0]] = 0

    while Q:
        x, y = Q.popleft()

        for i in range(4):
            child.clear()
            nx = x + dx[i]
            ny = y + dy[i]

            if nx < 0 or nx >= W or ny < 0 or ny >= H:
                continue
            if G[y][x][i] == 1:
                continue
            if dist[ny][nx] != -1:
                continue

            child.append((nx, ny))

            if len(child) > 0:
                for c in child:
                    dist[c[1]][c[0]] = dist[y][x] + 1
                    Q.append(c)


W, H = map(int, input().split())
while not (W == 0 and H == 0):
    G = [[[0 for _ in range(4)] for _ in range(W)] for _ in range(H)]

    w = []
    h = []
    for i in range(H - 1):
        w.append(list(map(int, input().split())))
        h.append(list(map(int, input().split())))
    w.append(list(map(int, input().split())))

    for i in range(H):
        for j in range(W):
            if j < W - 1:
                # 右
                G[i][j][0] = w[i][j]
            else:
                G[i][j][0] = 1
            if i < H - 1:
                # 下
                G[i][j][1] = h[i][j]
            else:
                G[i][j][1] = 1
            if j - 1 >= 0:
                # 左
                G[i][j][2] = w[i][j - 1]
            else:
                G[i][j][2] = 1
            if i - 1 >= 0:
                # 上
                G[i][j][3] = h[i - 1][j]
            else:
                G[i][j][3] = 1

    dist = [[-1 for _ in range(W)] for _ in range(H)]

    dx = [1, 0, -1, 0]  # 斜めも含むならその方向もプラス
    dy = [0, 1, 0, -1]

    bfs((0, 0))

    print(dist[H - 1][W - 1] + 1)

    W, H = map(int, input().split())



Measured memory_bytes: 6228
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define mod 1000000007
#define endl '\n'
typedef long long int ll ;
using namespace std;
#define MAX 100009
int  main()
{
    ll n,m; cin>>n>>m;
    ll arr[n+2];
    for(int i=1;i<=n;i++) arr[i]=-1;
    int flag=0;
    for(int i=1;i<=m;i++){
        ll a, b; cin>>a>>b;
        if(arr[a]==-1) arr[a]=b;
        else if(arr[a]==b) arr[a]=b;
        else flag=1;
    }
    if(arr[1]==0 && n!=1) flag=1;
    if(arr[1]==0 && n==1) { cout<<0<<endl; return 0; }
    if(flag){ cout<<-1<<endl; return 0; }
    if(arr[1]==-1 && n!=1) arr[1]=1;
    if(arr[1]==-1  && n==1) arr[1]=0;
    for(int i=1;i<=n;i++) if(arr[i]==-1) arr[i]=0;
    for(int i=1;i<=n;i++) cout<<arr[i];
    
    
}

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

const int maxn=2e5+10;
const int mo=1e9+7;

int n,root,Ans=1,tote=1,edge;
int fa[maxn],fw[maxn],tmp[maxn];
int fac[maxn],ifac[maxn],vis[maxn],q[maxn];
int FIR[maxn],TO[maxn*2],NEXT[maxn*2],W[maxn*2];
bool vise[maxn*2];

int power(int x,int k)
{
	int res=1;
	while (k)
	{
		if (k&1) res=(LL)res*x%mo;
		x=(LL)x*x%mo;
		k>>=1;
	}
	return res;
}

void addedge(int u,int v,int w)
{
	TO[++tote]=v;
	NEXT[tote]=FIR[u];
	W[tote]=w;
	FIR[u]=tote;
}

void dfs1(int u,int F)
{
	if (vis[u]==1) {root=u; return;}
	vis[u]=1;
	q[++q[0]]=u;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p];
		if (v==F) continue;
		if (!vise[p]) edge++,vise[p]=vise[p^1]=1;
		dfs1(v,u);
	}
}

void dfs2(int u)
{
	if (vis[u]==2) return;
	vis[u]=2;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p],w=W[p];
		if (v==fa[u]) continue;
		fa[v]=u;
		fw[v]=w;
		dfs2(v);
	}
}

namespace Tree{
	int n,fa[maxn],dp[maxn],sz[maxn];
	int tote,FIR[maxn],TO[maxn<<1],NEXT[maxn<<1];

	void addedge(int u,int v)
	{
		TO[++tote]=v;
		NEXT[tote]=FIR[u];
		FIR[u]=tote;
		fa[v]=u;
	}

	bool dfs(int u)
	{
		if (dp[u]) return 0;
		sz[u]=0;
		dp[u]=1;
		for (int p=FIR[u];p;p=NEXT[p])
		{
			int v=TO[p];
			if (!dfs(v)) return 0;
			sz[u]+=sz[v];
			dp[u]=(LL)dp[u]*dp[v]%mo;
			dp[u]=(LL)dp[u]*ifac[sz[v]]%mo;
		}
		dp[u]=(LL)dp[u]*fac[sz[u]]%mo;
		sz[u]++;
		return 1;
	}

	void solve(int &Ans)
	{
		int i,u;
		for (i=1;i<=q[0];i++)
		{
			u=q[i];
			if (!fa[u]) addedge(0,u);
		}
		for (i=1;i<=q[0];i++) u=q[i];
		if (!dfs(0)) {Ans=0; return;}
		(Ans+=dp[0])%=mo;
		for (i=1;i<=q[0];i++)
			u=q[i],FIR[u]=fa[u]=dp[u]=sz[u]=0;
		FIR[0]=fa[0]=dp[0]=sz[0]=0;
		tote=0;
	}
};

void dfs3(int u)
{
	if (vis[u]==3) return;
	vis[u]=3;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p],w=W[p];
		if (w<fw[u]) Tree::addedge(u,v);
		dfs3(v);
	}
}

void dfs4(int u)
{
	if (vis[u]==4) return;
	vis[u]=4;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p],w=W[p];
		if (w<fw[u]) Tree::addedge(u,v);
		dfs4(v);
	}
}

int main()
{
#ifdef h10
	freopen("F.in","r",stdin);
	freopen("F.out","w",stdout);
#endif
	int i,u,v;
	scanf("%d",&n);
	fac[0]=1;
	for (i=1;i<=n+n;i++)
		fac[i]=(LL)fac[i-1]*i%mo;
	ifac[n+n]=power(fac[n+n],mo-2);
	for (i=n+n;i>=1;i--)
		ifac[i-1]=(LL)ifac[i]*i%mo;
	for (i=1;i<=n+n;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(u,n+v,u+v);
		addedge(n+v,u,u+v);
	}
	for (i=1;i<=n+n;i++)
		if (!vis[i])
		{
			q[0]=0;
			root=0;
			edge=0;
			dfs1(i,0);
			if (!root||edge!=q[0]) {puts("0"); return 0;}
			dfs2(root);
			int Sum=0;
			dfs3(root);
			Tree::solve(Sum);
			for (u=root;;u=fa[u])
			{
				tmp[fa[u]]=fw[u];
				if (fa[u]==root) break;
			}
			for (u=root;;u=fa[u])
			{
				fw[u]=tmp[u];
				if (fa[u]==root) break;
			}
			dfs4(root);
			Tree::solve(Sum);
			Ans=(LL)Ans*Sum%mo;
			Ans=(LL)Ans*ifac[q[0]]%mo;
		}
	Ans=(LL)Ans*fac[n+n]%mo;
	printf("%d\n",Ans);
}


Measured memory_bytes: 18816
#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 <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

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

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int MOD = 1000000007;

struct Pony
{
    long a, b;
 
    Pony(long a_, long b_)
    {
        a = a_;
        b = b_;
    }
 
    bool operator<(const Pony &another) const
    {
        return b < another.b;
    };
};

int fac(int k){
    int sum = 0;
    for (int i = 1; i <= k; ++i)
    {
        sum += i;
    }
    return sum;
}

long a[200005];
vector<long> b[200005];
bool done[200005];

void f(int i, long v) {
  if (done[i]) return;

  a[i] += v;
  done[i] = true;

  rep(j, b[i].size()) {
    f(b[i][j], a[i]);
  }
}

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

  long n, q;

  cin >> n >> q;

  rep(i, n-1) {
    long x, y;
    cin >> x >> y;
    x--;
    y--;
    b[x].push_back(y);
    b[y].push_back(x);
  }

  rep(i, q) {
    long p, x;
    cin >> p >> x;
    a[p-1] += x; 
  }

  f(0, 0);

  rep(i, n) {
   cout << a[i] << endl;
  } 
}


Measured memory_bytes: 24448
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define int ll int
#define debug(x) cout << ">>" << #x << ':' << x << endl;
#define endl "\n"
#define pb push_back
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define umap unordered_map
#define pii pair<int , int>
#define remove erase
#define all(v) v.begin() , v.end()   

const int mod = 1e9 + 7;

signed main()
{
	IOS
	string s;
	cin>>s;
	int ans=0;
	for(int i=0 ; i<s.length() ; i++)
	{
		int temp = s[i] - '0';
		ans = ans + temp;
	}
	if(ans%9 == 0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}



Measured memory_bytes: 3752
s = str(input())
x = len(s)
ans = 0
if x % 2 == 0:
    y = int(x / 2)
    for i,j in zip(s[:y],s[:y-1:-1]):
        if i == j:
            pass
        else:
            ans += 1
else:
    z = int(x // 2)
    for i,j in zip(s[:z],s[:z:-1]):
        if i == j:
            pass
        else:
            ans += 1
print(ans)

Measured memory_bytes: 3064
import java.io.*;

class Main{
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String str = br.readLine();
			char c;
			for( int i=0; i<str.length(); i++ ){
				c = str.charAt(i);
				if( Character.isUpperCase(c) ) c = Character.toLowerCase(c);
				else if( Character.isLowerCase(c) ) c = Character.toUpperCase(c);
				System.out.print(c);
			}
			System.out.println();
		} catch(IOException e){
			System.out.println("Exception :" + e);
		}
	}
}

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

int main() {
  int A, B, C, D;
  cin>>A>>B>>C>>D;
  int l = A + B,r = C + D;
  if (l > r) {
    cout << "Left" << endl;
  }
  else if (l < r) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;
	map<int, int> mp;
	map<int, int> mp2;

	rep(i, n) {
		int x;
		cin >> x;
		mp2[x]++;
	}

	int ans = 0;

	each(i, mp2) {
		if (i.second % 2) {
			mp[i.first % m]++;
			i.second--;
		}
	}
	each(i, mp) {
		int x = i.first;
		int tm = min(mp[m - x], i.second);
		if (x == m - x) {
			tm /= 2;
			i.second -= tm * 2;
			ans += tm;
			continue;
		}
		i.second -= tm;
		mp[m - x] -= tm;
		ans += tm;
	}
	ans += mp[0] / 2;
	mp[0] -= (mp[0] / 2) * 2;

	bool f = true;
	while (f) {
		f = false;
		each(i, mp2) {
			int t = min(i.second, mp[m - i.first % m]);
			i.second -= t;
			mp[m - i.first % m] -= t;
			ans += t;
			if (i.second % 2) {
				mp[i.first % m]++;
				i.second--;
				f = true;
			}
		}
	}

	each(i, mp2) {
		ans += i.second / 2;
	}

	cout << ans << endl;

	return 0;
}

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

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

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

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

    rep(i,N)
    {
        rep(j,D) cin >> X[i][j];
    }
    ll ans = 0;
    rep(i,N)
    {
        for( int j = i+1;j < N; j++)
        {
            ll tmp = 0;
            rep(k,D) tmp += pow(X[i][k] - X[j][k],2);
            ll k = 1;
            while( tmp >= k*k )
            {
                if( tmp == k*k )
                {
                    ans++;
                    break;
                }
                k++;
            }
        }
    }
    cout << ans << endl;


    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int x; cin >> x;
    bool flag = true;
    if(x == 2){
        cout << x << endl;
        return 0;
    }
    while(flag){
        FOR(i, 2, sqrt(x)){
            flag = false;
            if(x % i == 0){
                flag = true;
                break;
            }
        }
        x++;
    }
    cout << x - 1 << endl;
}

Measured memory_bytes: 256
def resolve():
    N = int(input())
    A = [int(input()) - 1 for _ in range(N)]

    pressed = 0
    i = 0
    t = 0
    while i != 1:
        i = A[i]
        if pressed > N:
            t = -1
            break
        pressed += 1
        t += 1

    print(t)
    
resolve()

Measured memory_bytes: 79704
#include <iostream>
#include <set>

int main() {
    std::set<int> st;
    bool f=true;
    int n; std::cin >> n;
    for(int i=0; i<n; ++i) {
        int a; std::cin >> a;
        if (st.find(a) != st.end())
            f=false;
        st.insert(a);
    }
    std::cout << (f ? "YES" : "NO") << std::endl;
    return 0;
}

Measured memory_bytes: 12988
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;

int main(void) {
  int N;
  cin>>N;
  vector<vector<LL> >A(N,vector<LL>(N));
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      scanf("%d", &A[i][j]);

  for(int k=0;k<N;k++)
    for(int i=0;i<N;i++)
      for(int j=0;j<i;j++)
        if(A[i][j] > A[i][k]+A[k][j]){
          cout << -1 << endl;
          return 0;
        }

  LL ans=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<i;j++){
      int need=1;
      for(int k=0;k<N;k++){
        if(k!=i and k!=j and A[i][j]==A[i][k]+A[k][j])
          need=0;
      }
      if(need) ans+=A[i][j];
    }
  }
  
    cout << ans << endl;
    return 0;
}

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

#define all(n) n.begin(),n.end()
#define ll long long

#define pb push_back
#define eb emplace_back
#define endl "\n"
#define pll pair<ll,ll>
#define ff first
#define ss second

using namespace std;
const ll maxn=5e5+2;
const ll maxx=1e16;
const ll mod=1e9+7;
const ll mod1=998244353;
vector<ll> adj[maxn];
ll a[maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("TEAMS.INP","r"))
    {
        freopen("TEAMS.INP", "r", stdin);
        freopen("TEAMS.OUT", "w", stdout);
    }
    ll x, y;
     cin>>x >> y;
     if (y%2==0&&x*2<=y&&y<=x*4)
     {
         cout <<"Yes";
     }
     else
     {
         cout <<"No";
     }
}


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

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

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;

fn main() {
    let k:u32 = read();

    println!("{}", (k/2) * ((k+1)/2));

}


Measured memory_bytes: 4352
package main

import (
	"fmt"
	"math"
	"sort"
	"strconv"
)

func main() {

	var N int

	fmt.Scan(&N)

	max := int(math.Sqrt(float64(N))+1)

	var A,B string

	var result[] int


	for i:=1;i<=max;i++{

		if N%i==0{

			A = strconv.Itoa(i)
			B = strconv.Itoa(N/i)

			if len(A) > len(B){

				result = append(result,len(A))

			}else{

				result = append(result,len(B))

			}
		}
	}

	sort.Sort(sort.IntSlice(result))


	fmt.Println(result[0])

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  int k;
  cin >> k;
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a[k - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    h=int(input())
    w=int(input())
    n=int(input())

    v=max(h,w)
    cnt=0
    while n>0:
        n-=v
        cnt+=1
    print(cnt)

resolve()

Measured memory_bytes: 38256
using System;

class quiz
{
    public int solve(int n, int[] v)
    {
        int[] odd = new int[100000 + 1];
        int[] even = new int[100000 + 1];
        int[] no = new int[100000 + 1];
        int[] ne = new int[100000 + 1];

        for (int i = 0; i < n / 2; i++)
        {
            odd[v[2 * i]]++;
            even[v[2 * i + 1]]++;
        }

        for (int i = 0; i < 100000 + 1; i++)
        {
            no[i] = i;
            ne[i] = i;
        }

        Array.Sort(odd, no);
        Array.Sort(even, ne);

        if (no[100000] != ne[100000])
            return n - odd[100000] - even[100000];
        if (odd[100000] + even[99999] >= odd[99999] + even[100000])
            return n - odd[100000] - even[99999];
        else
            return n - odd[99999] - even[100000];
    }

    public int[] ParseIntBySpace(string str)
    {
        int[] array = new int[str.Length];
        int lastloc = 0, spaceloc = -1;

        for (int i = 0; i < str.Length; i++)
        {
            if (str[i] == ' ')
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc - 1));
                spaceloc = i;
            }
            else if (i == str.Length - 1)
            {
                array[lastloc++] = int.Parse(str.Substring(spaceloc + 1, i - spaceloc));
            }
        }

        Array.Resize(ref array, lastloc);

        return array;
    }
}

class Example
{
    static void Main()
    {
        quiz ex = new quiz();

        //while (true)
        //{
        Console.WriteLine(ex.solve(int.Parse(Console.ReadLine()), ex.ParseIntBySpace(Console.ReadLine())));
        //}
    }
}

Measured memory_bytes: 19424
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

int h,w,u,s;
int dat[35][35];
int rui[35][35];

mp dp[35][35][35][35];

int gets(int sy,int sx,int gy,int gx){
	return rui[gy+1][gx+1]-rui[gy+1][sx]-rui[sy][gx+1]+rui[sy][sx];
}

mp memo(int sy,int sx,int gy,int gx){
	mp& res=dp[sy][sx][gy][gx];
	if(res.fir!=-2)return res;
	{
		int rs=s-gets(sy,sx,gy,gx);
		//printf("%d %d %d %d %d\n",sy,sx,gy,gx,rs);
		if(rs<=u)res = mp(1,u-rs);
		else res = mp(-1,-1);
	}
	reg(y,sy,gy-1){
		mp pa=memo(sy,sx,y,gx);
		mp pb=memo(y+1,sx,gy,gx);
		if(pa.fir==-1 || pb.fir==-1)continue;
		mp tp(pa.fir+pb.fir,min(pa.sec,pb.sec));
		if(tp>res)res=tp;
	}
	reg(x,sx,gx-1){
		mp pa=memo(sy,sx,gy,x);
		mp pb=memo(sy,x+1,gy,gx);	
		if(pa.fir==-1 || pb.fir==-1)continue;
		mp tp(pa.fir+pb.fir,min(pa.sec,pb.sec));
		if(tp>res)res=tp;
	}	
	return res;
}

int main(void){
	for(;;){
		scanf("%d%d%d",&h,&w,&u);
		if(h==0)break;
		rep(y,h)rep(x,w)scanf("%d",&dat[y][x]);
		rep(i,35)rep(j,35)rep(p,35)rep(q,35)dp[i][j][p][q]=mp(-2,-2);
		memst(rui,0);
		s=0;
		reg(y,1,h)reg(x,1,w){
			s+=dat[y-1][x-1];
			rui[y][x]=rui[y-1][x]+rui[y][x-1]-rui[y-1][x-1]+dat[y-1][x-1];
		}
		mp ans=memo(0,0,h-1,w-1);
		printf("%d %d\n",ans.fir,ans.sec);
	}
	return 0;
}

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

int main()
{
     int n,l;
     cin>>n>>l;
     long long int a[n];
     for(int i=0;i<n;i++)
          cin >>a[i];
     long long int i,k=n-1;
     for(i=0;i<n-1;i++)
     {
          if(a[i]+a[i+1]>=l)
                {
                    k=i;
                    break;
                }
     }
     if(k==n-1)
          cout<<"Impossible"<<endl;
     else
     {
      cout << "Possible" << endl;
     for(int j=0;j<k;j++)
        cout <<j+1<<" ";
     for(int j=n-2;j>i;j--)
        cout <<j+1<<" ";
     cout<<i+1<<endl;
     }
}


Measured memory_bytes: 4388
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int a,b,c;
    cin >> a >> b >>c;
    if(abs(a-b)>abs(a-c)){
        cout << "B";
    }else{
        cout << "A";
    }
}

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

int main() {
  int s;

  cin >> s;

  if (s % 100 > 0 && s % 100 <= 12) {
    if (s / 100 > 0 && s / 100 <= 12) {
      cout << "AMBIGUOUS";
    } else {
      cout << "YYMM";
    }
  } else if (s / 100 > 0 && s / 100 <= 12) {
    cout << "MMYY";
  } else {
    cout << "NA";
  }

  return 0;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Mutable as MV
import Data.Ix
import Data.Ord (Down(Down))
import qualified Data.Sequence as Seq
import Data.Foldable (toList)
-- import Control.Lens

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)


readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

main :: IO ()
main = do
  n <- readInt
  as <- readInts
  let f a = if even a then 2 else 1
  let oddPos = product $ f <$> as
  print $ 3 ^ n - oddPos




Measured memory_bytes: 380
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_N 100000
int N;
ll A[MAX_N];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	map<ll, int> m;
	ll res = 0;
	rep(i, 0, N) {
		cin >> A[i];
		if(m[A[i]] == 0) {
			res++;
			m[A[i]]++;
		} else {
			m[A[i]]--;
			res--;
		}
	}

	cout << res << endl;

}


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

using namespace std;

string a,b;
int i,j;
int dp[3003][3003];
vector <char> wektor;

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> a >> b;
    for(i=1;i<=a.size();i++)
    {
        for(j=1;j<=b.size();j++)
        {
            if(a[i-1]==b[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
            {
                dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    i = a.size();
    j = b.size();
    while(i>0 && j>0)
    {
        if(dp[i][j]==dp[i-1][j])
        {
            i--;
        }
        else if(dp[i][j]==dp[i][j-1])
        {
            j--;
        }
        else if(dp[i][j]>dp[i-1][j-1])
        {
            wektor.push_back(a[i-1]);
            i--;
            j--;
        }
    }
    for(i=wektor.size()-1;i>=0;i--){
        cout << wektor[i];
    }
    return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pi;
#define int long long
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);
#define f first
#define s second

const int maxn = 200010;


int32_t main() {
	int n, d; cin >> n >> d;
	
	int ans = 0;
	for (int i =0;i<n;i++) {
		int x, y; cin >> x >> y;
		if (x*x + y * y <= d*d) {
			ans++;
		}
	}
	cout << ans;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <algorithm>
#include <queue>

using namespace std;

#define INT_MAX 2147483647
typedef long long ll;

ll gcd(ll m, ll n);
ll lcm(ll m, ll n);

int main(void) {

	long long ans = 0;
	long long a, b, c, d;
	cin >> a >> b >> c >> d;

	ll tmp = lcm(c, d);
	long long sum_b = b - (b / c) - (b / d) + (b / tmp);
	long long sum_a = a - 1 - ((a-1) / c) - ((a - 1) / d) + ((a - 1) / tmp);

	ans = sum_b - sum_a;

	cout << ans << endl;
	return 0;

}

// 2番目から3要素だけ抜き出した部分文字列を取得する
//std::string result = s.substr(2, 3);  
#if 1
//最大公倍数
ll gcd(ll m, ll n)
{
	ll temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
#endif

Measured memory_bytes: 256
import Data.List

main = do
  n <- readLn :: IO Int
  ps <- map read . words <$> getLine :: IO [Int]
  qs <- map read . words <$> getLine :: IO [Int]
  putStrLn $ show $ dist ps qs $ sort $ permutations [1..n]

foldlState :: (a -> c -> b -> (a, c)) -> a -> c -> [b] -> a
foldlState f a s l = fst $ foldl (\(a,s) -> f a s) (a, s) l

dist ps qs order | ps == qs = 0
                 | otherwise = foldlState step 0 False order
    where step a b rs = let c = (rs == ps || rs == qs) in (a + if b then 1 else 0, if b then not c else c)


Measured memory_bytes: 23932