akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
//#define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 100 + 5, LG = 19, MOD = 998244353;
const int SQ =225;
//int A, B, C, D;
//int dp[3005][3005];
//int solve(int X, int Y){
//  if(X < A || Y < B)
//    return 0;
//  if(X == A && Y == B)
//    return 1;
//  int &ret = dp[X][Y];
//  if(~ret)
//    return ret;
//  ret = 1ll * solve(X - 1, Y) * Y % MOD;
//  ret += 1ll * solve(X, Y - 1) * X % MOD;
////  cout << X << ' ' << Y << ' ' << solve(X-1,Y) * Y << ' '<< solve(X,Y-1) * X  << endl;
//  ret -= 1ll * solve(X-1,Y-1) * max(X-1,Y-1);
//  if(ret >= MOD)ret -= MOD;
//  if(ret < 0)ret += MOD;
//  return ret;
//}
//set<vector<string>>st;
//vector<string> vs;
//void bt(int x, int y){
//  if(x==C&&y==D){
//    st.insert(vs);
//    return;
//  }
//  if(y < D){
//  ///add column
//    for(int i = 0; i < x; i++){
//      vs[i][y] ^= 1;
//      bt(x, y + 1);
//      vs[i][y] ^= 1;
//    }
//  }
//  if(x < C){
//  ///add row
//    for(int i = 0; i < y; i++){
//      vs[x][i] ^= 1;
//      bt(x+1, y);
//      vs[x][i] ^= 1;
//    }
//  }
//}
int dp[305][305][305][2];
vector<int> vp;
int solve(int idx, int cnt, int lft, bool take){
  if(idx == vp.size())
    return (cnt == 0);
  int &ret = dp[idx][cnt][lft][take];
  if(~ret)
    return ret;
  ///take
  ret = 0;
  if(!take){
    for(int j = 1; j <= vp[idx] && j <= lft; j++){
        ret += solve(idx + 1, cnt + j, lft - j, 0);
        if(ret >= MOD)
          ret -= MOD;
    }
  }
  ret += solve(idx + 1, cnt, lft, 0);
  if(ret >= MOD)ret -= MOD;
  if(cnt)
    ret += solve(idx, cnt - 1, lft, 1);
  if(ret >= MOD)ret -= MOD;

  return ret;
}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  string s;
  int k;
  cin >> s >> k;
  k = min(k, 300);

  if(s.back() == '1')s.pb('0');


  for(int i = s.size() - 1; i >= 0; --i){
    if(s[i] == '0')vp.pb(0);
    else vp.back()++;
  }
//  for(auto x : vp)cout << x << ' ';
//  cout << accumulate(vp.begin(),vp.end(),0) << endl;
  memset(dp,-1,sizeof dp);
  cout << solve(0,0,k,0) << endl;


  return 0  ;
}


Measured memory_bytes: 225348
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    static int[][] paper = new int[10][10];

    static void drop(int x, int y) {
        try {
            paper[y][x]++;
        } catch (ArrayIndexOutOfBoundsException e) {
            return;
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String input;

        // initialize
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                paper[i][j] = 0;
            }
        }

        while ((input = br.readLine()) != null) {
            String[] info = input.split(",");
            int x = Integer.parseInt(info[0]);
            int y = Integer.parseInt(info[1]);

            drop(y, x);
            drop(y + 1, x);
            drop(y - 1, x);
            drop(y, x + 1);
            drop(y, x - 1);

            int size = Integer.parseInt(info[2]);

            if (size >= 2) {
                drop(y + 1, x + 1);
                drop(y + 1, x - 1);
                drop(y - 1, x + 1);
                drop(y - 1, x - 1);
            }
            if (size >= 3) {
                drop(y + 2, x);
                drop(y - 2, x);
                drop(y, x + 2);
                drop(y, x - 2);
            }

        }

        int clear = 0;
        int max = 0;

        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                if(paper[i][j] == 0){
                    clear++;
                }

                if(paper[i][j] > max){
                    max = paper[i][j];
                }
            }
        }

        System.out.println(clear);
        System.out.println(max);
    }
}


Measured memory_bytes: 24256
#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;
  if((S[2]==S[3])&&(S[4]==S[5])){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#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;
   if(s=="ABC")  
      cout << "ARC" << endl;
   else
      cout << "ABC" << endl;
   return 0;  
}

Measured memory_bytes: 3592
sa = list(reversed(input()))
sb = list(reversed(input()))
sc = list(reversed(input()))

s0 = sa.pop()

while True:
  if s0 == 'a':
    if not sa:
      print('A')
      break
    s0 = sa.pop()
  elif s0 == 'b':
    if not sb:
      print('B')
      break
    s0 = sb.pop()
  else:
    if not sc:
      print('C')
      break
    s0 = sc.pop()

