akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
using namespace std;

ll modinv(ll a,ll m){
   ll b=m,u=1,v=0;
   while(b){
      ll t=a/b;
      a-=t*b; 
      swap(a,b);
      u-=t*v; 
      swap(u,v);
   }
   u%=m;
   if(u<0) u+=m;
   return u;
}

ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}



int main(){
   int n;
   cin>>n;
   map<string,int> mp;
   rep(i,n){
      string s;
      cin>>s;
      mp[s]++;
   }
   int m;
   cin>>m;
   rep(i,m){
      string s;
      cin>>s;
      mp[s]--;
   }
   int ans=0;
   for(auto iter=mp.begin();iter!=mp.end();iter++){
      ans=max(ans,iter->second);
   }
   cout<<ans;
   return 0;
}



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

int main() {
	int n, h, w;

	scanf("%d %d %d", &n, &h, &w);

	printf("%d\n", (n - h + 1) * (n - w + 1));
}

Measured memory_bytes: 1700
#include<bits/stdc++.h>
using namespace std;
bool s[200001];
bool g[200001];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        if(a==1)s[b]++;
        if(b==n)g[a]++;
    }
    bool ans=false;
    for(int i=2;i<n;i++){
        if(s[i]&&g[i]){
            ans++;
        }
    }
    if(!ans)cout<<"IM";
    cout<<"POSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, C;
	cin >> N >> C; 
	vector<vector<int>> sum(C+1, vector<int>(100000 + 2));
	for (int i = 0;i<N;++i) {
		int s, t, c;
		cin >> s >> t >> c;
		sum[c][s]++;
		sum[c][t + 1]--;
	}
	int ans = 0;
	vector<vector<int>> now(C + 1, vector<int>(100000 + 2));
	for (int i = 1;i<=100000;++i) {
		int count = 0;
		for (int j = 1;j<=C;++j) {
			now[j][i] = now[j][i-1]+sum[j][i];
			if (now[j][i]>0) {
				count++;
			}
		}
		//cout << now << endl;
		ans = max(ans,count);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 27964
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>
#include <string>

using namespace std;

map<long, long> p;
long n,m,k;

int main(){
  cin >> n >> m >> k;
  for (long i=0;i<=n;i++) {
    for (long j=0;j<=m;j++) {
      if (k==i*(m-j)+j*(n-i)) {
	cout << "Yes" << endl;
	return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

cnt1 = a.count(1)
cnt2 = a.count(2)
cnt3 = a.count(3)

dp = [[[-1]*(cnt1 + cnt2 + cnt3 + 1) for _ in range(cnt2 + cnt3 + 1)] for _ in range(cnt3 + 1)]
dp[0][0][0] = 0
 
for c3 in range(cnt3 + 1):
    for c2 in range(cnt2 + cnt3 + 1 - c3):
        for c1 in range(cnt1 + cnt2 + cnt3 + 1 - c2 - c3):
            if c1 + c2 + c3 == 0:
                continue
            tmp = 0
            num = c1 + c2 + c3
            # c3を選ぶ
            if c3 != 0:
                tmp += (c3 / n) * dp[c3-1][c2+1][c1]
            # c2を選ぶ
            if c2 != 0:
                tmp += (c2 / n) * dp[c3][c2-1][c1+1]
            # c1を選ぶ
            if c1 != 0:
                tmp += (c1 / n) * dp[c3][c2][c1-1]
            dp[c3][c2][c1] = n / num * (tmp + 1)

print(dp[cnt3][cnt2][cnt1])


Measured memory_bytes: 498440
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int ans = 1;

		for(int i = 0; (ans+1)*(ans+1) <= n; i++){
			ans++;
		}
		System.out.println(ans*ans);
	}
}

Measured memory_bytes: 21844
#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>;
const int INF = 1 << 29;

int n, t[110], m;
P drink[110]; 
int main() {
	cin >> n;
	int all = 0;
	rep(i, n) {
		cin >> t[i];
		all += t[i];
	}
	cin >> m;
	rep(i, m) {
		int p, x; cin >> p >> x;
		drink[i] = make_pair(p-1,x);
	}
	rep(i, m) {
		auto p = drink[i].first, x = drink[i].second;
		cout << all - t[p] + x << endl;
	}
	return 0;
}

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

long long int digit(long long int x){
  long long int p=0;
  while(x>0){
    p++;
    x/=10;
  }
  return p;
}

int main(){
  string s;
  cin>>s;
  if(s=="SUN"){
    cout<<7<<endl;
  }
  if(s=="MON"){
    cout<<6<<endl;
  }
  if(s=="TUE"){
    cout<<5<<endl;
  }
  if(s=="WED"){
    cout<<4<<endl;
  }
  if(s=="THU"){
    cout<<3<<endl;
  }
  if(s=="FRI"){
    cout<<2<<endl;
  }
  if(s=="SAT"){
    cout<<1<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;

int main(){

	int c[3];
	while(cin >> c[0] >> c[1] >> c[2]){
		bool card[11];
		fill(card,card+11,false);
		for(int i = 0; i <= 2; i++)
			card[c[i]] = true;
		int sum = c[0] + c[1];

		int cnt=0;
		int match=0;
		for(int i = 1; i < 11; i++){
			if(card[i])
				continue;
			if(sum + i <= 20)
				match++;
			cnt++;
		}
		if(2*match/cnt >= 1)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
 
main(){
  char data[101];
  int i,temp,ans,p;
 
  while(1){
    if(scanf("%c", &data[0])==EOF) break;
    if(data[0]=='\n') continue;
    for(i=1;i<100;i++){
      scanf("%c", &data[i]);
      if(data[i]=='\n'){
    temp=i;
    break;
      }
    }
     
    ans=0; 
    p=0;
    for(i=temp-1;i>=0;i--){
      if(data[i]=='I'){
    if(p<=1){
      p=1;
      ans+=1;
    }
    else ans-=1;
      }
      if(data[i]=='V'){
    if(p<=2){
      p=2;
      ans+=5;
    }
    else ans-=5;
      }
      if(data[i]=='X'){
    if(p<=3){
      p=3;
      ans+=10;
    }
    else ans-=10;
      }
      if(data[i]=='L'){
    if(p<=4){
      p=4;
      ans+=50;
    }
    else ans-=50;
      }
      if(data[i]=='C'){
    if(p<=5){
      p=5;
      ans+=100;
    }
    else ans-=100;
      }
      if(data[i]=='D'){
    if(p<=6){
      p=6;
      ans+=500;
    }
    else ans-=500;
      }
      if(data[i]=='M'){
    if(p<=7){
      p=7;
      ans+=1000;
    }
    else ans-=1000;
      }
    }
 
    printf("%d\n", ans);
  }
  return 0;
}


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

using namespace std;

int gcd(double x, double y)
{
    int m = (int)floor(x);
    int n = (int)floor(y);
    int r;
    
    do {
        r = m % n;
        m = n;
        n = r;
    } while (r != 0);
    
    return m;
}

int main(int argc, const char * argv[]) {
    int n, pos, d, i, a, mx;
    mx = 1;
    vector<int> x, k;
    cin >> n >> pos;
    for(i = 0;i < n;i++){
        cin >> a;
        x.emplace_back(a);
    }
    x.emplace_back(pos);
    sort(x.begin(), x.end());
    for(i = 0;i < n;i++){
        k.emplace_back(x[i+1]-x[i]);
    }
    if(n == 1){
        mx = k[0];
    }else{
        mx = gcd(k[0], k[1]);
        for(i = 2;i < n;i++){
            mx = gcd(mx, k[i]);
            if(mx == 1)break;
        }
    }
    printf("%d\n", mx);
    return 0;
}

Measured memory_bytes: 1400
from collections import Counter
n = int(input())
a = [int(i) for i in input().split()]
cnt = Counter(a)
q = int(input())
s = sum(a)
for i in range(q):
    b, c = map(int, input().split())
    s += (c - b)*cnt[b]
    print(s)
    cnt[b], cnt[c] = 0, cnt[c] + cnt[b]

Measured memory_bytes: 23864
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx=tx-sx, dy=ty-sy;
    cout << string(dy, 'U') << string(dx, 'R');
    cout << string(dy, 'D') << string(dx, 'L');
    cout << 'L' << string(dy+1, 'U') << string(dx+1, 'R')<<'D';
    cout << 'R' << string(dy+1, 'D') << string(dx+1, 'L') << 'U';
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict, deque
from copy import deepcopy
    
input = sys.stdin.readline
def RD(): return input().rstrip()
def F(): return float(input().rstrip())
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float,input().split()))
def Init(H, W, num): return [[num for i in range(W)] for j in range(H)]
    
    
def main():
    move = [[1,0],[0,1],[-1,0],[0,-1]]
    while True:
        W, H = MI()
        result = 0
        if W == 0 and H == 0:
            sys.exit()
        maze = [LI() for i in range(2*H-1)]
        goal = [H-1,W-1]
        d = Init(H,W,-1)
        dq = deque()
        dq.append([0,0])
        d[0][0] = 0
        while dq:
            ht, wt = dq.popleft()
            for h, w in move:
                h += ht
                w += wt
                if h >= 0 and w >= 0 and h < H and w < W and d[h][w] == -1:
                    if ht != h:
                        if maze[2*min(ht, h)+1][w] == 0:
                            dq.append([h,w])
                            d[h][w] = d[ht][wt]+1
                            if h == goal[0] and w == goal[1]:
                                result = d[h][w]+1
                                break
                    elif wt != w:
                        #横への移動が可能か
                        if maze[2*h][min(w, wt)] == 0:
                            dq.append([h,w])
                            d[h][w] = d[ht][wt]+1
                            if h == goal[0] and w == goal[1]:
                                result = d[h][w]+1
                                break
            else:
                continue
            break
        print(result)

    
if __name__ == "__main__":
    main()


Measured memory_bytes: 6392
###
### atcorder test program
###

### math class
class math:
    ### pi
    pi = 3.14159265358979323846264338

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

math = math()

### input sample
#i = input()
#A, B, C = [x for x in i.split()]
#templist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))

while True:
    i = input()
    X, Y = [int(x) for x in i.split()]
    if X == 0:
        break
    for n in range(X):
        for m in range(Y):
            print("#", end="")
        print("")
    print("")



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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	vl a(4);
	cin>>a[0]>>a[1]>>a[2]>>a[3];
	ll n;cin>>n;
	ll ans=0;
	ans+=n/2*min({a[3],2*a[2],4*a[1],8*a[0]});
	ans+=n%2*min({a[2],2*a[1],4*a[0]});
	cout<<ans<<endl;
}

Measured memory_bytes: 256
# coding: utf-8
from collections import deque


def solve(*args: str) -> str:
    n = int(args[0])
    A = sorted(map(int, args[1].split()), reverse=True)

    Q = deque()

    ret = 0
    for i in range(-(-n//2)):
        if 0 < i:
            ret += min(Q[-1], Q[0])
        if i % 2:
            Q.appendleft(A[i])
        else:
            Q.append(A[i])

    for i in range(n-len(Q)):
        ret += min(Q[i], Q[(i+1) % len(Q)])

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 34128
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x;
	cin >> x;
	ll ans = (x / 500) * 1000;
	x %= 500;
	ans += (x / 5) * 5;
	cout << ans << endl;
	return 0;
}


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

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

    if (A <= 9 && B <= 9) {
        ret = A * B;
    } else {
        ret = -1;
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int n = in.nextInt();
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = in.nextInt();
			}
			long maxMask = 1;
			for (int i = 0; i < n; i++) {
				maxMask *= 3;
			}
			int count = 0;
			for (long mask = 0; mask < maxMask; mask++) {
				long cMask = mask;
				int product_2 = 1;
				for (int i = 0; i < n; i++) {
					product_2 *= ((cMask % 3) - 1) + a[i];
					product_2 %= 2;
					cMask /= 3;
				}
				if (product_2 == 0) {
					count++;
				}
			}
			out.println(count);
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

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

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

		public double nextFloat() {
			return Double.parseDouble(next());
		}

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

	}
}

Measured memory_bytes: 23380
def dot(a, b):
    return a.real * b.real + a.imag * b.imag


def cross(a, b):
    return a.real * b.imag - a.imag * b.real


n = int(input())
vertices = [complex(*map(int, input().split())) for _ in range(n)]
edges = [(p0, p1) for p0, p1 in zip(vertices, vertices[1:] + [vertices[0]])]

q = int(input())
while q:
    q -= 1
    p = complex(*map(int, input().split()))
    counter = 0
    for p0, p1 in edges:
        a, b = p0 - p, p1 - p
        if a.imag > b.imag:
            a, b = b, a
        crs = cross(a, b)
        if a.imag <= 0 and 0 < b.imag and crs < 0:
            counter += 1
        if crs == 0 and dot(a, b) <= 0:
            print(1)
            break
    else:
        print(2 if counter % 2 else 0)

Measured memory_bytes: 7768
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		 Scanner sc = new Scanner(System.in);
	        int s = sc.nextInt();
	        int x = 0;
	        
        	List<Integer> list = new ArrayList<>();
	        
	        for(int i=2; i<1000000; i++) {
	         	list.add(s);
	        	if(s%2==0) {
	        		x = s/2;
	        	}else {
	        		x = 3*s+1;
	        	}
	        	s = x;
	        	if(list.contains(x)) {
	        		System.out.println(i);
	                break;
	            }
	        }
	}

}


Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>
#define INF 1<<28
using namespace std;

int p[1000001];
int memo[1000001][6];
int memo2[1000001];

int solve(int n, int count){
  
  if(!n) return 0;
  if(n <= 0 || !count) return INF;
  if(memo[n][count]) return memo[n][count];
  
  int ans = INF;
  for(int i=0;p[i]<=n; i++) ans = min(ans, solve(n-p[i], count-1)+1);
  
  return memo[n][count] = ans;
}

int solve2(int n){
  
  if(!n) return 0;
  if(n<0) return INF;
  if(memo2[n]) return memo2[n];
  
  int ans = INF;
  for(int i=0;p[i]<=n; i++){
    if(!(p[i]%2)) continue;
    ans = min(ans, solve2(n-p[i])+1);
  }
  
  return memo2[n] = ans;
}

int main(){
  
  int n;
  
  for(int i=0;i<=1000000;i++) p[i] = i*(i+1)*(i+2)/6;
  for(int i=1;i<=1000000;i++)  solve2(i);
  
  while(cin >> n, n) cout << solve(n, 5) << " " << solve2(n) << endl;
}

Measured memory_bytes: 32408
n,m,c = map(int,input().split())
b = [int(_) for _ in input().split()]
a = []
ans = 0
for _ in range(n):
    a.append([int(_) for _ in input().split()])
for i in range(n):
    sum = 0
    for j in range(m):
        sum += a[i][j] * b[j]
    if sum + c > 0:
        ans += 1
    else:
        pass
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

struct edge { int from, to, cost; };

int main() {
    
    int N, M;
    
    long long d[1001];
    bool done[1001];
    
    cin >> N;
    cin >> M;
    
    edge es[2000];
    
    for ( int i = 0; i < M; i++ ) {
        
        int a,b;
        long long c;
        
        cin >> a;
        cin >> b;
        cin >> c;
        
        es[i].from = a;
        es[i].to = b;
        es[i].cost = c;
        
    }
    
    for ( int i = 0; i <= N; i++ ) {
        d[i] = LLONG_MIN;
        done[i] = false;
    }
    
    d[1] = 0;
    
    for ( int i = 0; i < N; i++ ) {
        
        for ( int j = 0; j < M; j++ ) {
            edge e = es[j];
            
            if ( done[e.from] || e.from == 1 ) {
                    
                if ( !done[e.to] ) {
                    done[e.to] = true;
                    
                    d[e.to] = d[e.from] + e.cost;
                }
                else if ( d[e.to] < d[e.from] + e.cost ) {
                    
                    d[e.to] = d[e.from] + e.cost;
                    
                    
                    if (  i == N-1 && e.to == N ) {
                        cout << "inf" << endl;
                        return 0;
                    }
                    
                }
            }
            
            
        }
    }
    
    cout << d[N] << endl;
    
    
    
    return 0;
}

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

const int maxn=200010;
const int inf=2e9;
int n,q;
int b[maxn];
int ans;
int sum[maxn];
vector<int> g[maxn];
int dp[maxn];

void read(int& x){
	x=0; char c=getchar();
	while(c<'0' || c>'9') c=getchar();
	while(c>='0' && c<='9') x=x*10+c-'0', c=getchar();
}

void chkmin(int& x,int y){ if(x>y) x=y; }

int Min[maxn<<2];
void pushup(int o){
	Min[o]=min(Min[o<<1],Min[o<<1|1]);
}
void build(int o,int l,int r){
	if(l==r){ Min[o]=dp[l]-sum[l]; return; }
	int mid=(l+r)>>1;
	build(o<<1,l,mid); build(o<<1|1,mid+1,r);
	pushup(o);
}
int query(int o,int l,int r,int ql,int qr){
	if(ql<=l && qr>=r){ return Min[o]; }
	int mid=(l+r)>>1, ret=inf;
	if(ql<=mid) ret=query(o<<1,l,mid,ql,qr); if(qr>mid) chkmin(ret, query(o<<1|1,mid+1,r,ql,qr));
	return ret;
}
void modify(int o,int l,int r,int pos){
	if(l==r){ Min[o]=dp[l]-sum[l]; return; }
	int mid=(l+r)>>1;
	if(pos<=mid) modify(o<<1,l,mid,pos); else modify(o<<1|1,mid+1,r,pos);
	pushup(o);
}

int main(){

	read(n);
	for(int i=1;i<=n;i++) read(b[i]), sum[i]=sum[i-1]+(b[i]^1);
	read(q);
	int l, r;
	for(int i=1;i<=q;i++) read(l), read(r), g[l-1].push_back(r);
	for(int i=1;i<=n;i++) dp[i]=inf;
	build(1,0,n);
	for(int i=0;i<=n;i++){
		if(i>0) chkmin(dp[i], dp[i-1]+(b[i])), modify(1,0,n,i);
		for(int j=0;j<g[i].size();j++){
			chkmin(dp[g[i][j]], query(1,0,n,i,g[i][j]-1)+sum[g[i][j]]);
			modify(1,0,n,g[i][j]);
		}
		// printf("%d : %d\n", i, dp[i]);
	}
	printf("%d\n", dp[n]);
	return 0;
}

Measured memory_bytes: 14336
a = []
for i in range(100):
    try:       
        n = int(input())
        a.append(n)
    except:    
        pass

M = 0
b = []
for i in range(100):
    bi = a.count(i)
    #print(bi)
    if bi == M:
        b.append(i)
        M = bi
    elif bi > M:
        b.clear()
        b.append(i)
        M = bi
for i in range(len(b)):
    print(b[i])
    


Measured memory_bytes: 5600
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue> 
using namespace std;
int main() 
{int a,b,k;
 cin>>a>>b>>k;
 if (k>(b-a+1)/2){
 for (int i=a;i<=b;i++)
 cout<<i<<endl;
 system("pause");
 return 0;} 
 for (int i=0;i<k;i++)
 cout<<a+i<<endl; 
 for (int i=k-1;i>=0;i--)
 cout<<b-i<<endl;
 system("pause");
 return 0;
}        


Measured memory_bytes: 504
input = raw_input
n, m = map(int, input().split(" "))

num_penals = [0 for _ in range(n+1)]
seikai = 0
ayamari = 0
for _ in range(m):
    nn, res = input().split(" ")
    nn = int(nn)
    if num_penals[nn] is not None:
        if res == "AC":
            seikai += 1
            ayamari += num_penals[nn]
            num_penals[nn] = None
        else:
            num_penals[nn] += 1

out = "%d %d" % (seikai, ayamari)            
print(out)

Measured memory_bytes: 37352
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

int n, rem = 0;
map<int, int> cnt;

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

  for(const auto& e : cnt){
    int val = e.fi;
    int how = e.se;
    if(how < val) rem += how;
    else rem += how - val;
  }

  printf("%d\n", rem);

  return 0;
}


