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

typedef long long ll;
 
const int INF= 1001001001;
const ll LINF= 1e18;

const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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

	int n;
	cin >> n;
	
	ll ans = 0;
	if(n%2) ans = n/2;
	else ans = n/2 - 1;

	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	class Island {

		int[][] map = new int[14][14];
		int num = 2;

		public Island(int[][] map) {
			this.map = map;
		}

		private void label(int row, int column) {
			map[row][column] = num;
			for(int i=0; i<4; i++) {
				if(i==0) {
					if(map[row][column-1] == 1) label(row, column-1);
				} else if(i == 1) {
					if(map[row-1][column] == 1) label(row-1, column);
				} else if(i == 2) {
					if(map[row][column+1] == 1) label(row, column+1);
				} else if(i == 3) {
					if(map[row+1][column] == 1) label(row+1, column);
				}
			}
		}

		public int count() {
			for(int i=1; i<13; i++) {
				for(int j=1; j<13; j++) {
					if(map[i][j] == 1) {
						num++;
						label(i, j);
					}
				}
			}
			return num-2;
		}

	}


	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(sc.hasNext()) {

			int[][] map = new int[14][14];

			// 外を埋める
			for(int i=0; i<14; i++) {
				map[0][i] = 0;
				map[13][i] = 0;
				map[i][0] = 0;
				map[i][13] = 0;
			}

			for(int i=1; i<13; i++) {
				String line = sc.next();
				for(int j=1; j<13; j++) {
					map[i][j] = Integer.parseInt(line.split("")[j-1]);
				}
			}

			Island island = new Main().new Island(map);
			System.out.println(island.count());
		}

		sc.close();


	}
}



Measured memory_bytes: 30568
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template<typename T> 
struct BIT{
  int n;
  vector<T> bit;
  //1-indexed
  BIT():n(-1){}
  BIT(int n_,T d):n(n_),bit(n_+1,d){}
  
  T sum(int i){
    T s=bit[0];
    for(int x=i;x>0;x-=(x&-x))
      s+=bit[x];
    return s;
  }
  void add(int i,T a){
    if(i==0) return;
    for(int x=i;x<=n;x+=(x&-x))
      bit[x]+=a;
  }
  
  int lower_bound(int w){
    if(w<=0) return 0;
    int x=0,r=1;
    while(r<n) r<<=1;
    for(int k=r;k>0;k>>=1){
      if(x+k<=n&&bit[x+k]<w){
	w-=bit[x+k];
	x+=k;
      }
    }
    return x+1;
  }
  
  T sum0(int i){
    return sum(i+1);
  }
  void add0(int i,T a){
    add(i+1,a);
  }

  T query(int l,int r){
    return sum(r-1)-sum(l-1);
  }

  T query0(int l,int r){
    return sum(r)-sum(l);
  }
};
//END CUT HERE

signed AOJ_DSL2B(){
  int n,q;
  cin>>n>>q;
  BIT<Int> bit(n+100,0);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c) cout<<bit.query(x,y+1)<<endl;
    else bit.add(x,y);
  }
  return 0;
}
/*
  verified on 2018/05/18
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B&lang=jp
*/

// lower_bound
signed ARC033_C(){
  int q;
  cin>>q;
  BIT<int> bit(2e5,0);
  while(q--){
    int t,x;
    cin>>t>>x;
    if(t==1) bit.add(x,1);
    if(t==2){
      int k=bit.lower_bound(x);
      bit.add(k,-1);
      cout<<k<<endl;
    }
  }
  return 0;
}
/*
  verified on 2017/12/31
  https://beta.atcoder.jp/contests/arc033/tasks/arc033_3
*/

signed main(){
  AOJ_DSL2B();
  //ARC033_C();
  return 0;
}



Measured memory_bytes: 3540
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
 
using namespace std;
 
#define f first
#define s second
#define pb push_back
#define pp pop_back
#define mp make_pair
#define ll long long
#define ld double
#define ull unsigned long long
#define PI pair < int, int > 
#define minus asfasdfj
 
const int N = 5e5 + 123;
const int M = 1e5 + 123;
const ld Pi = acos(-1);
const ll Inf = 1e18;
const int inf = 1e9;
int mod = 1e9 + 7;
const ld eps = 1e-12;
const int Sz = 350;
 
void add(int &a, int b) {
  a += b;
  if (a >= mod) a -= mod;
}
int mult(int a, int b) {
  return 1ll * a * b % mod;
}
int sum(int a, int b) {
  add(a, b);
  return a;
}
 
int n;
vector < int > g[N];
int deg[N];
queue < int > q;
bool used[N];

void dfs(int v, int p = -1) {
  for (auto to : g[v]) {
    if (to != p) {
      dfs(to, v);
      if (!used[to]) {
        if (used[v]) {
          cout << "First\n";
          exit(0);
        }
        used[to] = used[v] = 1;
      }
    }
  }
}

