akhauriyash/Code-Regression huggingface dataset:
import sys
#input = sys.stdin.readline

def main():
    H,W,N = map(int,input().split())
    sr,sc = map(int,input().split())
    S = input()
    T = input()
    xp,xd = sr,sr
    yp,yd = sc,sc
    
    for i in range(N):
        if S[i] == "D":
            xp += 1
            if xp == H+1:
                print("NO")
                exit()
        elif S[i] == "U":
            xd -= 1
            if xd == 0:
                print("NO")
                exit()
        elif S[i] == "R":
            yp += 1
            if yp == W+1:
                print("NO")
                exit()
        else:
            yd -= 1
            if yd == 0:
                print("NO")
                exit()
        if T[i] == "D":
            if xd != H:
                xd += 1
        elif T[i] == "U":
            if xp != 1:
                xp -= 1
        elif T[i] == "R":
            if yd != W:
                yd += 1
        else:
            if yp != 1:
                yp -= 1
            
    print("YES")

if __name__ == "__main__":
    main()


Measured memory_bytes: 3788
N = int(input())
S = list(str(input()))
ch = list(set(S))
cal = []
for i in ch:
  cal.append(S.count(i))
ans = 1
for i in cal:
  ans *= i+1  
  ans = ans %(10**9+7)

print((ans-1)%(10**9+7))

Measured memory_bytes: 49136
use proconio::input;

#[allow(unused_variables)]
fn main() {
    input! {
      n: usize, d: f64,
      a: [(f64, f64); n]
    };

    let mut ans = 0;

    for i in 0..n {
        let val = a[i].0.powi(2) + a[i].1.powi(2);
        if val.sqrt() <= d {
            ans += 1;
        }
    }

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


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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();

		int[] X = new int[M];
		for(int i=0; i<M; i++) {
			X[i] = scan.nextInt();
		}

		scan.close();
		
		if(M <= N) {
			System.out.println(0);
			return;
		}
		
		Arrays.sort(X);
		
		int distance[] = new int[M-1];
		for(int i=0; i<M-1; i++) {
			distance[i] = X[i+1] - X[i];
		}
		
		Arrays.sort(distance);
		
		int sum = 0;
		for(int i=0; i<(M-N); i++) {
			sum+=distance[i];
		}
		System.out.println(sum);


	}

}

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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    int A,B,C,a,b,c;
    cin >> A >> B >> C;

    if(A % 2 == 1 || B % 2 == 1 || C % 2 == 1){
        cout << 0 << endl;
    }else{

        a = A;
        b = B;
        c = C;

        int count = 0;

        do{

            int tmpc = c;
            int tmpb = b;

            c = (a + b) / 2;
            b = (a + tmpc) / 2;
            a = (tmpb + tmpc) / 2;

            count++;

            //cerr << a << " " << b << " " << c << endl;


            if(a == A && b == B && c == C){
                count = -1;
                break;
            }

        }while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0);

        cout << count << endl;
    }
    return 0;
}


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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M,C,cnt;
    cin >> N >> M >> C;
    vector<int> B;
    for(int i=0; i<M; i++){
        int x;
        cin >> x;
        B.push_back(x);
    }

    for(int i=0; i<N; i++){
        int s=C;
        for(int j = 0; j < M; j++)
        {
            int x;
            cin >> x;
            s += x * B[j];
        }
        //cout << s;
        if (s>0) cnt++;
    }
    
    cout << cnt;

    for(int i = 0; i < 10*9; i++)
    {
        int s=0;
        s = 1;
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		if(a < b){
			System.out.println("a < b");
		}

		if(a > b){
			System.out.println("a > b");
		}

		if(a == b){
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 26080
#include<stdio.h>
#include <queue>
#include <cstdio>
using namespace std;

int main(){
	int n, k;
	scanf("%d %d",&n, &k);
	int map[n+1];
	//int sorted[n+1];
	for(int i=0;i<n+1;i++){
		map[i]=0;
		//sorted[i]=0;
	}
	for(int i=0;i<n;i++){
		int ai;
		scanf("%d",&ai);
		map[ai]++;
	}
	priority_queue<int> pque;
	for(int i=0;i<n+1;i++){
		pque.push(map[i]);
	}
	int add=0;
	for(int i=0;i<k;i++){
		add=add+pque.top();
	//	printf("%d\n",add);
		pque.pop();
	}
	printf("%d\n", n-add);
}


Measured memory_bytes: 2168
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;

int main(){
    int n,max=0,next=0;;
    cin>>n;
    vector<int>a(10000000);
    
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end(),std::greater<>());

    cout<<-a[n/2]+a[n/2-1]<<endl;

   return 0;
}

Measured memory_bytes: 39296
#include<iostream>
#include<cstdlib>
#include<vector>
#include<cstring>
using namespace std;
const int N=205,M=1e7+10;
int n,a[N],pri[M/10],tot,ans;
bool vis[M],b[M],ur[N];
int ld[N],rd[N],cl,cr,even,odd;
int lf[N];
vector<int>G[N];
void sieve(int n){
	vis[1]=1;
	for(int i=2;i<=n;++i){
		if(!vis[i])pri[++tot]=i;
		for(int j=1;j<=tot&&i*pri[j]<=n;++j){
			vis[i*pri[j]]=1;
			if(i%pri[j]==0)break;
		}
	}
}
bool dfs(int u){
	for(int to:G[u])
	if(!ur[to]){
		ur[to]=1;
		if(!lf[to]||dfs(lf[to])){
			lf[to]=u;
			return 1;
		}
	}
	return 0;
}
int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		b[a[i]]=1;
	}
	for(int i=10000001;i;--i)if(b[i]^=b[i-1]){
		if(i&1)ld[++cl]=i;else rd[++cr]=i;
	}
	sieve(10000000);
	for(int i=1;i<=cl;++i)
	for(int j=1;j<=cr;++j)if(!vis[abs(ld[i]-rd[j])])G[i].push_back(j);
	memset(lf,0,sizeof lf);
	for(int i=1;i<=cl;++i){
		memset(ur,0,sizeof ur);
		ans+=dfs(i);
	}
	memset(ur,0,sizeof ur);
	for(int i=1;i<=cr;++i)ur[lf[i]]=1;
	for(int i=1;i<=cl;++i)if(!ur[i])++odd;
	for(int i=1;i<=cr;++i)if(!lf[i])++even;
	ans+=(odd>>1<<1)+(even>>1<<1)+(odd&1)*3;
	cout<<ans<<'\n';
	return 0;
}

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