Measured memory_bytes: 4736
program example
	implicit none

	integer,allocatable :: A(:)
    integer :: wa=0,H,N,i
    
    read(*,*) H,N
    
    allocate(A(N))
    
    read(*,*) A(:)
    
    wa=sum(A(:))
    
    if(wa<H) then
    	write(*,*) "No"
    else
    	write(*,*) "Yes"
    end if

 end program example

Measured memory_bytes: 1152
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
   int a;
   cin>>a;
   string s;
   cin>>s;
   int count=0;
   char tes='2';
   rep(i,a){
      if(s.at(i)!=tes){
         count++;
         tes=s.at(i);
      }
   }
   cout<<count<<endl;
}



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

int main(){
  int n,m;cin>>n>>m;
  int t = (n-m)*100 + m*1900;
  int p = 1;
  rep(i,m)p *= 2;
  cout << t*p << endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
        #define ll long long int
        using namespace std;
        #define mod 1000000007
        #define pb push_back
        #define fi first
        #define si second
        #define mp make_pair
        #define f(n) for(ll i=0;i<n;i++)
        #define ff(m) for(ll j=0;j<m;j++)
        #define fr(i,p,n) for(ll i=p;i<n;i++)
        #define in insert
        ll exp(ll a,ll b,ll m);
        #define vl vector<ll> 
        #define pll pair <ll,ll>

    
        void solve(){

        	int n;
        	cin>>n;
        	vl a[n];
        	int aa,b,c;
        	f(n){
        		cin>>aa>>b>>c;

        		a[i].push_back(aa);
        		a[i].push_back(b);
        		a[i].push_back(c);
        	}

        	vl dph(n,0);
        	vl dpc(n,0);
        	vl dps(n,0);
        	dph[0]=a[0][2];
        	dpc[0]=a[0][1];
        	dps[0]=a[0][0];




        	fr(i,1,n){
        		dph[i]=a[i][2]+max(dps[i-1],dpc[i-1]);
        		dpc[i]=a[i][1]+max(dph[i-1],dps[i-1]);
        		dps[i]=a[i][0]+max(dph[i-1],dpc[i-1]);
        	}

        	cout<<max(max(dps[n-1],dpc[n-1]),dph[n-1])<<endl;

        }
 
       int main(){
           
 
            int t=1;
 			//cin>>t;
            while(t--)
               solve();
    
    		return 0;
		}
 
		ll exp(ll a,ll b,ll m)
		{
			if(b==0)
			{
				return 1;
			}
			ll temp =exp(a,b/2,m);
			temp=(temp*temp)%m;
			if(b&1)
			{
				return (temp*(a%m))%m;
			}
			return temp;
		}	

Measured memory_bytes: 9600
import sys
input = sys.stdin.readline
def nibun_right(a, x):
 lo, hi = 0, len(a)
 while lo < hi:
  mid = (lo+hi)//2
  if x < a[mid][0]: hi = mid
  else: lo = mid+1
 return lo
N,D,A=map(int,input().split())
lst=[0]*N
for i in range(N):
 lst[i]=list(map(int,input().split()))
 lst[i][1]=int((lst[i][1]-1)/A)+1
lst.sort()
DMG=[0]*(N+1)
ans=0
for i in range(N):
 renji=nibun_right(lst,lst[i][0]+2*D)
 Z=max(lst[i][1]-DMG[i],0)
 DMG[i]+=Z
 DMG[renji]-=Z
 ans+=Z
 DMG[i+1]+=DMG[i]
print(ans)


Measured memory_bytes: 59864
N = int(input())
A = list(map(int, input().split()))

def main1(N, A):
    dic = {}
    res = ""
    for i in range(0, N):
        dic[A[i]] = i+1
    for i in range(1, N+1):
        res += " {}".format(dic[i])
    print(res[1:])

main1(N, A)


Measured memory_bytes: 19912
#include<stdio.h>
int main(void)
{
    int a,b,c,w;
	scanf("%d %d %d",&a,&b,&c);
	w=c-b;
	if(w<=0) printf("delicious\n");
	else if(w<=a) printf("safe\n");
	else printf("dangerous\n");
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;

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

    string s;
    cin >> s;
    bool a = 0, b = 0, c = 0;
    if (s[0] == 'A')
        a = 1;
    int cnt = 0;
    for (int i = 2; i <= s.size() - 2; i++) {
        if (s[i] == 'C')
            cnt++;
    }
    if (cnt == 1)
        b = 1;
    cnt = 0;
    rep(i, s.size()) {
        if (islower(s[i]))
            cnt++;
    }
    if (cnt == s.size() - 2)
        c = 1;

    if (a && b && c) {
        cout << "AC" << endl;
    } else {
        cout << "WA" << endl;
    }

    return 0;
}

Measured memory_bytes: 3576
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner stdIn = new Scanner(System.in);
		int x = 0; 
		while (1 > x || x > 101){
			x = stdIn.nextInt();
		}
		System.out.println(x * x * x);
		stdIn.close();
	}
}

