akhauriyash/Code-Regression huggingface dataset:
class Node():
   def __init__(self, key):
     self.parent = None
     self.right = None
     self.left = None
     self.key = key

class BST():
  def __init__(self):
    self.T = list()
    self.root = None
    self.res = []

  def insert(self,node:Node):
    y = None
    x = self.root
    while x is not None:
      y = x
      if node.key < x.key:
        x = x.left
      else:
        x = x.right
    node.parent = y
    if y is None:
      self.root = node
    elif node.key < y.key:
      y.left = node
    else:
      y.right = node

  def preorder(self,node:Node):
    if node is None:
      return
    #self.res.append(node.key)
    print(" " + str(node.key), end="")
    self.preorder(node.left)
    self.preorder(node.right)

  def inorder(self, node:Node):
    if node is None:
      return
    self.inorder(node.left)
    print(" " + str(node.key), end="")
    self.res.append(node.key)
    self.inorder(node.right)




def main():
  n = int(input())
  T = BST()
  for _ in range(n):
    cmd = input().split()
    if cmd[0] == "insert":
      key = int(cmd[1])
      T.insert(Node(key))
    else:
#      T.res = list()
      T.inorder(T.root)
      print()
#      print(" ".join(map(str,T.res)))
#      T.res = list()
      T.preorder(T.root)
      print()
#      print(" ".join(map(str,T.res)))

if __name__ == "__main__":
  import sys, io

  main()




Measured memory_bytes: 110216
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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 T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
signed main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    vector<int> rui(n + 1,0);
    for (int i = 0 ; i <= n; i++)
    {
        rui[i+1] = rui[i] + a[i];
    }
    ll l = 0, r = INF;
    int res = 0;
    int acnt = 0;
    while (l + 1 < r)
    {
      //  cerr << l << " " << r << endl;
        int x = (l + r) / 2;
     //   cerr << "x = " << x << endl;
        int ans = 0;
        int cnt = 0;
        bool ok = [&] {
            for (int i = 0; i < n; i++)
            {
                //x-a[i]以上
                //int p = lower_bound(ALL(a), x - a[i]);
                int c = a.end() - lower_bound(ALL(a),x-a[i]);
                int p = lower_bound(ALL(a), x - a[i]) - a.begin();
          //      cerr << "c= " << c << endl;
                ans += a[i] * c + rui[n] - rui[p];
                cnt += c;
            }
         //   cerr << "cnt = " << cnt << endl;
            return cnt >= m;
        }();
     //   cerr << ans << endl;
        if (ok)
        {
            l = x;
            res = ans;
            acnt = cnt;
        }
        else{
            r = x;
            ans = 0;
        }
    }
        cout << res - (acnt-m)*l << endl;

        return 0;
}

Measured memory_bytes: 1920
/*input
1
1
*/
#include "bits/stdc++.h"
using namespace std;
int a[200005],n;
set<int> pos[200005];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; ++i){
		cin >> a[i];
		pos[a[i]].insert(i);
	}
	if(pos[1].empty())
		return cout << -1, 0;
	int now = 1;
	for(int last = 1;; ++now){
		if(pos[now].empty() || *pos[now].rbegin() < last)
			break;
		last = *pos[now].lower_bound(last) + 1;
	}
	cout << n - now + 1 << endl;
}

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

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

  int a[10000];
  for(int i=0;i<n;i++) cin>>a[i];

  int mn = a[0], mx = a[0];
  long long sum = 0;

  for(int i=0;i<n;i++) {
    mn = min(mn, a[i]);
    mx = max(mx, a[i]);
    sum+=a[i];
  }

  cout<<mn<<" "<<mx<<" "<<sum<<endl;

  return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;
  	long long k=min({A,B,C,D,E});
	cout << (N-1)/k + 5 << endl;
	return 0;
}

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

