akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int g = sc.nextInt();
        int[] p = new int[d];
        int[] c = new int[d];
        for (int i = 0; i < d; i++) {
            p[i] = sc.nextInt();
            c[i] = sc.nextInt();
        }
        int ans = dfs(0, new boolean[d], p, c, g, 0);
        System.out.println(ans);

    }

    public static int dfs(int money, boolean[] use, int[] p, int[] c, int g, int u) {
        int min = 99999999;
        for (int id = 0; id < p.length; id++) {
            if (use[id]) {
                continue;
            }
            // 終了する時
            int tmp = g - money;
            int mone = (id + 1) * 100;
            int need = tmp / mone + (tmp % mone == 0 ? 0 : 1);
            if (need > p[id] && mone * p[id] + c[id] >= tmp) {
                min = Math.min(min, u + p[id]);
            } else if (need <= p[id]) {
                min = Math.min(min, u + need);
            } else {
                use[id] = true;
                min = Math.min(dfs(money + p[id] * mone + c[id], use, p, c, g, u + p[id]), min);
                use[id] = false;
            }
        }

        return min;
    }

}


Measured memory_bytes: 22864
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() throws IOException{
		HashMap<Integer, Integer> map1 = new HashMap<Integer, Integer>();
		HashMap<Integer, Integer> map2 = new HashMap<Integer, Integer>();

		String str;
		while (true) {
			str = br.readLine();
			if (str.equals("")) break;
			String[] s = str.split(",");
			int x = Integer.parseInt(s[0]);

			if (map1.containsKey(x)) {
				map1.put(x,map1.get(x)+1);
			} else {
				map1.put(x,1);
			}
		}

		while ((str = br.readLine()) != null) {
			String[] s = str.split(",");
			int x = Integer.parseInt(s[0]);

			if (map1.containsKey(x)) {
				if (map2.containsKey(x)) {
					map2.put(x,map2.get(x)+1);
				} else {
					map2.put(x,1);
				}
			}
		}

		ArrayList<int[]> list = new ArrayList<int[]>();
		for (int x : map2.keySet()) {
			list.add(new int[]{x, map1.get(x) + map2.get(x)});
		}

		Collections.sort(list, new Comparator<int[]>(){
			public int compare(int[] a, int[] b) {
				return a[0] - b[0];
			}
		});

		for (int[] i : list) {
			out.println(i[0] + " " + i[1]);
		}

	}

	public static void main(String[] args) throws Exception {
		long start = System.currentTimeMillis();

		solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		br.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 24512
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>

#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>

#include <sstream>
#include <iostream>

using namespace std;
typedef long long llint;
const llint inf = 1000000000000000000LL;

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

#define TRACE(x) cerr << #x << " = " << x << endl
#define _ << " _ " <<

const int MAX = 2e5 + 5;

int a[MAX];

int main(void) 
{
  int N;
  scanf("%d", &N);
  REP(i, N) scanf("%d", a + i);

  llint tot = 0;
  REP(i, N) tot += a[i];

  llint pref = 0;
  llint sol = inf;
  
  REP(i, N - 1) {
    pref += a[i];
    sol = min(sol, abs(2 * pref - tot));
  }

  printf("%lld\n", sol);

  return 0;
}


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

public class Main {

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

		String str;
		while((str=br.readLine())!=null){
			String[] sp = str.split(" ");

			int p = Integer.parseInt(sp[0]);
			int m = Integer.parseInt(sp[1]);
			int c = Integer.parseInt(sp[2]);

			System.out.println(p + m + c);
		}
	}

}