int main() {
  #ifdef wws
    freopen("in", "r", stdin);
  //  freopen("out", "w", stdout); 
  #endif 
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (int i = 1, u, v;i < n;i++) {
    cin >> u >> v;
    deg[u]++;
    deg[v]++;
    g[v].pb(u);
    g[u].pb(v);
  }
  dfs(1);
  if (!used[1]) cout << "First\n";
  else cout << "Second\n";
  return 0;
}


Measured memory_bytes: 16128
#include <stdio.h>
#include <string.h>
int main()
{   char s[100];
    scanf("%s",s);
    int l=strlen(s);
    for(int i=0;i<l/2;i++){
        if(s[i]!=s[l-i-1]){
            printf("No");
            return 0;
        }
    }
    for(int i=0;i<l/4;i++){
        if(s[i]!=s[l/2-i-1]){
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include <numeric>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
if(a+b==c)
cout<<"Yes"<<endl;
else if(c+a==b)
cout<<"Yes"<<endl;
else if(c+b==a)
cout<<"Yes"<<endl;
else 
cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
	static final int INF = 1_000_000_000; // 10^9
	private static int N;
    private static String A, B;
    private static int rank = 0;
	private static Map<String, Integer> mp = new HashMap<>();  
	private static void permutation(String s, int len) {
        if(len == N) {
            mp.put(s, rank++);
        } else {
            for(int i = 1;i <= N;i++) {
                if(!s.contains(Integer.toString(i))) {
                    permutation(s + Integer.toString(i), len+1);
                }
            }
        }
    }
    public static void main(String[] args) throws Exception {
		Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();scanner.nextLine();
        A = scanner.nextLine().replaceAll(" ", "");
        B = scanner.nextLine().replaceAll(" ", "");

		permutation("", 0);
        System.out.println(Math.abs(mp.get(A) - mp.get(B)));
		
	}
	
	
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

int main() {
    int n,ma,mb;
    scanf("%d%d%d", &n, &ma, &mb);
    int dp[401][401];
    memset(dp,-1,sizeof(dp));
    dp[0][0]=0;
    
    int a[n], b[n], c[n];
    for (int i=0; i<n; i++) scanf("%d%d%d", &a[i], &b[i], &c[i]);
    for (int i=0; i<n; i++) {
        for (int j=400-a[i]; j>=0; j--) {
            for (int k=400-b[i]; k>=0; k--) {
                if (dp[j][k]==-1) continue;
                if (dp[j+a[i]][k+b[i]]==-1) dp[j+a[i]][k+b[i]]=dp[j][k]+c[i];
                else dp[j+a[i]][k+b[i]]=min(dp[j][k]+c[i],dp[j+a[i]][k+b[i]]);
            }
        }
    }
    int ans=-1;
    for (int i=1; i<=400; i++) {
        for (int j=1; j<=400; j++) {
            if (dp[i][j]!=-1 && i*mb==j*ma) {
                if (ans==-1) ans=dp[i][j];
                else ans=min(ans,dp[i][j]);
            }
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 896
N, X = map(int, input().split())
L = list(map(int, input().split()))
ans = 0
D = 0
for i in range(N+1):
  if i == 0:
    D = 0
  else:
    D += L[i-1]
  if D <= X:
    ans += 1
  else:
    break

print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		Long a = in.nextLong();
		String op = in.next();
		Long b = in.nextLong();

		if(op.equals("+")) {
			System.out.println(a + b);

		} else {
			System.out.println(a - b);
		}
	}
}

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

public class Main implements Runnable {
	public static void main (String[] args) {new Thread(null, new Main(), "_cf", 1 << 28).start();}

	public void run() {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		System.err.println("");

		char[] str = fs.next().toCharArray();
		int n = str.length;
		boolean[] has = new boolean[n];
		for(int i = 0; i < n-1; i++) {
			has[i] = str[i] == 'R' && str[i+1] == 'L';
			if(has[i]) {
				has[i+1] = true;
			}
		}
		int[] where = new int[n];
		for(int i = 0, last = -1; i < n; i++) {
			if(has[i]) last = i;
			if(str[i] == 'L') where[i] = last;
		}
		for(int i = n-1, last = -1; i >= 0; i--) {
			if(has[i]) last = i;
			if(str[i] == 'R') where[i] = last;
		}
		int[] res = new int[n];
		for(int i = 0; i < n; i++) {
			int dist = Math.abs(i-where[i]);
			if(dist % 2 == 1) {
				if(str[where[i]] == 'L') res[where[i]-1]++;
				else res[where[i]+1]++;
			}
			else {
				res[where[i]]++;
			}
		}
		for(int i = 0; i < n; i++) {
			if(i > 0) out.print(" ");
			out.print(res[i]);
		}
		out.println();
		
		out.close();
	}

	class FastScanner {
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;

		public FastScanner() {
			in = new BufferedInputStream(System.in, BS);
		}

		public FastScanner(String s) {
			try {
				in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
			}
			catch (Exception e) {
				in = new BufferedInputStream(System.in, BS);
			}
		}

		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}                
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}

		public int nextInt() {
			return (int)nextLong();
		}

		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}

		public double nextDouble() {
			double cur = nextLong();
			return c!='.' ? cur:cur+nextLong()/num;
		}

		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
		
		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for(int i = 0; i < n; i++) res[i] = nextInt();
			return res;
		}
		
	}

}

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

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s[] = br.readLine().split(" ");
		int a = Integer.parseInt(s[0]);
		int b = Integer.parseInt(s[1]);
		int waru1 = a / b;
		int amari = a % b;
		double waru2 = (double) a / (double) b;
		System.out.println(waru1 + " " + amari + " " + String.format("%.16f", waru2));
	}
}


