akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<cctype>
#include<ctime>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
template<class T>
inline T qread(T &IEE){
	register T x = 0, f = 1;
	register char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-'){
			f = -f;
		}
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return IEE = x * f;
}
template<class T>
inline void qwrite(T a){
	if(!a){
		putchar('0');
		return ;
	}
 	if(a < 0){
		putchar('-');
		a = -a;
	}
	if(a > 9) qwrite(a / 10);
	putchar(a % 10 + 48);
	return ;
}
ll ans, cnt, n, m, q;
ll a[maxn], x[maxn], y[maxn], z[maxn], u[maxn];
void dfs(ll now){
	if(now == n + 1){
		cnt = 0;
		for(int i = 1;i <= q;i++){
			if(a[y[i]] - a[x[i]] == z[i]){
				cnt += u[i];
			}
		}
		ans = max(ans, cnt);
		return ;
	}
	for(int i = a[now - 1];i <= m;i++){
		a[now] = i;
		dfs(now + 1);
	}
	return ;
}
int main(){
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	qread(n);
	qread(m);
	qread(q);
	for(int i = 1;i <= q;i++){
		qread(x[i]);
		qread(y[i]);
		qread(z[i]);
		qread(u[i]);
	}
	a[0] = 1;
	dfs(1);
	cout << ans << endl;
	return 0;
}


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

int main() {
  int S;
  cin >> S;
  long long mod = 1000000007;
  
  vector<long long> a(S+5);
  
  a.at(3) = 1;
  a.at(4) = 1;
  a.at(5) = 1;
  
  for(int i = 6; i <= S; i++){
    for(int j = 3; j <= i-3; j++){
      a.at(i) += a.at(j);
    }
   	a.at(i) = (a.at(i)+1) % mod;
  }
  
  cout << a.at(S) << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N);
    REP(i,N){
        cin>>a[i];
        a[i]--;
    }

    vint dist(N,-1);
    dist[0]=0;

    int cur=0;
    while(true){
        int nxt=a[cur];
        if(dist[nxt]==-1){
            dist[nxt]=dist[cur]+1;
            cur=nxt;
        }
        else break;
    }
    cout<<dist[1]<<endl;

}