Measured memory_bytes: 3064
import itertools
import math

N = int(input())
S = tuple(map(int, input().split()))
T = tuple(map(int, input().split()))

input_list = [x + 1 for x in range(N)]


per = list(itertools.permutations(input_list))
f = 0
s = 0
for i, v in enumerate(per):
    if v == S:
        f = i + 1
    if v == T:
        s = i + 1

print(int(math.fabs(f - s)))


Measured memory_bytes: 7972
import java.util.Scanner;
import java.math.BigDecimal;

public class Main{
    public static void main(String argv[])
    {
	Scanner scan = new Scanner(System.in);
	int a = scan.nextInt();
	int b = scan.nextInt();
	int d,r;
	double f;
		
	d = a / b;
	r = a % b;
	f = (double)a / b;
	
	BigDecimal x = new BigDecimal(f);
	x = x.setScale(6,BigDecimal.ROUND_HALF_UP);
	System.out.println(d+" "+r+" "+x);


    }
}

Measured memory_bytes: 26568
#include<cstdio>
#include<iostream>

using namespace std;

typedef long long LL;

const LL mod=1e9+7;
const int N=2000;
int a[N+5];
int n,k;

int main()
{
	scanf("%d %d",&n,&k);
	
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	
	LL ans=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if(a[i]>a[j])
				ans = (ans+k)%mod;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(a[i]>a[j])
				ans = (ans+1ll*(k-1)*k/2%mod)%mod;
	
	printf("%lld\n",ans);
	return 0;
} 

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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
	string s,t;
	cin >> s >> t;
	if(s.size() != t.size()){
		cout << "No" << endl;
		return 0;
	}
	else{
		string u = s;
		u += s;
		for(int i=0;i<u.size()-t.size();i++){
			string tmp = u.substr(i,t.size());
			if(tmp == t){
				cout << "Yes" << endl;
				return 0;
			}
		}
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

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

    vector<int> common;

    for (int i = 0; i < n; i++) {
        string S;
        cin >> S;

        vector<int> letter(26);
        for (int j = 0; j < S.size(); j++)
            letter[S[j] - 'a']++;

        if (i == 0)
            common = letter;
        else 
            for (int j = 0; j < 26; j++)
                common[j] = min(common[j], letter[j]);
    }

    string out;
    for (int i = 0; i < 26; i++)
        for (int j = 0; j < common[i]; j++)
            out += (char)(i + 'a');
    cout << out << "\n";
    return 0;
}


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

const int MAXSIZ = 100;
int S[MAXSIZ];
int top=0;


void push(int x)
{
	S[++top] = x;
}

int pop()
{
	top--;
	return S[top+1];
}

int main()
{
	int a,b,k;
	char c[MAXSIZ];
	while(cin >> c){
		if(c[0] == '+'){
			a = pop();
			b = pop();
			push(a+b);

		}else if(c[0] == '-'){
			a = pop();
			b = pop();
			push(b-a);
		}else if(c[0] == '*'){
			a = pop();
			b = pop();
			push(a*b);
		}else{
			std::istringstream is(c);
			is >> k;
			push(k);	
		}
	}
	cout << pop() << endl;
	return 0;
}

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

using namespace std;

class disjoint_set {
private:
	vector<int> id;
	vector<int> rank;
public:

	disjoint_set(int size) {
		id = vector<int>(size);
		rank = vector<int>(size);
		for (size_t i = 0; i < size; i++) {
			id[i] = i;
		}
	}

	int size() {
		return id.size();
	}

	int getRoot(int x) {
		if (x != id[x]) {
			id[x] = getRoot(id[x]);
		}
		return id[x];
	}

	bool same(int x, int y) {
		return getRoot(x) == getRoot(y);
	}

	void merge(int x, int y) {
		int xRoot = getRoot(x);
		int yRoot = getRoot(y);
		if (xRoot == yRoot) return;
		if (rank[xRoot] < rank[yRoot]) {
			id[xRoot] = yRoot;
		} else if (rank[xRoot] > rank[yRoot]) {
			id[yRoot] = xRoot;
		} else {
			id[xRoot] = yRoot;
			rank[yRoot]++;
		}
	}
};

int main() {
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	disjoint_set s(n);
	for (size_t i = 0; i < q; i++) {
		int t,x, y;
		cin >> t >> x >> y;
		if (t == 0) s.merge(x, y);
		else cout << s.same(x, y) << endl;
	}
}

Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> array(n);
    for(int i=0;i<n;i++) cin >> array.at(i);
    sort(array.begin(),array.end());
    int back = array.at(n/2);
    int front = array.at((n-2)/2);
    cout << back - front << endl;
}