Measured memory_bytes: 24916
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, A[int(2e5+5)];
int ans[int(2e5+5)], DP[int(2e5+5)];
vector <int> Graph[int(2e5+5)];

int DFS(int node){
  int L = 0, R = N;
  while (R - L > 1){
    int Mid = (L + R) / 2;
    if (DP[Mid] < A[node]) L = Mid;
    else R = Mid;
  }
  int Before = DP[R];
  DP[R] = A[node];
  ans[node] = lower_bound(DP, DP + N + 1, 1e9 + 1) - (DP + 1);

  for (int i = 0; i < Graph[node].size(); i++){
    int next = Graph[node][i];
    if (ans[next] > 0) continue;
    DFS(next);
  }
  DP[R] = Before;
  return 0;
}

int main(){
  scanf("%d", &N);
  fill(DP + 1, DP + N + 2, 2e9);
  for (int i = 1; i <= N; i++) scanf("%d", A + i);
  for (int i = 0; i < N - 1; i++){
    int u, v; scanf("%d%d", &u, &v);
    Graph[u].push_back(v);
    Graph[v].push_back(u);
  }
  DFS(1);

  for (int i = 1; i <= N; i++) printf("%d\n", ans[i]);

  return 0;
}


Measured memory_bytes: 28608
#include<cstdio>
#include<array>
using namespace std;
void center(array<int, 100> &a, int x, int y){
  a[y*10+x]++;
}
void left(array<int, 100> &a, int x, int y){
  if(x>0){a[y*10+x-1]++;}
}
void right(array<int, 100> &a, int x, int y){
  if(x<9){a[y*10+x+1]++;}
}
void up(array<int, 100> &a, int x, int y){
  if(y>0){a[(y-1)*10+x]++;}
}
void down(array<int, 100> &a, int x, int y){
  if(y<9){a[(y+1)*10+x]++;}
}
void leftup(array<int, 100> &a, int x, int y){
  if(x>0&&y>0){a[(y-1)*10+x-1]++;}
}
void rightup(array<int, 100> &a, int x, int y){
  if(x<9&&y>0){a[(y-1)*10+x+1]++;}
}
void rightdown(array<int, 100> &a, int x, int y){
  if(x<9&&y<9){a[(y+1)*10+x+1]++;}
}
void leftdown(array<int, 100> &a, int x, int y){
  if(x>0&&y<9){a[(y+1)*10+x-1]++;}
}
void leftleft(array<int, 100> &a, int x, int y){
  if(x>1){a[y*10+x-2]++;}
}
void rightright(array<int, 100> &a, int x, int y){
  if(x<8){a[y*10+x+2]++;}
}
void upup(array<int, 100> &a, int x, int y){
  if(y>1){a[(y-2)*10+x]++;}
}
void downdown(array<int, 100> &a, int x, int y){
  if(y<8){a[(y+2)*10+x]++;}
}

void small(array<int, 100> &a,int x,int y){
  center(a,x,y);
  left(a,x,y);
  right(a,x,y);
  up(a,x,y);
  down(a,x,y);
}
void med(array<int, 100> &a,int x,int y){
  small(a,x,y);
  leftup(a,x,y);
  rightup(a,x,y);
  rightdown(a,x,y);
  leftdown(a,x,y);
}
void large(array<int, 100> &a,int x,int y){
  med(a,x,y);
  leftleft(a,x,y);
  rightright(a,x,y);
  upup(a,x,y);
  downdown(a,x,y);
}

int main(){
  array<int, 100> a{};
  int x,y,size;
  while(scanf("%d,%d,%d",&x,&y,&size)>0){
    switch(size){
    case 1:small(a,x,y);break;
    case 2:med(a,x,y);break;
    case 3:large(a,x,y);break;
    }
  }
  int zero=0,max=0;
  for(int i=0;i<100;i++){
    if(max<a[i]) max=a[i];
    if(a[i]==0) zero++;
  }
  printf("%d\n%d\n",zero,max);
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
#define pw(x) (1LL << (x))
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl

using namespace std;
typedef long long ll;
typedef double dbl;
const int INF = 1.01e9;

int fast(vector<int> a) {
    int n = a.size();

    vector<int> b(n);
    for (int i = 0; i < n; i++) b[a[i]] = i;

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int j = i;
        while (j < n - 1 && b[j + 1] > b[j]) j++;

        ans = max(ans, j - i + 1);
        i = j;
    }
    ans = n - ans;

    return ans;
}