Measured memory_bytes: 1792
char s[6];
  for(;scanf("%d",&n),n;printf("%d\n",x)){
    for(x=1,a=1,b=2,c=3,i=0;i<n;i++){
      scanf("%s",s);
      switch(*s){
        case 'L':
          p=a,  q=7-c,r=b;   break;
        case 'R':
          p=a,  q=c,  r=7-b; break;
        case 'N':
          p=b,  q=7-a,r=c;   break;
        case 'S':
          p=7-b,q=a,  r=c;   break;
        case 'E':
          p=7-c,q=b,  r=a;   break;
        case 'W':
          p=c,  q=b,  r=7-a; break;
      }
      a=p,b=q,c=r;x+=a;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <utility>
using namespace std;

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

  int a, b, c;
  a=b=c=0;
  for(int i=0; i<3; i++){
    if(s[i]=='a') a++;
    else if(s[i]=='b') b++;
    else if(s[i]=='c') c++;
  }

  if(a==1 && b==1 && c==1) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,m = inm()
ab = []
for i in range(m):
    a,b = inm()
    ab.append((b,a))
ab.sort()
cnt = 0
prev = -1
for b,a in ab:
    if prev<a:
        prev = b-1
        cnt += 1
print(cnt)


Measured memory_bytes: 17012
#include <stdio.h>

int main(){
    int r;
    scanf("%d",&r);
    
    if(r<1200){
        printf("ABC\n");
    }
    else if(r>=1200 && r<2800){
        printf("ARC\n");
    }
    
    else if(r>=2800 && r<=4208){
        printf("AGC\n");
    }
    
    
    return 0;
}

Measured memory_bytes: 128
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;

static class MainClass
{
    public static void Main(string[] args)
    {

         var nl  = Console.ReadLine().SplittedStringToInt32List();

        if (nl.Contains(1) && nl.Contains(7) && nl.Contains(9) && nl.Contains(4))
            Console.WriteLine("YES");
        else
            Console.WriteLine("NO");

        Console.ReadLine();
    }

    

    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<long> SplittedStringToInt64List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    public const int INF = int.MaxValue / 2;
    public const long LONGINF = long.MaxValue / 2;

    public static int Max(params int[] values)
    {
        var maxes = -1;
        for (int i = 0; i < values.Length; i++)
        {
            maxes = Math.Max(values[i], maxes);
        }
        return maxes;
    }

    public static void PrintArray(int[,] array)
    {
        for (int i = 0; i < array.GetLength(0); i++)
        {
            var sb = new StringBuilder();
            for (int j = 0; j < array.GetLength(1); j++)
            {
                sb.Append(array[i, j]).Append(" ");
            }
            Console.WriteLine(sb.ToString());
        }
    }
    // public static int[]

    #endregion
}



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

int main() {
  int N,A;
  int x;
  cin >> N >> A;
  
  x = N % 500;
  if (x <= A){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int gcd(int x, int y) {
    if(y == 0) return x;
    return gcd(y, x%y);
}
 
int main(){
    int n, ans=0; cin >> n;
    vector<int> a(n), l(n+1), r(n+1);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        if(i) l[i+1] = gcd(l[i], a[i-1]);
        r[n-1-i] = gcd(r[n-i], a[n-1-i]);
    }
    for(int i = 0; i < n; i++) ans = max(ans, gcd(l[i+1], r[i+1]));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll h,n,a[100005];
ll sum;
int main(void){
	cin>>h>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>=h){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	
	
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define sz size()
 
int main(){
  string a,b,c;
  cin >> a >> b >> c;
  if(a[a.sz-1] == b[0] && b[b.sz-1] == c[0])
    cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#Educational DP Contest
#B-Frog2

import sys
input = sys.stdin.readline

#n = int(input())
n,k = map(int,input().split())
lst1 = list(map(int,input().split()))

#dp table
dp = [float("inf")]*n
dp[0] = 0

#process1
for i in range(1,n):
    for j in range(max(0,i-k),i): #kの許容しうる範囲だけ回す
        b = abs(lst1[i]-lst1[j]) + dp[j] #(j迄の最小コスト)+(jからiまでのコスト)
        dp[i] = min(dp[i],b)

#output process
print(dp[-1])

Measured memory_bytes: 55388
#include<iostream>
#include<vector>
using namespace std;
const int N=2e5+2;
vector<int> lis;
int ar[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,l,lef,rig,mid,num,now;
	cin>>n;
	bool cac=true;
	for(i=1;i<=n;i++){
		cin>>ar[i];
		if(i-1&&ar[i]<=ar[i-1]){
			cac=false;
		}
	}
	if(cac){
		cout<<1;
		return 0;
	}
	rig=n;
	lef=1;
	while(rig>lef){
		mid=(lef+rig)/2;
		//cout<<mid<<endl;
		lis.clear();
		for(i=1;i<n;i++){
			if(ar[i]<ar[i+1]){
				continue;
			}
			while(lis.size()&&lis.back()>ar[i+1]){
				lis.pop_back();
			}
			now=ar[i+1];
			while(true){		
				if(lis.size()<mid||lis[lis.size()-mid]<now){
					lis.push_back(now);
					break;
				}
				else{
					for(j=0;j<mid;j++){
						lis.pop_back();
					}
					now--;
				}
			}	
		}
		if(!lis.size()||lis[0]>0){
			rig=mid;
		}
		else{
			lef=mid+1;
		}
	}
	cout<<lef+1;
}

Measured memory_bytes: 2168
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N,M = MI()
	NUM = [-1]*N
	ch = True
	for i in range(M):
		s,c = MI()
		s = s-1
		if(NUM[s]!=-1 and NUM[s]!=c):
			ch = False
		NUM[s]=c
	if(NUM[0]==0 and N!=1):
		ch=False
	if(ch==False):
		print(-1)
	else:
		ans = 0
		t = 10**(N-1)
		for i in range(N):
			if(NUM[i]==-1 and i==0):
				if(N!=1):
					ans += t
			elif(NUM[i]!=-1):
				ans += (t * NUM[i])
			t //= 10

		print(ans)




if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
int main(void){
    long long n,i,j;
    double sum=0;
    scanf("%lld",&n);
    int x[n],y[n];
    for(i=0;i<n;i++) scanf("%d%d",&x[i],&y[i]);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            int a=x[i]-x[j];
            int b=y[i]-y[j];
            sum+=sqrt(a*a+b*b);
        }
    }
    printf("%lf",sum/n);
    return 0;
}

Measured memory_bytes: 128
def find(s):
    for i in range(len(s)-1):
        if s[i]==s[i+1]:
            print(i+1,i+2)
            return
    for i in range(len(s)-2):
        if s[i]==s[i+2]:
            print(i+1,i+3)
            return 
        
    
    print(-1,-1)
find(input())

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


int main() {
  int a, b, x, y;
  scanf("%d%d%d%d", &a, &b, &x, &y);
  printf("%lf %d\n", double(a) * double(b) / 2, x * 2 == a&&y * 2 == b);
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_variables)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let a: Vec<usize> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    // 最小値を根とする木を考えればよい
    let mut c = vec![0; N];
    for &x in &a { c[x] += 1; }
    let m = *a.iter().min().unwrap();
    let ans = if (
        c[m] == 1 &&
        ((m + 1)..(2 * m + 1)).all(|i| c[i] >= 2) &&
        ((2 * m + 1)..N).all(|i| c[i] == 0)
    ) || (
        c[m] == 2 &&
        ((m + 1)..(2 * m)).all(|i| c[i] >= 2) &&
        ((2 * m)..N).all(|i| c[i] == 0)
    ) {
        "Possible"
    } else {
        "Impossible"
    };

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define gap " "
#define pi 2 * acos (0.0)

int main()
{
    char c;
    cin>>c;
    char s=toupper(c);
    if (c=='A') cout << "T\n";
    if (c=='T') cout << "A\n";
    if (c=='G') cout << "C\n";
    if (c=='C') cout << "G\n";

}


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

using namespace std;

int main(){
    
    int a, b, i;

    cin >> a >> b;

    vector<int> l(a);
    vector<int> resp(a+1, 0);

    for( i = 0; i < a; i++){
        cin >> l[i];
        resp[i+1] = resp[i] + l[i];
    }

    for( i = 0; i < a+1 && resp[i] <= b; ++i ){
    }

    cout << i << endl;

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)

const int INF = 100000000;

using namespace std;


int main() {
	int v[7] = { 1,3,5,7,8,10,12 }, vv[4] = { 4,6,9,11 };

	int x, y;
	cin >> x >> y;

	bool xx = false , yy = false;
	for (int i = 0; i < 7; i++) {
		if (v[i] == x)xx = true;
		if (v[i] == y)yy = true;
	}

	if (xx && yy) {
		cout << "Yes" << endl;
		return 0;
	}

	xx = false; yy = false;
	for (int i = 0; i < 4; i++) {
		if (vv[i] == x)xx = true;
		if (vv[i] == y)yy = true;
	}
	if (xx && yy) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define F 36

typedef struct {
  char mark;
  int  number;
} list;

int main(){
  int i,j,k,l,n,temp,v,minj,flag=0;
  list a[F],c,d[F],e;
  char b[F-1];
  int cnt=0;
  
  scanf("%d%*c",&n);
  for(i=0;i<n;i++){
    if(cnt>0){ scanf("%c",&b[cnt-1]); }
    scanf("%c%d",&a[i].mark,&a[i].number);
    cnt++;
  }
  
  for(i=0;i<n;i++){
   d[i]=a[i];
      }
  
  for (i=0;i<n-1;i++){
    for (j=n-1;j>=i+1;j--){
      if (a[j].number < a[j-1].number) {
	c = a[j];
	a[j]=a[j-1];
	a[j-1]=c;
      }
    }
  }

  for(i=0;i<n;i++){
    printf("%c%d",a[i].mark,a[i].number);
    if(i==n-1) break;
    printf(" ");
  }
  printf("\nStable\n");

  for(i=0;i<=n-1;i++){
    minj=i;
    for(j=i;j<=n-1;j++){
      if(d[j].number < d[minj].number){
	minj = j;
      }
    }
    e=d[i];  
    d[i] = d[minj];
    d[minj] = e;
  }

  for(i=0;i<n;i++){
    printf("%c%d",d[i].mark,d[i].number);
    if(i!=n-1) printf(" ");
  }

  for(i=0;i<n;i++){
    if(a[i].mark == d[i].mark){ continue; }
    else flag=1;
  }
  if(flag==0) printf("\nStable\n");
  if(flag==1) printf("\nNot stable\n");

return 0;
}


Measured memory_bytes: 2108
x, y = map(int, input().split())
a = [1, 3, 5, 7, 8, 10, 12,]
b = [4, 6, 9, 11]
c = 2

if x in a and y in a:
    print("Yes")
elif x in b and y in b:
    print("Yes")
elif x == c and y == c:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};
void visit(const vector<vector<int>> &g, int v, vector< vector<int> >& scc,
	stack<int> &S, vector<bool> &inS,
	vector<int> &low, vector<int> &num, int& time) {
	low[v] = num[v] = ++time;
	S.push(v); inS[v] = true;
	for (auto e : g[v]) {
		int w = e;
		if (num[w] == 0) {
			visit(g, w, scc, S, inS, low, num, time);
			low[v] = min(low[v], low[w]);
		}
		else if (inS[w])
			low[v] = min(low[v], num[w]);
	}
	if (low[v] == num[v]) {
		scc.push_back(vector<int>());
		while (1) {
			int w = S.top(); S.pop(); inS[w] = false;
			scc.back().push_back(w);
			if (v == w) break;
		}
	}
}
void stronglyConnectedComponents(const vector<vector<int>>& g,
	vector< vector<int> >& scc) {
	const int n = g.size();
	vector<int> num(n), low(n);
	stack<int> S;
	vector<bool> inS(n);
	int time = 0;
	REP(u, n) if (num[u] == 0)
		visit(g, u, scc, S, inS, low, num, time);
}
signed main() {
	stack<char> st;
	char c;
	while (scanf("%c", &c) != EOF) {
		if (c != '0' && c != '1' && c != 'B')
			break;
		if (c == 'B') {
			if (st.size())
				st.pop();
		}
		else {
			st.push(c);
		}
	}
	string out;
	while (!st.empty()) {
		out = st.top()+out;
		st.pop();
	}
	printf("%s", out.c_str());
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    int n;
    cin >> n;
    vector<pii>  v(n);
    rep(i, n) cin >> v[i].fi, v[i].se = i;
    sort(all(v));

    set<int> st;
    ll ans = 0LL;
    rep(i, n) {
        ll l, r;
        auto itL = st.lower_bound(v[i].se);
        if(itL == st.begin()) l = v[i].se;
        else {
            --itL;
            l = v[i].se - *itL - 1;
        }
        auto itR = st.upper_bound(v[i].se);
        if(itR == st.end()) r = n - v[i].se -1;
        else r = *itR - v[i].se -1;
        ans += (l + r + l * r + 1LL) * v[i].fi;
        st.insert(v[i].se);
    }
    cout << ans << endl;
    return 0;
}

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

int n,A[55];
string S[55],ans;
char C[55];

int main(){

cin>>n;

for(int i=0; i<n; i++){
  scanf("%s", C);
  S[i]=string(C);
}

for(int i=0; i<26; i++){
	char c='a'+i; A[i]=0;
	int Min=12345;
	for(int j=0; j<n; j++){
		int cnt=0;
		for(int k=0; k<S[j].size(); k++){
			if(S[j][k]==c) cnt++;
		}
		if(cnt>0&&cnt<Min) Min=cnt;
		if(cnt==0){
			Min=12345; break;
		}
	} 
	if(Min!=12345) A[i]=Min;
}

ans="";

for(int i=0; i<26; i++){
	while(A[i]){
		char c='a'+i; A[i]--;
		ans=ans+c;
	}
}

cout<<ans<<endl;

return 0;
 
}

Measured memory_bytes: 256
from collections import Counter,defaultdict
import sys,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

n,w = inpl()
ww = [0] * n
vv = [0] * n
for i in range(n):
    ww[i],vv[i] = inpl()
dp = [[0 for i in range(w+1)] for j in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j >= ww[i]:
            dp[i+1][j] = max(dp[i][j], dp[i][j-ww[i]]+vv[i])
        else:
            dp[i+1][j] = dp[i][j]
print(dp[n][w])


            


Measured memory_bytes: 171888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] fact = new int[n + 1];
		 long ans = 1;
		for (int j = 2; j <= n; j++) {
			for (int i = 2; i <= j; i++) {
				int m = j;
				if (sosuu(i)) {
					while (m % i == 0) {
						m = m / i;
						fact[i]++;
					}
				}
			}
		}
		for (int i = 2; i <= n; i++) {
			if (fact[i] > 0)
				ans *= (fact[i] + 1);
			ans=ans%(1000000000+7);
		}

		System.out.println(ans%(1000000000+7));
	}

	static boolean sosuu(int n) {
		if (n == 1)
			return false;
		else {
			for (int i = 2; i < n; i++) {
				if (n % i == 0)
					return false;
			}
			return true;
		}
	}
}


Measured memory_bytes: 10196
x, y= map(int,input().split())

if(x==1 or x== 3 or x==5 or x==7 or x==8 or x==10 or x==12)and(y==1 or y== 3 or y==5 or y==7 or y==8 or y==10 or y==12):
    print('Yes')
elif(x==4 or x==6 or x==9 or x==11)and(y==4 or y==6 or y==9 or y==11):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int gcd (int a, int b )
{
	if (a > b ){
		swap (a, b );
	} // end if
	while (b % a != 0 ){
		b = b % a;
		if (a > b ){
			swap (a, b );
		} // end if
	} // end while

	return a;
}

int main()
{
	int n, m;

	while (cin >> n >> m ){
		int res = gcd (n, m );
		cout << res << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define pp pair<ll,ll>
#define mp make_pair
#define PI acos(-1.0)
#define all(v) v.begin(),v.end()
#define pb push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FREV(i,a,b) for(i=a;i>=b;i--)
#define FORI(a) for(auto it=a.begin();it!=a.end();it++)
#define READ(a,i,n) FOR(i,0,n) { sll(a[i]);}
#define DEBUG(x) cerr<<"In file "<< __FILE__ <<" at line "<< __LINE__ <<" :: "<< #x <<" = "<<x<<endl
#define sll(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define INF 1e18
#define MOD 1000000007
 
using namespace std;
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    cout<<(t>=30?"Yes":"No");
}

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

int main() {
    int n;
    cin >> n;
    vector<tuple<string, int, int>> sp;
    for (int i=1; i<=n; i++) {
        string s;
        cin >> s;
        int p;
        cin >> p;
        sp.emplace_back(s, p, i);
    }
    sort(sp.begin(), sp.end(), [](auto a, auto b){
        return (get<0>(a) != get<0>(b)) ? (get<0>(a) < get<0>(b)) : (get<1>(a) > get<1>(b));
    });
    for(auto& e : sp) {
        cout << get<2>(e) << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#define REP(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main(){
  long long K;
  cin >> K;
  cout << 50 << endl;
  REP(i,50){
    if(i) cout << ' ';
    if(i >= K % 50){ 
      ll ans = 49 + 50 * (K/50) - (K - (K / 50 ));
      cout << ans;
    }else{
      ll ans = 49 + 50 * (K/50 + 1) - ( K - (K / 50 + 1 ));
      cout << ans;
    }/// ＋１回ーされる数
  }
  return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    for(int i = 0; i < K; i++){
        int a, b;
        cin >> a >> b;
        if(a + b < N+1){
            cout << (min(a, b)-1)%3 + 1 << endl;
        }else{
            cout << (min(N+1-a, N+1-b)-1)%3 + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>

using namespace std;

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

//sum between [l, l+1, ..., r-1, r] inclusive
ll sum(ll l, ll r) {
    return (l+r) * (r-l+1)/2;
}


int main () {
    int n, k;
    cin >> n >> k;
    mint res;
    for (int i = k; i <= n+1; ++i) {
        ll a = sum(0, i-1);
        ll b = sum(n-i+1,n);
        res += b - a + 1;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
long long co(int x){
	long long y=0;
	for(int i=1;i<=x-1;i++){
		y+=i;
	}
	return y;
}
int main(){
	int n;
	map<string,int> ma;
	string s[100001];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin >>s[i];
		getchar();
		sort(s[i].begin(),s[i].end());
		ma[s[i]]++;
	}
	map<string,int>::iterator it;
	long long t=0;
	for(it=ma.begin();it!=ma.end();it++){
		if( it ->second >1 )
			t+=co(it ->second);
			
	}
	printf("%lld",t);
	return 0;
}

Measured memory_bytes: 18176
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s >= 0;s--)

int main()
{
	ll n, ans = 0;

	cin >> n;

	vecll a(n + 1), b(n);

	forll(i, 0, n + 1)
		cin >> a[i];

	forll(i, 0, n)
		cin >> b[i];

	forllde(i, n-1)
	{
		if (b[i] >= a[i + 1])
		{
			ans += a[i + 1];
			b[i] -= a[i + 1];
			a[i+1] = 0;

			ans += min(a[i],b[i]);
			a[i] = max(a[i] - b[i], (ll)0);
		}
		else
		{
			ans += b[i];
			a[i+1] -= b[i];
		}
	}
	
	cout << ans;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const int INF = 1e9+1;
const ll MAXN = 1e9;

int main()
{
    int n,W;
    cin >> n >> W;
    vector<int> w(n),v(n);
    int max_v = 0;
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
        max_v = max(max_v,v[i]);
    }

    vector<vector<int> > dp(n+1,vector<int>(n*max_v+1,0));
    for(int i = 1; i < n*max_v+1; i++){
        dp[0][i] = INF;
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n*max_v+1; j++){
            dp[i+1][j] = min(dp[i][j],(j-v[i]>=0?dp[i][j-v[i]]+w[i]:INF));
        }
    }
    int ans = 0;
    for(int i = 0; i < n*max_v+1; i++){
        if(dp[n][i]<=W)ans = i;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 40192
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
#define ll long long

const int maxn=1e2+10;

int a[maxn];

int main()
{
    int n,i,sum=0;
    scanf("%d",&n);
    for (i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for (i=2;i<n;i++)
    {
        if (!(a[i]>a[i-1] && a[i]>a[i+1]) && !(a[i]<a[i-1] && a[i]<a[i+1]))
            sum++;
    }
    printf("%d",sum);
    return 0;
}


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

int N;

int main() {
    int K, i, L, a1, an, am;
  	cin >> K >> N;
  	L=0;
  	cin >> a1;
  	am = a1;
    for(i=2;i<=N;i++){
        cin >> an;
      	if(L<an-am) L=an-am;
      	am = an;
    }
    if(L<K-an+a1) L=K-an+a1;
    cout << K-L << endl;
}


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

using namespace std;

#define ll long long int
#define get(a) ll a; cin >> a;
#define show(a) cout << a << endl;
#define full(p) p.begin(), p.end()
#define sz(a) (ll)(a.size())
#define pb push_back

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(10);
	cout<<fixed;
	////////////////////////////////
	get(a);
	get(b);
	get(t);

	cout << (t/a)*b << endl;
		

	return 0;
}

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

#define ll long long
#define mod 1000000000007
#define pii pair<ll,ll>

#define debug(a) { cout << #a << " = " << a << endl;}

const int maxn = 1e3+1;
ll n, m, t, k;

ll __min(ll a, ll b) {
    return a < b ? a : b;
}

ll __max(ll a, ll b) {
    return a > b ? a : b;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
	cin>>n>>m>>k;
	ll mi=0;
	ll mj=0;
	ll m_i=-1;
	ll m_j=-1;
	ll i,j;
	
	unordered_map<string,ll> u;
	unordered_map<ll,ll>ci;
	vector<ll> c_i;
	unordered_map<ll,ll>cj;
	vector<ll> c_j;

	for (ll y=0;y<k;y++) {
		cin>>i>>j;
		--i;--j;
		string c= to_string(i) +"_"+to_string(j);
		u[c]=true;
		ci[i] = (ci[i]+1);
		cj[j] = (cj[j]+1);
		if (mi<ci[i]) {
			mi=ci[i];
			c_i = {i};
		} else if (mi==ci[i]) {
			c_i.push_back(i);
		}

		if (mj<cj[j]) {
			mj=cj[j];
			c_j = {j};
		} else if (mj==cj[j]) {
			c_j.push_back(j);
		}
	}

	ll ans=mi+mj;
	for (int i=0;i<c_i.size();i++) {
		for (int j=0;j<c_j.size();j++) {
			string c=to_string(c_i[i])+"_"+to_string(c_j[j]);
			if (u.find(c) == u.end()) {
				cout << ans << "\n";
				return 0;
			}
		}
	}
	cout << ans - 1<< "\n";
}



Measured memory_bytes: 57784
# encoding: utf-8
A, B, C, D, E, F = map(int, input().split())

max_rate = 0
ans = (1, 0, 0, 0)
for i in range(30 // A + 1):
    for j in range(30 // B + 1):
        water = A * i + B * j
        # escape
        if water == 0: continue # avoid 0 div.
        elif 100 * water > F: break
        elif (F - 100 * water) / water < max_rate: continue
        # search (safer version)
        salt_upper = int(E * water)
        max_rate_tmp = 0
        ans_tmp = None
        for k in list(range(salt_upper // C + 1))[::-1]:
            for l in list(range(salt_upper // D + 1))[::-1]:
                salt = k * C + D * l
                # escape
                if salt == 0: continue
                elif salt / water > E: continue
                elif salt + 100 * water > F: continue
                # judge (only for max l)
                if salt / water > max_rate_tmp:
                    ans_tmp = (i, j, k, l)
                    max_rate_tmp = salt / water
                break
        # end loop
        if max_rate_tmp == 0: continue
        elif max_rate_tmp > max_rate:
            ans = ans_tmp
            max_rate = max_rate_tmp
        if max_rate == E: break
    if max_rate == E: break

salt = C * ans[2] + D * ans[3]
water = 100 * (A * ans[0] + B * ans[1])
    
print(salt + water, salt)


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

def main():
    #n = int(input())
    #i = list(map(int,input().split()))
    #j = list(map(int,input().split()))

    a,b,c,d = map(int,input().split())

    if a+b == c+d :
        print('Balanced')
    elif a+b < c+d :
        print('Right')
    else:
        print('Left')

main()


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int m = 1001001001;
    ll sum = 0;
    vector<int> a(n);
    rep (i, n) {
        cin >> a[i];
        chmin(m, a[i]);
        sum += a[i];
    }
    if (n % 2 == 1) {
        if (sum % 2LL == 1) cout << "First\n";
        else cout << "Second\n";
    } else {
        if (m == 0) {
            if (sum % 2LL == 1) cout << "First\n";
            else cout << "Second\n";
        } else {
            if (m % 2 == 0 && sum % 2LL == 0) cout << "Second\n";
            else cout << "First\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int H = scan.nextInt();
    int A = scan.nextInt();
    scan.close();

    System.out.println(H%A == 0 ? H/A : H/A + 1);
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
main(){
  int n;
  double s=0.0,x=0.0;
  string u;
  cin>>n;
  while(n--){
    cin>>x>>u;
    s+=(u=="BTC"?380000.0:1.0)*x;
  }
  printf("%.6f",s);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	vector<int> pl = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47};
	vector<int> pg = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
	int n; cin >> n;
	for( int i = 2; i <= n; ++i ){
		for( int j = 0; j < 15; ++j ){
			int tmp = i;
			while( tmp % pl[j] == 0 ){
				tmp /= pl[j];
				++pg[j];
			}
		}
	}
	
	int p = 0;
	int p_ = 0;
	for( int i = 0; i < 15; ++i ){
		if( pg[i] >= 4 ) ++p;
		if( pg[i] >= 2 ) ++p_;
	}
	int q = p_-p;
	int ans = p*(p-1)*q/2;
	if( p >= 3 ) ans += p*(p-1)*(p-2)/2;
	
	int r = 0;
	int r_ = 0;
	for( int i = 0; i < 15; ++i ){
		if( pg[i] >= 14 ) ++r;
		if( pg[i] >= 4 ) ++r_;
	}
	int s = r_-r;
	ans += r*s;
	if( r >= 2 ) ans += r*(r-1);
	
	int t = 0;
	int t_ = 0;
	for( int i = 0; i < 15; ++i ){
		if( pg[i] >= 24 ) ++t;
		if( pg[i] >= 2 ) ++t_;
	}
	int u = t_-t;
	ans += t*u;
	if( t >= 2 ) ans += t*(t-1); 
	
	if( pg[0] >= 74 ) ++ans;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(register ll i=(a);i<(b);i++)
typedef long long ll;
inline ll read(){ll sign=1; ll x=0; char ch; while(!isdigit(ch=getchar())) if(ch=='-') sign=-1; while(isdigit(ch)) x=x*10+ch-'0',ch=getchar(); return x*sign;}
inline void write(ll k){ if(k<0) putchar('-'),k*=-1; char ch[20]; int num=0; while(k)ch[++num]=k%10,k/=10; if(num==0) ch[++num]=0; while(num)putchar(ch[num--]+'0');}
ll c[26];
char ch[110];
int main() {
	scanf("%s",ch);
	for(int i=0;ch[i]!=0;i++) c[ch[i]-'a']++;
	rep(i,0,26) if(c[i]%2) {
		printf("No");
		return 0;
	}
	printf("Yes");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		String s = sc.next();
		String q = "aiueo";
		boolean che = false;
		for(int i = 0 ; i < 5 && !che ; i++) if(s.charAt(0) == q.charAt(i)) che = true;
		if(che) ou.println("vowel");
		else ou.println("consonant");
		ou.flush();
	}
}

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

using namespace std;
typedef long long ll;

std::vector<std::string> split(const std::string &str, char sep)
{
    std::vector<std::string> v;
    std::stringstream ss(str);
    std::string buffer;
    while( std::getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

signed main() {
    string n;
    cin >> n;

    auto lines = split(n, '/');
    cout << "2018" << "/" << lines[1] << "/" << lines[2];
}



Measured memory_bytes: 256
fun main(args:Array<String>):Unit {
    val n = readLine()!!.trim().toInt()
    val state = Array(n + 1){Array(n + 1){0}}
    for (i in 1 .. n) {
        readLine()!!.trim().split(' ').map(String::toInt).forEachIndexed { j, num -> state[i][j + 1] = num }
    }
    for (y in 1 .. n) for (x in 1 .. n) state[y][x] += state[y - 1][x]
    var max = Int.MIN_VALUE
    for (upper in 0 until n - 1){
        for (bottom in upper + 2 .. n){//上がupper + 1、下がbottomである枠の最大値
            var current = 0
            for (x in 1 .. n){
                if (max < state[bottom][x] - state[upper][x]) max = state[bottom][x] - state[upper][x]
                current += state[bottom][x] - state[upper][x] - state[bottom - 1][x - 1] + state[upper + 1][x - 1]
                if (current < state[bottom][x] - state[upper][x] + state[bottom][x - 1] - state[upper][x - 1])
                    current = state[bottom][x] - state[upper][x] + state[bottom][x-  1] - state[upper][x - 1]
                if (max < current) {
                    max = current
                }
            }
        }
    }
    for (y in (1 .. n).reversed()) for (x in 1 .. n) state[y][x] -= state[y - 1][x]
    for (y in 1 .. n) for (x in 1 .. n) state[y][x] += state[y][x - 1]
    for (y in 1 .. n){
        var minLeft = state[y][1]
        var maxRight = state[y][1]
        for (x in 1 .. n){
            if (minLeft < state[y][x]) minLeft = state[y][x]
            if (maxRight > state[y][x]) maxRight = state[y][x]
            if (max < maxRight - minLeft) {
                max = maxRight - minLeft
            }
        }
    }
    println(max)
}


Measured memory_bytes: 65328
#include<stdio.h>

int x,y,chukan;

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

Measured memory_bytes: 1028
from collections import defaultdict

n, m = map(int, input().split())
d = defaultdict(int)
for i in range(n):
  al = [int(i) for i in input().split()][1:]
  for j in al:
    d[j] += 1
ans = 0
for k, v in d.items():
  if v == n:
    ans += 1
print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
const long MAX=100010;

typedef struct pp{
  char name[15];
  int t;
} P;
  
class Queue {
  public :
    P data[100100];
    long head;
    long tail;
    void enqueue(P proc);
    P dequeue();
    Queue(){};
};
void Queue::enqueue(P proc){
  data[tail]=proc;
  tail=(tail+1)%MAX;
}
P Queue::dequeue(){
  P x;
  x=data[head];
  head=(head+1)%MAX;
  return x;
}
  
int MIN(int a, int b) {return a<b ? a: b;}

int main(){
  Queue QE=Queue();
  long n,q;
  cin >> n >> q;
  P tmp;
  QE.tail=1;
  QE.head=0;
  for(int i=0;i<n;i++){
    scanf("%s",tmp.name);
    scanf("%d",&tmp.t);
    QE.enqueue(tmp);
  }
  //cout << QE.head << " " << QE.tail << endl;
  
  long ET=0;
  P u;
  int c;
  while(QE.head != QE.tail){
    u=QE.dequeue();
    c=MIN(u.t,q);
    u.t-=c;
    ET+=c;
    if(u.t>0) QE.enqueue(u);
    else if(ET!=0) cout << u.name << " "<< ET << endl;
  }
  return 0;
}


Measured memory_bytes: 5080
import copy
temp=input().split()
A=int(temp[0])
B=int(temp[1])
C=int(temp[2])

setT=[A,B,C]
setT.sort()
allSet=[]
allSet.append(setT)
ans=0
def distribute(x,y,z):
	temp=[y+z,z+x,x+y]
	for i in range(len(temp)):
		if temp[i]%4==0:
			temp[i]/=2
		else:
			return [0]
	return temp

setNext=copy.deepcopy(setT)
for i in setT:
	if i%2==1:
		break
else:
	setNext=distribute(setT[0],setT[1],setT[2])
	ans+=1
	while len(setNext)==3:
		#print(setNext)
		ans+=1
		setT=copy.deepcopy(setNext)
		setNext=distribute(setT[0],setT[1],setT[2])
		setNext.sort()
		if setNext in allSet:
			ans=-1
			break
		else:
			allSet.append(setNext)
print(ans)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using Graph = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int main(){
  ll a,b;
  cin >> a >> b;
  cout << (a * b) / gcd(a,b) << endl;
  return 0;
}


Measured memory_bytes: 3604
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b;
    cin>>a>>b;
    int ans =0;
    if(a>=13) ans =b;
    else if (a>5) ans = b/2;
    
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000009
const long long INF = 1LL<<60;

ll d[210][210];

int main() {
    int N,M,R;
    cin>>N>>M>>R;
    vector<int> r(R);
    rep(i,R){
        cin>>r[i];
        r[i]--;
    }

    rep(i,N){
        rep(j,N){
            if(i==j) continue;
            d[i][j]=INF;
        }
    }
    rep(i,M){
        int a,b;
        ll c;
        cin>>a>>b>>c;
        a--,b--;
        d[a][b]=c;
        d[b][a]=c;
    }
    rep(k,N){
        rep(i,N){
            rep(j,N){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }

    vector<int> ord(R);
    rep(i,R) ord[i]=i;

    ll ans=INF;

    do{ 
        ll tmp=0;
        rep(i,R-1){
            tmp+=d[r[ord[i]]][r[ord[i+1]]];
        }
        //cout<<tmp<<endl;
        ans=min(ans,tmp);
    }while(next_permutation(all(ord)));

    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	for (int i = a;i <= b;i++) {
		string str = to_string(i);
		for (int j = 0;j < 2;j++) {
			if (str[j] != str[4 - j])break;
			if (j == 1) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define rep(i,n) REP(i, 0, n)
int calc_time(string s){
    int t[3];
    for(int i = 0; i <= 6; i += 3)
      t[i / 3] = (s[i] - '0') * 10 + (s[i + 1] - '0');
    return t[0] * 3600 + t[1] * 60 + t[2];
}
typedef pair<int, bool> pib;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    while(cin >> N && N){
        vector<pib> t;
        rep(i, N){
            string a, b; cin >> a >> b;
            t.push_back(pib(calc_time(a), true));
            t.push_back(pib(calc_time(b), false));
        }
        sort(t.begin(), t.end());
        int res = 0, running = 0;
        for(const pib& k : t){
            if(k.second) running++; else running--;
            res = max(res, running);
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 3376
#include <bits/stdc++.h>
using namespace std;
int INF = 1e9+7;
int main()
{
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    int ans = INF;
    for(int i = 0; i < n; i++)
    {
        int x = a[i];

        int pos = 0;
        vector<int> al;
        while(pos < n)
        {
            priority_queue<int, vector<int>, greater<int>> que;
            while(pos < n && a[pos] >= x)
            {
                que.push(a[pos]);
                pos++;
            }
            if(que.size() >= k)
            {
                int s = que.size()-k+1;
                while(s)
                {
                    al.push_back(que.top());
                    que.pop();
                    s--;
                }
            }
            pos++;
        }
        if(al.size() < q) continue;
        sort(al.begin(), al.end());
        ans = min(ans, al[q-1] - al[0]);
    }
    cout << ans << endl;
}


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

int main(){
    long n,m;
    long h[N];
    long ma[N];
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        cin >> h[i];
        ma[i]=0;
    }
    for(int i=0;i<m;i++){
        long a,b;
        cin >> a >> b;
        ma[a]=max(ma[a],h[b]);
        ma[b]=max(ma[b],h[a]);
    }
    long ans=0;
    for(int i=1;i<=n;i++){
        ans+=ma[i]<h[i];
    }
    cout << ans;
    return 0;
}

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

int main() {
  int n, m, x, y;
  std::cin >> n >> m >> x >> y;
  std::vector<int> x_n(n);
  std::vector<int> y_m(m);

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

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

  if (std::max(x, *std::max_element(x_n.cbegin(), x_n.cend())) <
    std::min(y, *std::min_element(y_m.cbegin(), y_m.cend()))) {
      std::cout << "No War" << std::endl;
  } else {
    std::cout << "War" << std::endl;
  }
  return 0;
}

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

int main() {
  int N, A;
  cin >> N >> A;

  if ( N*A %2 == 0 ) {
    cout << "Even" << endl;
  }
  if ( N*A %2 == 1 ) {
    cout << "Odd" << endl;
  }

}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4]={1,0,-1,0} , dy[4]={0,1,0,-1} ;

int cnt[600][600];
int main(){
   int n,m,q;
   cin>>n>>m>>q;
   rep(i,m){
       int l,r;
       cin>>l>>r;
       cnt[l][r]++;
   }
   rep(i,n)rep(j,n){
       cnt[i][j+1]+=cnt[i][j];
   }
   while(q--){
       int x,y;
       cin>>x>>y;
       int ret=0;
       REP(i,x,y+1)ret+=cnt[i][y];
       cout<<ret<<endl;
   }
   return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

ll cntp(ll n){
    if(n == 0) return 1LL;
    return 2 * cntp(n-1) + 1;
}

ll volm(ll n){
    if(n == 0) return 1LL;
    return 2 * volm(n-1) + 3;
}

ll f(ll n, ll x){
    if(n == 0){
        if(x == 0) return 0; // いくら n == 0 でも、x == 0 なら 0
        else return 1LL;
    }
    
    if(x == 1 || x == 0) return 0;
    else if(2 <= x && x <= volm(n-1) + 1){
        return f(n - 1, x - 1);
    }
    else if(volm(n-1) + 2 <= x && x <= volm(n)){
        return cntp(n-1) + 1 + f(n - 1, x - 2 - volm(n-1));
    }
}


int main(void){
    ll n, x;
    cin >> n >> x;
    cout << f(n, x) << endl;
    return 0;
}

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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> sw(N, 0);
    int total = 0;
    for(int i=0; i<N; ++i){
        int w;
        cin >> w;
        total += w;
        sw[i] = total;
    }
    int m = INT_MAX;
    for(int i=0; i<N-1; ++i){
        int d = abs(2*sw[i] - total);
        m = min(m, d);
    }
    cout << m << endl;
}


Measured memory_bytes: 256