typedef long long int ll;

int main(){
  int n;
  cin >> n;
  ll a[n];
  for(int i = 0 ; i < n ; i++){
    cin >> a[i];
  }

  int res = 0;
  for(int i = 0 ; i < n ; i++){
    while(a[i] % 2 == 0){
      res++;
      a[i] /= 2;
    }
  }
  cout << res << endl;
  return 0;
}


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

int main(){
  string s;
  cin >> s;
  cout << (s == "ABC"? "ARC" : "ABC") << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);

int main () {
  int n, l;
  cin >> n >> l;
  vector<int> a(n);
  rep(i,n) {
    a[i] = l+i;
  }
  sort(a.begin(), a.end(), [](int x, int y) { return abs(x) < abs(y); });
  int ans = 0;
  for (int i = 1; i < n; ++i) {
    ans += a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <stdint.h>
#include <string>
#include <vector>
#include <cstring>

using namespace std;

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

  vector<int8_t> X;
  for (const auto c : N)
    X.push_back(atoi(&c));
  X.push_back(0);

  uint64_t usedBills = 0;
  bool carryOver = false;
  for (int ii=X.size()-1; ii>=0; --ii) {
    if (carryOver) {
      if (X[ii] == 9) {
	if (ii==0) {
	  ++usedBills;
	  break;
	} else {
	  continue;
	}
      }
      ++X[ii];
    }

    if (X[ii] < 5) {
      usedBills += X[ii];
      carryOver = false;
    } else if (X[ii]==5) {
      if (X[ii-1] < 5) {
	usedBills += X[ii];
	carryOver = false;
      } else {
	usedBills += 10-X[ii];
	carryOver = true;
      }
    } else {
      usedBills += (ii>0 ? 10-X[ii] : 10-X[ii]+1);
      carryOver = true;
    }

    //cerr << ii << " " << (int)X[ii] << " " << usedBills << endl;
  }

  cout << usedBills << endl;

  return 0;
}


Measured memory_bytes: 2820
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)

int main(){
  int n,m;
  scanf("%d%d",&n,&m);
  printf("%d\n",(n*(n-1))/2+(m*(m-1)/2));
  return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
int n;
/*
Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}
*/
Node treeSearch(Node u, int k){
  if(u==NIL || k == u->key){
    return u;
  }
  if(k < u->key){
    return treeSearch(u->left, k);
  }else{
    return treeSearch(u->right, k);
  }
}
/*
Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}
*/
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }else{
      x = x->right;
    }
  }
  z->parent = y;

  if (y == NIL) {
    root = z;
  }else if(z->key < y->key){
    y->left = z;
  }else{
    y->right = z;
  }


}

void inorder(Node u){
  if (u == NIL) {
    return;
  }else{
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if (u == NIL) {
    return;
  }else{
    printf(" %d",u->key );
    preorder(u->left);
    preorder(u->right);
  }
}

int main(){
  int i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } /*
      else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
    */
  }

  return 0;
}



