akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7

# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

X, A = [int(x) for x in input().split()]


if X < A:
    print(0)
else:
    print(10)



Measured memory_bytes: 3444
#include <stdio.h>

int main(void) {

	int H, W;
	int i, j;

	while (1) {

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

		if (H == 0 && W == 0)
			break;

		for (i = 0; i < H; i++) {
			for (j = 0; j < W; j++) {

				if (i%2 == 0 && j%2 == 0) {
					printf("#");
				}
				else if (i % 2 == 1 && j % 2 == 1) {
					printf("#");
				}
				else {
					printf(".");
				}
			}
			printf("\n");
		}

		printf("\n");
	}

	return(0);

}


Measured memory_bytes: 2044
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(void){
    double r;
    cin>>r;
    
    double pi=acos(-1);
    cout<<fixed<<setprecision(6);
    double area=r*r*pi;
    double cir=(r+r)*pi;
    cout<<area<<" "<<cir<<endl;
    
}


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

#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main(){
  int a,b;
  cin>>a;
  if(a==1){a=100;}
  cin>>b;
  if(b==1){b=100;}
  if(a==b){cout<<"Draw"<<endl;}
  else if(a>b){cout<<"Alice"<<endl;}
  else{cout<<"Bob"<<endl;}
}

Measured memory_bytes: 256
A_list = []
for i in range(5):
    A_list.append(input())
one_list = []
one_list.append(int(A_list[0][-1]))
one_list.append(int(A_list[1][-1]))
one_list.append(int(A_list[2][-1]))
one_list.append(int(A_list[3][-1]))
one_list.append(int(A_list[4][-1]))
min_num = max(one_list)
min_one_list_index = 1
for i in range(len(one_list)):
    if one_list[i] != 0 and min_num >= one_list[i]:
        min_num = one_list[i]
        min_one_list_index = i
A_list_min = A_list[min_one_list_index]
del A_list[min_one_list_index]


def ceil(src, range):
    if src % 10 == 0:
        return src
    else:
        return ((int)(src / range) + 1 ) * range


for i in range(len(A_list)):
    A_list[i] = ceil(int(A_list[i]), 10)
print(sum(A_list)+int(A_list_min))

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

int x, y, s;

inline int intax(int p, int x) {
    return (double)(p*(100+x))/100;
}

int main() {
    while(std::cin >> x >> y >> s) {
        if(x == 0 && y == 0 && s == 0) break;

        int a, b;
        int max = 0;
        for(a = 1; a < s; ++a) {
            for(b = 1; b < s; ++b) {
                if( (intax(a, x) + intax(b, x)) == s) {
                    max = std::max(max, intax(a, y) + intax(b, y));
                }
            }
        }
        std::cout << max << std::endl;
    }
}


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