Measured memory_bytes: 3788
import java.io.*;
import java.util.*;

public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    static FastReader s = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    private static int[] rai(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
        }
        return arr;
    }

    private static int[][] rai(int n, int m) {
        int[][] arr = new int[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextInt();
            }
        }
        return arr;
    }

    private static long[] ral(int n) {
        long[] arr = new long[n];
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextLong();
        }
        return arr;
    }

    private static long[][] ral(int n, int m) {
        long[][] arr = new long[n][m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j] = s.nextLong();
            }
        }
        return arr;
    }

    private static int ri() {
        return s.nextInt();
    }

    private static long rl() {
        return s.nextLong();
    }

    private static String rs() {
        return s.next();
    }
    public static void main(String[] args) throws IOException {
        StringBuilder ans = new StringBuilder();
//        int t=ri();
        int t=1;
        while (t-- > 0)
        {
            char c=rs().charAt(0);
            if(Character.isUpperCase(c))
            {
                ans.append("A\n");
            }
            else
            {
                ans.append("a\n");
            }
        }
        out.print(ans.toString());
        out.flush();

    }
}


Measured memory_bytes: 25440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin>>s;
  int i,count=0,n=s.size();
  for(i=0;i<n;i++){
	if(s[i]=='x'){
		count++;
    }
  }
  
  cout<<(count<8?"YES":"NO")<<endl; 
}
  
  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int main() {
    

    ll n,d;
    cin >> n >> d;
    if(n % (2*d+1) == 0){
        cout << n / (2*d+1) << endl;
    }else{
        cout << n / (2*d+1) + 1 << endl;
    }
}

Measured memory_bytes: 256
// ?????? a cm ?????? b cm ???????????¢?????¢?????¨??¨?????????????±???????????????°?????????????????????????????????

#include <stdio.h>
int main(){
	int a, b, s, l;
	
	scanf("%d %d", &a, &b);
	
	s = a * b;
	l = (2 * a) + (2 * b);
	
	printf("%d %d\n", s, l);
	
	return 0;
}

Measured memory_bytes: 596
# cook your dish here
import operator
N,K=map(int,input().split())
lst=list(map(int,input().split()))
x=[]
x=set(lst)
if len(x)<=K:
    print(0)
else:
    freq={}
    for i in lst:
        if i in freq:
            freq[i]+=1
        else:
            freq[i]=1
    # l=[]
    # l=list(freq.items())
    s={}
    s = dict(sorted(freq.items(), key=operator.itemgetter(1)))
    # print(s)
    # l.sort()
    cc=abs(len(x)-K)
    # print(cc)
    v=0
    for key,value in s.items():
        
        v+=s[key]
        # print(key)
        cc-=1
        if cc==0:
            print(v)
            break

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

int main() {
 int a,b,c,d;
  cin >> a >> b >> c >> d;
  vector<int> cnt(101,0);
  for(int i=0;i<101;i++){
  if(i>=a && i<=b && i>=c && i<=d)cnt[i]++;
  }

  int ans=0;
  for(int i=0;i<101;i++){
  if(cnt[i]==1)ans++;
  }
  if(ans==0) cout << ans << endl;
  else cout << ans -1 << endl;
}


Measured memory_bytes: 764
import itertools

def list_to_str(arr): 
    s = map(str, arr)
    s = ','.join(s).replace(',', '')
    return s

n = int(input())
P = list(map(int, input().split()))
P = list_to_str(P)
Q = list(map(int, input().split()))
Q = list_to_str(Q)


junretsu = []
for v in itertools.permutations(P, n):
    junretsu.append(list_to_str(list(v)))

junretsu.sort()
a = junretsu.index(P)
b = junretsu.index(Q)

print(abs(a-b))

Measured memory_bytes: 6168
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N;
  cin >> N;
  vector<i64> A(N - 1);
  for (i64 i = 0; i < N - 1; i++)
    cin >> A[i];
  vector<i64> ans(N);
  for (i64 i : A)
    ans[i - 1]++;
  for (i64 i : ans)
    cout << i << endl;
  return 0;
}


Measured memory_bytes: 6428
n,q=map(int,input().split())
s=input()
a=[0 for i in range(n)]
l=[]
r=[]


for i in range(1,n):
  if s[i-1]=="A" and s[i]=="C":
    a[i]+=a[i-1]+1
  else:
    a[i]=a[i-1]

for i in range(q):
  b,c=map(int,input().split())
  l.append(b-1)
  r.append(c-1)

for i in range(q):
  print(a[r[i]]-a[l[i]])
  
  
  

