akhauriyash/Code-Regression huggingface dataset:
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

using ll = int64_t;

int main(int, const char**)
{
    string s, t;
    cin >> s >> t;
    int ans = 10001;
    rep(i, s.size() - t.size() + 1)
    {
        int ta = 0;
        rep(j, t.size())
        {
            if(s[i + j] != t[j])
            {
                ta++;
            }
        }
        ans = min(ans, ta);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vs>		vvs;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	ll a, b;
	cin >> a >> b;
	bool positive = false;

	if (ll(a * b) <= 0) cout << "Zero" << endl;
	else {
		if (a > 0 && b > 0) positive = true;
		else {
			if ((b - a + 1) % 2 == 0) positive = true;
		}
		if (positive) cout << "Positive" << endl;
		else cout << "Negative" << endl;
	}

	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int x, h;
		
		x = sc.nextInt();
		h = sc.nextInt();
		while (x + h != 0) {
			double s = 0.0;
			double bottom = x * x * 1.0;
			double height = Math.sqrt(h * h * 1.0 + x * x * 1.0 / 4);
			double triangle = x * 1.0 * height / 2;
			
			s = bottom + 4 * triangle;
			System.out.println(s);
			
			x = sc.nextInt();
			h = sc.nextInt();
		}
	}
}

Measured memory_bytes: 11000
from heapq import heapify,heappop,heappush
N,M=map(int,input().split())
A=list(map(int,input().split()))
A=list(map(lambda x:x*(-1),A))
heapify(A)
while(M>0):
    temp=heappop(A)*-1
    
    heappush(A,temp//2*-1)
    M-=1
print(sum(A)*-1)

Measured memory_bytes: 14180
//解説Youtubeみて写計
 
 #include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;

// d: 現在のケタ数
// val: 現在の値
// all: ここに格納していく (参照型にしておく)
void rec(int d, long long val, vector<long long> &all) {
  // 格納
  all.push_back(val);

  // 10 桁だったらそれ以上やらずに打ち切り
  if (d == 10) return;

  // 次の桁へ進む処理
  for(int j=-1;j<=1;++j){
      int add = (val %10)+j;
      if(add>=0&&add<=9) rec(d+1,val*10+add,all);
  }
} 

int main(){
    int k;
    cin >> k;
    vector<long long> all;
    for(int v=1;v<10;++v)rec(1,v,all);

    //小さい順に並び替える
    sort(all.begin(),all.end());

    // K番目
    cout << all[k-1] << endl;
}


Measured memory_bytes: 5348
while True:    
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    else:
        if W % 2 == 0:
            i = H//2
            while i > 0:    
                print("#."*(W//2))
                print(".#"*(W//2))
                i -= 1
            if H % 2 == 1:
                print("#."*(W//2))
        else:
            i = H // 2
            while i > 0:    
                print("#."*(W//2)+"#")
                print(".#"*(W//2)+".")
                i -= 1
            if H % 2 == 1:
                print("#."*(W//2)+"#")
        print("")

Measured memory_bytes: 7624
class UnionFind(object):
    def __init__(self, size, weight):
        self.parent = [i for i in range(size)]
        self.rank = [0 for _ in range(size)]
        self.size = weight

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
            self.size[y]+=self.size[x]
        else:
            self.parent[y] = x
            self.size[x]+=self.size[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)
      
    def get_size(self, x):
        x = self.find(x)
        return self.size[x]
from collections import defaultdict
N, M = map(int, input().split())
X = list(map(int, input().split()))
edge = []
G = [[] for _ in range(N)]
for _ in range(M):
    a, b, y = map(int, input().split())
    edge.append((y, a-1, b-1))
edge.sort()
for i, (y, a, b) in enumerate(edge):
    G[a].append(i)
    G[b].append(i)
U = UnionFind(N, X)
candidate = [False]*M
for i, e in enumerate(edge):
    y, a, b = e
    U.unite(a, b)
    if U.get_size(a)>=y:
        candidate[i] = True
is_used = [False]*M
ans = 0
for i in range(M)[::-1]:
    y, a, b = edge[i]
    if is_used[i]:
        continue
    if candidate[i]:
        que = [i]
        is_used[i] = True
        while que:
            e = que.pop()
            _, a, b = edge[e]
            for ne in G[a]+G[b]:
                if edge[ne][0]<=y and not is_used[ne]:
                    que.append(ne)
                    is_used[ne] = True
print(M-is_used.count(True))
        

Measured memory_bytes: 140308
#include <bits/stdc++.h>
#define fin freopen("E:/in.txt", "r", stdin)
#define fout freopen("E:/out.txt", "w", stdout)
#define ms(a, x) memset(a, x, sizeof(a))
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define per(i, a, n) for(int i = n; i >= a; i--)
typedef long long ll;
typedef long double ld;
const int maxn = 1e5+5;
const int mod = 1e9+7;
using namespace std;
typedef pair<int, int> pii;
ll n, m;

int main(){
    cin >> n >> m;
    if(m % n == 0){
        cout << m/n << endl;
        return 0;
    }
    ll p = m/n;
    ll limit = sqrt(m);
    ll get = min(limit, p);
    ll ans = 0;
    per(i, 1, get){
        if(m%i == 0){
            ll x = m/i;
            ans = max(ans, (ll)i);
            if(x*n <= m) ans = x;
            else break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double

int ans=0;
int32_t main()
{
	IOS
	int a,b,k;cin>>a>>b>>k;
	vector<int>ans;
	for(int i=1;i<=100;i++)
	{
		if(a%i==0 && b%i==0)
		{
			ans.push_back(i);
		}
		
	}
	sort(ans.rbegin(),ans.rend());
	cout<<ans[k-1]<<endl;
	
}
			
	
	
	
	
	

	

	

	
		


Measured memory_bytes: 256
#include <stdio.h>

void CountingSort(int *,int *,int);

int A[2000001];
int B[2000001];
int n;

int main(){

  int i,max=0;
  
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }

  CountingSort(A,B,10000);

  for(i=1;i<=n;i++){
    printf("%d",B[i]);
    if(i<n) printf(" ");
  }
  printf("\n");

  return 0;
  
}

void CountingSort(int A[],int B[],int k){

  int C[k+1];
  int i,j;
  
  for(i=0;i<=k;i++){
    C[i]=0;
  }

  for(j=1;j<=n;j++){
    C[A[j]]++;
  }

  for(i=1;i<=k;i++){
    C[i]=C[i]+C[i-1];
  }

  for(j=n;j>=0;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
}

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

int main() {
  int n, s = 0;
  cin >> n;
  vector<int> vec(n);
  bool b = true;
  
  for (int i = 0; i < n; i++)
	cin >> vec.at(i);
  
  int x = 0;

  for (int j = 0; j < n; j++) {
    if (vec.at(x) == 2) {
      s++;
      cout << s << endl;
      s = -1;
      break;
    }
    else {
	  x = vec.at(x) - 1;
      s++;
    }
  }
  
  if (s != -1)
    cout << -1 << endl;
  
}


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

res=n
for i in range(n+1):
    cc=0
    t=i
    while t>0:
        cc=cc+t%6
        t=t//6
    t=n-i
    while t>0:
        cc=cc+t%9
        t=t//9
    if res>cc:
        res=cc

print(res)


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

int main(){
  ll n;
  cin >> n;
  
  ll left = 0, right = n+1;
  while(abs(right-left)>1){
    ll mid = (right + left)/2;
    if(mid*(mid+1)/2<n) left = mid;
    else right = mid;
  }
  vector<ll>vec;
  vec.push_back(left+1);
  
  ll ans = left+1;
  ll k = left;
  while(ans<n){
    ans += k;
    if(ans>n){
      ans -= k;
      k--;
    }
    else{
      vec.push_back(k);
      k--;
    }
  }
  
  ll m = vec.size();
  rep(i,m){
    cout << vec[i] << endl;
  }
  return 0;
  
}

Measured memory_bytes: 512
/* a */
#include <bits/stdc++.h>
#define N 55

using namespace std;

int n, t[N];
string s[N], X;

int main() {
	cin >> n;	
	for(int i = 1; i <= n; ++i)
		cin >> s[i] >> t[i];
	cin >> X;
	int ans = 0;
	for(int i = n; i >= 1; --i) {
		if(s[i] == X) break;
		ans += t[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

struct state {
	int p, c, g;
	state(int p, int c, int g) : p(p), c(c), g(g) {};
	bool operator<(const state &o)const {
		return o.c<c;
	}
};

int main() {
	int N, M, cap;
	while(cin >> N >> M >> cap, N) {
		string src, dest;
		cin >> src >> dest;
		int size = 0;
		vector<vs> data(N, vs(3)); 
		map<string, int> index;
		{
			set<string> cities;
			REP(i, N) {
				REP(j, 2) {
					cin >> data[i][j];
					cities.insert(data[i][j]);
				}
				cin >> data[i][2];
			}

			set<string>::iterator it = cities.begin();
			while(it != cities.end()) {
				index[*it] = size;
				size++;
				it++;
			}
		}

		vector<vector<pii> > dist(size);
		REP(i, N) {
			int c1 = index[data[i][0]];
			int c2 = index[data[i][1]];
			int cost = toInt(data[i][2]);

			dist[c1].push_back(make_pair(c2, cost));
			dist[c2].push_back(make_pair(c1, cost));
		}

		vi gas(size);
		string s;
		REP(i, M) {
			cin >> s;
			gas[index[s]] = 1;
		}

		vvi cost(size, vi(cap*10+1, INF));
		priority_queue<state> Q;
		Q.push(state(index[src], 0, cap*10));
		cost[index[src]][cap*10] = 0;
		while(!Q.empty()) {
			state st = Q.top();
			Q.pop();

			if(st.p == index[dest]) {
				cout << st.c << endl;
				goto end;
			}

			REP(d, dist[st.p].size()) {
				int np = dist[st.p][d].first;
				int nc = st.c + dist[st.p][d].second;
				int ng = st.g - dist[st.p][d].second;

				if(ng < 0) {
					continue;
				}
				if(gas[np]) {
					ng = cap*10;
				}

				if(nc < cost[np][ng]) {
					cost[np][ng] = nc;
					Q.push(state(np, nc, ng));
				}
			}
		}

		cout << -1 << endl;
		end:;
	}

	return 0;
}

Measured memory_bytes: 50700
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'


def main():
    a =ii()
    print(a+a**2+a**3)



main()



Measured memory_bytes: 9848
#include<iostream>
#include<set>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
string edge[10][2];

string substitute(string tar,string &from,string &to){
  string ret;
  for(int i=0;i<tar.size();i++){
    bool flag=true;
    rep(j,from.size()){
      if ( from[j]!=tar[i+j]){flag=false;break;}
    }
    if ( flag == false)ret+=tar[i];
    else {
      ret+=to;
      i+=from.size()-1;
    }
  }
  return ret;
}

int bfs(string &start,string &goal,int n){
  queue<pair<string,int> > Q;
  set<string>S;
  Q.push(make_pair(start,0));
  S.insert(start);
  while(!Q.empty()){
    pair<string,int> now =Q.front();
    Q.pop();
    if ( now.first == goal)return now.second;
    rep(i,n){
      string next = substitute(now.first,edge[i][0],edge[i][1]);
      if ( S.find(next) == S.end() && next.size()<= goal.size()){
	S.insert(next);
	Q.push(make_pair(next,now.second+1));
      }
    }
    
  }
  return -1;
}


main(){

  int n;
  while(cin>>n && n){
    string start,goal;
    rep(i,n)cin>>edge[i][0]>>edge[i][1];
    cin>>start>>goal;
    cout << bfs(start,goal,n) <<endl;
  }
}

Measured memory_bytes: 0
import java.util.Scanner;
public class Main {
	public static void main(String args[]){//double 处理果盘
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] num = new int[n];
		long sum = 0;
		for (int i=0;i<n;i++){
			num[i] = in.nextInt();
		}
		
		for (int i=0;i<n;i++){
			for (int j=i+1;j<n;j++){
				sum += num[i]*num[j];
			}
		}
		System.out.println(sum);
	}
}

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

#define DIV 1000000007

int main(void) {
	long long n;
	char s[100000] = { 0 };
	long long cnt[26] = { 0 };
	long long ans = 1;

	scanf("%lld", &n);
	scanf("%s", s);

	for (int i = 0; i < n; i++) cnt[s[i] - 97]++;
	for (int i = 0; i < 26; i++) ans = ans * (cnt[i] + 1) % DIV;
	printf("%lld", ans - 1);

	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8= {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	static int[][] directions4= {{-1,0},{1,0},{0,-1},{0,1}};
	static int ans;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while(true) {

			int n = sc.nextInt();

			if(n==0) {
				break;
			}
			int ans =0;
			int n2 = n*2;
			int end = (int)Math.sqrt(n2) +1 ;
			boolean[] isDividable = new boolean[n2+1];

			for(int i = 2; i < end; i++) {
				if(isDividable[i]) {
					continue;
				}

				for(int j = i; j < n2+1; j+=i) {
						isDividable[j] =true;
				}

			}
			for(int i = n+1; i < n2+1; i++) {
				if(!isDividable[i]) {
					ans++;
				}
			}
			System.out.println(ans);
		}
	}

	//BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for(int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}
}



Measured memory_bytes: 38280
# n,m = map(int, input().split())
s = input()

l = len(s)
f = int((l-1)/2)
b = int((l+3)/2) - 1

# print(f,b)

if s != s[::-1] or s[:f] != s[:f:-1] or s[b:] != s[b:][::-1]: 
  # print(s[::-1])
  print("No")
else: 
  print("Yes")

# if :
#   print(s[:f:-1])
#   print("No")

# if :
#   print(b,":",s[b:][::-1])
#   print("No")




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

void run() {
  int n;
  std::cin >> n;
  std::vector<int> l(n * 2);
  for (int i = 0; i < n * 2; ++i) {
    std::cin >> l[i];
  }
  std::sort(l.begin(), l.end());
  int ret = 0;
  for (int i = 0; i < n * 2; i += 2) {
    ret += l[i];
  }
  printf("%d\n", ret);
}

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


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  float a,b;
  int c,d;
  char t[][4]={
    "AAA","AA","A","B","C","D","E","NA"
  };
  while(scanf("%f%f",&a,&b)==2){
    if(a<35.5)c=0;
    else if(a<37.5)c=1;
    else if(a<40)c=2;
    else if(a<43)c=3;
    else if(a<50)c=4;
    else if(a<55)c=5;
    else if(a<70)c=6;
    else c=7;
    if(b<71)d=0;
    else if(b<77)d=1;
    else if(b<83)d=2;
    else if(b<89)d=3;
    else if(b<105)d=4;
    else if(b<116)d=5;
    else if(b<148)d=6;
    else d=7;
    puts(t[c>d?c:d]);
  }
  return 0;
}

Measured memory_bytes: 0
n, m = map(int, input().split())
data2 = []
for i in range(m):
    data2.append(input().split())

graph = [[] for i in range(n)]
for i in range(0,m):
    a, b = map(lambda z: int(z) - 1, data2[i])
    graph[a].append(b)
    graph[b].append(a)

size = [0 for i in range(n)]
check = [True for i in range(n)]
for i in range(n):
    if check[i]:
        tmp = 1
        stack = [i]
        check[i] = False
        while stack:
            now = stack.pop()
            size[now] = tmp
            tmp += 1
            for to in graph[now]:
                if check[to]:
                    check[to] = False
                    stack.append(to)
print(max(size))

Measured memory_bytes: 110432
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int max = -1;
    for (int i = 0; i <= n - 2; i++) {
      int[] x = new int[26];
      int[] y = new int[26];
      for (int j = 0; j <= i; j++) {
        x[s.charAt(j) - 'a']++;
      }
      for (int j = i + 1; j <= n - 1; j++) {
        y[s.charAt(j) - 'a']++;
      }
      int count = 0;
      for (int j = 0; j < 26; j++) {
        if (x[j] > 0 && y[j] > 0) {
          count++;
        }
      }
      if (max < count) {
        max = count;
      }
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 21844
import java.util.Arrays;
import java.util.Scanner;

class Main {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int[] arr = new int[10];
        for (int i=0; i<10; i++){
            arr[i] = scanner.nextInt();
        }
        Arrays.sort(arr);
        System.out.println(arr[9]);
        System.out.println(arr[8]);
        System.out.println(arr[7]);
    }
}


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

priority_queue<int, vector<int>, greater<int>> pq;
 
int main(){
    int N,T; cin >> N >> T;
    int c,t;
    rep(i,N){
        cin >> c >> t;
        if (t<=T) pq.push(c);
    }
    if (pq.empty()) cout << "TLE" << endl;
    else cout << pq.top() << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N;
vector<pair<int,int>> A[15];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>x;
		FOR(j,x) {
			cin>>k>>l;
			A[i].push_back({k-1,l});
		}
	}
	
	int ma=0;
	int mask;
	FOR(mask,1<<N) if(__builtin_popcount(mask)>ma) {
		int ok=1;
		FOR(i,N) if(mask&(1<<i)) {
			FORR(a,A[i]) {
				if(((mask>>a.first)&1)!=a.second) ok=0;
			}
		}
		if(ok) ma=__builtin_popcount(mask);
	}
	cout<<ma<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; } 
template<class T> void chmax(T &t, T f) { if (t < f) t = f; } 

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())



    const int MAX_N = 200010;
	int par_K[MAX_N];
	int _rank_K[MAX_N];
	int par_L[MAX_N];
	int _rank_L[MAX_N];

	void UF_init(int n){
        REP(i, n){
			par_K[i] = i;
            _rank_K[i] = 0;
			par_L[i] = i;
            _rank_L[i] = 0;
		}
	}

	int find_K(int x){
		if(par_K[x] == x) return x;
		else return par_K[x] = find_K(par_K[x]);
	}

	int find_L(int x){
		if(par_L[x] == x) return x;
		else return par_L[x] = find_L(par_L[x]);
	}

	void unite_K(int x, int y){
		x = find_K(x);
		y = find_K(y);
		if(x == y) return;
		if(_rank_K[x] < _rank_K[y]) par_K[x] = y;
		else{
			par_K[y] = x;
			if(_rank_K[x] == _rank_K[y]) _rank_K[x]++;
		}
	}

	void unite_L(int x, int y){
		x = find_L(x);
		y = find_L(y);
		if(x == y) return;
		if(_rank_L[x] < _rank_L[y]) par_L[x] = y;
		else{
			par_L[y] = x;
			if(_rank_L[x] == _rank_L[y]) _rank_L[x]++;
		}
	}

int N, K, L;

void init() {
}

void input() {
	cin >> N >> K >> L;
	UF_init(N);
	REP(i, K){
		int p, q; cin >> p >> q; p--; q--;
		unite_K(p, q);
	}
	REP(i, L){
		int p, q; cin >> p >> q; p--; q--;
		unite_L(p, q);
	}
}

map<pair<int, int>, VI> m;
int res[200010];

void solve() {
	m.clear();
	REP(i, N) m[make_pair(find_K(i), find_L(i))].PB(i);
	MSET(res, 0);
	FIT(it, m) {
		REP(a, SZ(it->second)){
			res[(it->second)[a]] = SZ(it->second);
		}
	}
	REP(i, N) cout << res[i] << " ";
	cout << endl;
}

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








Measured memory_bytes: 24448
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  ll N,A,B;
  cin >> N >> A>>B;
  if(A==B){
    cout << 1 << endl;
    return 0;
  }
  else if(N==1 || A>B) {
    cout << 0 << endl; 
    return 0;
  }
  cout  << A+B*(N-1) - (A*(N-1)+B) + 1 << endl;
}

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

using namespace std;

char s[200005], t[200005];

int main() {
	scanf("%s%s", s, t);
	int l = strlen(s);
	
	int res = 0;
	
	for (int i = 0; i < l; i++) {
		res += (s[i] != t[i]);	
	}
	
	printf("%d\n", res);
}


Measured memory_bytes: 4196
def resolve():
  N, T = map(int, input().split())
  tt = list(map(int, input().split()))
  ans = 0
  last = 0

  for t in tt:
    if t >= last:
      ans += T
      last = t + T
    else:
      ans += t + T - last
      last = t + T

  print(ans)

  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 25196
// Problem : D - Wall
// Contest : AtCoder - AtCoder Beginner Contest 079
// URL : https://atcoder.jp/contests/abc079/tasks/abc079_d
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
	int n,m;cin>>n>>m;
	int cost[10][10];
	for(int i=0;i<10;i++)
	for(int j=0;j<10;j++)
	cin>>cost[i][j];
	int a[n][m];
	int ans=0;
	for(int k=0;k<10;k++)
	{
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			cost[i][j]=min2(cost[i][k]+cost[k][j],cost[i][j]);		
		}
	}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			int x;cin>>x;
			if(x==-1)
			continue;
			else
			{
				ans+=cost[x][1];
			}
		}
	}
	cout<<ans;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3576
N = int(input())
v = sorted(list(map(int, input().split())), reverse=True)
ans = 0
tw = 2
for i in range(len(v) - 1):
    ans += v[i] * 0.5 ** (i + 1)
print(ans + v[-1] * 0.5 ** (len(v) - 1))


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

int main() {
  int k,s;cin>>k>>s;
  int cnt=0;
  rep(a,k+1) rep(b,k+1) {
    int c = s - a - b;
    if (c>=0 && c<=k) cnt++;
  }
  cout<<cnt;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprev(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define pc(c) putchar_unlocked(c)
typedef long long ll;

char arr[11];
int n;

void st(int cou, int t)
{
  if (cou == 0)
  {
    cout << arr << endl;
    return;
  }

  rep(i, t)
  {
    arr[n - cou] = 'a' + i;
    if (i + 1 == t)
      st(cou - 1, t + 1);
    else
      st(cou - 1, t);
  }
}

int main()
{
  cin >> n;
  arr[n] = '\0';
  st(n, 1);
}


Measured memory_bytes: 1536
#include<iostream>
using namespace std;
int main(){
  int a, b,c,d,e,f,min=d;
  cin>>a>>b>>c;
  d=a+b;
  e=b+c;
  f=a+c;
  if(d<=e&&d<=f){
    min=d;
  }
  if(e<=d&&e<=f){
    min=e;
  }
  if(f<=e&&f<=d){
    min=f;
  }
  cout<<min<<endl;
}

Measured memory_bytes: 256
class Node
  attr_accessor :key, :left, :right
  def initialize(arr)
    @key = arr[0]
    @left = arr[1]
    @right = arr[2]
  end
  def preorder
    print " ", key
    left.preorder if left != -1
    right.preorder if right != -1
  end
  def inorder
    left.inorder if left != -1
    print " ", key
    right.inorder if right != -1
  end
  def postorder
    left.postorder if left != -1
    right.postorder if right != -1
    print " ", key
  end
end
def to_node(n)
  $tree.each{ |m| n.left = m if n.left == m.key } if n.left != -1 
  $tree.each{ |m| n.right = m if n.right == m.key } if n.right != -1
end
arr = []
$tree = []
n = gets.to_i
n.times do
  node = Node.new(gets.split.map(&:to_i))
  $tree << node
  arr << node.left
  arr << node.right
end
$tree.each{ |n| $root = n unless arr.include?(n.key) }
$tree.each { |n| to_node(n) }
puts "Preorder"
$root.preorder
puts
puts "Inorder"
$root.inorder
puts
puts "Postorder"
$root.postorder
puts

Measured memory_bytes: 8748
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
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 main() {
  int N; cin >> N;
  vector<int> v(N);
  rep (i, N) cin >> v[i];
  sort(ALL(v));
  double ave = v[0];
  reps (i, N) {
    ave = (v[i] + ave) / 2.;
  }
  cout << ave << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}


Measured memory_bytes: 256
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int main()
{
	int a,p;
	cin>>a>>p;
	cout<<(a*3+p)/2<<endl;
	rt0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pll pair<ll,ll>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vbl vector<bool>
#define vvll vector<vll>
#define vld vector<ld>
#define vb vector<bool>
#define vc vector<char>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()

template<class T> ostream& operator<<(ostream &os, vector<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T> ostream& operator<<(ostream &os, set<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, map<T , R> V){
	os << "[ ";
	for(auto v  : V) os << "(" << v.first << ":" << v.second << ")";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, pair<T , R> V){
	return os << "(" << V.first << "," << V.second << ")";
}

#define cerr cout
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
    clock_t clk=clock();
    #define checktime() cout<<"\nTime Elapsed : "<<float(clock()-clk)/CLOCKS_PER_SEC<<endl
#else
    #define trace(...);
    #define checktime();
#endif

const ll Mod = 1e9 + 7;
// const ll Mod = 998244353;
const ll MAXN = 1e6;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<fixed<<setprecision(25);

    ll n,k;cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<=n+1;i++){
        ans=((ans+i*n-i*(i-1)+1)%Mod+Mod)%Mod;
    }
    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 3652
from math import floor , ceil

num = [int(_) for _ in input().split()]

x = ceil(num[0] / (8 / 100))
y = round(num[1] / (10 / 100))

if x == y:
    print(x)
    exit()
else:
    for temp in range(min(x,y), max(x,y)+1 ):
        if floor(temp * 0.08) == num[0] and floor(temp * 0.10) == num[1]:
            print("{}".format(temp))
            exit()
print(-1)

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    int K;
    cin>>K;
    int ans;
    int a;
    a=K/2;
    
    ans=a*(K-a);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
counter = Counter()

for ai in a:
    if ai % 4 == 0:
        counter[4] += 1
    elif ai % 2 == 0:
        counter[2] += 1
    else:
        counter[1] += 1

ans = 'No'
if counter[1] == 0 and counter[2] == 0:
    ans = 'Yes'
if counter[1] == counter[4]:
    ans = 'Yes'
if counter[2] == 0:
    if counter[1] == counter[4] + 1:
        ans = 'Yes'

print(ans)




Measured memory_bytes: 14636
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a = 0,b = 0,c = 0,d = 0,e = 0,n = 0,ans = 0;
  string s,ss,sss;
  cin>>s;
  if(s.size()%2){
    cout<<"No"<<endl;
    return 0;
  }
  for(int i=0;i<s.size();i+=2){
    if(!(s[i] == 'h' && s[i+1] == 'i')){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
using namespace std;
#define VMAX 10000

void countingSort(vector<int>& input, vector<int>& output, int num) {
    vector<int> counting(VMAX+1, 0);
    for(vector<int>::iterator itr = input.begin(); itr != input.end(); ++itr) {
        counting[*itr] += 1;
    }
    
    for(int i=1; i<=VMAX; i++) {
        counting[i] = counting[i] + counting[i-1];
    }
    for(int i=num-1; i>=0; i--) {
        output[counting[input[i]] - 1] = input[i];
        counting[input[i]] -= 1;
    }
}

int main() {
    int num;
    cin >> num;
    vector<int> array(num, 0);
    vector<int> output(num, 0);
    for(int i=0; i<num;i++) {
        int number;
        cin >> number;
        array[i] = number;
    }

    countingSort(array, output, num);

    for(int i=0; i<num; i++) {
        if(i != 0) cout << " ";
        cout << output[i];
    }
    cout << endl; 
}


Measured memory_bytes: 18340
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
using ll = long long;

int main(void) {
    int N; cin >> N;
    ll sum = 0;
    vector<int> A;
    int V[1000000] = {};
    for(int i=0; i<N; i++) {
        int temp; cin >> temp;
        sum += temp;
        A.push_back(temp);
        V[temp] += 1; 
    }

    int Q; cin >> Q;
    for(int i=0; i<Q; i++) {
        int B,C; cin >> B >> C;
        ll diff = C - B;
        sum += V[B] * diff;
        int x = V[B];
        V[B] = 0;
        V[C] += x;
        cout << sum << endl;
    }
}

Measured memory_bytes: 7820
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    ll n,k;
    cin >> n >> k;
    ll x = n % k;
    ll y = abs(n%k-k);
    if(x>y)cout << y << endl;
    else cout << x << endl;
}

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

int main(){

  long long i, N, K;
  double p = 0;
  cin >> N >> K;
  
  //N:サイコロ, K:これ以上になると勝ち
  for(i=1; i<=N; i++){
    long long ex = 0;
    while(i * pow(2, ex) < K) ex++;
    p += pow(0.5, ex);
  }
  p /= N;
  printf("%.12f\n", p);
  return 0;
}

Measured memory_bytes: 4060
#include <iostream>
#include <vector>
using namespace std;
int INF = 100000000;
int main(){
  int n, M = 1000000;
  vector<int> T, T_odd, A(M,INF), odd(M,INF);
  int t = 1, k = 3;
  A[0] = 0;
  odd[0] = 0;
  T.push_back(1);
  T_odd.push_back(1);
  while(t < 1000000){
    T.push_back(t);
    if (t%2) T_odd.push_back(t);
    ++k;
    t *= k;
    t /= (k-3);
  }
  odd.push_back(M);
  for(int i = 0; i < T.size(); ++i){
    for(int j = 1; j <= 5; ++j){
      for(int k = 0; k+T[i]*j < M; ++k){
	A[k+T[i]*j] = min(A[k+T[i]*j],A[k]+j);
      }
    }
  }
  for(int i = 0; i < T_odd.size()-1; ++i){
    for(int j = 1; j < 10; ++j){
      for(int k = 0; k+T_odd[i]*j < M; ++k){
	odd[k+T_odd[i]*j] = min(odd[k+T_odd[i]*j],odd[k]+j);
      }
    }
  }
  while(cin >> n, n){
    cout << A[n] << " " << odd[n] << endl;
  }
  return 0;
}

Measured memory_bytes: 14244
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B,C,X;
    int count = 0;
    cin >> A >> B >> C >> X;
    for(int a =0; a <= A; a++){
        for(int b=0; b<= B; b++){
            for(int c=0; c <= C; c++){
                int total = 500*a + 100*b + 50*c;
                if(total == X) count++;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL               long long
#define PB               push_back
using namespace std;
int main(){
    int n;cin>>n;
    int dp[n][3];
    int mat[n][3];
    for (int i=0;i<n;i++)
        cin>>mat[i][0]>>mat[i][1]>>mat[i][2];
    for (int i=0;i<3;i++)dp[0][i]=mat[0][i];
    for (int i=1;i<n;i++){
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+mat[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+mat[i][1];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+mat[i][2];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 5940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1000000;
int main() {
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }
    map<int, int> tansaku_flags;
    vector<int> basho(N, INF);
    int p = 0;
    int hosu = 0;
    while(tansaku_flags[p] == 0) {
        tansaku_flags[p] = 1;
        basho[p] = hosu;
        hosu++;
        p = A[p];
    }
    int ans;
    if (K < basho[p]) {
        for (int i = 0; i < N; i++) {
            if (basho[i] == K)
                ans = i;
        }
    }
    else {
        K -= basho[p];
        K %= (hosu-basho[p]);
        //cout << hosu-basho[p] << endl;
        for (int i = 0; i < N; i++) {
            if (basho[i]-basho[p] == K) {
                ans = i;
                //cout << i << " " << basho[i] << " " << basho[p] << endl;
            }
        }
    }
    cout << ans+1 << endl;
}

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

using namespace std;
using ll=long long;
struct Node {
    int x, y;
    Node() {}
    Node(int _x, int _y) : x(_x), y(_y) {}
    bool operator<(const Node& _oth) const {
        return x+y > _oth.x+_oth.y;
    }
};

void solve() {
    int n; cin >> n;
    vector<Node> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x >> a[i].y;
    }
    sort(a.begin(), a.end());
    ll res = 0;
    for (int i = 0; i < n; i++) {
        if (i&1) res -= a[i].y;
        else res += a[i].x;
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1024
def main():
    N = int(input())
    p = tuple(map(float, input().split()))

    dp = [0 for i in range(N+1)]
    # iまで見たときに表の枚数がj枚の確率

    dp[0] = 1 - p[0]
    dp[1] = p[0]
    for i in range(1, N):
        for j in range(i+1, -1, -1):

            dp[j] = dp[j]*(1-p[i]) + dp[j-1]*p[i]
            # else:
            #     dp[j] = dp[j]*(1-p[i])

    ans = sum(dp[N//2 + 1:])
    print(ans)


main()


Measured memory_bytes: 3444
#x, y, a, b, c = gets.split.map(&:to_i)

n, k = gets.split.map(&:to_i)

cnt = Array.new(10**5 + 1, 0)

n.times do 
    a, b = gets.split.map(&:to_i)
    cnt[a] += b
end

sum = 0
for i in 1..10**5
    sum += cnt[i]
    if sum >= k
        puts i
        exit
    end
end

Measured memory_bytes: 15108
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <typeinfo>

using namespace std;

///////////////////////////////////////////////////////////////////////////////

#define pb push_back

struct T2 {
        long t0;
        long t1;
};

struct T3 {
        long t0;
        long t1;
        long t2;
};

void longin(long &a)
{
        cin >> a;
}

void longinl1(auto &v, long count)
{
        for (long i = 0; i < count ; ++i) {
                long a;
                cin >> a;
                v.push_back(a);
        }
}

void longinl2(auto &v, long count)
{
        for (long i = 0; i < count ; ++i) {
                long a, b;
                cin >> a >> b;
                v.push_back({a, b});
        }
}

void longinl3(auto &v, long count)
{
        for (long i = 0; i < count ; ++i) {
                long a, b, c;
                cin >> a >> b >> c;
                v.push_back({a, b, c});
        }
}

void longina(auto &v, long count)
{
        longinl1(v, count);
}

long min(const vector<long> v)
{
        long ret = (long)numeric_limits<double>::infinity();
        for (auto i : v) ret = min(ret, i);
        return ret;
}

///////////////////////////////////////////////////////////////////////////////

static long nn;
static long mod = pow(10, 9) + 7;
map<string, long> memo[102];
bool ok(const string &last4)
{
        string last3 = string(last4, 1, 3);
        string last2 = string(last4, 2, 2);
        string first2 = string(last4, 0, 2);

        if (last3 == "AGC") return false;
        if (last3 == "ACG") return false;
        if (last3 == "GAC") return false;
        if (last4[0] == 'A' && last2 == "GC") return false;
        if (last4[3] == 'C' && first2 == "AG") return false;

        return true;
}

long dfs(long cur, const string & last3)
{
        if (memo[cur].count(last3) > 0) {
                return memo[cur][last3];
        }

        if (cur == nn) return 1;

        long ret = 0;
        for (const char &c : "ACGT") {
                if (c == 0) continue;
                string cs = string(1, c);
                if (ok(last3 + cs)) {
                        ret = (ret + dfs(cur + 1, string(last3, 1, 2) + cs)) % mod;
                }
        }

        memo[cur][last3] = ret;
        return ret;
}

int main()
{
        long n;
        longin(n);
        nn = n;

        cout << dfs(0, "TTT");

        return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){

  std::string S;
  std::cin >> S;
  int length = S.length();
  int first_zero=0, first_one=0, second_zero=0, second_one=0;
  for (int i=0; i<length; i++){
    if (i%2==0){
      if (S[i]=='0'){
        first_zero++;
      } else if (S[i]=='1'){
        first_one++;
      }
    } else {
      if (S[i]=='0'){
        second_zero++;
      } else if (S[i]=='1'){
        second_one++;
      }      
    }
  }
  int ans = std::min(first_zero+second_one, first_one+second_zero);
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 888