int main() {
    int64_t x;
    cin >> x;

    int64_t cnt = 0;
    int64_t yen = 100;

    while (true) {
        yen += yen/100;
        cnt++;
        if (yen>=x) {
            cout << cnt << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>

int isPrime(int n){
    int i;
    int flag = 1;
    for(i=2; i*i < n;i++){
        if(n%i==0){
            flag = 0;
            break;
        }
    }
    return flag;
}

int main(void){
    int i,n;
    scanf("%d", &n);
    printf("%d:", n);
    
    if(isPrime(n)){
        printf(" %d\n", n);
        return 0;
    }
    
    i=2;
    while(i <=n){
        while(n%i == 0){
            n = n/i;
            printf(" %d", i);
        }
        i++;
    }
    printf("\n");
    return 0; 
    
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
typedef pair<double,double> pdd;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) ll(i.size())
#define FOR(i, j, k, in) for (ll i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (ll i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

template<class T> inline bool cmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool cmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MOD=1000000007;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll MAXN=1e5+5;
const ll MAXLG=__lg(MAXN)+2;
ll n,t,a,h[MAXN],bst;
/********** Good Luck :) **********/
int main()
{
    IOS();
    cin>>n;
    cin>>t>>a;
    REP(i,n) {
        cin>>h[i];
        if(bst==-1) bst = i;
        if(abs(1000*t-6*h[i]-a*1000) < abs(1000*t-6*h[bst]-a*1000))bst = i;
    }

    cout<<bst+1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
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> T(N);
  for (int i = 0; i < (int)(N); ++i) cin >> T[i];
  int M;
  cin >> M;
  int S = accumulate((T).begin(), (T).end(), 0);
  for (int i = 0; i < (int)(M); ++i) {
    int P, X;
    cin >> P >> X;
    --P;
    cout << S - (T[P] - X) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner

fun main(args: Array<String>){
    val scanner = Scanner(System.`in`)
    var nums: Array<Int?> = arrayOfNulls(3)
    for (i in 0 until 3){
        nums[i] = scanner.nextInt()
    }
    nums.sort()
    val K = scanner.nextInt()
    for (j in 0 until K){
        nums[2] = nums[2]?.times(2)
    }
    println(nums[0]!! + nums[1]!! + nums[2]!!)
}

Measured memory_bytes: 33972
n = int(input())
ans = float("inf")
for i in range(n):
    if i * 9 > n:
        break
    j = (n-(i*9)) // 6
    k = (n-(i*9)) % 6

    tmp = 0
    tmp += k
    while i:
        tmp += i % 9
        i = i // 9
    while j:
        tmp += j % 6
        j = j // 6
    if tmp < ans:
        ans = tmp

print(ans)

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

bool judge(char a,char b) {
  int x = (a - '0')*10 + (b - '0');
  if ((1 <= x) && (x <= 12)) {
    return true;
  }
  else {
    return false;
  }
}
 
int main() {
  string S;
  cin >> S;
  bool a = judge(S.at(0),S.at(1));
  bool b = judge(S.at(2),S.at(3));
  if (a && b) {
    cout << "AMBIGUOUS" << endl;
  }
  else if (!a && !b) {
    cout << "NA" << endl;
  }
  else if (a && !b) {
    cout << "MMYY" << endl;
  }
  else {
    cout << "YYMM" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;

int main() {
  std::unordered_set<int> S;
  int n, k;
  std::cin >> n >> k;
  for(int i=0; i<k; i++){
    int d; std::cin >> d;
    for(int j=0; j<d; j++){
      int a;
      std::cin >> a;
      S.emplace(a);
    }
  }
  std::cout << n - S.size() << std::endl;
}

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

int main() {
    int a,b;

    cin >> a >> b;
    int x = (a+b)/2 +1;
    if((a+b)/2.0 == (a+b)/2 )
        x = (a+b)/2;   
    cout << x << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    N = input().strip()

    if N[0] == N[1] == N[2]:
        return "Yes"
    if N[1] == N[2] == N[3]:
        return "Yes"

    return "No"


if __name__ == "__main__":
    print(main())


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

int main(){
  int n,k,d,l,r,var,count,sum=0,ans=1;
  cin>> n >> k;
  vector<int> divide,a(n),remain(n);
  for (int i=0; i<n; i++){
    cin>> a[i];
    sum+=a[i];
  }
  
  for (int i=1; i*i<=sum; i++){
    if (sum%i==0){
      divide.push_back(i);
      divide.push_back(sum/i);
    }
  }
  sort(divide.begin(),divide.end()); //総和の約数を昇順に
  
  for (int i=divide.size()-1; i>0; i--){ //i=0はd=1になって必ず答えになる。あらかじめans=1にして省略
    d=divide[i];
    for (int j=0; j<n; j++) remain[j]=a[j]%d;
    sort(remain.begin(),remain.end()); //余りの配列を昇順に
    
    count=0; l=0; r=n-1;
    while (l<r){ //操作k回以内にremain配列を0とdだけにできるか
      if (remain[l]==0){ l++; continue;}
      if (remain[r]==d){ r--; continue;}
      var=min(remain[l],d-remain[r]);
      count+=var;
      if (k<count) break;
      remain[l]-=var; remain[r]+=var;
    }
    if (remain[l]%d==0){
      ans=d;
      break;
    }
  }
  
  cout<< ans << endl;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List as L

bigjump :: [[Int]] -> Int -> Int -> Int
bigjump a@([key, times]:left) goal previous
  | current < goal = bigjump left goal current
  | current >= goal = key
  where current = previous + times

main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]
  input <- replicateM n $ (map read . words) <$> getLine :: IO [[Int]]

  let sorted_input = L.sortBy (\a b -> compare (a !! 0) (b !! 0)) input
  let ans = bigjump sorted_input k 0
  print ans

Measured memory_bytes: 148860
#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;
int A,K;
int gr[101010];


int hoge(int A,int K) {
	if(A<K) return 0;
	if(A%K==0) return A/K;
	
	int dif=((A/K)+1);
	return hoge(A-max((A%K)/dif,1)*dif,K);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	/*
	for(i=0;i<=100;i++) {
		set<int> S;
		for(x=1;x<=i/N;x++) S.insert(gr[i-x]);
		while(S.count(gr[i])) gr[i]++;
		cout<<i<<" "<<gr[i]<<" "<<hoge(i,N)<<endl;
	}
	
	return;
	*/
	int nim=0;
	FOR(i,N) {
		cin>>A>>K;
		nim ^= hoge(A,K);
	}
	if(nim==0) cout<<"Aoki"<<endl;
	else cout<<"Takahashi"<<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<set>
#include<string>
#include<string.h>
using namespace std;
set<string>S;
int main(){
      int n;
      cin>>n;
      string s1,s2;
      while(n--){
            cin>>s1>>s2;
            if(s1=="insert"){
                  S.insert(s2);
            }
            else if(s1=="find"){
                  if(S.find(s2)==S.end())
                        cout<<"no"<<endl;
                  else
                        cout<<"yes"<<endl;
            }
      }
      return 0;
}


Measured memory_bytes: 32520
using System;
using System.Linq;
using System.Collections.Generic;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var abx = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var a = abx[0];
            var b = abx[1];
            var x = abx[2];

            var diviserB = b/x;
            var diviserA = a%x==0? a/x - 1 :a/x;

            var ans = diviserB - diviserA;

            Console.WriteLine(ans); 
        }
    }
}


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

struct node{
int key;
struct node *prev, *next;
};

struct node *nil;

void insert(int);
void delete(struct node*);
struct node* search(int);
void listPrint(void);

int main(){
  int n,i,x;
  char str[15];

  scanf("%d",&n);
  nil = (struct node*)malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;

  for(i = 0; i<n;i++){
    scanf("%s",str);
    if(str[0]== 'i'){
      scanf("%d",&x);
      insert(x);
    }else if(str[0]=='d'){
      if(str[6]=='\0'){
        scanf("%d",&x);
        delete(search(x));
      }else if(str[6]=='F'){
        delete(nil->next);
      }else{
        delete(nil->prev);
      }
    }
  }
  listPrint();
  return 0;
}




void insert(int key){
  struct node* newnode = (struct node*)malloc(sizeof(struct node));
  newnode->key = key;
  newnode->next = nil->next;
  nil->next->prev = newnode;
  nil->next = newnode;
  newnode->prev = nil;
 }

void delete(struct node* delnode){
  if(delnode == nil){;
  }else{
    delnode->prev->next = delnode->next;
    delnode->next->prev = delnode->prev;
    free(delnode);
  }
}

struct node* search(int key){
  struct node* searchnode = nil->next;
  while(searchnode != nil && searchnode->key != key){
    searchnode = searchnode->next;
  }
return searchnode;
}


void listPrint(){
  int i = 0;
  struct node* n= nil->next;
  while(1){
    if(n==nil)break;
    if(i>0)printf(" ");
    i++;
    printf("%d",n->key);
    n=n->next;
  }
  printf("\n");
}

Measured memory_bytes: 33008
n=int(input())
s=[input() for i in range(n)]
ct=[0]*4
for i in range(n):
  if s[i]=='AC':
    ct[0]+=1
  elif s[i]=='WA':
    ct[1]+=1
  elif s[i]=='TLE':
    ct[2]+=1
  else:
    ct[3]+=1
a1=['AC','x',str(ct[0])]
a2=['WA','x',str(ct[1])]
a3=['TLE','x',str(ct[2])]
a4=['RE','x',str(ct[3])]
print(' '.join(a1))
print(' '.join(a2))
print(' '.join(a3))
print(' '.join(a4))

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

using namespace std;
using ll = long long;

const ll MAX = 10000000;
const ll INF = 10000000000000000;


ll f(ll b, ll n) {
    if(b < 2)return -INF;
    ll sum = 0;
    while(n >= b)sum += n%b, n /= b;
    sum += n;
    return sum;
}


int main()
{
    ll n, s;
    cin >> n >> s;
    if(n == s) {
        cout << n + 1 << endl;
        return 0;
    }

    ll ans = INF;

    //小さいbについて全探索
    for(ll i = 2; i <= MAX; i++) {
        if(f(i, n) == s) {
            ans = min(ans, i);
        }
    }
    
    //大きいbについてはn / bを全探索
    for(ll i = 1; i <= MAX; i++) {
        ll lef = s - i;
        ll b = (n - lef) / i;
        if((n - lef) % i)continue;
        if(f(b, n) == s) {
            ans = min(ans ,b);
        }
    }
    if(ans != INF) {
        cout << (ans) << endl;
    } else {
        cout << (f(n, n) == s ? n : -1) << endl;
    }


}


Measured memory_bytes: 3556
# sys.stdin.readline()
import math
import sys
input = sys.stdin.readline


def decision(s,td,j):
    #index番目の文字が落ちるかどうかを判別
    #右に落ちるときは1，左に落ちるときは-1，落ちないときは0を返す
    global N,Q
    for [qi,v] in td:
        if j < 0 or j >= N:
            break
        if s[j] == qi:
            if v == 'L':
                j -= 1
            else:
                j += 1
    if j == -1:
        return -1
    elif j == N:
        return 1
    else:
        return 0
 
N,Q = map(int,input().split())
s = input()
td = [input().split() for _ in range(Q)]
    
#td[i][j]:i番目の文字(j=0)と方向(j=1)
    
    
RN = math.ceil(math.log2(N))
#2分探索
left = 0
right = N-1
#右側のボーダー
for i in range(RN):
    mid = (right+left)//2
    state = decision(s,td,mid)
    if state < 1:
        left = mid
    else:
        right = mid
    if (right - left) == 1:
        break
if right == N-1 and decision(s,td,right) == 0:
    right += 1
border_r = right
    
left = 0
right = N-1
#左側のボーダー
for i in range(RN):
    mid = ((right+left)//2)
    state = decision(s,td,mid)
    if state > -1:
        right = mid
    else:
        left = mid
    if (right - left) == 1:
        break
if left == 0 and decision(s,td,left) == 0:
    right -= 1
border_l = right
print(border_r-border_l)
 

Measured memory_bytes: 41332
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N, A = map(int, raw_input().split())
x = map(int, raw_input().split())
dp = [[0]*2505 for i in xrange(55)]
for xi in x:
    for i in xrange(2505 - xi - 1, -1, -1):
        for j in xrange(N, 0, -1):
            dp[j + 1][i + xi] += dp[j][i]
    dp[1][xi] += 1

ans = 0
for j in xrange(1, N + 1):
    ans += dp[j][j*A]
print ans


Measured memory_bytes: 5412
n=gets.to_i
move=5.times.map{gets.to_i}

people=Array.new(6,0)
people[0]=n
k=0
100.times{|i|
  k=[move[4],people[4]].min
  5.downto(1){|i|
    tr=[move[i-1],people[i-1]].min
    people[i]+=tr
    people[i-1]-=tr
  }
  if people.last==n
    puts i+1
    exit
  end
}

q,r=(n-people[5]).divmod(k)
q+=1 if r>0
puts 100+q

Measured memory_bytes: 1788
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
  int n;
  cin>>n;
  V<ll> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  ll ans=-1;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      ll tmp=a[i]*a[j];
      ll bfo=-1;
      bool ok=true;
      while(tmp){
        if(bfo==-1)bfo=tmp%10;
        else{
          if(bfo-1!=tmp%10)ok=false;
          bfo=tmp%10;
        }
        tmp/=10;
      }
      if(ok)chmax(ans,a[i]*a[j]);
    }
  }
  cout<<ans<<"\n";
}


Measured memory_bytes: 3236
#include<stdio.h>
#include<math.h>

int main(void){

  int th,ta,ah,aa;

  scanf("%d %d %d %d",&th,&ta,&ah,&aa);

  while(ah>0 && th>0){
    ah=ah-ta;
    th=th-aa;
  }
  if(ah<=0)printf("Yes");
  else if(th<=0)printf("No");
  return 0;
}

Measured memory_bytes: 1732
use std::vec::Vec;
use std::cmp::*;

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

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

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let (h, w) = read_touple::<usize>();
    let mut grid: Vec<Vec<char>> = Vec::new();
    for _ in 0..h {
      let line: Vec<char> = read::<String>().chars().collect();
      grid.push(line);
    }

    let mut res: usize = 0;
    for i in 0..h {
      for j in 0..w {
        if grid[i][j] == '#' {
           continue
        }
        let weight = grid_bfs(&grid, (i, j), '#');
        res = max(res, weight);
      }
    }
    // for i in 0..h {
    //   println!("{:?}", grid[i]);
    // }
    println!("{}", res);
}


use std::collections::VecDeque;
fn grid_bfs<T>(grid: &Vec<Vec<T>>, start: (usize, usize), skip: T) -> usize
where
    T: Eq + std::fmt::Debug,
{
    assert!(grid.len() > 0);
    assert!(grid[0].len() > 0);

    fn connect_vec(a: usize, b: usize, h: usize, w: usize) -> Vec<(usize, usize)> {
        let mut res = Vec::new();
        if a > 0 {
            res.push((a - 1, b));
        }
        if a < h - 1 {
            res.push((a + 1, b));
        }
        if b > 0 {
            res.push((a, b - 1));
        }

        if b < w - 1 {
            res.push((a, b + 1));
        }
        res
    }
    let h: usize = grid.len();
    let w: usize = grid[0].len();
    let mut q = VecDeque::new();
    let mut visit = vec![vec![false; w]; h];
    let mut res: Vec<Vec<usize>> = vec![vec![std::usize::MAX; w]; h];
    // init
    let (x, y) = start;
    visit[x][y] = true;
    res[x][y] = 0;
    q.push_back(start);

    while let Some(now) = q.pop_front() {
        let (a, b) = now;
        for (x, y) in connect_vec(now.0, now.1, h, w) {
            if grid[x][y] == skip {
                continue;
            }

            if !visit[x][y] {
                visit[x][y] = true;
                res[x][y] = min(res[x][y], res[a][b] + 1);
                q.push_back((x, y));
            }
        }
    }
    let mut ans: usize = 0;
    for i in 0..h {
      for j in 0..w {
        if res[i][j] == std::usize::MAX {
          continue
        }
        ans = max(ans, res[i][j]);
      }
    }

    
    // for i in 0..h {
    //   println!("{:?}", res[i]);
    // }
    // println!("");
    return ans;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define  ll  long long
int main()
{
    ft
    ll i,j,n,m;
    cin>>n>>m;
    m<<=1;
    n-=m;
    if(n<0)
    {
        n=0;
    }
    cout<<n<<"\n";
    return 0;
}


Measured memory_bytes: 256
MOD =  1000000007
res = 0
a = input()
n = len(a)
A = 13
dp=[[0 for i in range(A+1)] for j in range(n+1)]
dp[0][0] = 1
for i in range(n):
    c = 0
    if a[i] == '?': c = -1
    else: c = int(a[i])
    
    for j in range(10):
        if c != -1 and c != j: continue
        for ki in range(13):
            dp[i+1][(ki*10 + j)% 13] += dp[i][ki]
        
    for j in range(13):
        dp[i+1][j] %= MOD

print(dp[n][5])


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

int main() {
    int n;
    scanf("%d", &n);
    printf("%d\n", (n-30)/2);
}


Measured memory_bytes: 3200
n, k = map(int,input().split())
p = list(map(int, input().split()))

val = 0
for i in range(k):
    val += p[i]
point = 0

cnt = val
for i in range(k,n):
    cnt = cnt +  p[i] - p[i-k]
    if cnt > val:
        val = cnt
        point = i-k+1
#print(point)

ans = 0
for i in range(k):
    ans += (p[point] + 1) / 2
    point += 1

print(ans)

Measured memory_bytes: 71792
n = int(input())
AC = 0
WA = 0
TLE = 0
RE = 0
for i in range(n):
    a = input()
    if a == "AC":
        AC += 1
    elif a == "WA":
        WA += 1
    elif a == "TLE":
        TLE += 1
    else:
        RE += 1
print("AC"+" x "+str(AC))
print("WA"+" x "+str(WA))
print("TLE"+" x "+str(TLE))
print("RE"+" x "+str(RE))

Measured memory_bytes: 9204
import functools

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

def append_to_partial_sums(array, a_i):
    array.append((0 if len(array) == 0 else array[-1]) + a_i)
    return array

snuke = list(functools.reduce(append_to_partial_sums, a, []))
raccoon = list(reversed(functools.reduce(append_to_partial_sums, reversed(a), [])))
print(min(abs(snuke[i - 1] - raccoon[i]) for i in range(1, n)))


Measured memory_bytes: 30676
/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//  cout <<  s.at(1)-'0'-49  <<endl;
int main() {
  int x;
  cin >> x;
  int ma=0;
  int m=0;
  
  for(int i=1;i<1000;i++){
    for(int j=2;j<1000;j++){
      if(x >= pow(i, j) ) m = pow(i, j);
      ma = max(ma,m);
    }
  }
  cout << ma <<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] l = new int[N];
        for (int i = 0; i < N; ++i) {
            l[i] = sc.nextInt();
        }

        _out.println(search(0, K, l));
    }
    private Map<String, Long> memo = new HashMap<>();
    private long search(int d, int k, int[] l) {
        String key = d + ":" + k;
        if (memo.containsKey(key)) {
            return memo.get(key);
        }
        if (d == l.length) {
            return 0;
        }

        long res1 = search(d + 1, k, l);
        long res2 = 0;
        if (k - 1 >= 0) {
            res2 = search(d + 1, k - 1, l) + l[d];
        }

        long res = Math.max(res1, res2);
        memo.put(key, res);
        return res;
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 22868
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int A;
	string B;
	cin >> A >> B;
	int num = (int)(B[0] - '0') * 100 + (int)(B[2] - '0') * 10 + (int)(B[3] - '0');
	int ans = A * num / 100;
	cout << ans;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>

using namespace std;

#define Rep(i,a,b) for(ll i = a; i < b; ++i)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")

using ll = long long;

using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;


constexpr int inf = 1e9 + 7;
constexpr ll infll = 1ll << 60ll;
constexpr ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {
    template<typename T> void chmax(T& a, T b) { a = std::max(a, b); }
    template<typename T> void chmin(T& a, T b) { a = std::min(a, b); }
    template<typename T> void chadd(T& a, T b) { a = a + b; }

    void Cout(long long x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const T& x, const char* end = "\n") { std::cout << x << end; }
    template <typename T> void Cout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cout << x[i] << (i == sz - 1 ? end : sep); } }

    void CCout(long long x, const char* end = "\n") { std::cerr << x << end; }
    template <typename T> void CCout(const T& x, const char* end = "\n") { std::cerr << x << end; }
    template <typename T> void CCout(const std::vector<T>& x, const char* sep = " ", const char* end = "\n") { for (std::size_t i = 0, sz = x.size(); i < sz; i++) { std::cerr << x[i] << (i == sz - 1 ? end : sep); } }

    // 標準入出力
    struct inp {
        std::size_t sz;
        inp(std::size_t _sz = 1) : sz(_sz) {}
        template <typename T> operator T () const { T a; std::cin >> a; return a; }
        template <typename T> operator std::vector<T>() const { vector<T> a(sz); for (std::size_t i = 0; i < sz; i++) std::cin >> a[i]; return a; }
        template <typename T, typename U> operator std::pair<T, U>() const { T f; U s; std::cin >> f >> s; return std::pair<T, U>(f, s); }
    };

    inp inp1; // input one
}

int main() {

    ll n, k;
    cin >> n >> k;

    if (n >= k) n = (n % k);

    ll ans = min(n, abs(n - k));

    Cout(ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize ("02")
#define ll long long
#define oo 1000000007
using namespace std;

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

	string s;
	cin >> s;
	if(s[3] == s[2] && s[5] == s[4]) cout << "Yes";
	else cout << "No";

    return 0;
}


Measured memory_bytes: 256
from sys import stdin,stdout


n = int(stdin.readline())
dp = [0 for i in range(n)]
a  = list(map(int,stdin.readline().split()))
dp[1] = abs(a[1] - a[0])
if(n>1):
  for i in range(2,n):
  	dp[i] = min(dp[i-1] + abs(a[i]-a[i-1]) , dp[i-2] + abs(a[i]-a[i-2]))
print(dp[-1])


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

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  D(x)         cout << #x << " - " << x << endl;
  #define  D2(x)        cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
  #define  all(x)       (x).begin(), (x).end()
  #define  D2p(x)       cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;


  void solve(){
	int n;
	cin >> n;
	vpi v[n];
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		for(int j=0;j<a;j++){
			pi a1;
			cin >> a1.ff >> a1.ss;
			a1.ff--;
			v[i].push_back(a1);
		}
	}
	ll ans=0;
	for(int x=0;x<(1LL<<(n));x++){
		bool ok = true;
		for(int i=0;i<n;i++){
			if(x&(1LL<<i)){
				for(auto y:v[i]){			
					ok = ((y.ss) == (x&(1LL<<y.ff))>0);
					if(!ok)
						break;				
				}
			}
			if(!ok)break;
		}
		if(ok){
			ans = max(ans,(ll)__builtin_popcount(x));
		}
	}
	cout << ans;
  }

  int main(){
    IOS
    solve();
    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 3812
n,m=(int(i) for i in input().split())
l=[]
for i in input().split():
  l.append((int(i)+1)/2)
s=sum(l[0:m])
maxe=s
for i in range(n-m):
  s+=l[m+i]
  s-=l[i]
  if s>maxe:
    maxe=s
print(maxe)

Measured memory_bytes: 23524
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
#include <functional>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0スタート
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1スタート
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからb - 1まで
#define mREP(i,a,b) for (int i = a; i > (b); --i)  //aからb - 1まで
#define p(x) cout<<x<<endl  //xを改行付きで出力
const int INF = 1000000007;  //最大値兼MOD
//  cin.tie(0);
//  ios::sync_with_stdio(false);
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
  ll n;
  cin>>n;
  cout<<n * (n - 1) / 2<<endl;
  return 0;
}

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

int main(){
  int n; cin>>n;
  vector<int> mon(n+1);
  vector<int> hero(n);
  
  for(int i = 0; i<n+1; i++){
    cin >> mon[i];
  }
  
  for(int i = 0; i<n; i++){
    cin >> hero[i];
  }
  
  int prev = 0;
  long long int ans =0;
  
  for(int i=0; i<n;i++){
    if(prev+hero[i] <= mon[i]) {
      ans+=prev+hero[i];
      prev = 0;
    }else{
      ans+=mon[i];
      if(mon[i] > prev) prev=hero[i]-mon[i]+prev;
      else prev = hero[i];
    }
  }
  ans+=min(mon[n],prev);
  
  cout<< ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vll(v) sort((v).begin(), (v).end(), greater<long long>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}
const int IINF=(1<<30);
const ll LLINF = 1LL<<60;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string s; cin >> s;
  int base = 0;
  ll ans = 0;
  for (int i = 0; i < s.length(); i++){
    if(s[i] == 'W'){
      ans += ll(i - base);
      base++;
    }
  }
  say(ans);
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

void solve() {
    int s, w; scanf("%d%d", &s, &w);
    if (w >= s) printf("un");
    printf("safe");
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3740
#include<cstdio>

int main(void)
{
	int a, b, c, d;
	scanf("%d %d %d %d", &a, &b, &c, &d);
	while (1)
	{
		c -= b;
		if (c <= 0)
		{
			printf("Yes");
			break;
		}
		a -= d;
		if (a <= 0)
		{
			printf("No");
			break;
		}
	}
}

Measured memory_bytes: 1728
#!/usr/bin/env python3
#ABC128 A

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

a,p = LI()
print((3*a+p)//2)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
 
#define sec second
#define fir first
#define mo  998244353
#define inf 1e18
#define rep(i, s, n) for (ll i = s; i < n; i = i + 1)
#define rrep(i,s,n) for(ll i=s;i>=n;i--)
#define adiii\                               
  ios_base::sync_with_stdio(false);\                                      
  cin.tie(NULL);\
  cout.tie(NULL);									
 
ll mod(ll n) { return (n % (ll)mo + (ll)mo)%(ll)mo;}
ll gcd(ll a,ll b) {if (b == 0) return a;return gcd(b, a % b);}

int main(){
	adiii
	string s;cin>>s;
	ll n = s.length();
	vector <ll> cnt(2019,0);
	cnt[0]=1;
	ll ans=0;
	ll t=1;
	ll num=0;
	rrep(i,n-1,0){
		num = (num + t*(s[i] - '0'))%2019;
		t = (t*10)%2019;
		ans += cnt[num]++;
		
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    vector<vector<string>> S(N,vector<string>());
    vector<vector<int>> A(N,vector<int>());
    A[0].push_back(1);
    S[0].push_back("a");
    REP(i,N-1){
        REP(j,S[i].size()){
            REP(k,A[i][j]+1){
                char tm = 'a'+k;
                string tmp = S[i][j]+tm;
                S[i+1].push_back(tmp);
                A[i+1].push_back(max(k+1,A[i][j]));
            }
        }
    }
    REP(i,S[N-1].size())cout << S[N-1][i] << "\n";
}

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

int main()
{
    double A, B, H, M;
    cin >> A >> B >> H >> M;

    double diff = H + M / 60.;
    double a = diff * 2 * M_PI / 12.;
    double b = diff * 2 * M_PI;

    double ans = A * A + B * B - 2 * A * B * cos(a - b);
    cout << fixed << setprecision(12) << sqrt(ans) << endl;
}


Measured memory_bytes: 4256
s=int(input())
x1=0
y1=0
x2=1
y2=10**9
y3=(10**9)-(s%(10**9))
x3=s//(10**9)+1
if s==10**18:
  print(0,0,10**9,0,0,10**9)
else: 
  print(x1,y1,x2,y2,x3,y3)


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

int main(){
    string s;
    cin >> s;
    int k;
    cin >> k;
    int n = s.length();
    for (int i = 0; i < n; i++) {
    	if (s[i] == 'a') continue;
    	if ('z' + 1 - s[i] <= k) {
    		k -= ('z' + 1 - s[i]);
    		s[i] = 'a';
    	}
    }
    k %= 26;
    while (k--) {
    	s[n-1]++;
    	if (s[n-1] > 'z')
    		s[n-1] = 'a';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int n,si,qi;

bool find (int x){
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
	//		if(i==1||j==1)	continue;
			if(x==(i*4+j*7))
				return 1;
		}\
	}
	return 0;
}

signed main()
{
	scanf("%d",&n);
	if(find(n))	printf("Yes");
	else		printf("No");
	return 0;
}

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

int main()
{
    string str;

    while( cin >> str )
    {
        int x[str.size()];
        for( int i = 0; i < str.size(); i++ )
        {
            if( str[i] == 'M' )
                x[i] = 1000;
            else if( str[i] == 'D' )
                x[i] = 500;
            else if( str[i] == 'C' )
                x[i] = 100;
            else if( str[i] == 'L' )
                x[i] = 50;
            else if( str[i] == 'X' )
                x[i] = 10;
            else if( str[i] == 'V' )
                x[i] = 5;
            else
                x[i] = 1;
        }

        stack<int> s;
        s.push(x[0]);
        for( int i = 1; i < str.size(); i++ )
        {
            if( s.top() >= x[i] )
            {
                s.push(x[i]);        
            }
            else
            {
                int m = 0;
                while( s.top() < x[i] )
                {
                    m += s.top();
                    s.pop();
                    if( s.empty() == true )     //空なら抜ける。
                        break;
                }
                s.push( x[i] - m );
            }
        }
        int sum = 0;
        while( s.empty() == false )
        {
            sum += s.top();
            s.pop();
        }
        cout << sum << endl;
    }


    return 0;
}


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

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

  long long max_A = A[0], ans = 0;
  for (int i = 1; i < N; ++i) {
    if (A[i] < max_A) {
      ans += max_A - A[i];
    } else {
      max_A = A[i];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 4784
#include<stdio.h>

int solve(int,int);
int A[2000],m[2000],n;

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

  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&m[i]);
  }

  for(i=0; i<q; i++){
    if(solve(0,m[i]))printf("yes\n");
    else printf("no\n");
  }

  return 0;
  
  
}

int solve(int i,int m){
  int res;
  
  if(m == 0)
    return 1;
  
  if(i >= n)
    return 0;
  
  res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

Measured memory_bytes: 584
N, W = [int(x) for x in input().split()]
w = []
v = []

for _ in range(N):
    a, b = [int(x) for x in input().split()]
    w.append(a)
    v.append(b)

dp = [[0] * (W + 1) for _ in range(N + 1)]

for i in range(1, N + 1):
    for j in range(W + 1):
        a = dp[i - 1][j]
        b = (dp[i - 1][j - w[i - 1]] + v[i - 1]) if j - w[i - 1] >= 0 else 0
        dp[i][j] = max(a, b)

print(dp[N][W])


Measured memory_bytes: 120172
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a /g* b ;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
int  GetDigit(T num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};



int main()
{
    
    int N;
    cin>>N;
    int C[N],S[N],F[N];
    REP(i,0,N-1){
        cin>>C[i]>>S[i]>>F[i];
    }
    for ( int i =0; i < N ; i ++)
    {
        int t =0;
        for ( int j = i ;j <N -1; j ++)
        {
            if (t < S [ j ]) t = S [ j ];
            else if ( t % F [ j ]==0);
            else t = t + F [ j ] - t % F [ j ];
            t += C [ j ];
        }
        cout<<t<<endl;
    }

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int num[100001];
int main(void){
    int n;
    int a;
    int k=0;
    scanf("%d\n",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        num[a]++;
    }
    for(int i=0;i<100001;i++){
        if(num[i]>1) k+=(num[i]-1);
    }
    if(k%2) printf("%d\n",n-(k+1));
    else printf("%d\n",n-k);
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
	int a;
	int k=0;
	while(scanf("%d",&a),a){
		if(k)printf("\n");
		k=1;
		int b,c,d,e;
		scanf("%d%d%d%d",&b,&c,&d,&e);
		int rb=0,rc=0,rd=0,re=0,min=999999;
		for(int i=0;i<=b;i++)
			for(int j=0;j<=c;j++)
				for(int k=0;k<=d;k++)
					for(int l=0;l<=e;l++){
						int val=i*10+j*50+k*100+l*500-a;
						if(val<0)continue;
						if(i&&val%50/10)continue;
						if(j&&val%100/50)continue;
						if(k&&val%500/100)continue;
						if(l&&val/500)continue;
						if(min>b-i+c-j+d-k+e-l+val/500+val%500/100+val%100/50+val%50/10){
							min=b-i+c-j+d-k+e-l+val/500+val%500/100+val%100/50+val%50/10;
							rb=i;
							rc=j;
							rd=k;
							re=l;
						}
					}
		if(rb)printf("10 %d\n",rb);
		if(rc)printf("50 %d\n",rc);
		if(rd)printf("100 %d\n",rd);
		if(re)printf("500 %d\n",re);
	}
}

Measured memory_bytes: 0
n = int(input())
ta = [list(map(int, input().split())) for _ in range(n)]

import math
dp = ta[0]
for i in range(1, n):
    t = ta[i][0]
    a = ta[i][1]

    k1 = dp[0] // t
    if k1 * t != dp[0]:
        k1 += 1
    k2 = dp[1] // a
    if k2 * a != dp[1]:
        k2 += 1
    k = max(k1, k2)

    dp = [k * t, k * a]
print(sum(dp))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

void yes(){
  cout << "YES" << endl;
  exit(0);
}

void no(){
  cout << "NO" << endl;
  exit(0);
}

int main(){
  ll N, M; cin >> N >> M;
  vector<ll> cnt(N+1,0);
  REP(i,M){
    ll a,b; cin >> a >> b;
    cnt[a]++; cnt[b]++;
  }

  REP(i,N+1){
    if(cnt[i]%2==1) no();
  }
  yes();
}

Measured memory_bytes: 1024