akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
using namespace std;

int main() {
    long mod = 1e9+7;
    long N, M;
    cin>>N>>M;
    map<long, int> primemap;
    vector<long> primearr;
    long maxnum = 0;
    for(long i=2;i*i<=M;++i){
        while(M%i==0){
            if(primemap[i]==0) primearr.push_back(i);
            primemap[i]++;
            M /= i;
        }
    }
    if(M>1){
        primearr.push_back(M);
        primemap[M]++;
    }
    for(int i=0;i<primearr.size();++i){
        if(maxnum < primemap[primearr[i]]) maxnum = primemap[primearr[i]];
    }
    long shita = 1;
    for(long i=1;i<=N-1;++i){
        shita *= i;
        shita %= mod;
    }
    long shita1 = 1;
    long tmpshita;
    long tmp;
    long p = mod - 2;
    while(p>0){
        tmp = 1;
        tmpshita = shita;
        while(tmp*2<=p){
            tmp *= 2;
            tmpshita *= tmpshita % mod;
            tmpshita %= mod;
        }
        p -= tmp;
        shita1 *= tmpshita;
        shita1 %= mod;
    }
    long ans = 1;
    long ue;
    for(int i=0;i<primearr.size();++i){
        ue = 1;
        for(int j=0;j<N-1;++j){
            ue *= (N-1+primemap[primearr[i]]-j);
            ue %= mod;
        }
        ans *= (ue * shita1) % mod;
        ans %= mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
n = input()
N = int(n)

list1 = input().split(" ")
Numbers = list1[:N]

count = 0
for i in range(0, N):
    if (i+1) % 2 != 0:
        if int(Numbers[i]) % 2 != 0:
            count += 1
    else:
        continue
print(count)


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

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

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

  int con = 0;
  for (int i = gcd(A, B); i > 0; i--) {
    if (A % i == 0 && B % i == 0) con++;
    if (con == K) {
      cout << i << endl;
      return 0;
    }
  }
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	string S, T; cin >> S >> T;
	vector<int> s(26, 0), t(26, 0);
	rep(i, S.size()) {
		s[S[i] - 'a']++;
		t[T[i] - 'a']++;
	}

	sort(all(s)); sort(all(t));
	rep(i, 26) {
		if (s[i] != t[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 776
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	counter := make([]int, n)
	for i := 0; i < n; i++ {
		a := getNextInt(scanner) - 1
		counter[a]++
	}
	sort.Ints(counter)
	ss := make([]int, n+1)
	for i := 0; i < n; i++ {
		ss[i+1] = ss[i] + counter[i]
	}

	ans := n
	for k := 1; k <= n; k++ {
		for ans > 0 {
			ll := -1
			rr := n
			for ll+1 < rr {
				mm := (ll + rr) >> 1
				if counter[mm] < ans {
					ll = mm
					continue
				}
				rr = mm
			}
			if (n-rr)*ans+ss[rr] < ans*k {
				ans--
				continue
			}
			break
		}
		fmt.Println(ans)
	}
	writer.Flush()
}


Measured memory_bytes: 8576
n=int(input())
p=list(map(int,input().split()))
cnt=0
han=p[0]
for i in range(n):
    if p[i]>han:
        cnt+=1
        if p[i]<han:
            han=p[i]
    else:
        han=p[i]
ans=n-cnt
print(ans)

Measured memory_bytes: 24872
MOD = 10**9 + 7


def fact(n, MOD):
    res = 1
    for i in range(1, n + 1):
        res *= i
        res %= MOD
    return res


N, M = map(int, input().split())
ans = 0

if abs(N - M) < 2:
    ans += fact(N, MOD) * fact(M, MOD) % MOD
    if N == M:
        ans *= 2
        ans %= MOD
print(ans)

Measured memory_bytes: 62872
#include<bits/stdc++.h>
using namespace std;
int main(){
  long int H,W;
  cin>>H>>W;
  if(H==1||W==1) cout<<1<<endl;
  else if(H*W%2==0) cout<<H*W/2<<endl;
    else cout<<H*W/2+1<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <set>
using namespace std;

struct Edge;
typedef vector<vector<Edge> > G;

const int INF = (1<<28);

struct Edge {
  int to, cost;
};

struct State {
  int v, cost;
  bool operator < (const State &s) const {
    return cost > s.cost;
  }
};

void addEdge(int a, int b, int c, G *_g) {
  G &g = *_g;
  if(g.size() < max(a,b)+1) g.resize(max(a,b)+1);
  g[a].push_back((Edge){b, c});
  g[b].push_back((Edge){a, c});
}

vector<int> dijkstra(const G &g, int v) {
  vector<int> res(g.size(), INF);
  priority_queue<State> que;
  State s = {v, 0};
  res[v] = 0;
  que.push(s);
  while(!que.empty()) {
    s = que.top();
    que.pop();
    if(s.cost > res[s.v]) continue;
    for(int i = 0; i < g[s.v].size(); ++i) {
      const Edge &e = g[s.v][i];
      int ncost = s.cost + e.cost;
      if(ncost >= res[e.to]) continue;
      res[e.to] = ncost;
      que.push((State){e.to, ncost});
    }
  }
  return res;
}

void wf(vector<vector<int> > *_v) {
  vector<vector<int> > &v = *_v;
  int n = v.size();
  for(int k = 0; k < n; ++k) {
    for(int i = 0; i < v.size(); ++i) {
      for(int j = 0; j < v.size(); ++j) {
        v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
      }
    }
  }
}

template <class T>
class Convert {
private:
  map<T,int> id;
public:
  int operator [](const T &s) {
    if(!id.count(s)) {
      id[s] = id.size()-1;
    }
    return id[s];
  }

  int count(const T &s) {
    return id.count(s);
  }

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

int main() {
  while(1) {
    int N, M, cap, src, dest;
    cin >> N >> M >> cap;
    if(N == 0 && M == 0 && cap == 0) break;

    Convert<string> conv;
    G g;
    {
      string s, d;
      cin >> s >> d;
      src = conv[s];
      dest = conv[d];
    }

    for(int i = 0; i < N; ++i) {
      string a, b;
      int d;
      cin >> a >> b >> d;
      addEdge(conv[a], conv[b], d, &g);
    }

    Convert<int> conv2;
    conv2[src];
    conv2[dest];
    for(int i = 0; i < M; ++i) {
      string s;
      cin >> s;
      conv2[conv[s]];
    }

    vector<vector<int> > T(conv2.size());
    for(int i = 0; i < g.size(); ++i) {
      if(conv2.count(i)) {
        vector<int> v = dijkstra(g, i);
        vector<int> t(conv2.size());
        for(int j = 0; j < v.size(); ++j) {
          if(conv2.count(j)) {
            int &value = t[conv2[j]];
            if(v[j] > cap*10) value = INF;
            else value = v[j];
          }
        }
        T[conv2[i]] = t;
      }
    }

    wf(&T);
    if(T[0][1] == INF) cout << -1 << endl;
    else cout << T[0][1] << endl;
  }
}

Measured memory_bytes: 2404
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(u==s)
    {
        cout<<a-1<<" "<<b<<endl;;
    }
    else
    {
         cout<<a<<" "<<b-1<<endl;;
    }
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
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; }
using Graph = vector<vector<int>>;
signed main(){
  int a,b;
  cin>>a>>b;
  vector<int> c(a);
  rep(i,a)
    c[i]=b+i;
  int d=1e9,e=0;
  rep(i,a){
  if(d>abs(c[i])){
    d=abs(c[i]);
    e=c[i];
      }
  }
  int k=0;
  rep(i,a)
    k+=c[i];
  cout<<k-e<<endl;
  }

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

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

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

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//MOD
//--------------------------------------------
#define MUL(a,b) (((a) % MOD) * ((b) % MOD)) % MOD

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code
int main(int argc, char const* argv[])
{
	string s;
	cin >> s;
	LL n = s.size();
	VL a(n+1,0), ab(n+1,0), abc(n+1,0);
	LL i = 0;
	LL num = 1;
	while (char c = s[i]) {
		switch (c) {
			case 'A':
				a[i+1] = a[i] + num;
				ab[i+1] = ab[i];
				abc[i+1] = abc[i];
				break;
			case 'B':
				a[i+1] = a[i];
				ab[i+1] = ab[i] + a[i];
				abc[i+1] = abc[i];
				break;
			case 'C':
				a[i+1] = a[i];
				ab[i+1] = ab[i];
				abc[i+1] = abc[i] + ab[i];
				break;
			default:
				a[i+1] = a[i] * 3 + num;
				ab[i+1] = ab[i] * 3 + a[i];
				abc[i+1] = abc[i] * 3 + ab[i];
				num *= 3;
				break;
		}
		a[i+1] %= MOD;
		ab[i+1] %= MOD;
		abc[i+1] %= MOD;
		num %= MOD;
		i++;
	}
	cout << abc[n] << endl;
	return 0;
}



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

int main(void){
int n,x,y,i,j,min,sub;
int ans[2000]={};
(void)scanf("%d %d %d",&n,&x,&y);
for(i=1;i<n;i++){
    for(j=i+1;j<=n;j++){
        min=j-i;
        sub=abs(x-i)+abs(y-j)+1;
        if(sub<min) min=sub;
        ans[min]++;
    }
}
for(i=1;i<n;i++){
printf("%d\n",ans[i]);
}
return 0;
}

Measured memory_bytes: 128
fun main(args: Array<String>) {
    val (N, K, Q) = listOfInt()
    val ans = Array<Int>(N) { Q }
    repeat(Q) { ans[nextInt(-1)] -= 1 }
    ans.forEach { println(if (K - it > 0) "Yes" else "No") }
}
fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }

Measured memory_bytes: 48340
#include<iostream>
using namespace std;
int main(){
  char g;
  double len[11],total=0;
  double train1,train2;
  double a;
  while(1){
    total=0;
  for(int i=0;i<10;i++){
    cin >> len[i] >> g;
    total+=len[i];
  }
  cin >> train1 >> g >> train2;
  if(cin.eof()) break;
  a=total/(train1+train2);
  a*=train1;
  total=0;
  int i=0;
  while(a>total){
    total+=len[i];
    i++;
  }
  cout << i << endl;
  }
}

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

struct node
{
  int parent;
  int num_child;
  bool operator<(const node& rhs)const
  {
    return num_child < rhs.num_child;
  }
};


void solve(int N, std::vector<int> H)
{
    


}
int main(void) {
  int N;
  std::cin >> N;
  std::vector<int> H(N);
  std::priority_queue<node> nodes;
  node tmp_node;
  for(auto i0 = 0; i0 < N; ++i0)
  {
    std::cin >> H[i0];
    if(i0 == 0)
    {
      tmp_node.parent = i0;
      tmp_node.num_child = 0;
    }
    else if(i0 > 0&& 
            H[i0] <= H[tmp_node.parent] && 
            H[i0] <= H[i0-1] )
    {
      tmp_node.num_child++;
    }
    else if(i0 > 0&& H[i0] > H[i0-1])
    {
      nodes.push(tmp_node);
      tmp_node.parent = i0;
      tmp_node.num_child = 0;
    }
    
    if(i0 == N-1)
    {
      nodes.push(tmp_node);
    }
  }
  // std::cerr << "nodes size " << nodes.top().num_child << std::endl;
  // std::cerr << "nodes size " << nodes.top().parent << std::endl;
  std::cout << nodes.top().num_child << std::endl;
  // solve(N,H);
  return 0;
}


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



int main(){
	int N=0,Y=0;
	cin>>N>>Y;
	int p=0,q=0,r=0;
	int endflg =0;
	
	for(int i=0;i<N+1;i++){
		p=i;//1万円札の数

		for(int j=0;j<N-p+1;j++){
			q=j;
			r=N-p-q;
			if(10000*p+5000*q+1000*r==Y){
					
				endflg = 1;
				break;
			}
		}
		if(endflg ==1)break;
	}
	

	if(endflg == 1){
		cout<<p<<" "<<q<<" "<<r;
	}else{
		cout<<-1<<" "<<-1<<" "<<-1;
	}
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    int main() 
	
	{
      int n,m; cin>>n>>m;
      
      if( n==m) 
      {
      	for(int i=0;i<n;i++) cout<<n;
	  }
     
     else 
     {
     	 int mini=min(n,m);
     	 
     	 for( int i=0;i< max(n,m);i++)  cout<<mini;
	 }
        
     
    }

Measured memory_bytes: 3568
import java.util.*;
import java.io.*;
import java.util.function.*;

class Main {
    static Scanner scanner = new Scanner();
    static int mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        long t1 = scanner.nextLong();
        long t2 = scanner.nextLong();
        long a1 = scanner.nextLong() * t1;
        long a2 = scanner.nextLong() * t2;
        long b1 = scanner.nextLong() * t1;
        long b2 = scanner.nextLong() * t2;
        if (b1 > a1) {
            long temp = b1;
            b1 = a1;
            a1 = temp;
            temp = b2;
            b2 = a2;
            a2 = temp;
        }
        long a = b1 - a1;
        long b = b2 - a2;
        long d = a + b;
        if (d == 0) {
            System.out.println("infinity");
        } else if (d <= 0) {
            System.out.println(0);
        } else {
            long ans = (-a + d - 1) / d * 2 - 1;
            if (a % d == 0) {
                ans++;
            }
            System.out.println(ans);
        }
    }

    public static void main(String[]$) {
        try {
            new Main().solve();
            System.out.flush();
        } catch (Throwable t) {
            System.out.flush();
            t.printStackTrace();
        }
    }
}

class System {
    static PrintWriter out = new PrintWriter(java.lang.System.out);

    static void exit() {
        java.lang.System.exit(0);
    }
}

class Scanner {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(java.lang.System.in), 0x10000);
    private StringTokenizer tokenizer;

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

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

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

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}


Measured memory_bytes: 22612
n=int(input())
if n>=400 and n<=599:
    print("8")
elif n>=600 and n<=799:
    print("7")
elif n>=800 and n<=999:
    print("6")
elif n>=1000 and n<=1199:
    print("5")
elif n>=1200 and n<=1399:
    print("4")
elif n>=1400 and n<=1599:
    print("3")
elif n>=1600 and n<=1799:
    print("2")
elif n>=1800 and n<=1999:
    print("1")

Measured memory_bytes: 9120
//#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <climits>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define F first
#define S second
#define OUT(x) cout << x << "\n"
#define int long long
using namespace std;
using point = pair< int,int >;

signed main() {
    int q, h, s, d;
    cin >> q >> h >> s >> d;
    int n;
    cin >> n;

    int price[4];
    price[0] = q;
    price[1] = min(price[0] * 2, h);
    price[2] = min(price[1] * 2, s);
    price[3] = min(price[2] * 2, d);

    OUT(n / 2 * price[3] + n % 2 * price[2]);

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main( int argc, char* argv[] ){
  int a,b,c;
  cin >> a >> b >> c;
  int r = 0;
  int m = max({a,b,c});
  a = m - a;
  b = m - b;
  c = m - c;
  r += (a/2) + (b/2) + (c/2);
  int p = (a%2) + (b%2) + (c%2);
  if( p == 0 ) cout << r << endl;
  if( p == 1 ) cout << (r+2) << endl;
  if( p == 2 ) cout << (r+1) << endl;
  return 0;
}
  


Measured memory_bytes: 256
import sys
# read = sys.stdin.read
# readline = sys.stdin.readline
# readlines = sys.stdin.readlines
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    s = sys.stdin.readline().rstrip()
    print(s.count('1'))



if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
using namespace std;
typedef pair<int,int> P;//Pでpair<-,->を表す。
typedef long long LL; 
LL MOD=1000000007;

int main()
{ 
    int A,B,M;
    cin>>A>>B>>M;
    int a[A];
    int b[B];
    for(int i=0;i<A;i++){
        cin>>a[i];
    }
    for(int i=0;i<B;i++){
        cin>>b[i];
    }
    int ans=1000000;
    for(int i=0;i<M;i++){
        int x,y,c;
        cin>>x>>y>>c;
        int z=a[x-1]+b[y-1]-c;
        if(z<ans){ans=z;}
    }
    sort(a,a+A);
    sort(b,b+B);
    int z=a[0]+b[0];
    if(z<ans){ans=z;}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <queue>
#include <string>
#include <iostream>
using namespace std;
int main () {
  priority_queue<int> Q;
  string a; //??????
  while (cin >> a && a != "end") {
    int b; //?????\????????°
    if (a == "insert") {
      cin >> b;
      Q.push(b);
    }
    else {
      cout << Q.top() << endl;
      Q.pop();
    }
  }
}
      

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n, m;
int a[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>m>>n;
    int tot=0;
    for (int i=0; i<n; i++) {
	int x; cin>>x;
	tot += x;
	if (x>m) break;
    }

    if (tot>m) out(-1);
    int ans = m-tot;
    cout<<ans<<endl;  

    return 0;
}


Measured memory_bytes: 3696
import java.util.*;
 
public class Main{
  
	public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String s = sc.next();

        HashMap<String, String> map = new HashMap<String, String>();

        map.put("A", "T");
        map.put("T", "A");
        map.put("G", "C");
        map.put("C", "G");
        
        System.out.println(map.get(s));
        
        sc.close();
    } 
}

Measured memory_bytes: 21716
#include <cstdio>//头文件不解释
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define rr register
#define int long long
#define f_for(i,a,b) for(rr int i=a;i<=b;i++)
using namespace std;
const int maxx=1e4;
int n,m;
string a,b;
signed main(){
    cin>>a;
    b=a;// 把原来的赋到b上最后比较
    bool t=true;
    int len=a.length()-1;
    for(rr int i=0; i<=len; i++)
        switch(a[i]){
            case 'q': a[i]='p';break;
            case 'p': a[i]='q';break;
            case 'b': a[i]='d';break;
            case 'd': a[i]='b';break;
        }
    for(rr int i=0;i<=len;i++)
        if(a[i]!=b[len-i])
            t=false;//我这里没有翻转，我把它倒过来比较更省时间。
    if(t)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;//岛国题。。加回车
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;



int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall

	ini(n);
	int morty[n];
	FOR(i,0,n){
	in(morty[i]);}
	int tmp = 0;
	int tmp1 = 0;
	int T = 1;
	int rick = INF;
	FOR(i,0,2){
		tmp = 0;
		tmp1 = 0;
		if(i ==1 )T=-1;
		FOR(i,0,n){
			tmp+=morty[i];
			if(T == 1){
				if(tmp<T){tmp1+=1-tmp;tmp = T;}
			}
			if(T == -1){
				if(tmp>T){tmp1+=tmp+1;tmp = T;}
			}
			T = -T;
		}
		rick = min(rick,tmp1);
	}
	out(rick);






	return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
from math import sqrt

n = int(input())
a = 0

for i in range(1,int(sqrt(n))//1+1):
    if n%i == 0:
        b = i+n//i-2
        if i == 1:
            a = b
        elif b < a:
            a = b

print(a)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, K, p[1010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;
	rep(i, 0, N) cin >> p[i];

	int ans = 0;
	sort(p, p + N);
	rep(i, 0, K) ans += p[i];
	cout << ans << endl;
}







Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int mod_pow(int x, int y, int m) {
    if (!y) return 1;
    ll a = mod_pow(x, y >> 1, m);
    if (y & 1) return a * a % m * x % m;
    else return a * a % m;
}

int main() {
    int n;
    cin >> n;
    string x;
    cin >> x;
    
    int c = 0;
    REP(i, n) {
        if (x[i] == '1') ++c;
    }
    int m1 = 0, m2 = 0;
    REP(i, n) {
        if (c != 1) {
            m1 <<= 1;
            if (x[i] == '1') ++m1;
            m1 %= (c - 1);
        }
        m2 <<= 1;
        if (x[i] == '1') ++m2;
        m2 %= (c + 1);
    }
    
    REP(i, n) {
        if (x[i] == '0') {
            int m = m2;
            m += mod_pow(2, SZ(x) - i - 1, c + 1);
            m %= (c + 1);
            int ans = 1;
            while (m) {
                int cnt = 0;
                REP(j, 30) {if ((m >> j) & 1) ++cnt;}
                m %= cnt;
                ++ans;
            }
            cout << ans << "\n";
        } else {
            if (c == 1) {
                cout << 0 << "\n";
            } else {
                int m = m1;
                m -= mod_pow(2, SZ(x) - i - 1, c - 1);
                if (m < 0) m += c - 1;
                int ans = 1;
                while (m) {
                    int cnt = 0;
                    REP(j, 30) {
                        if ((m >> j) & 1) ++cnt;
                    }
                    m %= cnt;
                    ++ans;
                }
                cout << ans << "\n";
            }
        }
    }
    
    return 0;
}



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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int,int>;

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

int C, N, M, S, D;

vector<P> G[200];
int d[200][20];
priority_queue<P, std::vector<P>, std::greater<P>> pq;

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

    while(true){
        std::cin >> C >> N >> M >> S >> D;

        if(C == 0){return 0;}
        
        for(int i=0;i<N+1;++i){
            G[i].clear();
        }
    
        for(int i=0;i<M;++i){
            int A, B, F;
            std::cin >> A >> B >> F;

            G[A].emplace_back(B, F, -1);
            G[B].emplace_back(A, F, -1);        
        }

        fill(&d[0][0], &d[0][0] + 200 * 20, 1001001001);
        d[S][0] = 0;
        pq.emplace(0, S, 0);

        while(!pq.empty()){
            int c, u, uu;
            tie(c, u, uu) = pq.top();
            pq.pop();

            if(d[u][uu] < c){continue;}
        
            for(P& p : G[u]){
            
                int v, c2;
                tie(v, c2, ignore) = p;

                // std::cout << u << " -> " << v << ", " << uu << ", " << d[v][uu+1] << ", " << d[u][uu] << ", " << (c2 / 2) << std::endl;
            
                if(d[v][uu] > d[u][uu] + c2){
                    // std::cout << "?" << u << " -> " << v << ", " << uu << ", " << d[v][uu+1] << ", " << d[u][uu] << ", " << (c2 / 2) << std::endl;
                    d[v][uu] = d[u][uu] + c2;
                    pq.emplace(d[v][uu], v, uu);
                }
                if(uu + 1 <= C && d[v][uu+1] > d[u][uu] + c2 / 2){
                    // std::cout << "!" << u << " -> " << v << ", " << uu << ", " << d[v][uu+1] << ", " << d[u][uu] << ", " << (c2 / 2) << std::endl;
                    d[v][uu+1] = d[u][uu] + c2 / 2;
                    pq.emplace(d[v][uu+1], v, uu+1);
                }
            }
        }

        int mn = 1001001001;
        for(int i=0;i<=C;++i){
            mn = min(mn, d[D][i]);
        }

        std::cout << mn << std::endl;
    }
}

Measured memory_bytes: 3052
import java.util.*;

public class Main {
	public static void main(String[] args){
 
        Scanner sc = null;
        sc = new Scanner(System.in);
        int L = sc.nextInt();
        int R = sc.nextInt();
        int d = sc.nextInt();
        sc.close();

        int answer = 0;
        ArrayList<Integer> numList = new ArrayList<Integer>();
        for (int i = L; i <= R; i++) {
            numList.add(i);
        }

        for (int j: numList){
            if (j%d == 0){
                answer += 1;
            }
          }

        System.out.println(answer);
      
      }
}

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

using namespace std;

int main(){
	int n; cin >> n;
	vector <int> a(n), pref(n), suff(n+1);
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	pref[0] = a[0];
	suff[n-1] = a[n-1];
	for(int i = 1;i < n;i++){
		pref[i] = __gcd(a[i], pref[i-1]);
	}
	for(int i = n - 2;i >= 0;i--){
		suff[i] = __gcd(a[i], suff[i+1]);
	}
	int Max = -1;
	for(int i = 0;i < n;i++){
		Max = max(Max, __gcd(pref[i-1], suff[i+1]));
	}
	cout << Max;
	return 0;
}



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

class Dice{
public:
    int f[6];
    Dice(){}
    void roll_x(){ roll(1, 2, 4, 3);}
    void roll_y(){ roll(0, 2, 5, 3);}
    void roll_z(){ roll(0, 1, 5, 4);}
    void roll(int i, int j, int k, int l){
        int t= f[i]; f[i] = f[j]; f[j] = f[k]; f[k] = f[l]; f[l] = t;
    }
};

bool di( Dice d1, Dice d2){
    for(int i=0; i<6; i++)
        if(d1.f[i] != d2.f[i]) return false;
    return true;
    
}

bool equal( Dice d1, Dice d2 ){
    
    for(int i=0; i<6; i++){
        for(int j=0; j<4; j++){
            if( di(d1, d2)) return true;
            d1.roll_x();
        }
        
        if(i%2 == 0) d1.roll_y();
        else d1.roll_z();
    }
    
    return false;
}


int main(){
    Dice d1, d2;
    
    for(int i=0; i<6; i++) cin >> d1.f[i];
    for(int j=0; j<6; j++) cin >> d2.f[j];
    
    
    if( equal(d1, d2)) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
    return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int n,m,a[N];
struct dat{
	int x,y;
	bool operator < (const dat &rhs) const {
		return y>rhs.y;
	}
}b[N];

int main()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for (int i=1;i<=m;i++) scanf("%d%d",&b[i].x,&b[i].y);
	sort(b+1,b+m+1);
	int nowa=1,nowb=1;
	while (nowa<=n && nowb<=m) {
		if (b[nowb].y<=a[nowa]) break;
		for (int i=1;i<=b[nowb].x;i++) {
			if (nowa>n) break;
			if (b[nowb].y<=a[nowa]) break;
			a[nowa]=b[nowb].y; nowa++;
		}
		nowb++;
	}
	long long ans=0;
	for (int i=1;i<=n;i++) ans+=(long long)a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"log"
	"os"
	"strings"

)


const (
	minLength = 1
	maxLength = 1000
)

var (
	ErrLength         = errors.New("S,T は 1 ⽂字以上 1000 ⽂字以下")
	ErrRelativeLength = errors.New("T の⻑さは S の⻑さ以下")
	ErrNotLetter      = errors.New("S,T は 英⼩⽂字のみを含む")
)

type Solution struct {
	S, T string
}

func New(S, T string) *Solution {
	return &Solution{
		S: S,
		T: T,
	}
}

func (s *Solution) Validate() error {
	if s.isValidLength(s.S) {
		return ErrLength
	}
	if s.isValidLength(s.T) {
		return ErrLength
	}
	if len(s.S) < len(s.T) {
		return ErrRelativeLength
	}
	if !s.isLetter(s.S) {
		return ErrNotLetter
	}
	if !s.isLetter(s.T) {
		return ErrNotLetter
	}
	return nil
}

// MinimumCharacters returns a minimum number of characters that for
// changing T to become a substring of S.
//
// For example:
// - S: cabacc
// - T: abc
//
// Steps:
//    cabacc
// 1. abc    : 3
// 2.  abc   : 1
// 3.   abc  : 2
// 4.    abc : 1
func (s *Solution) MinimumCharacters() int {
	// Initialize the best result to the maximum - if the characters in S and
	// in T are in an empty set. In other words, every character in T does not
	// exist in S.
	res := len(s.T)
	for i := 0; i+len(s.T) <= len(s.S); i++ {
		num := 0
		for j := 0; j < len(s.T); j++ {
			if s.S[j+i] != s.T[j] {
				num++
			}
		}
		// If this result is better than the current best result.
		if num < res {
			res = num
		}
		// If T is already a substring of S, we can do an early return.
		if num == 0 {
			return 0
		}
	}
	return res
}

func (s *Solution) isValidLength(str string) bool {
	n := len(str)
	return n < minLength || n > maxLength
}

func (s *Solution) isLetter(str string) bool {
	for _, r := range str {
		if !(r >= 'a' && r <= 'z') {
			return false
		}
	}
	return true
}


func main() {
	reader := bufio.NewReader(os.Stdin)

	S, err := reader.ReadString('\n')
	if err != nil {
		log.Fatalf("err: %s\n", err)
	}
	S = strings.Trim(S, "\n")

	T, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		log.Fatalf("err: %s\n", err)
	}
	T = strings.Trim(T, "\n")

	var s Solution
	s.S = S
	s.T = T
/*	if err := s.Validate(); err != nil {
		log.Fatalln(err)
	}*/
	fmt.Printf("%d", s.MinimumCharacters())
}


Measured memory_bytes: 1836
# include <stdio.h>
# include <iostream>
# include <string.h>
# include <string>
# include <algorithm>
# include <math.h>
# include <queue>
using namespace std;
int f[3][101],a[3][101],n;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[1][i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[2][i]);
	for(int i=1;i<=2;i++)
		for(int j=1;j<=n;j++)
		{
			if(i!=1)
				f[i][j]=max(f[i][j],f[i-1][j]);
			if(j!=1)
				f[i][j]=max(f[i][j],f[i][j-1]);
			f[i][j]+=a[i][j];
		}
	cout<<f[2][n];
	return 0;
}



Measured memory_bytes: 256
n = int( input() )

d ={}
for _ in range( n ):
  s = input()
  if d.get( s ):
    d[ s ] += 1
  else:
    d[ s ] = 1
m = max( d.values() )

l=[]
for k, v in d.items():
  if v == m:
    l.append(k)
l = sorted( l )
for i in l:
  print( i )


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

int main() {
  string S;
  cin >> S;
  int count;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (S[i]==S[j]) {
        count++;
      }
    }
  }
  if (count==8) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

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

public class Prog
{
    public struct Pair { public int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } }
    public static void Solve()
    {
        int N = NextInt();
        Console.WriteLine("AB" + (N > 999 ? "D" : "C"));
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }
}

public class Input
{
    public const long MOD = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 13268
#include <vector>
#include <cstdio>
using namespace std;
typedef pair<int,int>pii;
main(){
	int n,x,i,q;
	pii p;
	for(;scanf("%d%d",&n,&x),n;printf("%d\n",x)){
		vector<pii>v;
		v.push_back(make_pair(x,1));
		for(i=1;i<n;i++)
			if(p=v.back(),scanf("%d",&x),x==p.first)v.back().second++;
			else if(i&1){
				v.pop_back();
				if(q=0,v.size())q=v.back().second,v.pop_back();
				v.push_back(make_pair(x,q+p.second+1));
			}else v.push_back(make_pair(x,1));
		for(x=i=0;i<v.size();i++)if(!v[i].first)x+=v[i].second;
	}
}

Measured memory_bytes: 1032
#include<stdio.h>
#define MAX 100001

typedef struct{
  char pattern;
  int num;
  int id;
} Card;

int Partition(Card*,int,int);
void QuickSort(Card*,int,int);

int main(void){
  int i,n,judge;
  Card A[MAX];
  char space;

  scanf("%d%d", &n, &space);
  for(i=0;i<n;i++){
    scanf("%c%d%c", &A[i].pattern, &A[i].num, &space);
    A[i].id=i;
  }
  //?¢??????¨
  //for(i=0;i<n;i++) printf("%c%d\n", A[i].pattern, A[i].num);
  //printf("\n");

  judge=0;
  QuickSort(A,0,n-1);

  for(i=0;i<n;i++){
    if(A[i].num == A[i+1].num && A[i].id > A[i+1].id && judge == 0){
      printf("Not stable\n");
      judge=1;
      break;
    }
  }
  if(judge==0) printf("Stable\n");

  for(i=0;i<n;i++) printf("%c %d\n", A[i].pattern, A[i].num);

  return 0;
}

int Partition(Card *A,int p, int r){
  int i,j,x;
  Card tmp;

  x=A[r].num;

  i=p-1;
  for(j=p;j<=r-1;j++){
    if(A[j].num<=x){
      i++;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }

  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;

  return i+1;
}

void QuickSort(Card *A,int p, int r){
  int q;

  if(p<r){
    q=Partition(A,p,r);
    QuickSort(A,p,q-1);
    QuickSort(A,q+1,r);
  }

  return;
}

Measured memory_bytes: 1780
#include<stdio.h>
int main(void){

	int x,y,z;
	while(1){
		scanf("%d %d",&x,&y);
		if(x == 0 && y == 0){
			break;
		}
		if(x > y){
			z = x;
			x = y;
			y = z;
		}
		printf("%d %d\n",x,y);
	}
	
	return 0;
}



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

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

    int n;
    cin >> n;

    int h;
    int highest = 0;
    int res = 0;

    rep(i, n){
        cin >> h;
        if(h >= highest) ++res;
        highest = max(h, highest);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
s=[]
s.append(int(input()))

cnt=0
while cnt==0:
  if s[-1]%2==0:
    s.append(s[-1]//2)
  else:
    s.append(s[-1]*3+1)
  for i in range(len(s)-1):
    if s[-1]==s[i]:
      ans=len(s)
      cnt+=1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::string a,b,c;std::cin>>a>>b>>c;
    lint ans=0;
    for(lint i=0;i<n;i++){
        std::vector<char>s={a.at(i),b.at(i),c.at(i)};
        std::sort(s.begin(),s.end());
        if(s.front()==s.back())continue;
        ans+=1+(s.at(0)!=s.at(1)&&s.at(1)!=s.at(2));
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll Nmax=1e9;
const ll INF=1e9;

int main(){
  int n;
  cin>>n;
  if(n%1000==0){
    cout<<0;
    return 0;
  }

  cout<<1000-n%1000;




}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
int main() {
	fast;
	lli a[5],i,index;
	fr(i,5)
	{
		cin>>a[i];
		if(a[i]==0)
		{
			index=i;
		}
	}
	cout<<index+1;
	
	return 0;
}

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

 int main () {

 int R,G,B,N;
 int sum,pair;
 cin >> R >> G >> B >> N ;

vector<int> v;
 v.push_back ( R );
 v.push_back ( G );
 v.push_back ( B );
 
 sort(v.begin(), v.end());

 R=v[2];
 G=v[1];
 B=v[0];

for(int r=0;r<=N/R;r++){
   for(int g=0;g<=(N-R*r)/G;g++){
       if((N-R*r-G*g)%B == 0)pair++;
     }
    
}
 cout << pair ;
 //cout << R << G << B;

 return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() 
{
	ll n;
	cin>>n;
	vector<int>pos;
	for(ll i=2; i*i<=n; i++){
		int cnt=0;
		while(n%i==0){
			n/=i;
			cnt++;
		}
		if(cnt)
		 pos.push_back(cnt);
	}
	if(n>1)
	 pos.push_back(1);
	int ans=0;
	for(int i=0; i<pos.size(); i++){
		int num=pos[i];
		int cnt=0;
		int j=1;
		while(true){
			num=num-j;
			if(num<0)
			 break;
			cnt++;
			j++;
		}
		ans+=cnt;
	}
	cout<<ans;
	return 0;
	
}


Measured memory_bytes: 3540
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        // int n = 5;
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        
        // 「上がる直前で買う、下がる直後で売る」の結果得するならそれをする
        
        boolean hold = false;
        long money = 1000;
        long min = array[0];
        long max = array[0];
        for (int i = 1; i < n; i++) {
            long now = array[i];
            if (hold) {
                if (max <= now) {
                    max = now;
                } else {
                    long getkabu = money / min;
                    long getmoney = max * getkabu;
                    // int remain = money - (getkabu * min);
                    long remain = money % min;
                    
                    money = getmoney + remain;
                    min = now;
                    hold = false;
                }
            } else {
                if (min >= now) {
                    min = now;
                } else {
                    max = now;
                    hold = true;
                }
            }
            
            // System.out.println(i + " " + money);
        }
        
        if (hold) {
            // System.out.println(123);
            long getkabu = money / min;
            long getmoney = max * getkabu;
            long remain = money % min;
            // System.out.println(getkabu);
            // System.out.println(array[n-1]);
            
            money = getmoney + remain;
        }
        
        System.out.println(money);
    }
}


Measured memory_bytes: 35708
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
 
using namespace std;

signed main()
{
    fast;
    int h,w;
    cin>>h>>w;

    int x = h*w;

    if ( h == 1 || w == 1 )
    {
        cout<<"1"<<endl;
        return 0;
    }

    if ( x % 2 == 0 )
    {
        cout<<x/2<<endl;
    }
    else
    {
        cout<<x/2 + 1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();

    if ((b <= a) && (c <= a)) {
      System.out.println(b + c);
    } else if ((a <= b) && (c <= b)) {
      System.out.println(a + c);
    } else {
      System.out.println(a + b);
    }

  }
}

Measured memory_bytes: 23764
def solve():
  N = int(input())
  dp = [[float('inf')]*3 for _ in range(N)]
  dp[0] = list(map(int, input().split()))
  for i in range(1,N):
    a, b, c = map(int, input().split())
    dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a
    dp[i][1] = max(dp[i-1][0],dp[i-1][2])+b
    dp[i][2] = max(dp[i-1][0],dp[i-1][1])+c
  ans = max(dp[-1])
  return ans
print(solve())

Measured memory_bytes: 87548
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        
        while(input.hasNext()){
             int round = input.nextInt();
 
             if(round > 999){
                 System.out.println("ABD");
             } else {
                 System.out.println("ABC");
             }
        }
    }
}

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

#pragma warning(disable : 4996)

#define mod 100000

using namespace std;

int H, W, dp[2][1 << 19][2][2]; string M[20];

int main()
{
	scanf("%d", &H);
	scanf("%d", &W);

	for (int i = 0; i < H; i++) cin >> M[i];

	if (M[0][0] == 'J' || M[0][0] == '?') dp[0][0][0][0] += 1;
	if (M[0][0] == 'O' || M[0][0] == '?') dp[0][0][1][0] += 1;
	if (M[0][0] == 'I' || M[0][0] == '?') dp[0][0][1][0] += 1;

	for (int i = 0; i < H * W - 1; i++)
	{
		for (int j = 0; j < (1 << (W - 1)); j++)
		{
			dp[(i ^ 1) & 1][j][0][0] = 0;
			dp[(i ^ 1) & 1][j][0][1] = 0;
			dp[(i ^ 1) & 1][j][1][0] = 0;
			dp[(i ^ 1) & 1][j][1][1] = 0;
		}

		for (int j = 0; j < (1 << (W - 1)); j++)
		{
			char c = M[(i + 1) / W][(i + 1) % W];

			int nxt = (j << 1) % (1 << (W - 1));

			int sum0 = (dp[i & 1][j][0][0] + dp[i & 1][j][1][0]) % mod;
			int sum1 = (dp[i & 1][j][0][1] + dp[i & 1][j][1][1]) % mod;

			if (c == 'J' || c == '?')
			{
				dp[(i ^ 1) & 1][nxt][0][0] += sum0;
				dp[(i ^ 1) & 1][nxt][0][1] += sum1;

				dp[(i ^ 1) & 1][nxt][0][0] %= mod;
				dp[(i ^ 1) & 1][nxt][0][1] %= mod;
			}

			if (c == 'O' || c == '?')
			{
				if ((M[i / W][i % W] == 'J' || M[i / W][i % W] == '?') && i % W != W - 1)
				{
					dp[(i ^ 1) & 1][nxt + 1][1][0] += dp[i & 1][j][0][0];
					dp[(i ^ 1) & 1][nxt + 1][1][1] += dp[i & 1][j][0][1];

					dp[(i ^ 1) & 1][nxt + 1][1][0] %= mod;
					dp[(i ^ 1) & 1][nxt + 1][1][1] %= mod;

					dp[(i ^ 1) & 1][nxt][1][0] += (sum0 - dp[i & 1][j][0][0] + mod);
					dp[(i ^ 1) & 1][nxt][1][1] += (sum1 - dp[i & 1][j][0][1] + mod);

					dp[(i ^ 1) & 1][nxt][1][0] %= mod;
					dp[(i ^ 1) & 1][nxt][1][1] %= mod;
				}
				else
				{
					dp[(i ^ 1) & 1][nxt][1][0] += sum0;
					dp[(i ^ 1) & 1][nxt][1][1] += sum1;
				
					dp[(i ^ 1) & 1][nxt][1][0] %= mod;
					dp[(i ^ 1) & 1][nxt][1][1] %= mod;
				}
			}

			if (c == 'I' || c == '?')
			{
				if (j & (1 << (W - 2)))
				{
					dp[(i ^ 1) & 1][nxt][1][1] += sum0;
				}
				else
				{
					dp[(i ^ 1) & 1][nxt][1][0] += sum0;
				}

				dp[(i ^ 1) & 1][nxt][1][1] += sum1;

				dp[(i ^ 1) & 1][nxt][1][0] %= mod;
				dp[(i ^ 1) & 1][nxt][1][1] %= mod;
			}
		}
	}

	int ret = 0;

	for (int i = 0; i < (1 << (W - 1)); i++)
	{
		ret += dp[(H * W - 1) % 2][i][0][1];
		ret += dp[(H * W - 1) % 2][i][1][1];

		ret %= mod;
	}

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

	return 0;
}

Measured memory_bytes: 19672
h,w = map(int, input().split())
cost = [list(map(int, input().split())) for _ in range(10)]
wall = [list(map(int, input().split())) for _ in range(h)]

nums = 10

for k in range(nums):
  for i in range(nums):
    for j in range(nums):
      cost[i][j] = min(cost[i][j],
                       cost[i][k] + cost[k][j])

ans = 0
for wi in wall:
  for wij in wi:
    ans += 0 if wij == -1 else cost[wij][1]
    
print(ans)

Measured memory_bytes: 3316