Measured memory_bytes: 14368
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<"!"<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll dist[1111][1111];
ll dist2[1111][1111];
bool used[1111][1111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>dist[i][j];
      dist2[i][j]=dist[i][j];
    }
  }
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	dist2[i][j]=min(dist2[i][j],dist[i][k]+dist[k][j]);
	if(i!=k && j!=k)
	  if(dist[i][j] == dist[i][k]+dist[k][j])used[i][j]=true;
      }
    }
  }
  bool fl=true;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      if(dist[i][j]!=dist2[i][j])fl=false;
  if(fl){
    ll ans=0;
    for(int i=0;i<n;i++)
      for(int j=i+1;j<n;j++)
	if(used[i][j]==false)
	  ans+=dist[i][j];
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }
  return 0;
}


Measured memory_bytes: 7296
#include<iostream>
#include<vector>
using namespace std;
const int INF=1001001001;
int a[12][12];

int main(){
int n,m,x;
  cin>>n>>m>>x;
  vector<int>c(n);
  for(int i=0;i<n;i++){
    cin>>c[i];
    for(int j=0;j<m;j++){
      cin>>a[i][j];
    }
  }
  int ans=INF;
  for(int s=0;s<(1<<n);s++){
    int cost=0;
    vector<int> d(m);
    for(int i=0;i<n;i++){
      if(s>>i&1){
        cost+=c[i];
        for(int j=0;j<m;j++) d[j]+=a[i][j];
      }
    }
    bool ok=true;
    for(int j=0;j<m;j++) if(d[j]<x) ok=false;
      if(ok) ans=min(ans,cost);
    
  }
    if(ans==INF) cout<<-1<<endl;
    else cout<<ans<<endl;
    return 0;
  
}


Measured memory_bytes: 3600
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
 
 
 
int main()
{
 
    queue < pair<int, int> > q;
    pair<int, int> p;
 
 
 
    char **m;
    char c[10] = { "123456789" };
    int **f;
	bool flg = false;
    int n, k, i, i1, c1, i2, sum = 0;
    cin >> n;
    cin >> k;
    cin >> c1;
 
    m = new char *[n + 2];
    f = new int *[n + 2];
 
    for (i = 0; i < n + 2; i++){
        m[i] = new char[k + 2];
        f[i] = new int[k + 2];
    }
 
    for (i = 1; i <= n; i++){
        for (i1 = 1; i1 <= k; i1++){
            cin >> m[i][i1];
        }
    }
 
    for (i = 0; i < n + 2; i++){
        for (i1 = 0; i1 < k + 2; i1++){
            if (i == 0 || i == n + 1){
                m[i][i1] = 'X';
            }
            else if (i1 == 0 || i1 == k + 1){
                m[i][i1] = 'X';
            }
        }
    }
 
    for (i = 1; i <= n; i++){
        for (i1 = 1; m[i][i1] != '\0'; i1++){
            if (m[i][i1] == 'S'){
                q.push(make_pair(i, i1));
            }
        }
    }
 
 
 
    pair<int, int> temp;
 
    temp = q.front();
 
    for (i = 0; i < c1; i++){

		for (i1 = 0; i1 < n + 2; i1++){
				for (i2 = 0; i2 < k + 2; i2++){
					if (i1 == 0 || i1 == n + 1){
						f[i1][i2] = 1;
					}
					else if (i2 == 0 || i2 == k + 1){
						f[i1][i2] = 1;
					}
					else
						f[i1][i2] = -1;
				}
			}

        f[temp.first][temp.second] = 0;
 
		while (!q.empty()){
            p = q.front();
            q.pop();
 
            int x[4] = { -1, 1, 0, 0 }, y[4] = { 0, 0, -1, 1 };
 
            for (int j = 0; j < 4; j++){
 
                //???????????´??????????´¢
                if (m[p.first + x[j]][p.second + y[j]] != 'X' && f[p.first + x[j]][p.second + y[j]] < 0){
                    q.push(make_pair(p.first + x[j], p.second + y[j]));
                    f[p.first + x[j]][p.second + y[j]] = f[p.first][p.second] + 1;
                }
            }
            //??´?????????????????????
            if (m[p.first][p.second] == c[i]){
                sum += f[p.first][p.second];
                temp = p;
                while (!q.empty()){
                    q.pop();
                }
                q.push(p);
                break;
			}
		}
	}
 
    cout << sum << endl;
 
    return 0;
}