Measured memory_bytes: 24168
#include <bits/stdc++.h>
using namespace std;
int main(){
long H, W, ans=1; cin >> H >> W;
long E1=H/2, E2=W/2, O1=H-E1, O2=W-E2;
if(H>1&&W>1){ ans=E1*E2+O1*O2; }
cout << ans << "\n";
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import pprint


sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	d = "abcdefghijklmnopqrstuvwxyz"
	s = []
	while n > 0:
		log.print(n // 26, n % 26)
		s.append(n % 26)
		if n % 26 == 0:
			n //= 26
			n -= 1
		else:
			n //= 26

	ans = ""
	for si in s[::-1]:
		ans += d[si - 1]
	print(ans)


main()

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

int main(void) {
  std::string input;
  int q;

  std::cin >> input;
  std::cin >> q;

  for (int i = 0; i < q; i++) {
    std::string command;
    int start = 0;
    int end = 0;
    
    std::cin >> command;
    std::cin >> start >> end;
      
    if (command == "print") {
      std::string output = input.substr(start, end - start + 1);

      std::cout << output << std::endl;
    } else if (command == "reverse") {
      for (int i = 0; i < ((end - start + 1) / 2); i++) {
	char tmp = input[start + i];
	input[start + i] = input[end - i];
	input[end - i] = tmp;
      }
    } else if (command == "replace") {
      std::string target;
      std::cin >> target;
      
      input = input.replace(start, end - start + 1, target);
    }
  }
  
  return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    set<int> s;
    pair<set<int>::iterator,bool> pr;
    int n,no;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>no;
        pr=s.insert(no);
        if(pr.second==false)
            s.erase(pr.first);
    }
    cout<<s.size();
    return 0;
}


Measured memory_bytes: 4864
#include <stdio.h>

int	main()
{
	long long	N, A, B;
	long long	sum, rest;

	scanf("%lld %lld %lld\n", &N, &A, &B);
	rest = N % (A + B);
	sum = N / (A + B) * A;
	if (rest > A)
		sum += A;
	else
		sum += rest;
	printf("%lld\n", sum);
	return (0);
}

Measured memory_bytes: 128
n, a, b = map(int, input().split())
m = 10**9 + 7

def nCr(n, r, mod):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod

ans = pow(2, n, m) - 1 - nCr(n, a, m) - nCr(n, b, m)

while ans < 0:
    ans += m

print(ans)


Measured memory_bytes: 3064
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#define lowbit(x) ((x)&(-(x)))
#define MAXN 1010
using namespace std;
int c[MAXN][MAXN];
int query(int x,int y)
{
	int f=0;
	while(x>0)
	{
		int tmp=y;
		while(tmp>0)
		{
			f+=c[x][tmp];
			tmp-=lowbit(tmp);
		}
		x-=lowbit(x);
	}
	return f;
}
void modify(int x,int y,int v)
{
	while(x<MAXN-10)
	{
		int tmp=y;
		while(tmp<MAXN-10)
		{
			c[x][tmp]+=v;
			tmp+=lowbit(tmp);
		}
		x+=lowbit(x);
	}
}
inline void change(int x,int y,int x1,int y1,int v)
{
	modify(x,y,v);
	modify(x1+1,y,-v);
	modify(x,y1+1,-v);
	modify(x1+1,y1+1,v);
}
int main()
{
	int n,m,Q,l,r;
	scanf("%d%d%d",&n,&m,&Q);
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&l,&r);
		change(1,r,l,n,1);
	}
	while(Q--)
	{
		int q1,q2;
		scanf("%d%d",&q1,&q2);
		printf("%d\n",query(q1,q2));
	}
	return 0;
}

Measured memory_bytes: 2944
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

s = input().rstrip()

if s == 'SAT':
    print(1)
elif s == 'SUN':
    print(7)
elif s == 'MON':
    print(6)
elif s == 'TUE':
    print(5)
elif s == 'WED':
    print(4)
elif s == 'THU':
    print(3)
elif s == 'FRI':
    print(2)

Measured memory_bytes: 3060
#include<stdio.h>

int main(){
    int H, W;
    char a[1100][1100];
    int dp[1100][1100];
    int i,j,k;

    for(i=0; i<1100; i++){
        for(j=0; j<1100; j++){
            dp[i][j] = 0;
        }
    }

    scanf("%d %d", &H, &W);

    for(i=0; i<H; i++){
        scanf("%s", &a[i]);
        //printf("%s", a[i]);
    }

    for(i=0; i<H; i++){
        for(j=0; j<W; j++){
            if(a[i][j] == '.'){
                dp[i+1][j+1] = 1;
            }
            //printf("%d ", dp[i+1][j+1]);
        }
        //printf("\n");
    }

    dp[0][1] = 1;

    for(i=1; i<=H; i++){
        for(j=1; j<=W; j++){
            if(dp[i][j] != 0){
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]) %1000000007;
            }
            //printf("%d ", dp[i][j]);
        }
        //printf("\n");
    }

    printf("%d", dp[H][W]);

    return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int[] ok = new int[31];
			for ( int i = 0; i < 28; i++)
				ok[sc.nextInt()]++;
			for ( int i = 1; i < ok.length; i++)
				if ( ok[i]==0 )System.out.println(i);
		}
	}
}

Measured memory_bytes: 12000
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> ae(5); cin >> ae;
    int ans = M;
    for(int i = 0; i < 120; i++){
        do{
            int cand = 0;
            for(auto& e : ae){
                cand = (cand + 9) / 10 * 10;
                cand += e;
            }
            ans = min(ans, cand);
        }while(next_permutation(ae.begin(), ae.end()));
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
  string s;
  string sen;
  int count=0;
  cin>>s;
  int n=s.length();
  for(int i=0;i<n;i++){
    if(s[i]>='A'&&s[i]<='Z')s[i]+='a'-'A';
  }
  // cout<<n<<endl;//can delete
  while(1){
    cin>>sen;
    if(sen=="END_OF_TEXT")break;
    n=s.length();
    for(int i=0;i<n;i++){
      if(sen[i]>='A'&&sen[i]<='Z')sen[i]+='a'-'A';
    }
    if(s==sen)count++;
  }
  cout<<count<<endl;
  return 0;
}



Measured memory_bytes: 3176
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
using namespace std;

class point{
public:
  int x, y, c, l;
  bool operator<(const point& another) const{
    return x < another.x;
  };
};