Measured memory_bytes: 20440
#include<iostream>

using namespace std;
using ll = long long;

int main() {
	int n, a;
	cin >> n >> a;
	int* x = new int[n];
	for (int i = 0;i < n;i++) {
		cin >> x[i];
	}
	ll*** dp = new ll * *[n + 1];
	for (int i = 0;i <= n;i++) {
		dp[i] = new ll * [n + 1];
		for (int j = 0;j <= n;j++) {
			dp[i][j] = new ll[2501];
			for (int k = 0;k < 2501;k++) {
				dp[i][j][k] = 0;
			}
		}
	}
	for (int i = 0;i <= n;i++) {
		dp[i][0][0] = 1;
	}
	for (int i = 1;i <= n;i++) {
		for (int j = 1;j <= i;j++) {
			for (int k = 0;k <= 2500;k++) {
				ll add = 0;
				if (k - x[i - 1] >= 0)add = dp[i - 1][j - 1][k - x[i - 1]];
				dp[i][j][k] = dp[i - 1][j][k] + add;
			}
		}
	}
	ll ans = 0;
	for (int i = 1;i <= n;i++) {
		ans += dp[n][i][a * i];
	}
	cout << ans << endl;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li a[20020];
li b[20020];
li p[20010];

int main() {
    li n;
    cin >> n;
    rin{
        cin >> p[i];
        p[i]--;
    }
    rin{
        a[i] = (i + 1) * 20001;
        b[i] = (n - i) * 20001;
    }
    rin{
        a[p[i]] += i;
    }
    rin{
        cout << a[i] << " ";
    } puts("");
    rin{
        cout << b[i] << " ";
    } puts("");
    return 0;
}

Measured memory_bytes: 1024
import math
n = int(input())
p = list((map(int,input().split())))
ch = 0
ans = 0
for i in range(n):
    if p[i]==i+1:
        ch+=1
    if p[i]!=i+1:
        if ch ==1:
            ans+=1
        if ch >1:
            ans+=math.ceil(ch/2)
        ch = 0
if ch ==1:
    ans+=1
if ch >1:
    ans+=math.ceil(ch/2)
print(ans)


Measured memory_bytes: 13812
def solve():
    ans = 0
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    for j in range(K):
        check = [0]*(N+1)
        for i in range(N):
            check[max(0,i-A[i])] += 1
            check[min(N,i+A[i]+1)] -= 1
        A = [check[0]]*N
        for i in range(1,N):
            A[i] = A[i-1]+check[i]
        if A==[N]*N:
            break
    return A
print(*solve())


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

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

    rep(i, S.size()/2){
        if(S[i]!=S[S.size()-1-i]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    rep(i, S.size()/2/2){
        if(S[i]!=S[S.size()/2-1-i]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    for(int i=S.size()/2; i<S.size()/2/2*3; i++){
        if(S[i]!=S[S.size()-1-i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
#define ll long long
int main(){
	ll a,b,c;
	cin >> a >> b >> c;
	set<ll> s;
	s.insert(a);
	s.insert(b);
	s.insert(c);
	cout << s.size() << '\n';
	return 0;
}

Measured memory_bytes: 256
import itertools
import sys
import numpy as np
import collections
n=int(input())
a=np.array(list(map(int,input().split())))
add_a=a+1
al=list(add_a)
minus_a=a-1
ml=list(minus_a)
l=list(a)+al+ml
print(collections.Counter(l).most_common()[0][1])


Measured memory_bytes: 41880
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int main() {
    int n; cin >> n;
    vector<int> p(n);
    for (auto &pi: p) cin >> pi;
    int sum = accumulate(begin(p), end(p), 0);
    int ma = *max_element(begin(p), end(p));
    cout << sum - (ma + 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<typename A,typename B>istream&operator>>(istream&is,pair<A,B> &p){is>>p.fi>>p.se;return is;}
template<typename A,typename B>ostream&operator<<(ostream&os,const pair<A,B> &p){os<<"("<<p.fi<<","<<p.se<<")";return os;}
template<typename T>istream&operator>>(istream&is,vector<T> &t){REP(i,t.size())is>>t[i];return is;}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&t){os<<"{";REP(i,t.size()){if(i)os<<",";os<<t[i];}cout<<"}";return os;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n,q;
    cin>>n>>q;
    string st;
    cin>>st;
    vi sum(n);
    REP(i,n-1){
        if(st[i]=='A'&&st[i+1]=='C'){
            sum[i+1]++;
        }
        sum[i+1]+=sum[i];
    }
    REP(i,q){
        int l,r;
        cin>>l>>r;
        l--;r--;
        int ans=sum[r];
        if(l){
            ans-=sum[l-1];
        }
        if(l&&st[l-1]=='A'&&st[l]=='C'){
            ans--;
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<par<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,T;
    cin>>n>>T;
    vi c(n),t(n);
    rep(i,n)cin>>c[i]>>t[i];
    int ans=inf;
    rep(i,n){
        if(t[i]<=T)ans=min(ans,c[i]);
    }
    if(ans==inf)cout<<"TLE"<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 256
while True:
    try:
        r,c = map(int,raw_input().split())
        if r == c == 0:
            break
    except EOFError:
        break
    
    array = []
    for i in range(r):
        array.append(map(int,raw_input().split()))
    
    # column sum
    # add a new sum-row 
    c_sum_row = [0 for ii in range(c)]
    for k in range(c):
        for j in range(r):
            c_sum_row[k] += array[j][k]
    array.append(c_sum_row)
    
    # row sum
    # append sum item to end of each row
    for k in range(r+1):
        array[k].append(sum(array[k]))
    
    for k in range(r+1):
        print ' '.join(map(str,array[k]))

Measured memory_bytes: 4324
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <fstream>
#include<map>
#include <cassert>
#include<sstream>
using namespace std;
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
long long mod = 1e9 + 7;
typedef pair<long long, long long>p;
signed main()
{
	int n;
	cin >> n;
	p arm[100004];
	long long x, l;
	for (int i = 1; i <= n; i++) {
		cin >> x >> l;
		arm[i].first = x - l;
		arm[i].second = x + l;
	}
	arm[n + 1] = p(LLONG_MAX, 0);
	sort(arm + 1, arm + n+1);
	int dp[100004];
	for (int i = 1; i <= n; i++) {
		dp[i] = 0;
	}
	for (int i = 1; i <= n; i++) {
		dp[i] = max(dp[i], dp[i - 1]);
		long long next = arm[i].second;
		int ind = lower_bound(arm + 1, arm + n + 1, p(next, LLONG_MIN))-arm;
		dp[ind] = dp[i] + 1;
	}
	cout << dp[n + 1];
}


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

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

}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    int ary[n][3];
    rep(i,n) rep(j,3) cin >> ary[i][j];

    ll dp[n][3];
    rep(i,n) rep(j,3) dp[i][j]=0;
    dp[0][0] = ary[0][0];
    dp[0][1] = ary[0][1];
    dp[0][2] = ary[0][2];

    REP(i,1,n) rep(j,3)
    {
        dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + ary[i][0];
        dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + ary[i][1];
        dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + ary[i][2];
    }
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;




}


Measured memory_bytes: 3840
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int n ; 
    cin >> n ;
    int count = 0 ;
    for(int i = 1 ; i < n +1 ; i++){
        if(n - i > 0 && i != n-i){
            count ++ ;
        }
    }
    cout << count / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    
    double n,a,b;
    cin>>n>>a>>b;
    vector<double> v;
    rep(i,n){
        ll vv;cin>>vv;
        v.push_back(vv);
    }
    sort(v.rbegin(),v.rend());
    double ave=0;
    rep(i,a){
        ave+=v[i];
    }
    ave=ave/a;
    //cout<<ave<<endl;
    printf("%f\n",ave);
    
    
    if(n==1){cout<<v[0]<<endl;return 0;}
    
    
    if(v[0]==v[a-1]){
        ll h=a;
        while(true){
            if(v[a-1]==v[h]&&h<v.size()){
                h++;
            }else{
                break;
            }
        }
        ll zentai=h;
        
        double ans=0;
        // cout<<"a"<<a<<h<<endl;
        for(int aa=a;aa<=b;aa++){
            cout<<setprecision(16);
            double cc=1,rr=1;
            for(int i=0;i<aa;i++){
                cc*=(zentai-i);
            }
            for(int i=0;i<aa;i++){
                rr*=(aa-i);
            }
            //  cout<<zentai<<" "<<aa<<" "<<cc/rr<<endl;
            ans+=cc/rr;
        }
        
        //ll anss=ans;
        //  printf("%f\n",ans);
       // cout<<anss<<endl;
       
        cout<<ans<<endl;
        
    }else{
        ll csum=1;
        ll o=a-2;
        while(true){
            if(v[a-1]==v[o]&&o>=0){
                csum++;
                o--;
            }else{
                break;
            }
        }
        o=a;
        ll tsum=0;
        while(true){
            if(v[a-1]==v[o]&&o<v.size()){
                o++;
                tsum++;
            }else{
                break;
            }
        }
        tsum+=csum;
        long double c=1,r=1;
        for(int i=0;i<csum;i++){
            c*=(tsum-i);
        }
        for(int i=0;i<csum;i++){
            r*=(csum-i);
        }
        // cout<<"b"<<endl;
        ll ansm=c/r;
        cout<<ansm<<endl;
    }
    
    
    
    return 0;
}


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

void com0(string str, int a, int b){
	cout << str.substr(a, b - a + 1) << "\n";
}
void com1(string& str, int a, int b){
	reverse(str.begin() + a, str.begin() + b + 1);
}
void com2(string& str, int a, int b){
	string p;
	cin >> p;
	str = str.substr(0, a) + p + str.substr(b+1);
}
int main(){
	string str;
	cin >> str;
	
	int q;
	cin >> q;
	
	
	for(int i=0; i<q; i++){
		string cmd;
		cin >> cmd;
		int a, b;
		cin >> a >> b;
		
		switch(cmd[2]){
		case 'i':
			com0(str, a, b);
			break;
		case 'v':
			com1(str, a, b);
			break;
		case 'p':
			com2(str, a, b);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <algorithm>
int main() {
	int A, B, C, D, N;
	std::cin >> N >> A >> B >> C >> D;
	int X = (N / A + 1) * B;
	int	Y = (N / C + 1) * D;
	if (N % A > 0) {
	}
	else {
		X -= B;
	}
	if (N % C > 0) {
	}
	else {
		Y -= D;
	}
	std::cout << std::min(X,Y) << std::endl;
	return 0;
}



Measured memory_bytes: 3112
package main

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

var maxInt = int(1e18)

func main() {
	n := readI()
	min := maxInt
	ans := 0
	for i := 0; i < n; i++ {
		p := readI()
		if min >= p {
			min = p
			ans++
		}
	}
	fmt.Println(ans)
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


Measured memory_bytes: 3360
S = "BB" + input()
N = len(S)

ans = 0
keep = 0

i = -2
while -1 * N <= i:
    s = S[i] + S[i + 1]
    if s == "AA":
        ans += keep * 2
        i -= 2
    elif s == "AB":
        i -= 2
        keep = 0
    elif s == "AC":
        i -= 2
        keep = 0
    elif s == "BA":
        ans += keep
        keep = 0
        i -= 2
    elif s == "BB":
        i -= 2
        keep = 0
    elif s == "BC":
        keep += 1
        i -= 2
        flag = True
    elif s == "CA":
        ans += keep
        i -= 1
    elif s == "CB":
        i -= 1
        keep = 0
    elif s == "CC":
        i -= 1
        keep = 0

print(ans)


Measured memory_bytes: 3500
def floodfill(matrix, x, y):
    global count
    #"hidden" stop clause - not reinvoking for "check" or "#", only for "," or "@".
    if (matrix[x][y] == ".") or (matrix[x][y] == "@"):
        count += 1
        matrix[x][y] = "check"
        #recursively invoke flood fill on all surrounding cells:
        if x > 0:
            floodfill(matrix, x - 1, y)
        if x < len(matrix) - 1:
            floodfill(matrix, x + 1, y)
        if y > 0:
            floodfill(matrix, x, y - 1)
        if y < len(matrix[0]) - 1:
            floodfill(matrix, x, y + 1)
    return count

while True:
    x, y = map(int, input().split())
    if x == y == 0: break
    room = []
    for i in range(y):
        room.append([i for i in input()])

    for key, list in enumerate(room):
        if "@" in list:
            ax, ay = key, list.index("@")

    count = 0
    print(floodfill(room, ax, ay))

Measured memory_bytes: 7788
#include<stdio.h>
#include<stdlib.h>
int compare(const void *a,const void *b){
	int *pa=(int*)a;
	int *pb=(int*)b;
	int num1=*pa;
	int num2=*pb;
	return num1-num2;
}
int main(){
	int n,m,i,flag=1;
	float sum=0;
	scanf("%d %d",&n,&m);
	int x[n];
	for(i=0;i<n;i++){
		scanf("%d",&x[i]);
		sum+=x[i];
	}
	sum=1.0/(4*m)*sum;
	qsort(x,n,sizeof(int),compare);
	for(i=n-1;i>n-1-m;i--){
		if(x[i]<sum)flag=0;
	}
	if(flag)printf("Yes");
	else printf("No");
	return 0;
} 

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

int main(){
    char b;
    cin >> b;
    char enki[4] = {'A', 'C', 'T', 'G'};
    int index_b = 0;
    for(int i=0;i<4;i++){
        if(enki[i] == b){
            index_b = i;
            break;
        }
    }
    cout << enki[(index_b+2)%4] << endl;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    s[b-1] = s[b-1] - 'A' + 'a';
    cout << s;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
int main(void){
    string data = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string into = "DEFGHIJKLMNOPQRSTUVWXYZABC";
    string in;cin >> in;
    for(int i=0;i<in.length();i++){
        for(int t=0;t<26;t++){
            if(in[i]==into[t]){
                cout<<data[t];
                break;
            }
        }
    }
    puts("");
    return 0;
}

Measured memory_bytes: 1168
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int n,aa,bb,cnt;
int a[10001],b[10001],c[10001];
bool equal(int x[],int y[],int len){
  for(int i=1;i<=len;i++){
    if(x[i]!=y[i])return false;
  }return true;
}
int main(){
  cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i];
  for(int i=1;i<=n;i++)cin>>b[i];
  for(int i=1;i<=n;i++)c[i]=i;
  do{
    cnt++;
    if(equal(a,c,n))aa = cnt;
    if(equal(b,c,n))bb = cnt;
  }while(next_permutation(c+1,c+1+n));
  cout<<abs(aa-bb);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
const int mod = 1e9+7;

ll mu(ll a,ll b){
  return (ll)a*b%mod;
}
ll ad(ll a,ll b){
  if((a+=b)>=mod)a-=mod;
  return a;
}
ll pw(ll a,ll b,ll c=1LL){
  for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
  return c;
}
ll dv(ll a,ll b){
  return mu(a,pw(b,mod-2));
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<ll > > dp(n+2,vector<ll >(n+2));
  //  vector<vector<int> > ndp(n+2,vector<int >(n+2));
  rep(i,n+2)rep(j,n+2) dp[i][j]=0;
  dp[0][0]=1;  
  rep(j,n+1){
    rep(l,n+1){      
      if(l>=1){
	dp[j+1][l-1]+=dp[j][l];
	dp[j+1][l-1]%=mod;
      }
      else{
	dp[j+1][0]+=dp[j][0];
	dp[j+1][0]%=mod;	  
      }
      dp[j+1][l+1]+=dp[j][l]*2;
      dp[j+1][l+1]%=mod;
    }
    //    cout << dp[j+1][s.size()] << endl;
  }
  cout << dv(dp[n][s.size()],pw(2,s.size())) << endl;
  
  
  /*  cout << endl << endl;
      cout << static_cast<double>(clock()) / CLOCKS_PER_SEC << "s"<<endl;*/
  return 0;
    

}


Measured memory_bytes: 195968
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int x=0,ans=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='I'){
      x++;
      ans=max(ans,x);
    }
    else{
      x--;
    }
  }
  cout<<ans<<endl;
}


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

public class Main {
    static final Scanner sc = new Scanner(System.in);
    static final int INF = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        int N = nint();
        int pow = (int) Math.pow(2, N);
        int[] S = nints(pow); 
        Arrays.sort(S);
        
        int[] a = new int[pow];
        a[pow-1] = S[pow-1];
        S[pow-1] = INF;
        
        for (int n = 1; n <= N; n++) {
            
            int is = pow-1;
            for (int ib = 0, ia = pow-1; ib < (int) Math.pow(2, n-1); ib++, ia--) {
                while (0 <= is && a[ia] <= S[is]) {
                    is--;
                }
                if (is == -1 && Arrays.stream(S).anyMatch(i -> i != INF)) {
                    System.out.println("No");
                    return;
                }
                a[ib] = S[is];
                S[is] = INF;
            }
            Arrays.sort(a);
        }
        System.out.println("Yes");
    }
    
    private static int nint() {
        return sc.nextInt();
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }
}


Measured memory_bytes: 93800
#include<iostream>
#include<cstdio>
#include<vector>
const int N=2e5+5;
std::vector<int> g[N];
int dis[N],n;
void dfs(int u,int f,int dep) {
    dis[u]=dep;
    for(int v:g[u]) if(v!=f) {
        dfs(v,u,dep+1);
    }
}
int main() {
    scanf("%d",&n);
    for(int u,v,i=1;i<n;i++) scanf("%d%d",&u,&v),g[u].push_back(v),g[v].push_back(u);
    dfs(1,1,1);
    int rt=1;
    for(int i=2;i<=n;i++) if(dis[i]>dis[rt]) rt=i;
    dfs(rt,rt,1);int mx=1;
    for(int i=1;i<=n;i++) mx=std::max(mx,dis[i]);
    printf("%s",mx%3==2?"Second":"First");
    return 0;
}


Measured memory_bytes: 21376
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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 main() {
  int n;
  cin >> n;
  int sum = 0;
  int m = 0;
  rep (i, n) {
    int tmp;
    cin >> tmp;
    sum += tmp;
    m = max(m, tmp);
  }
  if (sum - m > m) Yes;
  else No;
  return 0;

}

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

using namespace std;

typedef pair<int, int> pi;

const int N = 5e5 + 10;

struct Edge {
  int v, nxt;
} E[N << 1];

int n, m;
int deg[N], tot = 1, head[N];
bool del[N];
vector<int> l[N];

void addedge(int u, int v) {
  E[++tot] = (Edge) {v, head[u]};
  head[u] = tot;
}

int stk[N], top;
int pre[N], lst[N];

void dfs(int x){
  for (int i = head[x]; i; i = E[i].nxt) if (!del[i]) {
    int v = E[i].v;
    del[i] = del[i ^ 1] = 1;
    dfs(v);
  }
  stk[++top] = x;
  pre[top] = lst[x];
  lst[x] = top;
}

pi seg[N];
int scnt;

int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    addedge(u, v);
    addedge(v, u);
    deg[u]++;
    deg[v]++;
  }
  for (int i = 1; i <= n; i++) {
    if (deg[i] & 1) {
      puts("No");
      return 0;
    }
  }
  dfs(1);
  for (int i = 1; i <= top; i++) {
    if (i != top && pre[i]) {
      seg[++scnt] = pi(pre[i], i);
    }
  }
  sort(seg + 1, seg + scnt + 1);
  int Max = 0;
  for (int i = 1; i <= scnt; i++) {
    if (seg[i].second <= Max) {
      puts("Yes");
      return 0;
    }
    Max = max(Max, seg[i].second);
  }
  for (int i = 1; i <= scnt; i++) {
    if (seg[i].second <= seg[scnt].first) {
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 29952
#include<stdio.h>
int main()
{
    int k,x;
    char s[101];
    // 整数の入力
    // scanf("%d", &a);
    // スペース区切りの整数の入力
    scanf("%d %d",&k,&x);
  
    int a = 0;
    for (int i = (x - k + 1); i < (x + k); i++) {
      if (a++!=0) {
        printf(" ");
      }
      printf("%d", i);
    }
    // 文字列の入力
    // scanf("%s",s);
    // 出力
    // printf("%d %s\n",a+b+c,s);
    return 0;
}

Measured memory_bytes: 128
N, M = map(int,input().split())
list1 = [tuple(map(int,input().split())) for _ in range(M)]
list2 = [None for _ in range(N)]
imp = False
for nums in list1:
  s, c= nums[0]-1, nums[1]
  if list2[s] == c or list2[s] == None:
    list2[s] = c
  else:
    imp = True
if list2[0] == None:
  if N ==1:
    list2[0] = 0
  else:
    list2[0] = 1

if (list2[0] == 0 and N != 1) or imp:
  print(-1)
else:
  for s in list2:
    if s == None:
      s = 0
    print("{}".format(s),end='')
  

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

long long a,n;

int main()
{
	scanf("%lld",&n);
	a=1;
	for (long long i=1;i<=n;i++) 
	 a=a*i%1000000007;
	printf("%lld",a);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
int main(){
    string S,T;
    cin >> S >> T;
    set<char> s;
    int N = S.size(),M = T.size();
    for(int i=0;i<N;i++) s.insert(S[i]);
    for(auto c:T) if(s.count(c)==0){
        cout << -1 << endl;
        return 0;
    }
    string S2 = S + S;
    vector<vector<ll>> ne(2*N+1,vector<ll>(26,-1));
    for(int i=2*N-1;i>=0;i--){
        for(int j=0;j<26;j++) ne[i][j] = ne[i+1][j];
        ne[i][S2[i]-'a'] = i;
    }
    int s_id = -1;
    ll ans = 0;
 //   for(int i=0;i<N;i++) for(int j=0;j<26;j++) cerr << ne[i][j] << (j!=25? " ":"\n");
    for(int i=0;i<M;i++){
        int ne_id = ne[s_id+1][T[i]-'a'];
        ans += ne_id-s_id;
        s_id = ne_id%N;
//        cerr << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 49152
while(1):
  H,W = map(int, raw_input().split())
  if H == 0 and W == 0:
    break
  for i in range(H):
    if i == 0 or i == H-1:
      print "#"*W
    else:
      print "#" + "."*(W-2) + "#"
  print ""

Measured memory_bytes: 6284
#include <stdio.h>

using namespace std;

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a > b){
         printf("a > b\n");
    }else if(a < b){
    printf("a < b\n");
    }else{
        printf("a == b\n");
    }
}


Measured memory_bytes: 2616
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

H, W, A, B = MAP()

grid = list2d(H, W, '0')
for i in range(H):
    for j in range(W):
        if (i < B and j < A) or (i >= B and j >= A):
            grid[i][j] = '1'

for i in range(H):
    print(''.join(grid[i]))


Measured memory_bytes: 11892
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}



int main(){
fastio();

  int n;
  cin>>n;
  int arr[n];

  for(int i=0;i<n;i++) cin>>arr[i];
  int cnt=0;
  map<pair<pii,int>,int>mp;

  for(int i=0;i<n;i++)
  {
      for(int j=0;j<n;j++)
      {
          for(int k=0;k<n;k++)
          {
              if(i==j || i==k || j==k )  continue;

               if(arr[i]!=arr[j] && arr[i]!=arr[k] && arr[k]!=arr[j] && i<j && j<k      )
              {

                  if(arr[i]+arr[j]>arr[k] && arr[j]+arr[k]>arr[i] && arr[i]+arr[k]>arr[j] ) {



                  cnt++;
                  }
              }
          }
      }
  }

  cout<<cnt<<endl;







return 0;
}




Measured memory_bytes: 3632
import sys
from io import StringIO
import unittest

sys.setrecursionlimit(10**6)
def search(n, step, rec, seq, k):
	if rec[n] != -1:
		c = step - rec[n]
		sim = (k - rec[n]) % c
		v = n
		for i in range(sim):
			v = seq[v-1]
		print(v)
		return
	rec[n] = step
	if step == k:
		print(n)
		return
	search(seq[n-1], step + 1, rec, seq, k)
def resolve():
	n, k = map(int, input().split())
	seq = list(map(int, input().split()))
	rec = [-1]*(n+1)
	search(1, 0, rec, seq, k)

resolve()

Measured memory_bytes: 230492
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = sum(b)

for i in range(n - 1):
    if a[i] + 1 == a[i + 1]:
        ans += c[a[i] - 1]
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c;
    cin >> a >> b >> c;
    
    if (a+b == c || b+c == a || c+a == b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main() {
  int h,w;cin>>h>>w;
  string s;
  rep(i,h) {
    cin >> s;
    cout << s << endl << s << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
const int maxn = 2e5 + 5 ; 
ll b[maxn] ;
ll n , x , d ;
struct node
{
	ll l , r ;
	ll mod ;
} a[maxn] ;
bool cmp(node x , node y)
{
	if(x.mod != y.mod)
	  return x.mod < y.mod ;
	else if(x.l != y.l)
	  return x.l < y.l ;
	else
	  return x.r < y.r ;
}
ll cal(ll a1 , ll num)
{
	return num * a1 + num * (num - 1) / 2 ;
}
void init(ll i)
{
	ll chu ;
	ll mod ;
	//if(d < 0) x = -x , d = -d ;
    chu = (i * x) / d , mod = (i * x) % d ;
	ll l = cal(0ll , i) ;
	ll r = cal(n - i , i) ;
	l += chu ;
	r += chu ;
	a[i].l = l ;
	a[i].r = r ;
	a[i].mod = mod ;
}
ll solve(int x , int y)
{
	ll ans = 0 ;
	for(int i = x ; i <= y ; i ++)
	{
		ll l = a[i].l ;
		ll r = a[i].r ;
		int j = i ;
		while(j + 1 <= y && a[j + 1].l <= r)
		{
			r = max(r , a[j + 1].r) ;
			j ++ ;
		}
		ans += r - l + 1 ;
		i = j ;
	}
	return ans ;
}
int main()
{
	scanf("%lld%lld%lld" , &n , &x , &d) ;
	if(x == 0 && d == 0)
	{
		printf("1\n") ;
		return 0 ;
	}
	if(d == 0)
	{
		printf("%lld\n" , n + 1) ;
		return 0 ; 
	}
	for(ll i = 0 ; i <= n ; i ++)
	  init(i) ;
	sort(a , a + n + 1 , cmp) ;
	ll ans = 0 ;
	for(int i = 0 ; i <= n ; i ++)
	{
		int j = i ;
		while(j + 1 <= n && a[j + 1].mod == a[j].mod)
		  j ++ ;
		ans += solve(i , j) ;
		i = j ;
	}
	printf("%lld\n" , ans) ;
	return 0 ;
}

Measured memory_bytes: 6528
N = int(input())
numbers = [int(i) for i in input().split()]

flag = True

for num in numbers:
    if num % 2 == 0:
        if num % 3 != 0 and num % 5 != 0:
            flag = False
            break
            
if flag:
    print('APPROVED')
else :
    print('DENIED')

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

int main(){
    int N;
    cin >> N;
    long A[N], B[N];
    for(int i = 0; i < N; i++){
        cin >> A[i] >> B[i];
    }
    long plus = 0;
    for(int i = N - 1; i >= 0; i--){
        plus += B[i] - (A[i] + plus + B[i] - 1) % B[i] - 1;
    }
    cout << plus << endl;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    // N - 1 <= x * 2D + (x - 1) を変形すると x >= (N / (2 * D + 1))
    ll N, D; cin >> N >> D; cout << (ll) ceil((double)N / (2 * D + 1)) << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256