Measured memory_bytes: 6160
let () = Scanf.scanf "%d %d" (fun h w ->
  begin List.concat @@ List.map (fun (h, w) ->
    begin List.concat @@ List.map (fun d1 ->
      List.map (fun d2 ->
         let h1 = h / 3 + d1 in
         let h2 = h / 3 + d2 in
         let h3 = h - h1 - h2 in
         if 0 <= h3 then [h1 * w; h2 * w; h3 * w] else []) [0; 1; 2]) [0; 1; 2] end @
    begin List.concat @@ List.map (fun d1 ->
      List.map (fun d2 ->
        let h1 = h / 3 + d1 in
        let h2 = h - h1 in
        let w1 = w / 2 + d2 in
        let w2 = w - w1 in
        if 0 <= h2 && 0 <= w2 then [h1 * w; h2 * w1; h2 * w2] else []) [0; 1]) [0; 1; 2] end) [(h, w); (w, h)] end
  |> List.map (function [] -> 1145141919810 | s :: ss -> List.fold_left max s ss - List.fold_left min s ss)
  |> List.fold_left min 1145141919810
  |> Printf.printf "%d\n")


Measured memory_bytes: 4480
#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 <cmath>
#include <limits>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<int> A(N),B(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
    B[i]=A[i];
    B[i]+=i+1;
  }
  sort(B.begin(),B.end());
  ll ans=0;
  for(int i=0;i<N;i++){
    if(i+1-A[i]<=1){
      continue;
    }
    ans+=upper_bound(B.begin(),B.end(),i+1-A[i])-lower_bound(B.begin(),B.end(),i+1-A[i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4800
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"from fractions import*;_,X,*x=map(int,open(0).read().split());s,*x=[abs(X-t)for t in x]\n"
"for t in x:s=gcd(s,t)\n"
"print(s)\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 16388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


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

    int a,b;
    cin >> a >> b;
    if(a>12){cout << b << endl; return 0;}
    else if(12>=a && a>=6){cout << b/2 << endl; return 0;}
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
#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 ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int w,a,b;
    cin>>w>>a>>b;
    if (a >= b){
        if (a > b+w) cout<<a-b-w<<endl;
        else cout<<0<<endl;
    }
    else{
        if (b > a+w) cout<<b-a-w<<endl;
        else cout<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
  double n,count=0;
cin>>n;
  rep(i,n+1){
    if(i%2==1)
      count++;
}
  cout<<count/n<<endl;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
    long small, large;
    std::cin >> small >> large;

    if (small > large) {
        long tmp = small;
        small = large;
        large = tmp;
    }

    long mod;
    while ((mod = large % small) != 0) {
        large = small;
        small = mod;
    }

    std::cout << small << std::endl;

    return 0;
}

Measured memory_bytes: 1160
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> resultList = new List<int>();
            string input;
            while ((input = Console.ReadLine()) != null)
            {
                int d = int.Parse(input);
                int s = 0;
                for (int i = 1; i < 600 / d; i++)
                {
                    s +=  i * i * d * d * d;
                }

                resultList.Add(s);
            }

            foreach (int a in resultList)
            {
                Console.WriteLine(a);
            }

        }
    }
}

Measured memory_bytes: 11804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin>>n;
    vector<ll> b;
    ll ans=0;
    for(ll i=0; i<n; i++){
        ll a;cin>>a;
        auto itr = upper_bound(b.begin(),b.end(),-a);
        if(itr==b.end()){ans++;b.push_back(-a);}
        else *itr=-a;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        double d=sc.nextDouble();
        double t=sc.nextDouble();
        double s=sc.nextDouble();
        double sum=d/s;

        //System.out.println(sum);

        if(sum<=t){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
        sc.close();
    }
}

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

int main ( void )
{
	int H, A, temp, i;
	i = 0;
	cin >> H >> A;

	if ( ( H < 1 ) || ( 10000 < H ) ){
		cout << "ERROR!\n";
		return 0;
	}
	if ( ( A < 1 ) || ( 10000 < A ) ){
		cout << "ERROR!\n";
		return 0;
	}

	temp = H;

	while ( 1 ){
		temp -= A;
		i++;
		if ( temp <= 0 )
			break;
	}

	cout << i << "\n";
	return 0;
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] b = Console.ReadLine().Split();
            int A = int.Parse(b[0]); int B = int.Parse(b[1]);
            string an;
            if (A * B % 2 == 0) { an = "No"; }
            else { an = "Yes"; }
            Console.Write(an);
        }
    }
}

Measured memory_bytes: 11092
let (h, n) = Scanf.sscanf (read_line ()) "%d %d" @@ fun h n -> (h, n)
let ab = Array.init n @@ fun _ -> Scanf.sscanf (read_line ()) "%d %d" @@ fun a b -> (a, b)

let () =
  let ans = Array.make (h + 1) max_int in
  ans.(0) <- 0;
  for i = 1 to h do
    Array.iter (fun (a, b) -> ans.(i) <- min ans.(i) (ans.(max 0 (i - a)) + b)) ab
  done;
  Printf.printf "%d\n" ans.(h)

Measured memory_bytes: 2816
#include <stdio.h>
#include <string.h>
#define N 1046557
#define M 1000000
#define L 14