void solve(){
  int n; cin >> n;
  vector<point> p(2 * n);
  for(int i = 0; i < 2 * n; i++){
    cin >> p[i].x >> p[i].y;
    if(i <= n - 1) p[i].c = 0;
    else p[i].c = 1;
    p[i].l = 1;
  }
  sort(p.begin(), p.end());
  /*for(int i = 0; i < 2 * n; i++){
    cout << p[i].x << " " << p[i].y << " " << p[i].c << endl;
  }*/
  unsigned long long int ans = 0;
  for(int i = 0; i < 2 * n; i++){
    if(p[i].c == 0) continue;
    int y = p[i].y;
    int j;
    for(j = i - 1; j >= 0; j--){
      if(p[j].c == 0 && p[j].l == 1 && p[j].y < y) break;
    }
    if(j == -1) continue;
    int maxyid = j;
    for(int k = j; k >= 0; k--){
      if(p[k].c == 1 || p[k].l == 0) continue;
      if(p[k].y < y && p[k].y > p[maxyid].y) maxyid = k;
    }
    p[maxyid].l = 0;
    ans++;
  }
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c) {
  stack<int> S;
  S.push(r);
  color[r] = c;
  while ( !S.empty() ) {
    int u = S.top(); S.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (color[v] == NIL) {
        color[v] = c;
        S.push(v);
      }
    }
  }
}

void assignColor() {
  int id = 1;
  for (int i = 0; i < n; i++) color[i] = NIL;
  for (int u = 0; u < n; u++) {
    if (color[u] == NIL) dfs(u, id++);
  }
}

