akhauriyash/Code-Regression huggingface dataset:
from collections import deque

n, m = map(int, input().split())
uv = [list(map(int, input().split())) for _ in range(m)]
s, t = map(int, input().split())

adj = [[] for _ in range(3 * n)]
for u, v in uv:
    u -= 1
    v -= 1
    adj[u].append(v + n)
    adj[u + n].append(v + 2 * n)
    adj[u + 2 * n].append(v)


def bfs(s):
    q = deque([s])
    d = [-1] * (3 * n)
    d[s] = 0
    while q:
        u = q.popleft()
        for v in adj[u]:
            if d[v] == -1:
                d[v] = d[u] + 1
                q.append(v)

    return d


dist = bfs(s - 1)
ans = dist[t - 1]
print(ans // 3)


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

int main(void)
{
    vector <int> a;
    int b;

    for (int i = 0; i < 10; i++){
    cin>>b;
a.push_back(b);
}
sort(a.begin(), a.end());
cout << a[9] << endl << a[8] << endl << a[7] << endl;

return 0;
}

Measured memory_bytes: 0
# bit全探索
# 全探索して求めたい個数のパターンが見つかったらansにプラス1している。
#
# H:高さ W:幅 K:残したい'#'の個数
# 高さと幅のMAXは6
H,W,K = map(int,input().split())

c = []
ans = 0

# 入力文字の取得
# (例)
# ..#
# ###
for i in range(H):
    c.append(list(input()))

for i in range(2**H): # 000000, 000001, 0000010, 000011, ..., 111111

    for j in range(2**W): # 000000, 000001, 0000010, 000011, ..., 111111

        now = 0
        for x in range(H): # 0, 1, ..., 5行
            for y in range(W): # 0, 1, ..., 5列

                # 高さ：i(000000) の一番右の桁から順番に見ていき、&が1
                # 幅　：i(000000) の一番右の桁から順番に見ていき、&が1
                # そして"#"のときにカウントを1増やす。
                # ↓これでも良いみたいだけど、よくわからなかった。
                # if 2**x & i > 0 and 2**y & j > 0 and c[x][y] == "#":
                if i >> x & 1 and j >> y & 1 and c[x][y] == "#":
                    now += 1

        # nowが今回求めたい個数の場合にansをプラス1する
        if now == K:
            ans += 1

print (ans)


Measured memory_bytes: 9120
import math
import itertools

n = int(input())

xy = []
for i in range(n):
    x, y = map(float, input().split())
    xy.append([x, y])

l = list(itertools.permutations(xy, 2))

res = 0
for i in range(len(l)):
    x1, x2 = l[i][0][0], l[i][1][0]
    y1, y2 = l[i][0][1], l[i][1][1]

    res += math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

print(res / n)


Measured memory_bytes: 3064
#include <iostream>
#include <limits>
#include <vector>
#include <stack>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ITER(it,v) for(auto it=v.begin();it!=v.end();++it)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"
const int INF = numeric_limits<int>::max();

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

  IN(N); IN(M);

  vector<vector<pii>> edge(N);
  vi sorted;
  int h[N];
  fill(h, h+N, 0);
  REP(i, M) {
    IN(l); IN(r); IN(d);
    edge[l-1].push_back(make_pair(r-1, d));
    ++h[r-1];
  }
  stack<int> st;
  REP(i, N) {
    if (h[i] == 0)
      st.push(i);
  }
  while (!st.empty()) {
    int from = st.top(); st.pop();
    sorted.push_back(from);
    ITER(it, edge[from]) {
      int to = it->first;
      --h[to];
      if (h[to] == 0) st.push(to);
    }
  }
  if (sorted.size() != N)
    OUT("No");
  else {
    vi val(N, INF);
    REP(i, N) {
      int from = sorted[i];
      if (val[from] == INF) {
        val[from] = 0;
      }
      ITER(it, edge[from]) {
        int to = it->first, cost = it->second;
        if (val[to] == INF)
          val[to] = val[from] + cost;
        else if (val[to] != val[from] + cost) {
          OUT("No");
          return 0;
        }
      }
    }
    OUT("Yes");
  }

  return 0;
}


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