char H[N][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return (key % N); }
int h2(int key){ return 1+(key % (N-1)); }

int insert(char str[]){
    long long i = 0, j, key;
    key = getKey(str);
    while(1){
	j = (h1(key) + i*h2(key)) % N;
	if(strcmp(H[j], str) == 0) return 1;
	if(H[j][0] == '\0'){
	    strcpy(H[j], str);
	    return j;
	}else i++;
    }
}

int find(char str[]){
    long long i = 0, j, k, key;
    key = getKey(str);
    while(1){
	k = (h1(key) + i*h2(key));
	j = k % N;
	if(strcmp(H[j], str) == 0 ) return 1;
	else if(H[j][0] == '\0' ) return 0;
	else i++;
    }
}

//--------------------------------------------------------------------
int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 15988
#include<iostream>
#include<vector>
#include<string>
#include <map>
#include<algorithm>
using namespace std;
int search(string, pair<string, int>*, pair<string, vector<string> >*);
int n;
int m,si;
int main()
{
     
    while (true){
        pair<string, int>p[101];
        pair<string, vector<string> >chan[101];
        cin >> n;
        if (n == 0){
            break;
        }
        for (int i = 0; i < n; i++){
            cin >> p[i].first >> p[i].second;
        }
 
        cin >> m;
        for (int i = 0; i < m; i++){
            cin >> chan[i].first >> si;
            for (int i2 = 0; i2 < si; i2++){
                string s;
                cin >> s;
                chan[i].second.push_back(s);
            }
        }
        string s;
        cin >> s;
        int ans = search(s,p,chan);
        cout << ans << endl;
    }
}
int search(string s, pair<string, int>*p, pair<string, vector<string> >*chan){
    int num = 0;
    bool flag = true;
    for (int i = 0; i < m; i++){
        if (chan[i].first == s){
            flag = false;
            for (int i2 = 0; i2 < chan[i].second.size(); i2++){
                num += search(chan[i].second[i2],p,chan);
            }break;
        }
    }
    if (!flag){
        int k;
        for (int i = 0; i < n; i++){
            if (p[i].first == s){
                num=min(p[i].second,num);
                break;
            }
        }
    }
    if (flag){
        for (int i = 0; i < n; i++){
            if (p[i].first == s){
                num += p[i].second;
            }
        }
    }
    return num;
}

Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int> d(N);
	for (int i = 0; i < N; ++i) {
		cin >> d[i];
	}
	sort(d.begin(),d.end());
	cout << d[N/2]-d[N/2-1] << endl;
	return 0;
}


Measured memory_bytes: 640
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
for l in range(len(N)):
    a,b,c,d,e,f = [float(i) for i in N[l].split()]
    x = (c*e-f*b)/(a*e-b*d)
    y = (f*a-c*d)/(a*e-b*d)
    print(format(x+0.0,'.3f'), format(y+0.0,'.3f'))



Measured memory_bytes: 5584
import sys, re
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    s = readline().strip()
    ans = []
    for w in re.split("[ .,]", s):
        if 3 <= len(w) <= 6:
            ans.append(w)
    write(" ".join(ans))
    write("\n")