Measured memory_bytes: 26224
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int N;

int main(int argc, char const *argv[]) {
	cin >> N;
	int a;
	// int cnt = 0;
	// map<int, int> mp;
	set<int> se;

	for (int i = 0; i < N; i++) {
		cin >> a;
		se.insert(a);
		// a--;
		// if (!mp.count(a)) {
		// 	mp[a] = 0;
		// 	cnt++;
		// }
		// else mp[a]++;
	}

	// if ((N - cnt) % 2 == 0) cout << cnt << endl;
	// else cout << cnt - 1 << endl;
	int size = se.size();
 	if ((N - size) % 2 == 0) cout << size << endl;
	else cout << size - 1 << endl;
	return 0;
}

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

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define MOD 1000000009
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    int N, X;
    cin >> N >> X;
    LLI sum = 0;
    LLI c = 1;
    REP(i, N) {
        int t;
        cin >> t;
        sum += t;
        if(sum <= X) {
            c++;
        } else {
            cout << c;
            return 0;
        }
    }

    cout << c;
    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, K = mapint()
mod = 998244353
dp = [0]*(N+1)
dp[1] = 1

Ks = [list(mapint()) for _ in range(K)]
Ks.sort()

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sums(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

bit = Bit(N)
bit.add(1, 1)

for i in range(2, N+1):
    for l, r in Ks:
        if i-l<0:
            break
        dp[i] += bit.sums(i-l) - bit.sums(max(0, i-r-1))
        dp[i] %= mod
    bit.add(i, dp[i])

print(dp[-1])

Measured memory_bytes: 72400
def q*a;a.delete a[0];a.empty?end
$<.map{|x|
  a,b,c,d,e=x.chop.split(",").map(&:to_i).sort;
  puts case
  when q(a,b,c,d)||q(b,c,d,e);"four card"
  when a==b&&q(c,d,e)||q(a,b,c)&&d==e;"full house"
  when (s=[a,b,c,d,e])==(a..e).to_a||s==[1,10,11,12,13];"straight"
  when q(a,b,c)||q(b,c,d)||q(c,d,e);"three card"
  when a==b&&(c==d||d==e)||b==c&&d==e;"two pair"
  when a==b||b==c||c==d||d==e;"one pair"
  else "null"
  end
}

Measured memory_bytes: 6116
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, k) = (v[0], v[1]);
    let mut a = read_vec::<i32>();
    for _ in 0..k {
        let mut next = vec![0i32; n + 1];
        for i in 0..n {
            let left = max(0, i as i64 - a[i] as i64) as usize;
            let right = min(n - 1, i + a[i] as usize);
            next[left] += 1;
            next[right + 1] -= 1;
        }
        let mut next_sum = vec![0; n];
        next_sum[0] = next[0];
        for i in 1..n {
            next_sum[i] = next[i] + next_sum[i - 1];
        }
        a = next_sum;
        if a.iter().all(|&x| x as usize == n) {
            break;
        }
    }
    for num in a {
        print!("{} ", num);
    }
    println!("");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4700