class SuffixArray {
public:
  int sz, index1, index2;
  vector<int> rnk, tmp, sa, lcp;
  SuffixArray(const string &arg) : sz((int)arg.size()), rnk(sz + 1), tmp(sz + 1), sa(sz + 1), lcp(sz + 1) { make_sa(arg), make_lcp(arg); }
  void make_sa(const string &s) {
    index1 = sz;
    for (int i = 0; i <= index1; i++) {
      sa.at(i) = i;
      rnk.at(i) = (i < index1) ? s.at(i) : -1;
    }
    auto comp = [&](const int i, const int j) {
      if (rnk.at(i) != rnk.at(j)) {
        return rnk.at(i) < rnk.at(j);
      } else {
        const int ri = (i + index2 <= index1) ? rnk.at(i + index2) : -1;
        const int rj = (j + index2 <= index1) ? rnk.at(j + index2) : -1;
        return ri < rj;
      }
    };
    for (index2 = 1; index2 <= index1; index2 *= 2) {
      sort(sa.begin(), sa.end(), comp);
      tmp.at(sa.at(0)) = 0;
      for (int i = 1; i <= index1; i++) {
        tmp.at(sa.at(i)) = tmp.at(sa.at(i - 1)) + (comp(sa.at(i - 1), sa.at(i)) ? 1 : 0);
      }
      for (int i = 0; i <= index1; i++) {
        rnk.at(i) = tmp.at(i);
      }
    }
  }
  void make_lcp(const string &s) {
    for (int i = 0; i <= sz; i++) {
      rnk.at(sa.at(i)) = i;
    }
    int h = 0;
    lcp.at(0) = 0;
    for (int i = 0; i < sz; i++) {
      int j = sa.at(rnk.at(i) - 1);
      if (h > 0) {
        --h;
      }
      for (; j + h < sz && i + h < sz; h++) {
        if (s.at(j + h) != s.at(i + h)) {
          break;
        }
      }
      lcp.at(rnk.at(i) - 1) = h;
    }
  }
};

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  string S;
  cin >> S;
  int N = S.size();
  SuffixArray SA(S);
  long ans = 0;
  for (int i = 0; i < N; i++) {
    ans += N - SA.sa.at(i + 1) - SA.lcp.at(i);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 11612
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
    int n;
    cin >> n;
    vector<int> H(n);
    for (int i = 0; i < n; i++) {
        cin >> H[i];
    }
    if (n == 1) {
        cout << "Yes" << endl;
        return 0;
    }
    for (int i = n - 1; i >= 1; i--) {
        if (H[i - 1] <= H[i])
            continue;
        else {
            if (H[i - 1] - H[i] == 1)
                H[i - 1] -= 1;
            else {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 640
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

minP = min(a) + min(b)

for i in range(M):
	x, y, c = map(int, input().split())
	x, y = x - 1, y - 1
	price_with_coupon = a[x] + b[y] - c
	minP = min(minP, price_with_coupon)

print(minP)

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

const int MAX = 1e5+10;
int n;
int vet[MAX];
int memo[MAX];

int pd(int i) {
    if(i < 0) return 0;
    else if(memo[i] != -1) return memo[i];
    else if(i == 1) return memo[i] = abs(vet[i] - vet[i-1]);
    return memo[i] = min(abs(vet[i] - vet[i-1]) + pd(i-1),
                         abs(vet[i] - vet[i-2]) + pd(i-2));
}
int main() {

    memset(memo, -1, sizeof memo);

    memo[0] = 0;

    cin>>n;
    for(int i = 0; i < n; ++i) {
        cin>>vet[i];
    }
    int ans = pd(n - 1);
    cout<<ans<<"\n";
}


Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
def inpl(): return map(int, input().split())

N, M = inpl()

prob = [False]*(N+1)
prob[1] = True

balls = [1]*(N+1)

for _ in range(M):
    x, y = inpl()
    if prob[x]:
        prob[y] = True

    balls[x] -= 1
    balls[y] += 1

    if balls[x] == 0:
        prob[x] = False

print(sum(prob))

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int main() {
   int a, b;
   cin >> a >> b;

   cout << (a + b + 1) / 2 << endl;

   return 0;
}

Measured memory_bytes: 764
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        int K = sc.nextInt();
        sc.close();

        for(int i = 0; i <= N; i++){
            for(int j = 0; j <= M; j++){
                if(i*M+j*N - 2*i*j == K){
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
   }
}

Measured memory_bytes: 23764
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		long mod = 1000000007;
		string s = Console.ReadLine();
		long answer = 1;
    long rest = 0;

    for(int i = 0; i < 2*n; i++)
    {
      if(i == 0 && s[i] != 'B')
      {
        answer = 0;
        break;
      }

      if(s[i] == 'B')
      {
        if(rest % 2 == 0)
        {
          rest++;
        }else
        {
          if(rest <= 0)
          {
            answer = 0;
            break;
          }
          answer *= rest;
          rest--;
          answer %= mod;
        }
      }else
      {
        if(rest % 2 == 1)
        {
          rest++;
        }else
        {
          if(rest <= 0)
          {
            answer = 0;
            break;
          }
          answer *= rest;
          rest--;
          answer %= mod;
        }
      }
    }

    if(rest != 0) answer = 0;

    answer *= ModFactorial(n,mod);
    answer %= mod;

		Console.WriteLine(answer);
	}

  static long ModFactorial(long x, long p)//戻り値はx!(mod p)
  {
    long answer = 1;
    for(int i = 2; i <= x; i++)
    {
      answer *= i;
      answer %= p;
    }
    return answer;
  }
  
}

Measured memory_bytes: 13240
import itertools
N, M, Q = map(int, input().split())
A = [list(map(int,input().split())) for i in range(Q)]
li = []
for B in itertools.combinations_with_replacement(range(1,M+1),N):
    t = 0
    for a in A:
        if B[a[1]-1] - B[a[0]-1] == a[2]:
            t += a[3]
    li.append(t)
print(max(li))

Measured memory_bytes: 12492
#include<iostream>
#include<string>
using namespace std;
int main() {
	int x, a, b, c;
	string ans[10000];
	cin >> x;
	for (int i = 1; i <= x; i++) {
		cin >> a >> b >> c;
		a *= a;
		b *= b;
		c *= c;
		if (a + b == c || a + c == b || b + c == a) {
			ans[i] = "YES";
		}
		else {
			ans[i] = "NO";
		}
	}
	for (int i = 1; i <= x; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3280
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

ll tmp[200001];
void pakuri_sort(int N, ll A[]) {
	const int b = 8;
	for (int k = 4; k < 8; k++) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
	}
}

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


	const int m = (1 << 20) - 1;
	int N = getint(), K = getint();
	ll A[200001];
	A[0] = 0;
	rep(i, N) {
		ll kari = (getint() + K - 1) % K;
		kari = (A[i] >> 32) + kari;
		if (kari >= K) kari -= K;
		A[i + 1] = (kari << 32) + i + 1;
	}

	pakuri_sort(N + 1, A);
	int kazu = 0;
	int mae = A[0] >> 32;
	rep(i, N + 1) {
		if (mae != A[i] >> 32) {
			kazu++;
			mae = A[i] >> 32;
		}
		tmp[A[i] & m] = kazu;
	}
	rep(i, N + 1) A[i] = 0;

	ll kotae = 0;
	rep(i, N + 1) {
		kotae += A[tmp[i]];
		A[tmp[i]]++;
		if (i - K + 1 >= 0) A[tmp[i - K + 1]]--;
	}

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 3456
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int count = 1;
        while(true){
            String str = input.nextLine();
            if(!str.equals("0")){
                System.out.println("Case "+ count + ": " + str);
                count = count + 1;
            }else{
                break;
            }
        }
    }
}


Measured memory_bytes: 60356
#include <cstdio>
const int N=1000005,Mod=998244353;
int fac[N],inv[N];
inline int qpow(int a,int b){
	int ans=1;
	while (b){
		if (b&1) ans=(1ll*ans*a)%Mod;
		a=(1ll*a*a)%Mod,b>>=1;
	}
	return ans;
}
inline int Min(int a,int b){
	return a<b?a:b;
}
inline int Max(int a,int b){
	return a>b?a:b;
}
inline int C(int n,int m){
	return 1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;
}
int main (){
	int n,m;scanf ("%d%d",&n,&m);
	fac[0]=1;
	for (int i=1;i<=n+m;i++) fac[i]=1ll*fac[i-1]*i%Mod;
	inv[n+m]=qpow(fac[n+m],Mod-2);
	for (int i=n+m-1;i>=0;i--) inv[i]=1ll*inv[i+1]*(i+1)%Mod;
	int t=Min(n,m),ans=0;
	for (int i=1;i<=t;i++) ans=(1ll*ans+1ll*C(i*2,i)*C(n+m-2*i,n-i))%Mod;
	ans=1ll*ans*qpow(2,Mod-2)%Mod*qpow(C(n+m,n),Mod-2)%Mod;
	printf ("%d",(ans+Max(n,m))%Mod);
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)
#define maxn 200001
#define int ll

string S;


int32_t main(){
	fast;
	
	cin>>S;
	
	int ans = 0;
	
	int co = 0;
	aFOR(i,S){
		if (i == 'R') co++;
		else{
			ans = max(ans,co);
			co = 0;
		}
	}
	cout<<max(ans,co);
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 ;

ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll vis[100001]={0};
void dfs(ll node,vector<vector<ll>>&g)
{
  vis[node]=1;
  for(auto x:g[node])
  {
    if(!vis[x]) dfs(x,g);
  }
  return ;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //   #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    //compute();
    //Sieve();
    
   ll tests=1;
 // cin>>tests;
  ll t=1;
    while(tests--)
    {
      ll n,i,j;
      cin>>n;
      vector<vector<ll>>tree(n+1);
      vector<ll>cnt(n+1,0);
      for(i=2;i<=n;i++)
      {
        cin>>j;
        cnt[j]++;
        
      }
      //vector<ll>val(n+1,0)
      for(i=1;i<=n;i++) cout<<cnt[i]<<"\n";


        t++;
    }
    return 0;
   }

Measured memory_bytes: 20356
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	ans := a
	if b < a {
		ans = b
	}
	if c < d {
		ans += c
	} else {
		ans += d
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#import copy
def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト
    # ord(c) chr(2) alphabet <=> number
    n,q = map(int,input().split()) 
    s=input()
    cnt=[0 for _ in range(n+1)]
    for i in range(n):
        cnt[i+1]=cnt[i]+(1 if s[i:i+2]=="AC" else 0)
    for _ in range(q):
        l,r = map(int,input().split())
        print(cnt[r-1]-cnt[l-1])
main()

Measured memory_bytes: 53408
#include <iostream>
#include <cstdlib>

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

    int n;
    cin >> n;
    int a[n][3],h[n][3];

    for(int i=0;i<n;i++)
        for(int j=0;j<3;j++)
            cin >> h[i][j];

    a[0][0]=h[0][0];
    a[0][1]=h[0][1];
    a[0][2]=h[0][2];

    for(int i=1;i<n;i++)
        for(int j=0;j<3;j++)
        {
            a[i][j]=-1;
            for(int k=0;k<3;k++)
            {
                if(j==k)continue;
                a[i][j]=max(a[i][j],a[i-1][k]+h[i][j]);
            }
        }

    cout << max(max(a[n-1][0],a[n-1][1]),a[n-1][2]) << endl;
}


Measured memory_bytes: 2560
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let r: usize = read();
    let mut ans = "AGC";

    if r < 2800 {
        ans = "ARC";
    }

    if r < 1200 {
        ans = "ABC";
    }

    println!("{}", ans);
}


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

struct UnionFind {
    vector<int> Parent;

    UnionFind(int N) { Parent = vector<int>(N, -1); }

    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }

    int size(int A) { return -Parent[root(A)]; }

    bool connect(int A, int B) {
        A = root(A);
        B = root(B);
        if (A == B) {
            return false;
        }

        if (size(A) < size(B)) swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }

    bool same(int A, int B) { return root(A) == root(B); }

    int num(int N) {
        set<int> s;
        for (int i = 0; i < N; i++) {
            s.insert(root(i));
        }
        return s.size();
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind Uni(N);
    for (int i = 0; i < M; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--, y--;
        Uni.connect(x, y);
    }
    set<int> se;
    for (int i = 0; i < N; i++) {
        se.insert(Uni.root(i));
    }
    cout << se.size() << endl;
}

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

int main(){
	int n,p;
	bool flag;
	while(cin >> n >> p && n || p){
		int owan = p;
		vector<int> temoto(n,0);
		int i=0;
		while(1){
			if(owan == 1){
				owan--;
				temoto[i%n]++;
				flag = true;
				for(int j=0;j<n;j++){
					if(j == i%n)continue;
					if(temoto[j])flag = false;
				}
				if(flag)break;
			}else if(owan){
				owan--;
				temoto[i%n]++;
			}else{
				owan = temoto[i%n];
				temoto[i%n]=0;
			}
			i++;
		}
		cout << i%n << endl;
		
	}
}

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

void boost(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
    boost();
    ll n;
    cin >> n;
    ll i,ans=0;
    for(i=1;i<=n;i++){
        ll lo=i;
        ll hi=(n/i)*i;
        ll count=n/i;
        ans+=(count*(lo+hi))/2;
    }
    cout << ans << endl;
}

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

int main() {
  int n;
  std::cin >> n;
  std::vector<int> h(n);

  for (auto &i : h) {
    std::cin >> i;
  }

  int ans = 0;
  for (auto itr = h.cbegin(); itr != h.cend(); itr++) {
    if (*std::max_element(h.cbegin(), itr) <= *itr) {
      ans++;
    }
  }

  std::cout << ans << std::endl;
  return 0;
}


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

#ifndef LOCAL
#define cerr dolor_sit_amet
#endif

#define mp make_pair
#define sz(x) ((int)((x).size()))
#define X first
#define Y second

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int , int > ipair;
typedef pair < ll , ll > lpair;
const int IINF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;
const double DINF = numeric_limits<double>::infinity();
const int MOD = 1000000007;
const double EPS = 1e-9;
const int DX[] = { 1,  0, -1,  0,  1, -1,  1, -1};
const int DY[] = { 0,  1,  0, -1,  1, -1, -1,  1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll sqr(ll x) { return x*x; } ll sqr(int x) { return (ll)x*x; }
double sqr(double x) { return x*x; } ld sqr(ld x) { return x*x; }
mt19937 mmtw(960172);
ll rnd(ll x, ll y) { static uniform_int_distribution<ll> d; return d(mmtw) % (y - x + 1) + x; }

// ========================================================================= //

const int N = 555;

int main() {
    ios::sync_with_stdio(false);

    int sx, sy;
    int d;
    cin >> sx >> sy >> d;

    if (d % 2 == 1) {
        for (int i = 0; i < sx; ++i) {
            for (int j = 0; j < sy; ++j)
                cout << "RGBY"[(i%2)*2 + (j%2)];
            cout << "\n";
        }
    } else {
        int r = d / 2;
        for (int x = 0; x < sx; ++x) {
            for (int y = 0; y < sy; ++y) {
                int x1, y1;
                if ((x + y) % 2 == 0) {
                    x1 = (x+y) / 2;
                    y1 = N + (x-y) / 2;
                } else {
                    x1 = (x+1+y) / 2;
                    y1 = N + (x+1-y) / 2;
                }
                cout << "RGBY"[((x1/r)%2)*2 + ((y1/r)%2)];
            }
            cout << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int f(int i,int x){
	return i*(100+x)/100;
}

int main(){
	while(1){
		int n,a,b,c,x;
		cin>>n>>a>>b>>c>>x;
		if(n==0) break;
		queue<int> st;
		for(int i=0;i<n;i++){
			int y;
			cin>>y;
			st.push(y);
		}
		int cnt=0;
		if(st.front()==x) st.pop();
		while(!st.empty()&&cnt<=10000){
			cnt++;
			x=(a*x+b)%c;
			if(st.front()==x) st.pop();
		}
		if(cnt==10001) cnt=-1;
		cout<<cnt<<endl;
	}
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void){
  vector<int> price(3);
  
  for(int i = 0 ; i < 3 ; i++){
    cin >> price[i];
  }
  
  sort(price.begin(),price.end());
  
  cout << price[0] + price[1] << endl;
  
  return 0;
}

Measured memory_bytes: 256
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (ma (read))
         (mb (read))
         ;; ma, mb
         (dp (make-array (list (+ n 1) 401 401)
                         :element-type 'uint32
                         :initial-element #xffffffff)))
    (declare (uint8 ma mb n))
    (setf (aref dp 0 0 0) 0)
    (dotimes (i n)
      (let ((a (read))
            (b (read))
            (c (read)))
        (declare (uint8 a b c))
        (dotimes (suma 401)
          (dotimes (sumb 401)
            (setf (aref dp (+ i 1) suma sumb)
                  (min (aref dp (+ i 1) suma sumb)
                       (aref dp i suma sumb)))
            (when (and (<= (+ suma a) 400)
                       (<= (+ sumb b) 400))
              (setf (aref dp (+ i 1) (+ suma a) (+ sumb b))
                    (min (aref dp i (+ suma a) (+ sumb b))
                         (+ c (aref dp i suma sumb)))))))))
    (loop for a from ma to 400 by ma
          for b from mb to 400 by mb
          minimize (aref dp n a b) into res
          finally (println
                   (if (= res #xffffffff)
                       -1
                       res)))))

#-swank(main)


Measured memory_bytes: 39400
#include<vector>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int d,m,n,p;
  int sm;
  vector<int> a;
  while(cin>>d&&d){
    cin>>m>>n;
    a.clear();
    a.push_back(0);
    for(i=0;i<m-1;i++){
      int c;
      cin>>c;
      a.push_back(c);
    }
    a.push_back(d);
    sort(a.begin(),a.end());
    sm=0;
    for(i=0;i<n;i++){
      cin>>p;
      for(j=0;;j++){
	if(a[j]<=p&&p<a[j+1])
	  break;
      }
      sm+=min(p-a[j],a[j+1]-p);
    }
    cout<<sm<<endl;
  }
  return 0;
}

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

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;

int main() {
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	if (x + r <= w && y + r <= h && x - r >= 0 && y - r >= 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<ll> temp = a;
    sort(all(temp));
    ll l = temp[n/2-1], r = temp[n/2];
    rep(i,n){
        ll ans;
        if(a[i] <= l)ans = r;
        else ans = l;
        cout << ans << "\n";
    }
}

Measured memory_bytes: 5376
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => ({
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    })
}
#[allow(unused_macros)]
macro_rules! swap { ($a:expr, $b:expr) => ({ let t = $b; $b = $a; $a = t; }) }

const M: usize = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let mut b = VecDeque::new();
    let mut dir = true;
    let n: usize = sc.cin();
    for _ in 0..n {
        let a: usize = sc.cin();
        if dir {
            b.push_back(a);
            dir = false;
        } else {
            b.push_front(a);
            dir = true;
        }
    }
    let result: Vec<&usize> = if dir {
        b.iter().collect()
    } else {
        b.iter().rev().collect()
    };
    for i in 0..(result.len() - 1) {
        print!("{} ", result[i]);
    }
    println!("{}", result[result.len() - 1]);
}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
    fn get_char(&mut self) -> char {
        self.reserve();
        let head = self.buffer[0].chars().nth(0).unwrap();
        let tail = String::from( &self.buffer[0][1..] );
        if tail.len()>0 { self.buffer[0]=tail } else { self.buffer.pop_front(); }
        head
    }
}


Measured memory_bytes: 16108
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100000

int N;
double table[NUM];

void func(){

	double sum = 0;

	for(int i = 0; i < N; i++){
		scanf("%lf",&table[i]);
		sum += table[i];
	}

	int ans = 0;

	double average = sum/(double)N;

	for(int i = 0; i < N; i++){
		if(table[i] <= average){
			ans++;
		}
	}

	printf("%d\n",ans);
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}




Measured memory_bytes: 3308
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#include <cassert>
#include <numeric>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, r) for (int i = (l); i < (r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET{IOSET(){cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

// Main Code
constexpr int maxd = 10;
int n, m, q;
vector<int> v, d, c;
vector<vector<int>> g, dp;

void peint(int ve, int di, int num) {
    if (dp[ve][di] != q) return;
    dp[ve][di] = num;
    peint(ve, di - 1, num);
    for (int u: g[ve]) peint(u, di - 1, num);
    return;
}

int main() {
    cin >> n >> m;
    g = vector<vector<int>>(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b); g[b].push_back(a);
    }
    cin >> q;
    v = d = c = vector<int>(q);
    rep(i, q) {
        cin >> v[i] >> d[i] >> c[i];
        --v[i];
    }
    
    dp = vector<vector<int>>(n, vector<int>(maxd + 1, q));
    for (int i = q - 1; i >= 0; --i) peint(v[i], d[i], i);
    
    rep(i, n) {
        if (dp[i][0] == q) cout << 0 << "\n";
        else cout << c[dp[i][0]] << "\n";
    }
    return 0;
}


Measured memory_bytes: 18820
use proconio::marker::Chars;

fn main() {
    proconio::input! {
        s: Chars,
        t: Chars,
    }
    let h = s.len();
    let w = t.len();
    let mut dp = vec![vec![0u16; w + 1]; h + 1];
    for (i, a) in s.iter().enumerate().rev() {
        for (j, b) in t.iter().enumerate().rev() {
            dp[i][j] = if *a == *b {
                dp[i + 1][j + 1] + 1
            } else {
                std::cmp::max(dp[i + 1][j], dp[i][j + 1])
            };
        }
    }
    let mut ans = String::new();
    let mut pos = (0, 0);
    while pos.0 < h && pos.1 < w {
        if s[pos.0] == t[pos.1] {
            ans.push(s[pos.0]);
            pos.0 += 1;
            pos.1 += 1;
        } else if dp[pos.0][pos.1] == dp[pos.0][pos.1 + 1] {
            pos.1 += 1;
        } else {
            pos.0 += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 19744
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;

int main(){
    lint N, K, ans = 0; cin >> N >> K;

    for(lint i=K+1;i<=N;i++){
        ans += N / i * (i-K) + max(N-N/i*i-K+1, 0LL);
        if(K == 0) ans--;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;


int main(){
   ll a,b;cin >>a>>b;
   if(a*b<=0){
       puts("Zero");
       return 0;
   }
   if(a>0){
       puts("Positive");
       return 0;
   }
   if(a<0){
       if((b-a)%2==0)puts("Negative");
       else puts("Positive");
       return 0;
   }
    return 0;
}

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

int main() {
  int a, b, c, ans;
  scanf("%d %d %d", &a, &b, &c);
  if (a == b && b == c) {
    ans = 1;
  } else if (a == b || b == c || c == a) {
    ans = 2;
  } else {
    ans = 3;
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 128
def gc(a,b):
  while b!=0:
    a,b=b,a%b
  return a

n=list(map(int,input().split()))
if n[0]==n[1]:
  print(gc(n[0],n[1]))
elif n[0]>n[1]:
  a=n[0]%n[1]
  print(gc(n[1],a))
else:
  a=n[1]%n[0]
  print(gc(n[0],a))


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

int n,m;
int before[200],after[200];

void cut(int k){
        for(int i=0;i<n*2;i++){
                after[i]=before[(k+i)%(n*2)];
        }

        for(int i=0;i<n*2;i++){
                before[i]=after[i];
        }

        return;
}

void riffle(){
        for(int i=0;i<n*2;i++){
                if(i%2==0){
                        after[i]=before[i/2];
                } else{
                        after[i]=before[n+i/2];
                }
        }

        for(int i=0;i<n*2;i++){
                before[i]=after[i];
        }

        return;
}

int main() {
        cin>>n>>m;

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

        for(int i=0;i<m;i++){
                int k;
                cin>>k;

                if(k){
                        cut(k);
                } else{
                        riffle();
                }
        }

        for(int i=0;i<n*2;i++){
                cout<<after[i]<<endl;
        }

        return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
 
int main(){
	int n;
	cin>>n;
	string s[n];
	rep(i,n){
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
	}
	string ans="";
	rep(i,26){
		int num=100;
		rep(j,n){
			int tmp=0;
			rep(k,s[j].size())if(s[j][k]==(char)('a'+i))tmp++;
			num=min(num,tmp);
		}
		rep(j,num)ans+=(char)('a'+i);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N, *LR = map(int, open(0).read().split())
LR = list(zip(*[iter(LR)] * 2))

max_l = max(l for l, _ in LR)
min_r = min(r for _, r in LR)

ab = [(max(0, r - max_l + 1), -max(0, min_r - l + 1)) for l, r in LR]
ab.sort()

mi = float("inf")
ma = max(r - l + 1 for l, r in LR) + max(0, min_r - max_l + 1)
for i in range(N - 1):
    mi = min(mi, -ab[i][1])
    ma = max(ma, mi + ab[i + 1][0])

print(ma)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  ll H = nextLong();
  ll W = nextLong();
  int N = nextLong();
  set< pair<int,int> > ps;
  map< pair<int,int>, int> mp;
  REP(i, N) {
    int a = nextLong()-1;
    int b = nextLong()-1;
    mp[ {a, b} ] = 1;

    for (int dx = -1; dx <= 1; dx++)
      for (int dy = -1; dy <= 1; dy++)
      if (1 <= a + dx && a + dx < H-1 && 1 <= b + dy && b + dy < W-1)
        ps.insert({a + dx, b + dy});
  }

  vector<ll> count(10);
  count[0] = (H-2) * (W-2);
  for (auto p : ps) {
    int a = p.first;
    int b = p.second;
    int j = 0;
    for (int dx = -1; dx <= 1; dx++)
      for (int dy = -1; dy <= 1; dy++)
        if (mp.count({a + dx, b + dy}))
          j++;

    count[0]--;
    count[j]++;
  }

  REP(j, 10) cout << count[j] << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 52136
#include <bits/stdc++.h>
#define int LL 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}
int lcm(int a,int b)
{
	return a/__gcd(a,b)*b;
}
const int MAX_N=105;
vec pre[4];
int v[MAX_N],w[MAX_N],n,W;
signed main()
{
	cin>>n>>W;
	rep(i,0,n)cin>>w[i]>>v[i];
	rep(i,0,n)
	{
		pre[w[i]-w[0]].pb(v[i]);
	}
	rep(i,0,4)sort(all(pre[i]));
	rep(i,0,4)pre[i].pb(0);
	rep(i,0,4)reverse(all(pre[i]));
	rep(i,0,4)
	{
		rep(j,1,pre[i].size())
		{
			pre[i][j]+=pre[i][j-1];
		}
	}
	int ans=0;
	rep(p0,0,pre[0].size())
	{
		rep(p1,0,pre[1].size())
		{
			rep(p2,0,pre[2].size())
			{
				int p3=(W-w[0]*p0-(w[0]+1)*p1-(w[0]+2)*p2)/(w[0]+3);
				if(p3<0)continue;
				if(p3>=pre[3].size())p3=pre[3].size()-1;
				if(W-w[0]*p0-(w[0]+1)*p1-(w[0]+2)*p2<0)continue;
				ans=max(ans,pre[0][p0]+pre[1][p1]+pre[2][p2]+pre[3][p3]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    PrintWriter pw = new PrintWriter(System.out);

    int n = sc.nextInt();

    Map<String, Set<Integer>> cards = new LinkedHashMap<>();
    Arrays.asList("S", "H", "C", "D").forEach(pattern -> {
        cards.put(pattern, new TreeSet<>(Arrays.asList(1,2,3,4,5,6,7,8,9,10,11,12,13)));
    });

    IntStream.range(0, n).forEach(i ->  cards.get(sc.next()).remove(sc.nextInt()));
    
    cards.forEach((p, nums) -> nums.forEach(x -> pw.println(p + " " + x)));

    pw.flush();
    sc.close();
  }
}


Measured memory_bytes: 32052
#include <stdio.h>

int main(){
  char line[100];
  int a, b;
  char op;
  while(1){
	fgets(line, sizeof(line), stdin);
	sscanf(line, "%d %c %d", &a, &op, &b);
	if(op=='?')
	  break;
	switch(op){
	case '+':
	  printf("%d\n", a+b);
	  break;
	case '-':
	  printf("%d\n", a-b);
	  break;
	case '*':
	  printf("%d\n", a*b);
	  break;
	case '/':
	  printf("%d\n", a/b);
	  break;
	default:
	  break;
	}
  }
  return 0;
}



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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Five Dishes
            var dishes = GetDishes().OrderBy(x => x.First).ToList();
            int lastTime = 0;
            int time = 0;

            foreach(var dish in dishes)
            {
                if (dish.First == 0)
                {
                    time += dish.Time;
                }
                else
                {
                    if (lastTime == 0)
                    {
                        lastTime = dish.Time;
                    }
                    else
                    {
                        time += dish.Time;
                        time = (time / 10 + 1) * 10;
                    }
                }
            }

            time += lastTime;
            Console.WriteLine(time);
        }

        static IEnumerable<Dish> GetDishes()
        {
            var lines = ReadLines(5);

            foreach(var line in lines)
            {
                int first = line % 10;
                yield return new Dish(line, first);
            }
        }

        static List<int> ReadLines(int count = 0)
        {
            //[summary]コンソールの値を読み込む
            var list = new List<int>();

            //読み込む行数が未指定のときは、1行目の値を"count"とみなす
            if (count == 0)
            {
                string s = Console.ReadLine().TrimEnd();
                count = int.Parse(s);
            }

            for (int i = 0; i < count; i++)
            {
                string s = Console.ReadLine().TrimEnd();
                list.Add(int.Parse(s));
            }

            return list;
        }
    }

    struct Dish
    {
        public int Time { set; get; }
        public int First { set; get; }

        public Dish(int time, int first)
        {
            Time = time;
            First = first;
        }
    }
}

Measured memory_bytes: 13396
// ABC_163_A

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
	cout << fixed << setprecision(15) << endl;
	int r;
	cin >> r;

	double s = (double)(2 * r) * 3.14159265359;

	cout << s << "\n";

	return 0;
}

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

int main(){

  int n,a,b,c,d,e;

  while(cin >> n, n){
    int z[1000] = {0};

    for(int i=0;i<n;i++){
      cin >> a >> b >> c >> d >> e;
      z[i] = a + b + c + d + e;
    }

    sort(z,z+n);
    cout << z[n-1] << " " << z[0] << endl;

  }
}

Measured memory_bytes: 1180
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	vector<int> a(9);
	rep(i, 9) cin >> a[i];
	int n;
	cin >> n;
	vector<bool> flag(9);
	rep(i, n) {
		int k;
		cin >> k;
		rep(j, 9) {
			if (a[j] == k) flag[j] = true;
		}
	}
	if (flag[0] == true && flag[1] == true && flag[2] == true || flag[4] == true && flag[3] == true && flag[5] == true || flag[6] == true && flag[7] == true && flag[8] == true || flag[0] == true && flag[3] == true && flag[6] == true || flag[1] == true && flag[4] == true && flag[7] == true || flag[2] == true && flag[5] == true && flag[8] == true || flag[0] == true && flag[4] == true && flag[8] == true || flag[2] == true && flag[4] == true && flag[6] == true) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //SUN, MON, TUE, WED, THU, FRI, or SAT
    string s;
    cin>>s;
    if(s=="SUN")
    {
        cout<<7;
    }
    else if(s=="MON")
        cout<<6;
    else if(s=="TUE")
        cout<<5;
    else if(s=="WED")
        cout<<4;
    else if(s=="THU")
        cout<<3;
    else if(s=="FRI")
        cout<<2;
    else if(s=="SAT")
        cout<<1;




    return 0;
}


Measured memory_bytes: 256
#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 - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    vll water(31, 0), sugar(1501, 0);
    REP(i, 31){
        REP(j, 31){
            if(a * i + b * j > 30) continue;
            water[a * i + b * j] = 1;
        }
    }
    REP(i, f / 2 + 2){
        REP(j, f / 2 + 2){
            if(c * i + d * j > 1500) continue;
            sugar[c * i + d * j] = 1;
        }
    }
    ll resw = 1, ress = 0;
    FOR(i, 1, 30){
        FOR(j, 1, 1500){
            if(!water[i] || !sugar[j]) continue;
            ll w = 100 * i, s = j;
            if(w + s > f || s > e * i) continue;
            if(s * (resw + ress) > ress * (w + s)){
                resw = w;
                ress = s;
            }
        }
    }
    if(resw == 1){
        cout << a * 100 << " " << 0 << endl;
        return 0;
    }
    cout << resw + ress << " " << ress << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;

int main() {
  string a;
  cin >> a;
  string array[6] = {"abc","acb","bac","bca","cab","cba"};
  for (size_t i = 0; i < 6; i++) {
    if (a == array[i]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;

int main()
{
    double x=0.0;
    double y=0.0;
    double rad = 90.0 / 180.0 * M_PI;

    while(1)
    {
        int d,a;
        scanf("%d,%d", &d, &a);
        if(d==0 && a==0)
        {
            break;
        }
        x += d * cos(rad);
        y += d * sin(rad);
        rad -= a /180.0 * M_PI; 
    }
    cout << (int)x << endl;
    cout << (int)y << endl;
    return 0;
}

Measured memory_bytes: 3440
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a<b) {
            System.out.println("a < b");
        } else if (a > b) {
            System.out.println("a > b");
        }else{
            System.out.println("a == b");
            }
        }
    }


Measured memory_bytes: 26136