solve()



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

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

  int sum = 0;
  for(auto c:a)sum+=c;

  set<int>candidates;
  for(int i=1;i*i<=sum; i++){
    if(sum%i)continue;

    candidates.insert(i);
    candidates.insert(sum/i);
  }

  int ans = 0;
  for(auto c:candidates){
    vector<ll>aa(n);
    rep(i, n)aa[i] = a[i]%c;
    sort(aa.begin(), aa.end());

    int tot = 0;
    rep(i, n)tot+=aa[i];
    int rcount = tot/c;

    ll rsum=0;
    rep(i, rcount)rsum += c-aa[n-1-i];
    if(rsum <= k)ans = max<ll>(ans, c);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3564
import java.util.Scanner;

class Main{

	Main(){
		Scanner scan = new Scanner(System.in);	
		while(true){
			int yen=scan.nextInt();
			if(yen==0){
				break;
			}
			yen=1000-yen;
			System.out.println(hantei(yen));
		}
	}

	int[] init(int[] w){
		for(int i=0;i<w.length;i++){
			w[i]=0;
		}	
		return w;
	}

	int hantei(int yen){
		int coin=0;

		if((yen/500)>0){
			int a=yen/500;
			for(int i=0;i<a;i++){
				coin++;	
			}
			yen=yen%500;
		}
		if((yen/100)>0){
		int a=yen/100;
			for(int i=0;i<a;i++){
				coin++;	
			}
			yen=yen%100;
		}
		if((yen/50)>0){
			int a=yen/50;

			for(int i=0;i<a;i++){
				coin++;	
			}
			yen=yen%50;
		}
		if((yen/10)>0){
				int a=yen/10;

			for(int i=0;i<a;i++){
				coin++;	
			}
			yen=yen%10;
		}
		if((yen/5)>0){
			int a=yen/5;

			for(int i=0;i<a;i++){
				coin++;	
			}
			yen=yen%5;
		}
		for(int i=0;i<yen;i++){
			coin++;
		}

		return coin;
	}

	public static void main(String[] args){
		Main a = new Main();
	}


}

Measured memory_bytes: 17232
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;

class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

class UnionFind {
private:
	vector<int> par;
public:
	UnionFind(int N) { par = vector<int>(N, -1); }
	int find(int x);
	ll size(int x);
	void unite(int x, int y);
	bool same(int x, int y);
};

int UnionFind::find(int x) {
	if (par[x] < 0) return x;
	else return par[x] = find(par[x]);
}
 
ll UnionFind::size(int x) {
	return -par[find(x)];
}
 
void UnionFind::unite(int x, int y) {
	x = find(x);
	y = find(y);
 	if (x == y) return;
	//大きい方に小さい方をくっ付ける
	if (size(x) < size(y)) swap(x, y);
	par[x] += par[y];
	par[y] = x;
}
 
bool UnionFind::same(int x, int y) {
	x = find(x);
	y = find(y);
	return x == y;
}

bool solve() {
    int n,a,b; cin >> n >> a >> b;
    int x[n]; REP (i,n) cin >> x[i];
    int lim = b/a;
    if (lim * a < b) lim++;
    int ans = 0;
    FOR (i,1,n) {
        if (x[i] - x[i-1] >= lim) {
            ans += b;
        } else {
            ans += a * (x[i]-x[i-1]);
        }
    }
    cout << ans << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
}


Measured memory_bytes: 1024
/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* ]]] */

int t[256];

int main(){
  string s;
  cin >> s;
  each(c, s) t[c] = 1;
  int a = (t['N'] ^ t['S']);
  int b = (t['W'] ^ t['E']);
  cout << (a || b ? "No\n" : "Yes\n");
}



Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
stack<ll> st[100010];
ll cnt2[100010] = {};
vector<ll> atode[100010];
ll cnt[100010] = {};
ll X[100010];


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    rep(i,0,N) cin >> X[i];
    vector<ll> val[100010];
    rep(i,0,N) val[X[i] % M].push_back(X[i]);
    ll ans = 0;
    rep(i,0,M/2+1){
        if(i == 0){
            ans += val[i].size() / 2;
        }else if(M % 2 == 0 && i == M/2){
            ans += val[i].size() / 2;
        }else{
            ll j = M - i;
            ans += min(val[i].size(), val[j].size());
            if(val[i].size() > val[j].size()){
                ll diff = val[i].size() - val[j].size();
                map<ll,ll> mp;
                ll cnt = 0;
                rep(k,0,val[i].size()){
                    mp[val[i][k]]++;
                    if(mp[val[i][k]] % 2 == 0){
                        cnt++;
                    }
                }
                ans += min(cnt, diff/2);

            }else{
                ll diff = val[j].size() - val[i].size();
                map<ll,ll> mp;
                ll cnt = 0;
                rep(k,0,val[j].size()){
                    mp[val[j][k]]++;
                    if(mp[val[j][k]] % 2 == 0){
                        cnt++;
                    }
                }
                ans += min(cnt, diff/2);         
            }

        }

    }
    print(ans);
}

Measured memory_bytes: 76800
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    int c=0;
    if(s[0]=='1'){
        c+=1;
    }
    if(s[1]=='1'){
        c+=1;
    }
    if(s[2]=='1'){
        c+=1;
    }
    cout<<c;
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.util.Calendar.Builder;

import javax.jws.soap.SOAPBinding.Use;



public class Main {
	static int INF = 2 << 27;
	public static void main(String[] args) {	
		//FastScanner sc = new FastScanner();
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		while(true) {
			int T = sc.nextInt();
			if(T == 0) break;
			int[] t = new int[T];
			for(int i = 0; i < T; i++) {
				t[i] = sc.nextInt();
			}
			int N = sc.nextInt();
			int[] DM = new int[100];
			for(int i = 0; i < DM.length; i++) {
				DM[i] = INF;
			}
			for(int i = 0; i < N; i++) {
				int D = sc.nextInt()-1;
				DM[D] = Math.min(DM[D], sc.nextInt());
			}
			int[][] dp = new int[101][T];
			for(int i = 0; i < dp.length; i++) {
				Arrays.fill(dp[i], INF);
			}
			dp[0][0] = 0;
			for(int i = 0; i < DM.length; i++) {
				for(int j = 0; j < T; j++) {
					if(dp[i][j] == INF) continue;
					if(t[j] <= DM[i]) {
						dp[i+1][(j + 1) % T] = Math.min(dp[i + 1][(j + 1) % T], dp[i][j]);
					}
					dp[i + 1][1] = Math.min(dp[i+1][1], dp[i][j]+1);
				}
			}
			int min = INF;
			for(int i = 0; i < T; i++) {
				min = Math.min(min, dp[100][i]);
			}
			System.out.println(min);
		}
	}
}

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