int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif

    int n;
    while (cin >> n) {
        vector<int> a(n);
        for (int i = 0; i < n; i++) scanf("%d", &a[i]), a[i]--;

        printf("%d\n", fast(a));
    }

#ifdef HOME
    cerr << "time = " << (clock() * 1. / CLOCKS_PER_SEC) << "\n";
#endif
    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include<string>
#include <algorithm>
#include<math.h>
#include<queue>
#include<stack>

typedef long long ll;

#define veci            vector<int>
#define vecs            vector<string>

#define vecpii          vector<pair<int,int>>
#define vecpis          vector<pair<int,string>>
#define vecpss          vector<pair<string,string>>
#define mkp             make_pair

#define vecvi(vv,n,m,l) vector<vector<int>> vv(n,veci(m,l))
                                                     // lで初期化
#define vecvs           vector<vector<string>>

using namespace std;

int main()
{
 long long int a, b, c, k;
 cin >> a >> b >> c >> k;
 long long int ans = 0;

 if (k <= a) {
   cout << k;
 } else {
   ans += a;
   k -= a;

   if (k <= b) {
     cout << ans;
   } else {
     k -= b;
     ans -= k;
     cout << ans;
   }
 }

 
  return (0);
}

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

int dp[105][200005];

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a[105][2];
    int n,w;
    cin>>n>>w;
    for(int i=1;i<=n;i++)
        cin>>a[i][0]>>a[i][1];
    for(int i=0;i<=100;i++)
        for(int j=0;j<=100000;j++)
            dp[i][j]=1e15;
    dp[0][0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=100000;j++)
            dp[i][j]=dp[i-1][j];
        for(int j=0;j<=100000;j++)
            dp[i][j+ a[i][1]]=min(dp[i][j+a[i][1]],dp[i-1][j] + a[i][0]);
    }
    int ans=0;
    for(int i=0;i<=100000;i++)
        if(dp[n][i]<=w)
            ans=i;

    cout<<ans;
} 

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

const int A_MAX = 1000000;
bool flag[A_MAX + 1];