int main() {
  int s, t, m, q;

  cin >> n >> m;

  for (int i = 0; i < m; i++) {
    cin >> s >> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assignColor();

  cin >> q;

  for (int i = 0; i < q; i++) {
    cin >> s >> t;
    if (color[s] == color[t]) {
      cout << "yes" << endl;
    } else {
      cout << "no" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 8968
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
int main()
{
	int a=1;
	int b;
	int c;
	int d;
	int e;
	int f;
	int g;
	int h;
	int i;
	int j;
	while (1)
	{
		cin >> a;
		if (a == 0){ break; }
		cin >> b;
		cin >> c;
		cin >> d;
		cin >> e;
		cin >> f;
		cin >> g;
		cin >> h;
		cin >> i;
		cin >> j;
		cout << a - b - c - d - e - f - g - h - i - j << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define ll long long
//#define int long long
using namespace std;
void boost()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}
void free()
{
	freopen("A.in", "r", stdin);
	freopen("A.out", "w", stdout);
}
char a[3][3];
main()
{
	//free();
	boost();
	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
			cin >> a[i][j];
	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
			if(i == j) cout << a[i][j];
	exit(0);
}



Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n):
    res = [None] * n
    for i in range(n):
        res[i] = II()
    return res
def LIR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI()
    return res
def FR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LFR(n):
    res = [None] * n
    for i in range(n):
        res[i] = IF()
    return res
def LIR_(n):
    res = [None] * n
    for i in range(n):
        res[i] = LI_()
    return res
def SR(n):
    res = [None] * n
    for i in range(n):
        res[i] = S()
    return res
def LSR(n):
    res = [None] * n
    for i in range(n):
        res[i] = LS()
    return res
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n = II()
    ans = []
    while n:
        x = (n-1) % 26
        n = (n-1) // 26
        ans.append(chr(x + ord("a")))
    print("".join(ans[::-1]))
    return


#main
if __name__ == '__main__':
    solve()


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

int main() {
  int A, B;
  cin >> A >> B;
  vector<int> vec = {13,1,2,3,4,5,6,7,8,9,10,11,12};
  if (vec.at(A-1) == vec.at(B-1)) cout << "Draw" << endl;
  else if (vec.at(A-1) > vec.at(B-1)) cout << "Alice" << endl;
  else cout << "Bob" << endl;
  return 0; 
}

Measured memory_bytes: 256
n,k,s=map(int,input().split())

ans=[]
cnt=0
if s!=10**9:
    for i in range(n):
        if cnt<k:
            ans.append(s)
            cnt+=1
        else:
            ans.append(s+1)
else:
    for i in range(n):
        if cnt<k:
            ans.append(s)
            cnt+=1
        else:
            ans.append(1)
print(*ans)


Measured memory_bytes: 13792
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

const int NMax = 100000;
const int MMax = 100000;
int N, M;

int bridge[NMax - 1] = {};

int search(int from, int max)
{
    for (int i = from; i <= max; ++i)
    {
        if (bridge[i] > 0)
        {
            int m = i + bridge[i] - 1;
            if (max > m) { max = m; }
            return search(i + 1, max);
        }
    }
    return max + 1;
}

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

    for (int i = 0; i < M; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        int len = b - a;
        if (bridge[a] == 0 || bridge[a] > len) { bridge[a] = len; }
    }

    int cnt = 0;
    for (int i = 0; i < N - 1; ++i)
    {
        if (bridge[i] > 0)
        {
            ++cnt;
            int s = search(i + 1, i + bridge[i] - 1);
            i = s - 1;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 764
S=list(input())
N=len(S)
n=N//2
if S[0]=='0':
  L=['0','1']*(n+1)
else:
  L=['1','0']*(n+1)
ans=0
for n in range(N):
  if S[n]!=L[n]:
    ans+=1
print(ans)

Measured memory_bytes: 4652
#include<bits/stdc++.h>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
	char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
const int maxn=5e5+5;
int q[maxn],dp[maxn],pos[maxn];
int n,D,Q;
inline int ABS(int x) {return x>=0?x:-x;}
int main() {
	n=read();D=read();dp[n+1]=1;
	for(re int i=1;i<=n;i++) q[i]=read();
	for(re int i=n;i;--i) {
		if(q[i]>=2*dp[i+1]) {
			dp[i]=dp[i+1];
			if(q[i]>2*dp[i+1]) dp[i]=min(dp[i],q[i]-dp[i+1]);
		}
		else dp[i]=dp[i+1]+q[i];
	} 
	pos[0]=D;
	for(re int i=1;i<=n;i++) pos[i]=min(ABS(pos[i-1]-q[i]),pos[i-1]);
	Q=read();int x;
	while(Q--) x=read(),puts(dp[x+1]<=pos[x-1]?"YES":"NO");	
	return 0;
}


Measured memory_bytes: 7808
import java.util.Scanner;

class Main{

  public static void main(String[] args){

    Scanner scan = new Scanner(System.in);
   
  	int a = scan.nextInt();
  	int b = scan.nextInt();
	int c = scan.nextInt();
  	
  	if(a < b && b < c){
  		System.out.println("Yes");
  	}else{
  		System.out.println("No");
	}
  }
}

Measured memory_bytes: 26260
import collections

N = int(input())
L_list = list(map(int, input().split()))
L_list = sorted(L_list)

L = collections.Counter(L_list)
L_modi = list(L.keys())
#print(L_modi)
#print(L[L_modi[0]])
#print(L.items())

cnt = 0

for i in range(len(L_modi)-2):
    for j in range(i+1, len(L_modi)-1):
        for k in range(j+1, len(L_modi)):
            if L_modi[i] + L_modi[j] > L_modi[k]:
                cnt += L[L_modi[i]]*L[L_modi[j]]*L[L_modi[k]]
                #print(i,j,k,L[L_modi[i]]*L[L_modi[j]]*L[L_modi[k]])

print(cnt)

Measured memory_bytes: 68460
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W = map(int, input().split())

A = [0] * H
for i in range(H):
    A[i] = list(input())

row = [False] * H
col = [False] * W
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            row[i] = True
            col[j] = True

for i in range(H):
    if not row[i]:
        continue
    for j in range(W):
        if not col[j]:
            continue
        print(A[i][j], end="")
    print()

Measured memory_bytes: 9580
#include <stdio.h>
int main ()
{
	int N, K;
	scanf ("%d", &N);
	scanf ("%d", &K);
	int hasil = 1;
	for (int i = 0; i < N; i++)
	{
		if (hasil < K)
		{
			hasil *= 2;
		}
		else if (hasil >= K)
		{
			hasil += K;
		}
	}
printf ("%d", hasil);
return 0;
}

Measured memory_bytes: 1716
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 1000000
#define M 1000001

typedef struct card{
	char key[15];
	struct card *next;
}card;

card *a[M];

long long convert(char str[]){
	int x=0;
	long p=1;
	
	for(int i=0;i<strlen(str);i++){
		x+=(str[i]-'A')*p;
		p*=5;
	}
	
	return x%M;
}

void insert(char str[]){
	card *new=malloc(sizeof(card));
	new->next=NULL;
	strcpy(new->key,str);
	
	card **p=&a[convert(str)];
	
	while((*p)!=NULL)
		p=&((*p)->next);
	
	(*p)=new;
	
	return;
	
}

int find(char str[]){
	long long hash=convert(str);
	card *p=a[hash];
	
	while(p!=NULL){
		if(strcmp(p->key,str)==0)
			return 1;
		p=p->next;
	}
	
	return 0;
	
}


int main(){
	int n,i;
	char com[10];
	char str[15];
	
	for(i=0;i<M;i++)
		a[i]=NULL;
	
	scanf("%d",&n);
	
	for(int i=0;i<n;i++){
		scanf("%s %s",com,str);
		
		if(com[0]=='i'){
			insert(str);
		}
		
		else {
			if(find(str))
				printf("yes\n");
			else 
				printf("no\n");
		}
		
	}
	
	return 0;
	
}



Measured memory_bytes: 27360
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
using namespace std;

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin,(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

string s;
vector<char> v;
bool removablep(int i){
  if(v[i]=='0'&&v[i+1]=='1' ||
      v[i]=='1'&&v[i+1]=='0')
    return true;
  return false;
}

int solve(int i){
  if(i==s.length()) return s.length()-(int)v.size();
  v.push_back(s[i]);
  while(removablep(v.size()-2)){
    v.pop_back();
    v.pop_back();
  }
  return solve(i+1);
}

int main(){
  cin >> s;
  cout << solve(0) << endl;
  return 0;
}


Measured memory_bytes: 640
// "static void main" must be defined in a public class.
import java.util.* ;
public class Main {
    public static void main(String[] args) {
        Scanner S = new Scanner( System.in ) ;
        Main obj = new Main() ;
        int t = S.nextInt() ;
        if( 400<=t && t<=599 ) {
            System.out.println("8") ;
            return ;
        }
        if( 600<=t && t<=799 ) {
            System.out.println("7") ;
            return ;
        }
        if( 800<=t && t<=999 ) {
            System.out.println("6") ;
            return ;
        }if( 1000<=t && t<=1199 ) {
            System.out.println("5") ;
            return ;
        }if( 1200<=t && t<=1399 ) {
            System.out.println("4") ;
            return ;
        
        }
    if( 1400<=t && t<=1599 ) {
            System.out.println("3") ;
            return ;
    }
        if( 1600<=t && t<=1799 ) {
            System.out.println("2") ;
            return ;
        }if( 1800<=t && t<=1999 ) {
            System.out.println("1") ;
            return ;
        }
    }
}






Measured memory_bytes: 35684
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int s=0;
    for(int i=0;i<c;i++){
        if(b>=a){
            s++;
            b-=a;
        }
        else break;
    }
    cout<<s<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Vec2(T, n, m, xs) vector<vector<T>> xs(n, vector<T>(m))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

using P = pair<int, int>;

int main(void){
    Cin(int, n, m);
    Cins(int, n, a);
    vector<P> q(m);
    For(i, m){
        // first : 変化後の数字, second : 変化させられる個数
        cin >> q[i].second >> q[i].first;
    }
    Sort(a);
    DeSort(q);
    // For(i, m) Cout(q[i].first, " ", q[i].second);
    ll ans = 0;
    For(i, n) ans += a[i];
    
    int k = 0;
    For(i, m){
        For(j, q[i].second){
            if(a[k] < q[i].first){
                ans += q[i].first - a[k];
                k ++;
                if(k == n){
                    Cout(ans);
                    return 0;
                }
            }
            else{
                Cout(ans);
                return 0;
            }
        }
    }
    Cout(ans);
}


Measured memory_bytes: 1408
#include<iostream>
#include<string>

int main(void){
    std::string number;
    int sum;
    while(1){
        std::cin>>number;
        sum=0;
        if(number=="0") break;
        for(int i=0;i<number.size();i++){
            sum+=number[i]-'0';
        }
        std::cout<<sum<<std::endl;
    }
    return 0;
}

Measured memory_bytes: 3188
N = int(input())
B = list(int(i) for i in input().split())
A = B[0]
for i in range(N-2):
    if i == N-2:
        A += B[i+1]
    elif B[i+1] >= B[i]:
        A += B[i]
    else:
        A += B[i+1]
    #print(A)
print(A+B[N-2])

Measured memory_bytes: 3060
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()

//グローバル変数宣言
 ll p=0,q=0,r=0;

int main(){
  ll n;
  cin>>n;
  vl a(n);
  rep(i,n){
    cin>>a[i];
    rep(j,1000000000){
      if(a[i]%2==1)break;else p++;
      a[i]/=2;
    }
    if(i==0)q=p;
    q=min(p,q);
    p=0;
    }
    print(q)
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
#define oo 1e9
#define fi first
#define se second
#define sp(iiii) setprecision(iiii)
#define IO ios_base::sync_with_stdio(false); cin.tie(0)
#define ms(aaaa,xxxx) memset(aaaa,xxxx,sizeof(aaaa))
#define cntbit(xxxx) __builtin_popcount(xxxx)
#define getbit(xxxx,aaaa) ((xxxx>>(aaaa-1))&1)
#define _cos(xxxx) cos(xxxx*acos(-1)/180)
#define _sin(xxxx) sin(xxxx*acos(-1)/180)
#define _tan(xxxx) tan(xxxx*acos(-1)/180)
#define PE cout<<fixed
 
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> piii;
typedef pair<long long,long long> pll;
typedef pair<pair<long long,long long>,long long> plll;
 
const ld pi=acos(-1);

ll n,x,t;

int main() {
    IO;
    cin>>n>>x>>t;
    cout<<((n+x-1)/x)*t<<'\n';
}
    

Measured memory_bytes: 3628
import static java.util.Arrays.deepToString;

import java.util.Arrays;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc = new Scanner(System.in);
	void run() {
 		for (int testcase = sc.nextInt(); testcase-->0;) {
 			String s = sc.next();
 			if (isA(s)) System.out.println("A");
 			else if (isB(s)) System.out.println("B");
 			else System.out.println("NA");
		}
	}
	
	boolean isA(String s) {
		Pattern p = Pattern.compile(">'(=+)#(=+)~");
		Matcher matcher = p.matcher(s);
		if (matcher.matches()) {
			if (matcher.group(1).equals(matcher.group(2))) return true;
		}
		return false;
	}
	boolean isB(String s) {
		return s.matches(">\\^(Q=)+~~");
	}
}

Measured memory_bytes: 29924
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, m, p;
    while(cin >> n >> m >> p, n|m|p){
        vector<int> v(n);
        for (auto &&i : v) scanf("%d", &i);
        if(v[m-1] == 0){
            puts("0");
            continue;
        }
        int s = accumulate(v.begin(), v.end(), 0);
        cout << s*(100-p)/v[m-1] << "\n";
    }

    return 0;
}



Measured memory_bytes: 3132
import java.util.Scanner;
 
public class Main {
public static void main(String args[]){
Scanner sn=null;
sn= new Scanner(System.in);
String S=sn.nextLine();
if(S.equals("abc") || S.equals("acb") || S.equals("bac") ||S.equals("bca")||S.equals("cab")||S.equals("cba")){
System.out.println("Yes");
}else{
System.out.println("No");
}
}
}

Measured memory_bytes: 21972
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int main(){
    int n,x;
    int d=0,db=0;
    int cnt=0;
    int i;
    int *str;
    cin >> n >> x;
    str=new int[n];
    for(i=0;i<n;i++){
        if(scanf("%d",&str[i])==1);
    }
    cnt++;
    for(i=0;i<n;i++){
        d+=str[i];
        
        //printf("%d:%d:%d",cnt,d,x);
        if(d<=x){
            cnt++;
        }
        
    }
    cout << cnt <<endl;
            return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	string s,t;cin>>s>>t;
  	long long l=0;
  	for(int i=0;i<s.length();i++){
      if(s[i]!=t[i])l++;
    }
  	cout<<l<<"\n";
	return 0;
}

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

typedef long long ll;

int main()
{
    ll N, M;
    cin >> N >> M;
    if (N == 1 && M == 1)
    {
        cout << 1 << endl;
        return 0;
    }
    if (N == 1)
    {
        cout << max((ll)0, M - 2) << endl;
    }
    else if (M == 1)
    {
        cout << max((ll)0, N - 2) << endl;
    }
    else
    {
        cout << (N - 2) * (M - 2) << endl;
    }
}


Measured memory_bytes: 3564
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
const int MR=1e6+10;
typedef long long LL;

int main() {
	int s,w;
	cin>>s>>w;
	if(w>=s) printf("unsafe\n");
	else printf("safe\n");
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cmath>
using namespace std;
static const int MAX_N = 100000;

int main(void){
    int n;
    int H[MAX_N];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> H[i];
    }
    int dp[n];
    dp[0] = 0;
    dp[1] = abs(H[0]- H[1]);
    for(int i=0; i<n-2; i++){
        dp[i+2] = min(dp[i+1]+abs(H[i+1]-H[i+2]), dp[i]+abs(H[i]-H[i+2]));
    }
    cout << dp[n-1];

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define mod 1000000007
#define MAX 20000000009
using namespace std;

int main(){
    cout << fixed << setprecision(6);
    // cout << 22.0 / 7.0 << endl;
    long double r;
    cin >> r;
    cout << 2.0 * (22.0 / 7.0) * r << endl;
}



Measured memory_bytes: 3768
#include<stdio.h>
  
#define AMAX 20
#define MMAX 200
 
int A[AMAX+1];
int n, q;

int solve( int p, int t, int res )
{
	return  ( n < p ) ? res: solve( p+1, t-A[p], !t||res  ) || solve( p+1, t, !t||res );
}
 
int main( void ) 
{
    int i;
    int num;
     
    scanf( "%d", &n );  
    for( i=0; i<n; i++ ) {
        scanf( "%d", &A[i] );
    }   
    scanf( "%d", &q );
    for( i=0; i<q; i++ ) {
        scanf( "%d", &num );
        if( solve( 0, num, 0 ) ) {
            printf( "yes\n" );      
        } else {
            printf( "no\n" );
        }
    }
    return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int A,B,K,cnt = 0,ans[1000000],cntt = 0;
  map<int,int> mp;
  cin >> A >> B >> K;
  for(int i = A;i <= B;i++){
    cnt++;
    mp[i]++;
    cout << i << endl;
    if(cnt >= K)break;
  }
  cnt = 0;
  for(int i = B; i >= A;i--){
    cnt++;
    mp[i]++;
    if(mp[i] == 1)ans[cntt++]=i;
    if(cnt >= K)break;
  }
  reverse(ans,ans + cntt);
  for(int i = 0;i < cntt;i++){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
// D.

#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	int h, w, c[10][10];
	cin >> h >> w;
	for (int i = 0; i < 10; ++i) {
		for (int j = 0; j < 10; ++j) {
			cin >> c[i][j];
		}
	}
	for (int k = 0; k < 10; ++k) {
		for (int i = 0; i < 10; ++i) {
			for (int j = 0; j < 10; ++j) {
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			int a;
			cin >> a;
			if (a >= 0 && a != 1) {
				ans += c[a][1];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){

    int N, D, X;
    cin >> N;
    cin >> D >> X;

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

    int ans = X + N;
    for(int i=0; i<N; i++){
        ans += (D-1)/A[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define endl "\n";
int main() {
#ifndef ONLINE_JUDGE
	freopen("i.txt", "r", stdin);
	freopen("o.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, k, ans, sum = 0;
	cin >> n >> k;
	for (ll i = 0; i < n; i++) {
		ll t;
		cin >> t;
		if (t == 1)ans = i;
	}
	ll m = (n - 1) / (k - 1);
	ll rem1 = (n - 1) % (k - 1);
	if (rem1 != 0)rem1 = 1;
	cout << m + rem1;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
   #define PP pair<int,pair<int,int>>
const int MAX = 200004;
const int MOD =998244353
 ;
const int INV2 = (MOD+1)/2;
int k,x,y;


     signed main(){
string s;
cin>>s;
for(int i=0;i<s.size();i++)for(int j=i+1;j<s.size();j++)if(s[i]==s[j]){
     cout<<"no"<<endl;
     return 0;
}
cout<<"yes"<<endl;

return 0;





}


        


Measured memory_bytes: 256
fn main() {
    proconio::input! {
        h: usize,
        w: usize,
        ch: usize,
        cw: usize,
        dh: usize,
        dw: usize,
        ss: [proconio::marker::Chars; h],
    }
    let ch = ch - 1;
    let cw = cw - 1;
    let dh = dh - 1;
    let dw = dw - 1;
    let mut deque = std::collections::VecDeque::new();
    let mut costs = vec![vec![std::i64::MAX; w]; h];
    deque.push_back((ch, cw, 0));
    while let Some((curh, curw, curcost)) = deque.pop_front() {
        let nexts = [
            (-1, 0, 0),
            (1, 0, 0),
            (0, -1, 0),
            (0, 1, 0),
            (-2, -2, 1),
            (-2, -1, 1),
            (-2, 0, 1),
            (-2, 1, 1),
            (-2, 2, 1),
            (-1, -2, 1),
            (-1, -1, 1),
            (-1, 1, 1),
            (-1, 2, 1),
            (0, -2, 1),
            (0, 2, 1),
            (1, -2, 1),
            (1, -1, 1),
            (1, 1, 1),
            (1, 2, 1),
            (2, -2, 1),
            (2, -1, 1),
            (2, 0, 1),
            (2, 1, 1),
            (2, 2, 1),
        ];
        for (y, x, cost) in &nexts {
            let nexth = curh as i64 + y;
            let nexth = if nexth < 0 || h as i64 <= nexth {
                continue;
            } else {
                nexth as usize
            };
            let nextw = curw as i64 + x;
            let nextw = if nextw < 0 || w as i64 <= nextw {
                continue;
            } else {
                nextw as usize
            };
            if ss[nexth][nextw] == '#' {
                continue;
            }
            let nextcost = curcost + cost;
            if costs[nexth][nextw] <= nextcost {
                continue;
            }
            costs[nexth][nextw] = nextcost;
            if curcost == nextcost {
                deque.push_front((nexth, nextw, nextcost));
            } else {
                deque.push_back((nexth, nextw, nextcost));
            }
        }
    }
    let ans = if costs[dh][dw] == std::i64::MAX {
        -1
    } else {
        costs[dh][dw]
    };
    println!("{}", ans);
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

  //000 - 111
  REP(i,8){
    int t=S[0]-'0';
    string ans = S.substr(0,1);
    REP(j,3){
      if(i & (1<<j)){
        t += S[j+1] - '0';
        ans += "+";
      }else{
        t -= S[j+1] - '0';
        ans += "-";
      }
      ans += S.substr(j+1,1);
    }
    if(t==7){
      cout << ans << "=7" << endl;
      exit(0);
    }else{
//      cout << t << " " << s << endl;
    }
  }


}



Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod = 1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 2011;
int n;
bool f[maxn];
int head[maxn], nxt[maxn*2], to[maxn*2], tot=1;
void addedge(int x, int y)
{
	nxt[++tot] = head[x];
	head[x] = tot;
	to[tot] = y;
}
bool vis[maxn*2];
int dp[maxn*2], mx[maxn*2], sz[maxn*2];
int calcdp(vector<int> &v)
{
	int ret = 0;
	int mxi = 0, sum = 0;
	for (int i=0; i<v.size(); i++)
	{
		int x = v[i];
		if (dp[x]+sz[x]>=dp[mxi]+sz[mxi]) mxi = x;
		sum += dp[x]+sz[x];
	}
	int M = dp[mxi]+sz[mxi];
	if (M*2<=sum) return 0;
	int mxsum = 0;
	for (int i=0; i<v.size(); i++)
	{
		int x = v[i];
		if (x==mxi) continue;
		mxsum += mx[x]+sz[x];
	}
	return max(0, M-mxsum);
}
void dfs(int e)
{
	vis[e] = true;
	int pre = to[e^1], x = to[e];
	sz[e] = f[x];
	mx[e] = 0;
	vector<int> v;
	for (int i=head[x]; i; i=nxt[i])
	{
		int u = to[i];
		if (u==pre) continue;
		if (!vis[i]) dfs(i);
		sz[e] += sz[i];
		mx[e] += mx[i]+sz[i];
		v.PB(i);
	}
	dp[e] = calcdp(v);
}
int main()
{
	geti(n);
	for (int i=1; i<=n; i++) f[i] = getreal()=='1';
	for (int i=1; i<n; i++)
	{
		int x, y;
		getii(x, y);
		addedge(x, y);
		addedge(y, x);
	}
	for (int i=2; i<=tot; i++)
	{
		if (!vis[i]) dfs(i);
	}
//	for (int i=2; i<=tot; i++) cerr<<to[i^1]<<","<<to[i]<<" "<<sz[i]<<" "<<mx[i]<<" "<<dp[i]<<endl;
	int ans = 2e9;
	for (int i=1; i<=n; i++)
	{
		vector<int> v;
		int sum = 0;
		for (int j=head[i]; j; j=nxt[j]) v.PB(j), sum += mx[j]+sz[j];
		int cur = calcdp(v);
//		cerr<<i<<" "<<sum<<" "<<cur<<endl;
		if (cur==0&&sum%2==0)
		{
			ans = min(ans, sum/2);
		}
	}
	if (ans>1e9) puts("-1");
	else cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin>>N;
    long long x,y;
    long long t,a;
    for(int i=0;i<N;i++){
        if(i==0){
            cin>>x>>y;
        }else{
            cin>>t>>a;
            long long k=max((x+t-1)/t,(y+a-1)/a);
            x=t*k;
            y=a*k;
        }
    }
    cout<<x+y<<endl;
    return 0;
}

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

N, M, S = mapint()
S = min(S, N*50)
query = [[[] for _ in range(N*50+1)] for _ in range(N)]
for _ in range(M):
    u, v, a, b = mapint()
    for coin in range(a, N*50+1):
        query[u-1][coin].append((v-1, a, b))
        query[v-1][coin].append((u-1, a, b))
for i in range(N):
    c, d = mapint()
    for coin in range(N*50+1):
        query[i][coin].append((i, -c, d))

inf = 10**18
dp = [[inf]*(N*50+1) for _ in range(N)]
dp[0][0] = 0

import heapq
queue = [(0, 0, S)]
checked = [0]*N
cnt = 0

while queue:
    t, now, coin = heapq.heappop(queue)
    if cnt==N:
        break
    if not checked[now]:
        checked[now] = 1
        cnt += 1
    qlis = query[now][coin]
    for nx, a, b in qlis:
        if 0<=coin-a:
            coin = min(coin, N*50+a)
            if t+b<dp[nx][coin-a]:
                dp[nx][coin-a] = t+b
                heapq.heappush(queue, (t+b, nx, coin-a))

for i in range(1, N):
    print(min(dp[i]))


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

int distance(int x , int y , int D , vector<vector<int>> cont){
  
  int result = 0;
  for(int i = 0 ; i < D ; i++){
    
    result += ( cont.at(x).at(i) - cont.at(y).at(i) )*( cont.at(x).at(i) - cont.at(y).at(i) ); 
  }
  return result;
}
  
  
int main() {
  
  int N,D;
  cin >> N >> D;
  int n_sum = 0;
  
  vector<vector<int>> cont(N , vector<int>(D));
  
  for(int i = 0 ; i < N ; i++){
    
    for(int j = 0; j < D ; j++){
      
      cin >> cont.at(i).at(j);
      
    }
  }
  
  for(int i = 0 ; i < N ; i++){
    
    for(int j = 0 ; j < N ; j++){
      
      for(int k = 1 ; k < 129 ; k++){
        
        if( distance(i , j , D , cont) == k*k){
          
          n_sum++;
          break;
        }
      }
    }
  }
  
  cout << n_sum / 2 << endl;
  
}
  
  

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S;
	cin >> S;
	if (S[0] == 'S')
	{
		cout << "Cloudy" << endl;
	}
	else if (S[0] == 'C')
	{
		cout << "Rainy" << endl;
	}
	else
	{
		cout << "Sunny" << endl;
	}

	return 0;
}

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

using ll = long long;
using db = long double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"
db prob[3004];
int n;
db dp[3004][3004];
db go (int indx, int head) {
    if (indx == n+1) {
        if (head > n/2)
            return 1;
        else
            return 0;
    }
    if (dp[indx][head] != -1)
        return dp[indx][head];
    db &ans = dp[indx][head];
    ans = prob[indx]*go(indx+1, head+1) + (1-prob[indx])*go(indx+1, head);
    return ans;
}

void testCase() {
    //int n;
    cin >> n;
    //db prob[n+3];
    for (int i=1; i<=n; i++)
        cin >> prob[i];
    for (int i=1; i<=n; i++) {
        for (int j=0; j<=n; j++)
            dp[i][j] = -1;
    }
    cout << fixed << setprecision(15) << go (1, 0) << endl;
}

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 141312
import java.util.*;

// https://beta.atcoder.jp/contests/arc102/submissions/3118322

class Edge{
	int a,b,c;
	public Edge(int A,int B,int C){
		a=A;
		b=B;
		c=C;
	}
	@Override
	public String toString(){
		return a+" "+b+" "+c;
	}
}

class Main{
	public static void main(String[] $){
		int L=new Scanner(System.in).nextInt()-1;
		if(L==1){
			System.out.println("2 2\n1 2 0\n1 2 1");
			return;
		}

		int n=Integer.numberOfTrailingZeros(Integer.highestOneBit(L));

		BitSet sb=new BitSet();
		sb.set(n+1);

		for(int i=n;i>=0;i--)
			sb.set(n-i,(L&(1<<i))>0);

		List<Edge> ret=new ArrayList<>();

		for(int i=1;i<=n;++i){
			ret.add(new Edge(i,i+1,0));
			ret.add(new Edge(i,i+1,1<<(n-i)));
		}

		int num=0;
		for(int i=0;i<=n;++i){
			if(!sb.get(i))
				continue;
			num+=1<<(n-i);
			ret.add(new Edge(1,Math.min(n,sb.nextSetBit(i+1))+1,num));
		}

		System.out.println(n+1+" "+ret.size());
		ret.forEach(System.out::println);
	}
}


Measured memory_bytes: 28628