int main() {

	long long n, m; cin >> n >> m;	
	
	vector<long long> c;
	for (long long i = 1; i * i <= m; ++i) {
		if (m % i == 0LL) {
			if(i * n <= m) c.push_back(i);
			if (m / i * n <= m)c.push_back(m / i);
		}
	}
	
	sort(c.begin(), c.end());

	cout << c[c.size() - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include<stdlib.h>
#include<stdio.h>
#define test ll t; cin>>t; while(t--)
#define FOR(p,n) for(ll i=p;i<(ll)n;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 998244353
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[2000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<200007;i++)fact[i]=(fact[i-1]*i)%998244353;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%998244353; res=(res*(power(fact[n-r],998244353-2)))%998244353; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
using namespace std;
signed main()
{
	facto();
	int n,m,k;
	cin>>n>>m>>k;
	int sum=0;
	for(int k1=0;k1<=k;k1++)
	{
		int x=m;
		x=x*ncr(n-1,k1)%mod;
		x=x*power(m-1,n-1-k1)%mod;
		sum=(sum+x)%mod;
	}
	cout<<sum<<endl;
}












Measured memory_bytes: 5208
import sys
sys.setrecursionlimit(10**7)

N = int(input())
h = list(map(int, input().split()))

dp = [-1] * N # dp[i] := i から N-1 までの移動にかかる最小コスト
dp[N-1] = 0

for i in reversed(range(N - 1)):
    if i == N - 2:
        dp[i] = dp[i + 1] + abs(h[i + 1] - h[i])
    else:
        dp[i] = min(dp[i + 2] + abs(h[i + 2] - h[i]), dp[i + 1] + abs(h[i + 1] - h[i]))

print(dp[0])

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;

#define LINF		((ll)1 << 63 -1)
#define INF 		(1<<29)
#define MINF		-2000000007
#define MAX 		205

const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

//
int main(){
	int N;cin>>N;
	int nf[5]={0,0,0,0,0};

	REP(i,N){
		string s;cin>>s;
		switch(s[0]){
			case 'M':nf[0]++;break;
			case 'A':nf[1]++;break;
			case 'R':nf[2]++;break;
			case 'C':nf[3]++;break;
			case 'H':nf[4]++;break;
			default:
			;
		}
	}

	ll ans = 0;
	REP(i,5-2)REPS(j,i+1,5-1)REPS(k,j+1,5){
		ans += (ll)nf[i]*nf[j]*nf[k];
	}

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




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

typedef long long ll;
const ll kInf = 1LL << 50;
const int kMax = 150;

int N, Si[kMax];
ll A, B, Ri[kMax];

int sum;
ll f[2][kMax + 1][kMax + 1];
bool fv[2][kMax + 1][kMax + 1];

void read();
void solve();

ll dp(int, int, int);

int main() {
	while (cin >> N >> A >> B)
		read(), solve();
	
	return 0;
}

void read() {
	for (int i = 0; i < N; ++i)
		cin >> Ri[i] >> Si[i];
}

void solve() {
	int res;
	
	sum = accumulate(&Si[0], &Si[N], 0);
	fill(&fv[0][0][0], &fv[2][0][0], false);
	for (res = sum; res > 0; --res)
		if (dp(0, 0, res) <= A - B)
			break;
	cout << res << " " << sum - res << "\n";
}

ll dp(int p, int b, int s) {
	if (s < 0)
		return -kInf;
	
	if (s > sum)
		return kInf;
	
	if (fv[p][b][s])
		return f[p][b][s];
	
	fv[p][b][s] = true;
	if (b == N)
		return f[p][N][s] = (s == 0 ? -kInf : kInf);
	
	// alice
	if (p == 0) {
		f[0][b][s] = dp(0, b, s + 1);
		f[0][b][s] = min(f[0][b][s], dp(1, b + 1, s - Si[b]) - Ri[b]);
		f[0][b][s] = min(f[0][b][s], max(dp(0, b + 1, s) + Ri[b] + 1, 1LL));
	}
	// brianna
	else {
		f[1][b][s] = dp(1, b, s - 1);
		f[1][b][s] = max(f[1][b][s], dp(0, b + 1, s) + Ri[b]);
		f[1][b][s] = max(f[1][b][s], min(dp(1, b + 1, s - Si[b]) - Ri[b] - 1, 0LL));
	}
	
	return f[p][b][s];
}

Measured memory_bytes: 2964
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
 
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979
 
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

int main(void){
	int M;
	cin>>M;
	print(24+(24-M));
	return 0;
}


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

int main() {
	/****input****/
  ll a,b,k;
  cin >> a >> b >> k;

  /****calc****/
  ll ansA = a;
  ll ansB = b;
  if(a == 0 && b == 0){
	  cout << '0' << " " << '0' << endl;
	  return 0;
  }
  ansA = a - k;
  if(ansA < 0) ansA = 0;

  k -= a;
  if(k < 0) k = 0;

  ansB = b - k;
  if(ansB < 0) ansB = 0;

  /****output****/
  cout << ansA << " " << ansB << endl;
  return 0;
}


Measured memory_bytes: 256
/*
N! 通りの経路を全探索し, 各経路の長さを計算し, その平均値を出力します.
N! 通りの経路の全探索は, 例えば C++ では next permutation 関数を使うと容易に実装出来ます.
時間計算量は O (N!N) です
*/
#include <bits/stdc++.h>
using namespace std;

int N;
int x[10], y[10];

double dist(int i, int j) {
  double dx = x[i] - x[j];
  double dy = y[i] - y[j];
  return pow(dx * dx + dy * dy, 0.5);
}

int main() {
  cin >> N;
  for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];
  double sum = 0.0;
  vector<int> v(N);
  for(int i = 0; i < N; i++) v[i] = i + 1;
  do {
    for(int i = 0; i < N - 1; i++){
      sum += dist(v[i], v[i+1]);
    }
  } while(next_permutation(v.begin(), v.end()));
  //平均値
  int Factorial = 1;
  for(int i = 2; i <= N; i++) Factorial *= i;
  cout << fixed << setprecision(10) << sum / Factorial << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first 
#define se second
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

 
int main(){
 ll h , w, m ;
 cin>>h>>w>>m ;
 vector<ll> tate(h),yoko(w) ;
 vector<P> re(m) ;
 rep(i,m){
    ll a,b ;cin>>a>>b ;
    a-- ;b-- ;
    re[i].fi=a ;re[i].se=b ;
    tate[a]++ ;yoko[b]++ ;
 }
 sort(re.begin(),re.end()) ;
 ll ans=-1 ;
 rep(i,h){
   chmax(ans,tate[i]) ;
 }
 ll bns=-1 ;
 rep(i,w){
    chmax(bns,yoko[i]) ;
 }
 vector<ll> p,q ;
 rep(i,h){
    if(tate[i]==ans) p.pb(i) ;
 }
 rep(i,w){
    if(yoko[i]==bns) q.pb(i) ;
 }
 if(p.size()*q.size()>m) cout<<ans+bns<<endl ;
 else{
    ll now=0 ;
    ll xx= p.size() ;
    ll yy=q.size() ;
    bool ok=0 ;
    bool unti=0 ;
    rep(i,xx){
       if(ok) break ;
       rep(j,yy){
          bool kkk=0 ;
        while(now<m){
        if(p[i]==re[now].fi&&q[j]==re[now].se) {
          
           kkk=1 ;
           break ;
        }
        now++ ;
        }
        if(!kkk){
        ok=1 ;
        unti=1 ;
        break ;
        }

       }

    }
   
    if(!unti) cout<<ans+bns-1<<endl ;
    else cout<<ans+bns<<endl ;

 }
    
   return 0 ;
}


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

using namespace std;


int main(){
    int a, z = -1;
    string s;
    cin >> s;
    int n = s.length();
    for(int i = n-1; i >= 0; i--){
        if(z == -1 && s[i] == 'Z') z = i;
        else if(s[i] == 'A') a = i;
    }

    cout << z-a + 1 << endl;




    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    ll N;
    cin >> N;
    vector<char> name;
    while (N > 0) {
        N--;
        ll c = N % 26L;
        name.push_back('a' + c);
        N /= 26L;
    }
    reverse(name.begin(), name.end());
    for (char c : name) {
        cout << c;
    }
    cout << endl;
    return 0;
}



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

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

    int ans = 0;
    for (int i = 0; i < N - 2; i++) {
        if (S.substr(i, 3) == "ABC") {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
const int  inf=10000000;

int main(){
  int a[3][3];
  rep(i,3)rep(j,3) cin>>a[i][j];
  int a1=a[0][0]+a[1][1]+a[2][2];
  int a2=a[0][1]+a[1][2]+a[2][0];
  int a3=a[0][2]+a[1][0]+a[2][1];
  ans(a1==a2 && a2==a3);
}

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

def re_define(input_):
    '''強さ順にする'''
    if input_ == 1:
        return 13
    
    return input_ - 1

A = re_define(A)
B = re_define(B)

if A > B:
    print('Alice')
elif A < B:
    print('Bob')
else:
    print('Draw')


Measured memory_bytes: 3060
from numba import njit
import numpy as np


@njit
def main(A, B):
    for a in A:
        B[a] += 1

    for a in set(A):
        v = 2*a
        while v <= 10**6:
            B[v] += 1
            v += a

    ans = 0
    for a in A:
        if B[a] == 1:
            ans += 1

    print(ans)


if __name__ == '__main__':
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [0]*(10**6+1)
    main(np.array(A), np.array(B))


Measured memory_bytes: 147404
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
int gcd(ll a,ll b){
	if(a<b)swap(a,b);
	if(b==0)return a;
	return gcd(a%b,b);
}
int main(){
	ll in[6]={0};
	while(cin>>in[0]>>in[1]>>in[2]>>in[3]>>in[4]>>in[5],in[0]+in[1]+in[2]+in[3]+in[4]+in[5]){
	rep(i,3){
		ll a=in[i*2],b=in[i*2+1];
		ll co=0;
		ll d=1;
		while(1){
			co++;
			d=(a*d)%b;
			if(d==1)break;
		}
		in[i]=co;
	}
	ll d=in[1]*in[2]/gcd(in[1],in[2]);
	cout<<d*in[0]/gcd(in[0],d)<<endl;
}}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int a,b,k; cin >> a >> b >> k;
  int i = 100;
  while(i>0) {
    if (a%i==0 && b%i==0) {
      k--;
      if(k == 0) { COUT(i); break; }
    }
    i--;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF (1LL<<60)
#define MOD1 1000000007
#define MAX_N (1 << 17)


void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{
    ll aa;
    ll bb;
}frequent;

int main(void){
    char s[15];
    ll n,ans=0;
    scanf("%s",s);
    n=strlen(s);
    ll l;
    rep(i,0,n){
        if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T' ){
            l=1;
            while(1){
                i++;
                if(i==n){
                    ans=max2(ans,l);
                    break;
                }
                if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T' ) l++;
                else{
                    ans=max2(ans,l);
                    break;
                }
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
3 5
0 0 1
0 1 2
0 2 3
1 0 2
1 1 2

output:
1
2
"""

import math
import sys

INIT_MAX = pow(2, 31) - 1


class SegmentTree(object):
    __slots__ = ('dat', 'ceil_n')

    def __init__(self, n):
        """
        Init a SegmentTree with update and find for range minimum queries.
        """
        self.ceil_n = pow(2, math.ceil(math.log2(n)))
        self.dat = [INIT_MAX] * (2 * self.ceil_n - 1)

    # let A[k]=a
    def update(self, k, a):
        k += self.ceil_n - 1
        self.dat[k] = a
        while k > 0:
            k = (k - 1) // 2
            self.dat[k] = min(self.dat[k * 2 + 1], self.dat[k * 2 + 2])

    # get min(A[s] A[s+1] ... A[t])
    def find(self, s, t, k=0, left=0, right=float('inf')):
        if right <= s or t <= left:
            return INIT_MAX
        elif s <= left <= right <= t:
            return self.dat[k]
        else:
            vl = self.find(s, t, k * 2 + 1, left, (left + right) // 2)
            vr = self.find(s, t, k * 2 + 2, (left + right) // 2, right)
            return min(vl, vr)


def cmd_exec(queries, n_num):
    case = SegmentTree(n_num)
    end = pow(2, math.ceil(math.log2(n_num)))

    for query in queries:
        cmd, ele_1, ele_2 = map(int, query)
        if cmd == 0:
            case.update(ele_1, ele_2)
        elif cmd == 1:
            # assert ele_1 <= ele_2
            res = case.find(s=ele_1, t=ele_2 + 1, right=end)
            print(res)

    return None


def solve():
    _input = sys.stdin.readlines()
    n_num, q_num = map(int, _input[0].split())
    queries = map(lambda x: x.split(), _input[1:])

    cmd_exec(queries, n_num)
    return None


if __name__ == '__main__':
    solve()

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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double eps = 1e-7;
#define Loop(i, n) for(int i = 0; i < int(n); i++)
#define Loopll(i, n) for(ll i = 0; i < ll(n); i++)
#define Loop1(i, n) for(int i = 1; i <= int(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= ll(n); i++)
#define Loopr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = int(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = ll(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
#define INF INFINITY
bool feq(double x, double y) { return abs(x - y) <= eps; }
bool inrange(ll x, ll t) { return x >= 0 && x < t; }
bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
int ceillog2(ll x) { int ret = 0;	x--; while (x > 0) { ret++; x >>= 1; } return ret; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

/*******************************************************/

int main() {
	string s; cin >> s;
	int k = s.length();
	int cnt = 0;
	Loop(i, k) {
		if (s[i] == 'o') cnt++;
	}
	cnt += 15 - k;
	if (cnt >= 8) cout << "YES" << endl;
	else cout << "NO" << endl;
}

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

int main() {
    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p.at(i);

    int cnt = 0;
    ll m = 1000000000;
    for(int i=0; i<n; i++){
        if(m>p.at(i)) {
            cnt++;
            m = p.at(i);
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int N,K,X,res=0;
bool digit[10];

bool cek(int x)
{
	while(x)
	{
		if(!digit[x%10])
			return false;
		x/=10;
	}
	return true;
}

int main()
{
	cin>>N>>K;
	memset(digit,true,sizeof digit);
	while(K--)
	{
		scanf("%d",&X);
		digit[X]=false;
	}
	for(int i=N;res==0;++i)
		if(cek(i))
			res=i;
	printf("%d\n",res);
}

Measured memory_bytes: 256
#include <stdio.h>

void solve(int r, int g, int b);


int main()
{
  int r, g, b;

  /* 標準入力より入力 */
  scanf("%d %d %d", &r, &g, &b);
  solve(r, g, b);

  return 0;
}

void solve(int r, int g, int b)
{
  int temp;

  temp = r * 100 +  g * 10 + b;
  if (temp % 4 == 0)
    {
      printf("YES\n");
    }
  else
    {
      printf("NO\n");
    }
}

Measured memory_bytes: 128
from fractions import gcd
from functools import reduce
#from math import gcd
n, k = map(int, input().split())
a = list(map(int, input().split()))

if k > max(a):
    print('IMPOSSIBLE')
    exit(0)
if k in a:
    print('POSSIBLE')
    exit(0)


def gcds(*numbers):
    return reduce(gcd, numbers)


if k % gcds(*a) == 0:
    print('POSSIBLE')
    exit(0)
print('IMPOSSIBLE')


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<unsigned int> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }

    vector<unsigned int> b(n + 1);
    for (int i = n; i >= 1; --i) {
        unsigned int t = 0;//b[2i],b[3i],...に合計何個入れるか
        for (int j = 2; i * j <= n; ++j) {
            t ^= b[i * j];//偶数か奇数かがわかれば十分
        }
        b[i] = t ^ a[i];
    }

    vector<int> ans;
    for (int i = 1; i <= n; ++i) {
        if (b[i]) ans.emplace_back(i);
    }

    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); ++i) {
        cout << ans[i] << ((i == ans.size()) ? "\n" : " ");
    }
    return 0;
}

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

using namespace std;

void a_two_rectangles(void) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int sa = a * b;
	int sb = c * d;
	
	if (sa == sb) cout << sa << endl;
	else {
		cout << (sa > sb ? sa : sb) << endl;
	}
}

int main()
{
    a_two_rectangles();
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	long long int a = 0;
	long long int b = 0;
	while (cin >> a, cin >> b)
	{
		long long int c = 0;
		long long int d = 0;
		long long int e = 0;
		c = a;
		d = b;
		if (c < d)
		{
			long long int i = 0;
			i = d;
			d = c;
			c = i;
		}
		while (1)
		{
			e = c % d;
			if (e == 0)
			{
				break;
			}
			c = d;
			d = e;
		}
		cout << d << " " << a / d * b << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3068
/*
  AUTHOR:SOURABH
  CREATED:12:02:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<ll , null_type, less< ll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 1000000007
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("in.txt","r",stdin);
    //freopen(2 "out.txt","w",stdout);

    ll t,n,i,ok;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>n;
        vll a(n);
        ok=1;
        fn(i,n)
        {
            cin>>a[i];
            if(a[i]%2==0)
            {
                if(a[i]%3 && a[i]%5)
                ok=0;
            }
        }
        if(ok)
            cout<<"APPROVED";
            else
                cout<<"DENIED";
            }
    return 0;
}












Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define PI acos(-1)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}

int main(){
   int n,k;
   cin>>n>>k;
   vector<int> a(n);
   rep(i,n){
      cin>>a[i];
   }
   int count=0;
   rep(i,n){
      if(i>=k){
         if(a[count]<a[i]){
            cout<<"Yes"<<endl;
         }
         else cout<<"No"<<endl;

         count++;
      }
   }
   return 0;
}


Measured memory_bytes: 4004
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

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



int main() {
    string S;
    cin >> S;
    if(S == "ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
}

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

int main()
{
  int n, m, ac[100000] = {0}, wa[100000] = {0}, r1 = 0, r2 = 0;

  cin >> n >> m;
  for (int i = 0; i < m; i++)
  {
    string tmp;
    int p;
    cin >> p;
    cin >> tmp;
    if (tmp == "AC")
    {
      ac[p - 1]++;
    }
    else if (ac[p - 1] == 0)
    {
      wa[p - 1]++;
    }
  }
  for (int i = 0; i < n; i++)
  {
    if (ac[i] >= 1)
    {
      r1++;
      r2 += wa[i];
    }
  }
  cout << r1 << " " << r2 << endl;
}


Measured memory_bytes: 1152
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
lo = 1
hi = 10**12
ans = max(arr)
while lo<=hi:
    t = 0
    m = (hi+lo)//2
    for i in range(n):
        if arr[i]>m:
            req = arr[i]//m
        else:
            req=  0
        t+=req
    if t<=k:
        ans = m
        hi = m-1
    else:
        lo = m+1
print(ans)

Measured memory_bytes: 93808
#include<stdio.h>
int main(void)
{
	int a,s,d,f,g,h,i,j;
	scanf("%d",&a);
	for(i=1;i<=a;i++){
		if(i%3==0)
			printf(" %d",i);
		else if(i%10==3)
			printf(" %d",i);
		else{
			d=i;
			while(1){
				if(d<10)
					break;
				d=d/10;
				h=d%10;
				if(h==3){
					printf(" %d",i);
					break;
				}
			}
		}
	}
	printf("\n");
	return 0;
}




  

 



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

int main(){
    int n;
    cin >> n;
    while(n > 0){
        vector<int> a(n);
        for(int i=0; i<n; i++){
            cin >> a[i];
        }
        int ans = 101010101;
        for(int i=0; i<n; i++){
            for(int j=i+1; j<n; j++){
                ans = min(ans, abs(a[i]-a[j]));
            }
        }
        cout << ans << endl;
        cin >> n;
    }
}


Measured memory_bytes: 3108
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m;
    cin>>m;
    cout<<(24-m)+24<<'\n';
    
    return(0);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

int N; pair<int, int> P[2020];
long long D[2020][2020];

int main()
{
	scanf ("%d", &N);
	for (int i = 0; i < N; i++) scanf ("%d", &P[i].first), P[i].second = i;
	sort(P, P + N);
	reverse(P, P + N);

	for (int i = 0; i < N; i++) for (int j = 0; i + j < N; j++){
		int k = i + j;
		D[i + 1][j] = max(D[i + 1][j], D[i][j] + 1ll * P[k].first * abs(P[k].second - i));
		D[i][j + 1] = max(D[i][j + 1], D[i][j] + 1ll * P[k].first * abs(P[k].second - (N - 1 - j)));
	}

	long long a = 0;
	for (int i = 0; i <= N; i++){
		a = max(a, D[i][N - i]);
	}
	printf ("%lld\n", a);

	return 0;
}


Measured memory_bytes: 24424
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
const int mod = MOD9;
using ll=long long;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
const ll max_n=200100;
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}comb(max_n);
int main(){
    ll n,m,k;cin >> n >>m >>k;
    if(m==1){
        if(n-1==k)cout << 1 <<endl;
        else cout << 0 <<endl;
        return 0;
    }
    ll def=m*modpow(m-1,n-1,MOD9);
    def%=MOD9;
    mint defo=def;
    mint ans=0;
    ans+=defo;
    rep(i,k){
        defo/=(m-1);
        defo*=comb(n-1,i+1);
        ans+=defo;
        defo/=comb(n-1,i+1);
    }
    cout << ans <<endl;
}

Measured memory_bytes: 6256
#include<ctype.h>
#include<stdio.h>
#include<string.h>
int main()
{
	char m[256];
	gets(m);
	int i;
	for(i=0;i<strlen(m);i++){
		if(islower(m[i])){
			m[i]=toupper(m[i]);
		}
	}
	printf("%s\n",m);
	return 0;
}

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

using namespace std;

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

int abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int abs_B(long long num, long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

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

long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

bool permutation(vector<int>& vec,vector<int>& P) {
    bool ok = true;
    for (int i = 0; i < vec.size(); i++) {
        //cout << vec.at(i);
        if (vec.at(i) != P.at(i)) {
            ok = false;
        }
    }
    return ok;
}

/*bool nibu(vector<int>& retu,int key) {
    
}*/

const long long MOD = 1000000007;
const int INF = 1001001001;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> ans(N,0);
    vector<bool> C(N,false);
    //vector<int> B(M);
    
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        
        if (C.at(a-1) == true && b != ans.at(a-1)) {
            cout << "-1" << endl;
            return 0;
        }

        C.at(a-1) = true;
        ans.at(a-1) = b;
    }
    if (M == 0) {
        if (N != 1) {
            ans.at(0) = 1;
            for (int i = 0; i < N; i++) {
                cout << ans.at(i);
            }
            return 0;
        }
        else {
            cout << "0" << endl;
            return 0;
        }
        
    }
    if (C.at(0) == false) {
        ans.at(0)++;
    }
    if (C.at(0) == false && M == 0) {
        cout << "0" << endl;
        return 0;
    }
    if (ans.at(0) == 0 && N > 1) {
        cout << "-1" << endl;
        return 0;
    }
    for (int i = 0; i < N; i++) {
        cout << ans.at(i);
    }
    cout << endl;

    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n,w;
  cin >> n >> w;
  vector<ll> a(n),b(n);
  rep(i,n){
    cin >> a[i] >> b[i];
  }

  vector<vector<ll>> dp(110, vector<ll>(mx,0));
  rep(i,n)rep(j,w+1){
    dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
    if(j-a[i]>=0) dp[i+1][j] = max(dp[i+1][j], dp[i][j-a[i]]+b[i]);
  }
  ll ans = 0;
  rep(i,w+1){
    ans = max(ans, dp[n][i]);
  }
  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 173824
// AOJ 0251: Magic Square
// 2017.12.16 bal4u@uu
// 2018.1.19

#include <stdio.h>
#include <string.h>

#define MAX 100002

/* UNION-FIND library */
int id[MAX], size[MAX];

void init(int n)
{
	int i;
	for (i = 0; i < n; i++) id[i] = i, size[i] = 1;
}

int root(int i)
{
	while (i != id[i]) id[i] = id[id[i]], i = id[i];
	return i;
}

int connected(int p, int q) { return root(p) == root(q); }

void unite(int p, int q)
{
    int i = root(p), j = root(q);
	if (i == j) return;
    if (size[i] < size[j]) id[i] = j, size[j] += size[i];
    else                   id[j] = i, size[i] += size[j];
}

char f[MAX];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int n, m, a, b, ans;

	while (n = in()) {
		m = in();

		init(n);
		memset(f, 0, n+1);

		ans = 1;
		while (m--) {
			a = in(), b = in();
			if (ans) {	
				if (++f[a] > 2) ans = 0;
				if (++f[b] > 2) ans = 0;
				if (connected(a, b)) ans = 0;
				unite(a, b);
			}
		}
		puts(ans? "yes": "no");
	}
	return 0;
}


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


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int ans = 0;
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());
		int[] X = new int[M];
		for(int i=0; i<M; i++){
			X[i] = Integer.parseInt(sc.next());
		}
		Arrays.sort(X);
		int[] diff = new int[M-1];
		for(int i=0; i<M-1; i++){
			diff[i] = X[i+1] - X[i];
		}
		Arrays.sort(diff);
		if(N>=M){
			ans = 0;
		}else{
			for(int i=0; i<M-N; i++){
				ans += diff[i];
			}
		}
		System.out.println(ans);
		
	}
	
}


Measured memory_bytes: 49320
#include <bits/stdc++.h>
using namespace std;
#ifdef _debug
#define out(i) cout << #i << ' ' << i << ' '
#else 
#define out(i) //
#endif
using ll = long long;
using ull = unsigned long long;
ll a, b, c, d;
ll up(ll v){return v * v;}
ll bs(ll v){
	if(v == 1)return 2;
	ll l = 1, r = 1000000001ll, mid;
	while(l != r){
		mid = (l + r)>>1;
		if(up(mid) > v)
			if(up(mid-1) <= v)l = r = mid;
			else r = mid;
		else l = mid + 1;
	}
	return l;
}
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	ll s;
	cin >> s;
	if(s == 1000000000000000000ll)return cout << 0 << ' ' << 0 << ' ' << 1000000000ll << ' ' << 0 << ' ' << 0 << ' ' << 1000000000ll << '\n', 0;
	d = a = bs(s);
	c = 1;
	b = a * a - s;
	cout << 0 << ' ' << 0 << ' ' << a << ' ' << b << ' ' << c << ' ' << d << '\n';
	out(a * d - b * c);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdlib> 
using namespace std;
int top,S[1000];
void push(int x){
	S[++top] = x;
}
int pop(){
	top--;
	return S[top+1];
}
int main(){
	int a,b;
	top = 0;
	char s[100]; 
	while(cin>>s){
		if(s[0]=='+'){
			a = pop();
			b =pop();
			push(a+b);
		}
		else if(s[0]=='-'){
			b = pop();
			a = pop();
			push(a-b);
		}
		else if(s[0]=='*'){
			a = pop();
			b = pop();
			push(a*b);
		}
		else {
			push(atoi(s));
		}
	}
	cout<<pop()<<endl;
	return 0;
}




Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  int num = 0;
  for (int i = 100; i > 0; i--)
  {
    if (A % i == 0 && B % i == 0)
      num++;
    if (num == K)
    {
      cout << i << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

constexpr int INF = 1e9+7;
constexpr ll INFL = 9*1e18;

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

// constexpr int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
// constexpr int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

int inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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<typename T>inline void print(T&& x){cout<<setprecision(32)<<x<<endl;}


// TODO: write
int main() {
  int n;cin>>n;
  ll ans = 0;
  for(int i = 1;i <= n;++i){
    ans += n/i;
    if(n%i == 0)ans--;
  }
  print(ans);
  
  return 0;
}

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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

int _runtimeTerror_()
{
    ll a;
    cin>>a;
    cout<<a+a*a+a*a*a<<'\n';
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

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

#define N_MAX n+1

int main() {
	
	int a,b,c,d;
	cin >> a >> b >> c >>d;
	
	if( ( abs(a-c)<=d ) || ( abs(a-b)<=d && abs(b-c)<=d ) )cout << "Yes";
	else cout << "No";
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
#define INF (1<<29)

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


Measured memory_bytes: 256