int main() {
    int N;
    std::cin >> N;

    int A[N];
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
    }
    std::sort(A, A + N);

    int ans = 0;
    for (int i = 0; i < N; ++i) {
        int cur = A[i];
        if (flag[cur] == true) {
            continue;
        }

        if ((i < (N - 1) && A[i+1] == A[i]) == false) {
            ++ans;
        }

        while (cur <= A_MAX) {
            flag[cur] = true;
            cur += A[i]; 
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 5404
n,k=[int(x) for x in input().split()]
p=[(int(x)-1) for x in input().split()]
alp=[0 for _ in range(n)]
a=[0]
i=0
alp[0]=1
while alp[p[i]]==0:
  a.append(p[i])
  alp[p[i]]=1
  i=p[i]
l=a.index(p[i])
if k<=l: print(1+a[k])
else: print(1+a[l+(k-l)%(len(a)-l)])

Measured memory_bytes: 107480
s=list(input())
a=0 #aを見つけたか
ans=1
z_index=0
for i in range(len(s)):
    if a==0 and s[i]=="A":
        ans-=i
        a=1
        #print(i)
    if a==1 and s[i]=="Z":
        z_index=i
        #print(i)
print(ans+z_index)

Measured memory_bytes: 4840
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

#n = int(input())
#n,a = [int(i) for i in readline().split()]
a,b,q = [int(i) for i in readline().split()]
s = [-10**12]+[int(readline()) for i in range(a)]+[10**12]
t = [-10**12]+[int(readline()) for i in range(b)]+[10**12]

xx = [int(readline()) for i in range(q)]

from bisect import *
for x in xx:
    ans = 10**11
    i = bisect_left(s,x)
    j = bisect_left(t,x)
    d1 = max(s[i],t[j])-x
    d2 = x- min(s[i-1],t[j-1])

    d3 = (x-s[i-1]) + (t[j]-x) + min((x-s[i-1]), (t[j]-x))
    d4 = (x-t[j-1]) + (s[i]-x) + min((x-t[j-1]), (s[i]-x))

#    print(ans,d1,d2,d3,d4)
    ans = min(ans,d1,d2,d3,d4)
    print(ans)





Measured memory_bytes: 137964
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

int main()
{
	int a;
	std::string s;

	std::cin >> a >> s;

	if (a >= 3200)
		std::cout << s << "\n";
	else
		std::cout << "red\n";
}


Measured memory_bytes: 764
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int alice=0, bob=0, n;

    cin >> n;
    if(n<1 || n>100)return -1;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i]<1 || a[i]>100)return -1;
    }
    sort(a,a+n,greater<>());
    for(int i=0; i<n; i++){
        if(i%2 == 0 ){
            alice = alice + a[i];
        }
        else{
            bob = bob + a[i];
        }
    }
    cout<<alice -bob;

    return 0;
    }


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class E
{
	public static void Main()
	{
		int N = GetInt();
		int M = GetInt();
		int[] S = Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
		int[] T = Enumerable.Range(0, M).Select(_ => GetInt()).ToArray();

		long mod = (long)1e9 + 7;
		long[,] dp = new long[N + 1, M + 1];
		long[,] csum = new long[N + 1, M + 1];
		for(int i = 0; i < N; i++)
		{
			for(int j = 0; j < M; j++)
			{
				dp[i + 1, j + 1] = (S[i] == T[j]) ? (csum[i, j] + 1) % mod : 0;
				csum[i + 1, j + 1] = (mod + csum[i, j + 1] + csum[i + 1, j] - csum[i, j] + dp[i + 1, j + 1]) % mod;
			}
		}

		Console.WriteLine((csum[N, M] + 1) % mod);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 75224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc153_b
{
  class Program
  {
    static void Main(string[] args)
    {
      var H = CIn.ReadInt();
      var N = CIn.ReadInt();
      var A = CIn.ReadIntArray(N);

      Console.WriteLine(A.Sum() >= H ? "Yes" : "No");
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(long h, long w)
    {
      var array = new char[h, w];
      for (var i = 0L; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0L; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


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

namespace ConsoleApplication58
{
    class Program
    {
        static void Main()
        {
            double a, b, c;a = b = c = 0;
            while (true)
            {
                string d = Console.ReadLine();
                if (d == null) break;
                int[] e = d.Split(',').Select(int.Parse).ToArray();
                a += e[0] * e[1];
                b += e[1];
                c++;
            }
            Console.WriteLine(a);
            Console.WriteLine("{0,0:F0}",b/c);
        }
    }
}

Measured memory_bytes: 9532
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n, ll mod){
    ll res = 1;
    while(n){
        if(n & 1){
            (res *= a) %= mod;
        }else{
            (a *= a) %= mod;
        }
        n >>= 1;
    }
    return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    vector<ll> r(n+1), g(n+1), b(n+1);
    r[0] = 0;
    g[0] = 0;
    b[0] = 0;
    for(ll i=1;i<=n;++i){
        if(s[i-1] == 'R'){
            r[i] = r[i-1] + 1;
            g[i] = g[i-1];
            b[i] = b[i-1];
        }else if(s[i-1] == 'G'){
            r[i] = r[i-1];
            g[i] = g[i-1] + 1;
            b[i] = b[i-1];
        }else if(s[i-1] == 'B'){
            r[i] = r[i-1];
            g[i] = g[i-1];
            b[i] = b[i-1] + 1;
        }
        //cout<<r[i]<<' '<<g[i]<<' '<<b[i]<<endl;
    }

    ll ans = 0;
    for(ll i=0;i<n-2;++i){
        for(ll j=i+2;j<n;++j){
            ll sum = 0;
            if((s[i] == 'R' and s[j] == 'G') or (s[i] == 'G' and s[j] == 'R')){
                sum = b[j+1] - b[i+1];
                if((j+i) % 2 == 0 and s[(j+i)/2] == 'B'){
                    sum--;
                }
            }else if((s[i] == 'R' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'R')){
                sum = g[j+1] - g[i+1];
                if((j+i) % 2 == 0 and s[(j+i)/2] == 'G'){
                    sum--;
                }
            }else if((s[i] == 'G' and s[j] == 'B') or (s[i] == 'B' and s[j] == 'G')){
                sum = r[j+1] - r[i+1];
                if((j+i) % 2 == 0 and s[(j+i)/2] == 'R'){
                    sum--;
                }
            }
            ans += sum;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3680
N, A, B, C, D = map(int, input().split())

def solve() :
    if N % 2 == 0 :
        l = (N // 2) * C - (N // 2) * D
        r = (N // 2) * D - (N // 2) * C
        for _ in range(N // 2 + 1) :
            if A + l <= B <= A + r :
                return 'YES'
            if A - r <= B <= A - l :
                return 'YES'
            l += C + D
            r += C + D
            
    else :
        l = (N // 2 + 1) * C - (N // 2) * D
        r = (N // 2 + 1) * D - (N // 2) * C
        for _ in range(N // 2 + 1) :
            if A + l <= B <= A + r :
                return 'YES'
            if A - r <= B <= A - l :
                return 'YES'
            l += C + D
            r += C + D
            
    return 'NO'
    
N -= 1    
print(solve())

Measured memory_bytes: 38768
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(A: int, B: int):
    print(max(A-2*B, 0))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


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

using namespace std;

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

int main() {
	
	int a, b;
	cin >> a >> b;
	int sub = a - b;
	int flag = 1;
	vector<string>A(a);
	vector<string>B(b);

	rep(i, 0, a) {
		cin >> A[i];
	}
	rep(i, 0, b) {
		cin >> B[i];
	}

	for (int i = 0; i <= sub; i++) {
		for (int j = 0; j <= sub; j++) {
			if (A[i][j] == B[0][0]) {
				int cnt = 0;
				for (int k = 0; k < b; k++) {
					for (int l = 0; l < b; l++) {
						if (A[i + k][j + l] != B[k][l])cnt++;
					}
				}
				if (cnt == 0)flag = 0;
			}
		}
	}

	if (flag == 0)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
s = [input()for i in range(n)]
c0 = 0
c1 = 0
c2 = 0
c3 = 0
for i in range(n):
    if s[i] == 'AC':
        c0 += 1
    elif s[i] == 'WA':
        c1 += 1
    elif s[i] == 'TLE':
        c2 += 1
    else:
        c3 += 1
print(f'AC x {c0}\nWA x {c1}\nTLE x {c2}\nRE x {c3}')



Measured memory_bytes: 16200
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{

    internal class Solution
    {
        public int A, B, C, X;

        public void Run()
        {
            A = Input.ReadInt();
            B = Input.ReadInt();
            C = Input.ReadInt();
            X = Input.ReadInt();

            int ret = 0;
            for (int a = 0; a <= A; a++)
            for (int b = 0; b <= B; b++)
            {
                int x = X - 500 * a - 100 * b;
                if (x >= 0 && x % 50 == 0 && C >= x / 50 ) ret++;
            }
            Console.WriteLine(ret);
        }

    }

    internal static class Input
    {
        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13140
#pragma GCC optimize("O3", "unroll-loops")
#include <bits/stdc++.h>

using namespace std;
const int maxn = 2000 + 10;
char mp[maxn][maxn];
int h, w, ans = 0, tp[maxn][maxn], lf[maxn][maxn], bt[maxn][maxn], rt[maxn][maxn];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> h >> w;
	for (int i = 1; i <= h; i++)
		for (int j = 1; j <= w; j++) {
			cin >> mp[i][j];
			if (mp[i][j] == '.')
				tp[i][j] = tp[i - 1][j] + 1, lf[i][j] = lf[i][j - 1] + 1;
			else
				tp[i][j] = lf[i][j] = 0;
		}
	for (int i = h; i > 0; i--)
		for (int j = w; j > 0; j--) {
			if (mp[i][j] == '.')
				bt[i][j] = bt[i + 1][j] + 1, rt[i][j] = rt[i][j + 1] + 1, ans = max(ans, tp[i - 1][j] + lf[i][j - 1] + bt[i + 1][j] + rt[i][j + 1] + 1);
			else
				bt[i][j] = rt[i][j] = 0;
		}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 67328
n, m= map(int, (input().split()))
a = list(map(int, input().split()))
count = 0
total = 0
for i in a:
  total += i
for j in a:
  if not (j / total < 1 / (4 * m)):
    count += 1
if count >= m:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	int64 nn, ans = 1000, tmp;
	cin >> nn;
	for(int64 ii = 1;ii <= sqrt(nn) + 1;ii++)
	{
		if(nn % ii == 0)
		{
			tmp = max((int64)((log10(ii)) + 1), (int64)((log10(nn / ii)) + 1));
			ans = min(ans, tmp);
		}
	}
	cout << ans << endl;;
	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>
#include <map>
#include <set>
using namespace std;

int main() {
    int N;
    while(cin >> N, N != 0) {
        vector<set<int>> v(N);
        for(int i=0; i<N; ++i) {
            int M;
            cin >> M;
            for(int j=0; j<M; ++j) {
                int p;
                cin >> p;
                v[i].insert(p);
            }
        }
        int K;
        set<int> s2;
        cin >> K;
        for(int i=0; i<K; ++i) {
            int t;
            cin >> t;
            s2.insert(t);
        }
        int ret=0;
        int id=0;
        for(int i=0; i<v.size(); ++i) {
            if(includes(v[i].begin(), v[i].end(), s2.begin(), s2.end())) {
                ret++;
                id = i+1;
            }
        }
        if(ret != 1) {
            cout << -1 << endl;
        } else {
            cout << id << endl;
        }
    }
}

Measured memory_bytes: 3472
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N; 
	cin >> N; 
	pair<int, int> X[510] = {}; 
	int Y[510] = {}; 
	int A[250010] = {}; // 解答用の配列
	for(int i = 0; i < N; i++){
		cin >> X[i].first; 
		Y[i] = X[i].first; 
		X[i].second = i+1; 
		A[X[i].first-1] = i+1; 
	}
	sort(X, X+N); 
	vector<int> L = {}; // 指定箇所よりも左を貪欲に
	vector<int> R = {}; // 指定箇所よりも右を貪欲に
	for(int i = 0; i < N; i++){
		for(int j = 0; j < X[i].second-1; j++){
			L.push_back(X[i].second); 
		}
		for(int j = 0; j < N-X[i].second; j++){
			R.push_back(X[i].second); 
		}
	}
	int l = 0, r = 0; 
	for(int i = 0; i < N * N; i++){
		if(A[i]) continue; 
		else if(l < N * (N - 1) / 2){
			A[i] = L.at(l); 
			l++; 
		}
		else{
			A[i] = R.at(r); 
			r++;
		}
	}
	vector<int> B[510] = {}; // 最後に十分性の確認
	for(int i = 0; i < N * N; i++){
		B[A[i]].push_back(i+1); 
	}
	string ans = "Yes"; 
	for(int i = 1; i <= N; i++){
		if(B[i].at(i-1) != Y[i-1]) ans = "No"; 
	}
	cout << ans << endl; 
	if(ans == "Yes"){
		for(int i = 0; i < N * N; i++){
			cout << A[i] << " "; 
		}
		cout << endl; 
	}
}

Measured memory_bytes: 4188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    string s;
    cin >> s;
    vector<int> a;
    rep(i, sz(s)) {
        a.eb(s[i] - '0');
    }
    rep(i, 1 << 3) {
        int sum = a[0];
        string ans; ans += s[0];
        rep(j, 3) {
            if (i & (1 << j)) { sum += a[j + 1]; ans += '+'; }
            else { sum -= a[j + 1]; ans += '-'; }
            ans += s[j + 1];
        }
        ans += "=7";
        // cout << bitset<3>(i) << " " << sum << endl;
        if (sum == 7) {
            cout << ans << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
package main

import(
  "fmt"
)

func main(){

    var n , a , b , sum int
    fmt.Scan( &n , &a , &b )

    for i := 1 ; i <= n ; i++ {
      man := i / 10000
      t := i % 10000

      sen := t / 1000
      t = t % 1000

      hyaku := t / 100
      t = t % 100

      juu := t / 10

      ichi := t % 10

      temp := man + sen + hyaku + juu + ichi
      if a <= temp && temp <= b {
        sum += i
      }
    }

    fmt.Print( sum )

}


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

int gcd(int a, int b, vector<vector<int>> &GCD){
  if(GCD.at(a).at(b)!=0) return GCD.at(a).at(b);
  if(a < b) return gcd(b, a, GCD);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  GCD.at(a).at(b) = b;
  return b;
}

int main() {
  int N;
  cin >> N;
  vector<vector<int>> GCD(N+1,vector<int>(N+1));
  int ans = 0;
  rep(i,N){
    rep(j,N){
      rep(k,N){
        ans += gcd(gcd(i+1,j+1,GCD),k+1,GCD);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3792
#include <stdio.h>
#include <math.h>
#include <limits.h>
 
int r[100], c[100];
int M[100][100];
int Matrix(int,int);   
 
int main()
{
  int N;
  int i, j;
   
  scanf("%d", &N);
  for (i = 0; i < N; i++){
    scanf("%d %d", &r[i], &c[i]);
  }
  for(i = 0; i < 100; i++){
    for(j = 0; j < 100; j++){
      M[i][j] = -1;
    }
  }
  printf("%d\n", Matrix(0, N - 1));
  return 0;
}

int Matrix(int left, int right)
{
  int res, i;
 
  if (M[left][right] >= 0){
    return M[left][right];
  }
  if (left == right){
    return 0;
  }
  res = INT_MAX;
  for (i = left; i < right; i++){
    res = fmin(res, Matrix(left, i) + Matrix(i + 1, right) + r[left] * c[i] * c[right]);
  }
  M[left][right] = res;
  return M[left][right];
}
 

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

typedef long long ll;

#define PB push_back
#define MP make_pair

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    int x, n; cin >> x >> n;
    unordered_set<int> p;
    for (int i = 0; i < n; ++i) {
        int pi; cin >> pi;
        p.insert(pi);
    }
    if (n == 0) cout << x << "\n";
    else {
        int difference = 0;
        bool ok = false;
        int ans;
        while (!ok) {
            int low = x - difference;
            int high = x + difference;
            if (p.count(low) == 0 && p.count(high) == 0) {
                ans = low;
                break;
            }
            else if (p.count(low) == 0) {
                ans = low;
                break;
            }
            else if (p.count(high) == 0) {
                ans = high;
                break;
            }
            else difference++;
        }
        cout << ans << "\n";
    }
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/



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

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans = INT_MAX;
    
    for (int i = 0; i <= max(x, y); i++) {
        ans = min(ans, a * max(x - i, 0) + b * max(y - i, 0) + c * i * 2);
    }
    
    cout << ans << endl;
    return 0;
}

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

int main() {
    int Q;
    cin >> Q;
    for (int q = 0; q < Q; ++q) {
        ll A, B;
        cin >> A >> B;
        if (A >= B) {
            swap(A, B);
        }  // A < B

        ll ok = A, ng = B + 1;
        while (ng - ok > 1) {
            ll mid = (ok + ng) / 2;

            ll m = (mid + A) / 2;
            if (mid == A) --m;
            if (m * (A + mid - m) < A * B) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        cout << ok + A - 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
N_str=input()
K=int(input())

#print(N_str)
digit_N=len(N_str)

#dp[i][j][k]
#i:eqflag, j:digit, k:K
#dp=[[[0]*2 for _ in range(digit_N)] for _ in range(K+1)]
dp=[[[0]*(K+1) for _ in range(digit_N)] for _ in range(2)]
dp[0][0][0]=1
dp[0][0][1]=int(N_str[0])-1
dp[1][0][1]=1
#print(dp)

for j in range(1,digit_N):
  digit=int(N_str[j])
  for k in range(K+1):
    if digit==0:
      if k==0:
        dp[0][j][0]=dp[0][j-1][0]
      else:
        dp[0][j][k]=dp[0][j-1][k]+9*dp[0][j-1][k-1]
        dp[1][j][k]=dp[1][j-1][k]
    else:
      if k==0:
        dp[0][j][0]=dp[0][j-1][0]
      else:
        dp[0][j][k]=dp[0][j-1][k]+9*dp[0][j-1][k-1]+dp[1][j-1][k]+(digit-1)*dp[1][j-1][k-1]
        dp[1][j][k]=dp[1][j-1][k-1]
    
#print(dp)
print(dp[0][-1][K]+dp[1][-1][K])

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
#define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    
    ll n,W;
    cin>>n>>W;
    ll w[n+1];
    ll v[n+1];
    for (int i = 1; i<=n; ++i)
    {
        cin>>w[i];
        cin>>v[i];
    }
    ll max_v = n*1010;
    ll dp[n+1][max_v];

    for (int i = 0; i < n+1; ++i)
    {
        for (int j = 0; j < max_v; ++j)
        {
            dp[i][j]=inf;
        }
    }

    for (int i = 0; i < n+1; ++i)
    {
        dp[i][0]=0;
    }

    for (int i = 1; i < n+1; ++i)
    {
        for (int j = 1; j < max_v; ++j)
        {
            dp[i][j]=dp[i-1][j];
            if((j-v[i])>=0){
                dp[i][j] = min(dp[i][j], dp[i-1][j-v[i]]+w[i]);
            }
        }
    }

    ll ans=0;
    for (int i = 0; i<max_v; ++i)
    {
        if(dp[n][i]<=W){
            ans=max(ans, i);
        }
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 80000
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end
a,b = gets.chomp.split
a = a.to_i
b = b.to_f
b = (b*1000).to_i
p (a*b)/1000


Measured memory_bytes: 14432
#include <bits/stdc++.h>
using namespace std;
int arr[200005];
int rep[200005];
int main()
{
    int diff = 0;
    int n,k;
    cin >> n >> k;
    for(int i = 0;i < n;i++)
    {
        scanf("%d",&arr[i]);
        rep[arr[i]]++;
        if(rep[arr[i]] == 1)
            diff++;
    }
    vector<int> minChange;
    for(int i = 0;i < 200001;i++)
    {
        if(rep[i] > 0)
            minChange.push_back(rep[i]);
    }
    sort(minChange.begin(),minChange.end());
    int d = 0;
    for(int i = 0;i < minChange.size() && diff > k;i++)
    {
        d += minChange[i];
        diff--;
    }
    cout << d;
}


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

int main() {
  string s;
  cin>>s;
  int a, b;
  for (int i=0;i<s.size();i++){
    if(s[i]=='A') {
      a=i;
      break;
    }
  }
  for (int i=s.size()-1;i>=0;i--){
    if(s[i]=='Z') {
      b=i;
      break;
    }
  }
  cout<<b-a+1<<endl;
  return 0;
}

Measured memory_bytes: 640
N, M = map(int, input().split())
G = [[0] * N for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[a-1][b-1] = 1
    G[b-1][a-1] = 1

visited = None
def dfs(v):
    visited[v] = True
    for u,e in enumerate(G[v]):
        if e == 0 or visited[u] == True: continue
        dfs(u)

ans = []
for i in range(N):
    for j in range(i+1, N):
        if G[i][j] is 0:continue
        G[i][j] = G[j][i] = 0
        visited = [False] * N
        dfs(0)
        G[i][j] = G[j][i] = 1
        if not all(visited):ans.append(i)

print(len(ans))

Measured memory_bytes: 3064