#include<stdio.h>
 
int main(){
    int i;
    int a,b;
    int answer;
    while(scanf("%d %d",&a,&b)!=EOF){
        a = a + b;
        answer = 1;
        while(a/10){
            a /= 10;
            answer += 1;
        }
        printf("%d\n",answer);
    }
    return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;
 
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INF=1LL<<60;
 
int main() {
   string s,t;
   cin>>s>>t;
   ll n=s.size();
   ll m=t.size();
ll dp[n+1][m+1];
rep(i,n+1)rep(j,m+1)dp[i][j]=0;
for(ll i=1;i<=n;i++){
    for(ll j=1;j<=m;j++){
        if(s[i-1]==t[j-1]){
            dp[i][j]=dp[i-1][j-1]+1;
        }
        else{
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
}

string rewsna=" ";
while(n>0 && m>0){
    if(dp[n][m]==dp[n-1][m])n--;
    else if(dp[n][m]==dp[n][m-1])m--;
    else{
        rewsna+=s[n-1];
        n--;
        m--;
    }
}

ll z=rewsna.size();
for(ll i=z-1;i>=0;i--)cout<<rewsna[i];
cout<<endl;
return 0;
}


Measured memory_bytes: 70656
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

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

ll T[110];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    //cout << fixed << setprecision(15);
    int N;
    cin >> N;

    ll ans = 0;

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

    ans = T[0];
    for (int i = 1; i < N; ++i)
    {
        ll d = gcd(ans, T[i]);
        ans = ans / d * T[i];
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
   int n;
   cin >> n;
   vector<int> h(n);
   rep(i,n) cin >> h[i];
   vector<int> dp(n,INF);
   dp[0] = 0;
   for(int i = 0; i < n-1;i++)
   {
      int c1 = abs(h[i+1] - h[i]);
      dp[i+1] = min(dp[i+1], dp[i] + c1);
      if(i == n-2) continue;
      int c2 = abs(h[i+2] - h[i]);
      dp[i+2] = min(dp[i+2], dp[i] + c2);
   }
   cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
// Aizu 1116: Jigsaw Puzzles for Computers
// 2017.9.16 bal4u@uu

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

char dice[9][6];
char map[3][3][4];
char tr['z'];
int f[10];
int ans;
int rot[4][4] = {{0,1,2,3},{1,2,3,0},{2,3,0,1},{3,0,1,2}};

void combi(int k)
{
	int r, c, i, j, m;

	if (k == 9) { ans++; return; }
	r = k / 3, c = k % 3;
	for (i = 0; i < 9; i++) {
		if (f[i]) continue;
		for (j = 0; j < 4; j++) {
			for (m = 0; m < 4; m++) map[r][c][m] = dice[i][rot[j][m]];
			if (r > 0 && map[r][c][0] + map[r-1][c][2] != 0) continue;
			if (c > 0 && map[r][c][3] + map[r][c-1][1] != 0) continue;
			f[i] = 1, combi(k+1), f[i] = 0;
		}
	}
}

int main()
{
	int n, i, j;

	tr['R'] =  1, tr['G'] =  2, tr['B'] =  3, tr['W'] =  4;
	tr['r'] = -1, tr['g'] = -2, tr['b'] = -3, tr['w'] = -4;
	scanf("%d", &n); while (n-- > 0) {
		for (i = 0; i < 9; i++) {
			scanf("%s", dice[i]);
			for (j = 0; j < 4; j++) dice[i][j] = tr[dice[i][j]];
		}
		memset(f, 0, sizeof(f)), ans = 0;
		combi(0);
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1836
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll a; cin >> a;
  string s; cin >> s;

  ll b = (s[0] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0');
  cout << a * b / 100 << endl;

  return (0);
}


Measured memory_bytes: 3576
class UnionFind():
  def __init__(self,size):
    self.table=[-1for _ in range(size)]
  def root(self,x):
    while self.table[x]>=0:
      x=self.table[x]
    return x
  def unite(self,x,y):
    s1=self.root(x)
    s2=self.root(y)
    if s1!=s2:
      if self.table[s1]!=self.table[s2]:
        if self.table[s1]<self.table[s2]:
          self.table[s2]=s1
        else:
          self.table[s1]=s2
      else:
        self.table[s1]-=1
        self.table[s2]=s1
    return
  def same(self,x,y):
    return self.root(x)==self.root(y)
I=lambda:list(map(int,input().split()))
n,m=I()
p=I()
u=UnionFind(n)
for _ in range(m):
  a,b=I()
  u.unite(a-1,b-1)
print(sum(u.same(i,j-1)for i,j in zip(range(n),p)))

Measured memory_bytes: 66668
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        int M = sc.nextInt();
        boolean[] s = new boolean[N];
        boolean[] t = new boolean[N];
        for (int i = 0; i < M; i++) {
            int A = sc.nextInt() - 1;
            int B = sc.nextInt() - 1;
            if (A == 0) {
                s[B] = true;
            }
            if (B == N - 1) {
                t[A] = true;
            }
        }
        boolean ans = false;
        for (int i = 0; i < N; i++) {
            if(s[i] && t[i]) ans = true;
        }
        System.out.println(ans ? "POSSIBLE" : "IMPOSSIBLE");
    }

}


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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int num  = 0;
  for (int a = 0; a <= A; a++) {
    for ( int b = 0; b <= B; b++) {
      for ( int c = 0; c <= C; c++) {
        int ans = 500*a + 100*b + 50*c;
        if (ans == X)   num++;
      }
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

ll fac[MAX_N], inv[MAX_N], fiv[MAX_N]; //fiv:inv(fac(i))

ll mod_pow(ll a, ll n) {
	if(n == 0) return 1;
	ll res = mod_pow(a, n / 2);
	if(n % 2 == 0) return res * res % mod;
	else return a * res % mod * res % mod;
}

ll invf(ll a) {
	return mod_pow(a, mod - 2);
}

void C_init(int n) {
	fac[0] = fac[1] = 1; inv[1] = 1;
	fiv[0] = fiv[1] = 1;
	rep(i, 2, n + 1) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fiv[i] = fiv[i - 1] * inv[i] % mod;
	}
}

ll C(int a, int b) { //assume a >= b
	if(a < b || a < 0 || b < 0) return 0;
	return fac[a] * fiv[b] % mod * fiv[a - b] % mod;
}

int N;
ll A[MAX_N];
ll E[MAX_N];

void solve() {
	cin >> N;
	C_init(N);
	rep(i, 0, N) {
		cin >> A[i];
	}
	rep(i, 0, N) {
		ADD(E[0], invf(i + 1));
	}
	rep(i, 0, N - 1) {
		E[i + 1] = (mod + E[i] - invf(N - i) + invf(i + 2)) % mod;
	}
	ll res = 0;
	rep(i, 0, N) {
		ADD(res, E[i] * A[i] % mod);
	}
	cout << res * fac[N] % mod << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 6400
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#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;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e15 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;
const int N = 2e3 + 2;

int dp[N][N], n;
pii Data[N];

int go(int l, int r) {
    if(l > r) return 0;
    int &x = dp[l][r];
    if(x != -1) return x;
    
    int ind = n - (r-l);
    int temp1 = Data[ind].ff * abs(l-Data[ind].ss) + go(l+1, r);
    int temp2 = Data[ind].ff * abs(r-Data[ind].ss) + go(l, r-1);

    return (x = max(temp1, temp2));
}

void solve() {
    cin >> n;
    memset(dp, -1, sizeof(dp));
    for(int i = 1; i <= n; i++) {
        cin >> Data[i].ff;
        Data[i].ss = i;
    }
    sort(Data+1, Data+n+1);
    reverse(Data+1, Data+n+1);
    cout << go(1,n) << '\n';
}

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

    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //   //freopen("output.txt", "w", stdout);
    // #endif
    int t = 1; // cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }
}


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

using namespace std;
using ll = long long;

int main() {
    ll tmp = 0;
    for(int i = 0;i < 5;i++){
        cin >> tmp;
        if(tmp == 0){
            cout << i + 1 << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,sg[N];
vector<int> e[N];
void dfs(int x,int fa){
	for (int i=0;i<e[x].size();i++){
		int v=e[x][i];
		if (v==fa) continue;
		dfs(v,x);
		sg[x]^=(sg[v]+1);
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1,0);
	puts(sg[1]?"Alice":"Bob");
	return 0;
}

Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];} 
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";} cout<<endl;
#define S second
#define F first
#define SZ(x) (int)x.size()
typedef long long ll;
const int  MOD = 1e9 + 7;
const int  N = 1e5 + 7;

string fun(int a , int b){
    string aa = to_string(a);
    string res = "";
    for(int i = 0 ; i < b ; i++){
        res += aa;
    }
    return res;

}

int main(){
    ios::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
    int a , b;
    cin>>a>>b;
    cout<<(a <= b? fun(a , b) : fun(b , a))<<endl;
    
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  bool found[26] = {};
  int i;
  for (i = 0; i < s.length(); i++) {
    found[s.at(i) - 'a'] = true;
  }
  char res = 'a';
  for (i = 0; i < 26; i++) {
    if (!found[i]) {
      res += i;
      cout << res << endl;
      break;
    }
    if (i == 25) {
      cout << "None" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 512