int f[10][10], x[23], y[23], dat[10][10], dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

int main() {
	int m, n;
	while (scanf("%d%d", &m, &n), m) {
		int p = 0, sx, sy;
		rep(i, n)rep(j, m) {
			scanf("%d", &f[i][j]);
			if (f[i][j] == 1)x[p] = i, y[p] = j, dat[i][j] = p++;
			if (f[i][j] == 2)sx = i, sy = j;
		}
		map<P, int>dp;
		rep(k, 4) {
			for (int nx = sx, ny = sy; 0 <= nx&&nx < n && 0 <= ny&&ny < m; nx += dx[k], ny += dy[k]) {
				if (f[nx][ny] == 1) {
					dp[{1 << dat[nx][ny], dat[nx][ny]}] = 1;
					break;
				}
			}
		}
		int ans = 0;
		rep(i, 1 << p)rep(j, p) {
			if (dp.find({ i,j }) == dp.end())continue;
			if (i == (1 << p) - 1) {
				if (x[j] == sx || y[j] == sy)ans += dp[{i, j}];
				continue;
			}
			rep(k, 4) {
				for (int nx = x[j], ny = y[j]; 0 <= nx&&nx < n && 0 <= ny&&ny < m; nx += dx[k], ny += dy[k]) {
					if (f[nx][ny] == 1 && !(i >> dat[nx][ny] & 1)) {
						dp[{i | 1 << dat[nx][ny], dat[nx][ny]}] += dp[{i, j}];
						break;
					}
				}
			}
			dp.erase({ i,j });
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 8412
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b + c) cout << 0 << endl;
    else cout << c - (a - b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
    char W[10], T[8];
    int count = 0, i;
    scanf("%s", W);
    while (scanf("%s", T) != EOF && strcmp(T, "END_OF_TEXT")) {
        for (i = 0; T[i]; i++) {
            T[i] = tolower(T[i]);
        }
        if (!strcmp(W, T)) {
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 552
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

class UnionFind{
private:
  vector<int> par, rank;
public:
  UnionFind(int n){
	par.assign(n, 0);
	rank.assign(n, 0);
	for(int i=0;i<n;++i)
	  par[i] = i;
  }

  //find root of x
  int find(int x){
	if(par[x] == x)
	  return x;
	return (par[x] = find(par[x]));
  }

  void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(rank[x] < rank[y])
	  par[x] = y;
	else{
	  par[y] = x;
	  if(rank[x] == rank[y])
		++rank[x];
	}
  }

  bool same(int x, int y){
	return find(x) == find(y);
  }
};


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

  int N; cin >> N;
  VI cost(N);
  map<string,int> table;
  REP(i,N){
	string s; int x;
	cin >> s >> x;
	table[s] = i;
	cost[i] = x;
  }
  UnionFind uf(N);
  int M; cin >> M;
  REP(i,M){
	string s, t;
	cin >> s >> t;
	int m = min(cost[uf.find(table[s])], cost[uf.find(table[t])]);
	uf.unite(table[s], table[t]);
	cost[uf.find(table[s])] = m;
  }

  int ans = 0;
  REP(i,N)
	ans += cost[uf.find(i)];
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    map<int,int> mp;
    for(int i = 0;i<n;i++) {
        int x;
        cin >> x;
        mp.insert({x,(i+1)});
    }
    for(int i = 0;i<n;i++){
        cout << mp[i+1] << " ";
    }
    return 0;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
int dig(int a) {
    int rse = 0;
    while (a > 0) {
        rse += a % 10;
        a /= 10;
    }
    return rse;
}
int main() {
    srand(time(0));
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    int mn = 1000000;
    int n;
    cin >> n;
    for (int i = 1; i <= n - 1; i++) {
        mn = min(mn, dig(i) + dig(n - i));
    }
    cout << mn;
    return 0;
}


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

int main(){
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    ll na = v * t;
    ll nb = w * t;
    bool exist = true;
    if(a < b){
        if(b + nb <= a + na){
            exist = true;
        }else{
            exist = false;
        }
    }else{
        if(b - nb >= a - na){
            exist = true;
        }else{
            exist = false;
        }
    }
    if(exist) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3632