akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

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

long long MOD = 1000000000 + 7;
long long MAX = 1000000000000000000;

int main(){
  cout << setprecision(10);
  string S;
  cin >> S;
  int N; N = S.size();
  int K; cin >> K;

  vector<vector<ll>> dp1(N, vector<ll>(K+1, 0));
  vector<vector<ll>> dp2(N, vector<ll>(K+1, 0));

  // 初期化
  int d0 = S[0] - '0';
  for(int i = 0; i <= d0; i++){
    if(i == d0){
      dp2[0][1]++;
    } else { 
      if(i == 0){
        dp1[0][0]++;
      } else {
        dp1[0][1]++;
      }
    }
  }

  for(int i = 0; i < N-1; i++){
    int d = S[i+1] - '0';
    for(int j = 0; j <=K; j++){
      for(int k = 0; k <= d; k++){
        if(k == d){
          if(k == 0){
            dp2[i+1][j] += dp2[i][j];
          } else {
            if(j+1<=K) dp2[i+1][j+1] += dp2[i][j];
          }
        } else { 
          if(k == 0){
            dp1[i+1][j] += dp2[i][j];
          } else {
            if(j+1<=K) dp1[i+1][j+1] += dp2[i][j];
          }
        }
      }
    }
  }

  for(int i = 0; i < N-1; i++){
    for(int j = 0; j <= K; j++){
      for(int k = 0; k <= 9; k++){
        if(k == 0){
          dp1[i+1][j] += dp1[i][j];
        } else { 
          if(j+1<=K) dp1[i+1][j+1] += dp1[i][j];
        }
      }
    }
  }
  cout << dp1[N-1][K] + dp2[N-1][K] << endl;
}


Measured memory_bytes: 256
#include<cstdio>

int main(){
    char s[10];
    scanf("%s",s);
    int res = -1;
    if(s[0]=='S' && s[1]=='U') res = 7;
    else if(s[0]=='M') res = 6;
    else if(s[0]=='T' && s[1]=='U') res = 5;
    else if(s[0]=='W') res = 4;
    else if(s[0]=='T' && s[1]=='H') res = 3;
    else if(s[0]=='F') res = 2;
    else res = 1;
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 128
import heapq
x,y,a,b,c = map(int,input().split())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
R = [-int(i) for i in input().split()]
P.sort(reverse=True)
P = P[:x]
Q.sort(reverse=True)
Q = Q[:y]
heapq.heapify(P)
heapq.heapify(Q)
heapq.heapify(R)
while R:
    if P[0] >= Q[0]:
        if Q[0] < -R[0]:
            heapq.heapreplace(Q, -heapq.heappop(R))
        else:
            break
    else:
        if P[0] < -R[0]:
            heapq.heapreplace(P,-heapq.heappop(R))
        else:
            break
print(sum(P)+sum(Q))

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

int main(){
	while(1){
		string s1,s2;
		cin >> s1;
		if(s1 == ".") return 0;
		cin >> s2;
		string s11[201], s22[201];
		for(int i=0;i<201;i++){
			s11[i] = "."; s22[i] = ".";
		}
		int now1=0,now2=0;
		for(int i=0;i<(int)s1.length();i++){
			if(s1[i] == '"'){
				now1++;
				s11[now1] = "";
			}else s11[now1] += s1[i];
		}
		for(int i=0;i<(int)s2.length();i++){
			if(s2[i] == '"'){
				now2++;
				s22[now2] = "";
			}else s22[now2] += s2[i];
		}
		int d=0;
		for(int i=0;i<201;i++){
			if(s11[i] != s22[i]){
				if(i&1){
					d++;
				}else d+=2;
			}
		}
		if(d==0)cout<<"IDENTICAL";
		else if(d==1)cout<<"CLOSE";
		else cout<<"DIFFERENT";
		cout<<"\n";
	}
}


Measured memory_bytes: 3128
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  int N;
  scanf("%d", &N);

  int ans = 0;
  int tmp = N;
  while (tmp != 0) {
    ans += tmp % 10;
    tmp /= 10;  
  }
  printf(N % ans == 0 ? "Yes\n" : "No\n");
  return 0;
}


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

int main() {
	int		s,a,b,c,j,k,n,m,x[3],y,ans = 0;
	string	str;
	
	cin >> a >> b;
	
	ans = -1;
	for(float i = 1;i < 2000; i++) {
		if ( ( (int)(i * 0.08) == a) && ( (int)(i * 0.1) == b) ) {
			ans = (int)i;
			break;
		}
	}

	cout << ans << endl;


}


Measured memory_bytes: 256
#deque未使用
n,q=map(int,input().split())
que=[]

for i in range(n):
    name,time=input().split()
    time=int(time)
    que.append([name,time])
    
t=0
while len(que)>0:
    top=que.pop(0)
    score=min(top[1],q)
    top[1] -=score
    t +=score
    if top[1]==0:print(top[0],t)
    else:que.append(top)

#deque使用
"""from collections import deque

que=deque([])
n,q=map(int,input().split())

for i in range(n):
    name,time=input().split()
    time=int(time)
    que.append([name,time])

t=0
while len(que)>0:
    top=que.popleft()
    score=min(q,top[1])
    top[1] -=score
    t +=score
    if top[1]==0:print(top[0],t)
    else:que.append(top)"""


Measured memory_bytes: 13024
using System;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text.RegularExpressions;
using System.Threading;

namespace Atcoder
{
	class Program
	{
		//string s = Console.ReadLine();
		//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		//int H = intArray[0];
		//int W = intArray[1];
		//int N = int.Parse(Console.ReadLine());
		//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());
		//Boolean ok = false;
		//List<int> dp = Enumerable.Repeat(個数, 値).ToList();

		//Console.WriteLine(ans);
		//Console.WriteLine("Yes");
		//Console.WriteLine("No");
		//Console.ReadKey();
		//

		//string[] strArray = Console.ReadLine().Split(' ').ToArray();
		//string S = strArray[0];
		//string T = strArray[1];
		static void Main(string[] args)
		{

			int K = int.Parse(Console.ReadLine());
			if(K % 2 == 0)
            {
				Console.WriteLine(-1);
				return;
			}

			List<int> num = new List<int>();
			num.Add(7 % K);
			for (int i = 1; i <= K; i++)
				num.Add((num[i - 1] * 10 + 7) % K);
			for (int i = 0; i <= K; i++)
            {
				if (num[i] == 0)
				{
					Console.WriteLine(i + 1);
					return;
				}
			}
			Console.WriteLine(-1);
		}

		/// <summary>
		/// 回文
		/// </summary>
		/// <param name="Target"></param>
		/// <param name="len"></param>
		/// <returns></returns>
		static bool Palindrome(string Target , int len)
        {
			bool yes = true;

			for(int i = 0;i < len; i++)
            {
				if(Target[i] != Target[len - 1 - i])
                {
					yes = false;
					break;
                }
            }
			return yes;
        }

		/// <summary>
		/// アナグラム
		/// </summary>
		/// <param name="word1"></param>
		/// <param name="word2"></param>
		/// <returns></returns>
		static bool IsAnagramOf(string word1, string word2)
		{
			return word1.OrderBy(x => x).SequenceEqual(word2.OrderBy(x => x));
		}
		/// <summary>
		/// 最小公倍数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Lcm(BigInteger a, BigInteger b)
		{
			return a * b / Gcd(a, b);
		}

		/// <summary>
		/// 最大公約数
		/// </summary>
		/// <param name="a"></param>
		/// <param name="b"></param>
		/// <returns></returns>
		public static BigInteger Gcd(BigInteger a, BigInteger b)
		{
			if (a < b)
				// 引数を入替えて自分を呼び出す
				return Gcd(b, a);
			while (b != 0)
			{
				var remainder = a % b;
				a = b;
				b = remainder;
			}
			return a;
		}
	}
}

Measured memory_bytes: 35960
import java.util.Scanner;

public class Main {

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

		int p = in.nextInt();
		int q = in.nextInt();
		int r = in.nextInt();

		int max = 0;
		if ( p >= q && p >= r ) max = p;
		if ( q >= p && q >= r ) max = q;
		if ( r >= q && r >= p ) max = r;

		System.out.println(p + q + r - max);
		in.close();
	}
}

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

int main() {
  double W,H,x,y;
  cin >> W>>H>>x>>y;
  if(x == W/2 && y == H/2){
    cout << fixed << setprecision(16);
    cout << (W/2)*H << " " << 1 << endl;
  }
  else {
    cout << fixed << setprecision(16);
    cout << (W/2)*H << " " << 0 << endl;
  }
}


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

uint64_t gcd_impl( uint64_t n, uint64_t m ) {
        for( int i = 0; i < 10; ++i ) {
                uint64_t t = n - m;
                bool q = m > t;
                n = q ? m : t;
                m = q ? t : m;
                if( m == 0 ) { return n; }
        }
        return gcd_impl( m, n % m );
}

uint64_t gcd( uint64_t n, uint64_t m ) {
        return n > m ? gcd_impl( n, m ) : gcd_impl( m, n );
}
uint64_t lcm(uint64_t a, uint64_t b){return a/gcd(a,b)*b;}

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

    numerator = 1;
    for(int i=0;i<N;i++) {
        numerator = lcm(numerator,A[i]);
    }

    denominator = 0;
    for(int i=0;i<N;i++) {
        denominator += (numerator/A[i]);
    }

    cout << setprecision(12) << (double)numerator/(double)denominator << "\n";
    
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int arr[n];
int ans=0;
for(int i=0;i<n;i++)
{
    cin>>arr[i];
}
for(int i=0;i<n;i++)
{
    for(int j=i+1;j<n;j++)
    {
        ans+=arr[i]*arr[j];
    }
}
cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
input = lambda: sys.stdin.readline().rstrip()

def main():
    a, b, n = map(int, input().split())
    if n < b:
        print(math.floor(a*n/b)-a*math.floor(n/b))
    else:
        print(math.floor(a*(b-1)/b))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9136
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();
		int area = a * b;
		int length = 2 * (a + b);
		System .out.println(area + " " + length);
	}
}

Measured memory_bytes: 17352
// in the name of Allah

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

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))
#define all(x) (x).begin(), (x).end()

#define fr first
#define se second

const ll mod = 1000000007;

inline ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

inline ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

inline ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

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

	int n;
	cin >> n;
	ll a[n];
	for(int i=0; i<n; i++) cin >> a[i];
	sort(a, a+n);
	double res = a[0];
	for(int i=1; i<n; i++) {
		res = (res + a[i]) / 2.0;
	}
	cout << fixed << setprecision(12) << res << endl;

	return 0;
}

Measured memory_bytes: 256
import sys
import bisect
input = sys.stdin.readline


def main():
    N = int(input())
    L = list(map(int, input().split()))
    L.sort()

    ans = 0
    for i in range(N-1, -1, -1):
        a = L[i]
        for j in range(i-1, -1, -1):
            b = L[j]
            ci = bisect.bisect_right(L, a-b, lo=0, hi=j)
            ans += j - ci
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42332
N = int(input())

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

ans = 0

for i in range(N):
    if A[i] > B[i]:
        ans += B[i]
        continue
    ans += A[i]
    B[i] -= A[i]
    if A[i+1] > B[i]:
        A[i+1] -= B[i];
        ans += B[i]
    else:
        ans += A[i+1]
        A[i+1] = 0
print(ans)



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

int main() {
	long long N, K; scanf("%lld%lld",&N,&K);
	long long ans = (N / K) * (N / K) * (N / K);
	if(K % 2LL == 0LL) ans += ((N + K/2) / K) * ((N + K/2) / K) * ((N + K/2) / K);
	printf("%lld", ans);
	return 0;
}


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

long long v[100000];

int main() {
	
	long long n,k;
	
	cin >> n >> k;
	
	for(int i = 0;i < n;i++){
		
		long long a,b;
		
		cin >> a >> b;
		
		v[a - 1] += b;
		
	}
	
	for(int i = 0;i < 100000;i++){
		
		if(v[i] >= k){
			cout << i + 1 << endl;
			return 0;
		}
		
		k -= v[i];
		
	}
	
	return 0;
}

Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

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



int main(){fastio
    ll a[3];rep(i,0,2)cin>>a[i];
    sort(a,a+3);
    ll cnt=a[2]*2-a[1]-a[0];
    if(cnt%2==0){
        cout<<cnt/2<<endl;
    }else{
        cout<<(cnt+3)/2<<endl;
    }
    
    return 0;
}


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

using namespace std;

typedef long long ll;
const ll INFTY=1ll<<40;

struct Spell{
	int m,d;
	Spell(){}
	Spell(int m,int d):m(m),d(d){}
};

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

int main()
{
	for(int n,m;cin>>n,n;){
		vector<int> hs(n);
		for(int& h:hs) cin>>h;
		cin>>m;
		vector<Spell> ss,as; // single,all
		for(int i=0;i<m;i++){
			string n,t; int m,d;
			cin>>n>>m>>t>>d; chmin(d,100000);
			if(t=="Single") ss.emplace_back(m,d);
			else            as.emplace_back(m,d);
		}
		
		vector<ll> sdp(100001,INFTY); sdp[0]=0;
		for(int i=0;i<ss.size();i++){
			for(int j=1;j<ss[i].d;j++)
				chmin<ll>(sdp[j],ss[i].m);
			for(int j=ss[i].d;j<sdp.size();j++)
				chmin<ll>(sdp[j],sdp[j-ss[i].d]+ss[i].m);
		}
		vector<ll> adp(100001,INFTY); adp[0]=0;
		for(int i=0;i<as.size();i++){
			for(int j=1;j<as[i].d;j++)
				chmin<ll>(adp[j],as[i].m);
			for(int j=as[i].d;j<adp.size();j++)
				chmin<ll>(adp[j],adp[j-as[i].d]+as[i].m);
		}
		
		ll res=INFTY;
		for(int i=0;i<=100000;i++){
			ll temp=adp[i];
			for(int& h:hs)
				temp+=sdp[max(h-i,0)];
			chmin(res,temp);
		}
		cout<<res<<endl;
	}
}

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

double a[50];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n;i++)
		a[0]=(a[0]+a[i])/2;
	cout<<fixed<<setprecision(10)<<a[0]<<endl;
}


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

using namespace std;

long long a, b, c;
vector<int> V;
string s;

int main()
{
    cin>>s;
    for (int i=0; i<s.size(); i++)
    {
        if (V.empty()) {
            V.push_back(s[i]);
            continue;
        }
        if (V.back()!=s[i])
            V.pop_back();
        else
            V.push_back(s[i]);
    }
    cout<<s.size()-V.size();
    return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int r, c, k;
    cin >> r >> c >> k;

    vector< vs64 > field(r + 1, vs64(c + 1, 0));
    rep (i, k)
    {
        int r, c, v;
        cin >> r >> c >> v;
        field[r][c] = v;
    }

    vector< vector< vs64 > > dp(r + 1, vector<vs64>(c + 1, vs64(4)));
    rep (i, r + 1) rep (j, c + 1) rep (k, 4) dp[i][j][k] = 0;

    rep (i, r + 1)
    {
        rep (j, c + 1)
        {
            rep (k, 4)
            {
                if (i < r)
                {
                    if (field[i + 1][j] > 0)
                    {
                        dp[i + 1][j][1] = max(dp[i + 1][j][1], dp[i][j][k] + field[i + 1][j]);
                    }
                    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
                }
                if (j < c)
                {
                    if (field[i][j + 1] > 0 && k < 3)
                    {
                        dp[i][j + 1][k + 1] = max(dp[i][j + 1][k + 1], dp[i][j][k] + field[i][j + 1]);
                    }
                    dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
                }
            }
        }
    }

    s64 ans = 0;
    rep (i, 4) ans = max(ans, dp[r][c][i]);
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 707188
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int a, b, c, ans = 0, mi, ma, mc, m;
    cin >> a >> b >> c;
    ma = max({a, b, c});
    mi = min({a, b, c});
    mc = a + b + c - ma - mi;
    m = ma;

    if((ma + mi + mc) % 2 == m % 2){
        while(mc != m){
            mc++; mi++; ans++;
        }
        while(mi != m){
            mi += 2; ans++;
        }
    }
    else{
        m++;
        ma++; mc++; ans++;
        while(mc != m){
            mc++; mi++; ans++;
        }
        while(mi != m){
            mi += 2; ans++;
        }
    }

    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
# もしかして：こるとんさん作

n, m, x = list(map(int, input().split()))

price = []
a = []

for i in range(n):
    arr = list(map(int, input().split()))
    price.append(arr[0])
    a.append(arr[1:])

ans = 10 ** 10
for num in range(2 ** n):
    rikaido = [0] * m
    cost = 0
    for i in range(n):
        # i冊目を買うか
        buy = num & (1 << i) > 0
        if buy:
            for j in range(m):
                rikaido[j] += a[i][j]
            cost += price[i]
    
    target = True
    # 条件を満たすか
    for j in range(m):
        if rikaido[j] < x:
            target = False
    
    if target:
        ans = min(cost, ans)

if ans == 10 ** 10:
    ans = -1
print(ans)



Measured memory_bytes: 9236
/*
 * ARC083_C.cpp
 *
 *  Created on: Jun 1, 2018
 *      Author: 13743
 */
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end()
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

bool memo[3001];
bool wamemo[3001];

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

	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;

	vector<int> sugar;
	REP(i, 3001) {
		REP(j, 3001) {
			int su = i*c + j*d;
			if(su >= 0 && su <= 3000 && !memo[su]) {
				sugar.pb(su);
				memo[su] = true;
			}
		}
	}

	vector<int> water;
	REP(i, 3001) {
			REP(j, 3001) {
				int wa = i*100*a + j*100*b;
				if(wa >= 1 && wa <= 3000 && !wamemo[wa]) {
					water.pb(wa);
					wamemo[wa] = true;
				}
			}
		}

	double maxP = -1;
	int x, y;
	REP(i, SZ(sugar)) {
		REP(j, SZ(water)) {
			int s = sugar[i];
			int w = water[j];
			if(w+s<=f && 100*s<= e*w) {
				if((double)s/(w+s) > maxP) {
					maxP = (double)s/(w+s);
					x = w;
					y = s;
				}
			}
		}
	}

	cout << x+y << " " << y << endl;


}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N=5050,M=202,OO=1e18;
int a[M][N];
int dp[N][N];
int pt[N][N];
int dist[N];
int lv[N],rt[N],s[N],p;
int32_t main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<n;++i)cin>>dist[i];
	for(int i=1;i<=n;++i)forn(j,m)cin>>a[j][i];
	forn(j,m){
		s[p=0]=0;
		a[j][0]=OO;
		for(int i=1;i<=n;++i){
			while(a[j][s[p]]<a[j][i])--p;
			lv[i]=s[p]+1;
			s[++p]=i;
		}
		a[j][n+1]=OO;
		s[p=0]=n+1;
		for(int i=n;i>=1;--i){
			while(a[j][s[p]]<=a[j][i])--p;
			rt[i]=s[p]-1;
			s[++p]=i;
		}
		for(int i=1;i<=n;++i){
			int xl=lv[i],xr=i;
			int yl=i,yr=rt[i];
			int val=a[j][i];
			pt[xl][yl]+=val;
			pt[xl][yr+1]-=val;
			pt[xr+1][yl]-=val;
			pt[xr+1][yr+1]+=val;
		}
	}
	for(int l=1;l<=n;++l){
		for(int r=l;r<=n;++r){
			dp[l][r]=dp[l][r-1]+dp[l-1][r]-dp[l-1][r-1]+pt[l][r];
		}
	}

	int ans=0;
	for(int l=1;l<=n;++l){
		int su=0;
		for(int r=l;r<=n;++r){
			upx(ans,dp[l][r]-su);
			su+=dist[r];
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 165756
#include<stdio.h>
#include<string.h>
int main()
{
  char A[10],B[10],C[10];
  int a,b;
  scanf("%s %s",A,B);
  scanf("%d %d",&a,&b);
  scanf("%s",C);
  if(strcmp(A,C)==0)
  {
    a=a-1;
  }
  else if(strcmp(B,C)==0)
  {
    b=b-1;
  }
  printf("%d %d",a,b);
  return 0;
}
  

Measured memory_bytes: 128
type t =
  | Leaf
  | Node of body
and body = { left : t; right : t; data : int; l : int; r : int }

let rec init l xs = function
  | 1 ->
      Node
        { left = Leaf;
          right = Leaf;
          data = max_int; l;
          r = List.hd xs }, xs
  | n ->
      let (left, m :: ys) = init l xs (n / 2) in
      let (right, (r :: _ as zs)) = init m ys ((n + 1) / 2) in
      Node { left; right; data = max_int; l; r }, zs
let init (x :: xs) = fst @@ init x xs (List.length xs)

let rec update a b x = function
  | Leaf -> Leaf
  | Node ({ left; right; data; l; r } as t) ->
      if b <= l || r <= a || t.data <= x
      then Node t
      else begin
        if a <= l && r <= b
        then Node { t with data = min x t.data }
        else Node { t with left = update a b x left; right = update a b x right }
      end

let rec query acc i = function
  | Leaf -> acc
  | Node { left; right; data; l; r } ->
      if i < l || r <= i
      then acc
      else query (query (min acc data) i left) i right
let query = query max_int

let () = Scanf.scanf "%d %d\n" @@ fun n q ->
  let stxs =
    Array.init n @@ fun _ ->
      Scanf.scanf "%d %d %d\n" @@ fun s t x -> s, t, x in
  let tr =
    Array.fold_right (fun (s, t, x) -> update (s - x) (t - x) x) stxs @@
    init @@
    List.sort_uniq compare @@
    Array.fold_left (fun acc (s, t, x) -> s - x :: t - x :: acc) [] stxs in
  for i = 0 to q - 1 do
    Printf.printf "%d\n" @@ Scanf.scanf "%d\n" @@ fun d ->
      let ans = query d tr in
      if ans = max_int then -1 else ans
  done


Measured memory_bytes: 115832
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll X[100010];
int main()
{
	int N;
	ll A, B;
	cin >> N >> A >> B;
	for (int i = 0; i < N; i++) cin >> X[i];
	ll ans = 0;
	for (int i = 0; i < N - 1; i++) {
		ans += min((X[i + 1] - X[i]) * A, B);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back
const ll mod = 1000000007;
// const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

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

	cout << max(0, c - (a - b)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll n;
    cin>>n;
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            if(i*j==n)
            {
                cout<<"Yes";
                exit(0);
            }
        }
    }
    cout<<"No";}

Measured memory_bytes: 3640
// #include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <iomanip> // setprecision
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

// #define int long long

// loop
#define FOR(i, a, b) for (int i = (a); i < (b); i++) 	// a ~ b-1	(ascending)
#define REP(i, n) FOR(i, 0, n)							// 0 ~ n-1
#define NREP(i, n) FOR(i, 1, n + 1)						// 1 ~ n
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)	// a ~ b	(descending)
#define RREP(i, n) RFOR(i, n, 0)						// n ~ 0
#define RNREP(i, n) RFOR(i, n, 1)						// n ~ 1
 
// container operation
#define all(v) v.begin(), v.end()
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ASORT(c) std::sort((c).begin(), (c).end())
#define DSORT(c) std::sort((c).begin(), (c).end(), std::greater<typeof((c).front())>())
#define SIZE(x) ((int)(x).size())
// union of two containers
template <typename T>
void container_union(T &c1, T &c2, T &c3) {
  std::vector<int> vec;
  std::set_union(c1.begin(), c1.end(),
                 c2.begin(), c2.end(),
                 std::back_inserter(vec));
  T tmp(vec.begin(), vec.end());
  c3 = tmp;
}

// chmax, chmin
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

// grid-search
std::vector<int> dx = {1, -1, 0,  0};
std::vector<int> dy = {0,  0, 1, -1};
 
// debug
#define check(x) std::cout << #x << " = " << x << '\n'
 
// print
#define cout(x) std::cout << x << '\n'
 
// type alias
using VI = std::vector<int>;
using VII = std::vector<VI>;
using VB = std::vector<bool>;
using VBB = std::vector<VB>;
using VS = std::vector<std::string>;
using PII = std::pair<int, int>;

// yes/no
std::string yes = "Yes";
std::string no = "No";
std::string YES = "YES";
std::string NO = "NO";

void solve();

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  solve();
  return 0;
}

void solve() {
  int n, k;
  std::cin >> n >> k;
  VI p(n);
  std::vector<double> e(n);
  REP(i, n) {
    std::cin >> p.at(i);
    e.at(i) = (p.at(i) + 1.0) / 2.0;
  }

  double max = 0.0;
  double sum = 0.0;
  REP(i, n - k + 1) {
    if (i == 0) {
      REP(j, k) {
        sum += e.at(j);
      }
    } else {
      sum -= e.at(i-1);
      sum += e.at(i+k-1);
    }
    chmax(max, sum);
  }
  std::cout << std::fixed << std::setprecision(10);
  cout(max);
}


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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> c(n,0);
  rep(i,m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    c[a]++; c[b]++;
  }
  bool can = true;
  rep(i,n){
    if(c[i]%2) can = false;
  }
  cout << (can? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <map>
#include <cstring>
using namespace std;
typedef long long ll;
const ll maxn = 1e6+10;
const ll inf = 1e16;
const ll mod = 998244353;

ll N;
map<ll,ll> mp;
ll arr[maxn];
ll ksm(ll a,ll b){
    ll res = 1;
    while(b){
        if(b&1) res = res*a%mod;
        a = a*a%mod;
        b>>=1;
    }
    return res;
}


int main(){
//    freopen("in.txt", "r", stdin);
    cin>>N;
    ll t;
    for(ll i = 1;i<=N;i++){
        scanf("%lld",&t);
        arr[i] = t;
        mp[t]++;
    }
    ll res;
    if(!(mp[0] == 1) || arr[1] != 0 ) res = 0;
    else{
        res = 1;
        for(auto m:mp){
            if(m.first == 0) continue;
            res = res*ksm(mp[m.first-1], m.second)%mod;
        }
    }
    cout<<(res+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define FIO "a"
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define lb(x) ((x)&(-(x)))
#define dalao 1000000007
#define inf 0x3f3f3f3f
#define N 15
using namespace std;
typedef long long ll;
int n,m,a[N][N],pw[N*N]={1},cnt[1<<N],f[1<<N],g[1<<N];
inline void upd(int& a,int b){a=a+b>=dalao?a+b-dalao:a+b;}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<n*(n-1);i++)pw[i]=(pw[i-1]<<1)%dalao;
	while(m--){
		int a,b;scanf("%d%d",&a,&b),--a,--b,::a[a][b]=::a[b][a]=1;
	}
	for(int i=0;i<(1<<n);i++)for(int j=0;j<n;j++)if(i>>j&1)for(int k=j+1;k<n;k++)if(i>>k&1)cnt[i]+=a[j][k];
	f[1]=1;
	for(int i=2;i<(1<<n);i++)if((i&1)&&!(i&2)){
		int S=i^1;f[i]=pw[cnt[i]];
		for(int j=S&(S-1);;j=(j-1)&S){
			upd(f[i],dalao-1ll*f[j|1]*pw[cnt[S^j]]%dalao);
			if(!j)break;
		}
	}
	g[2]=1;
	for(int i=3;i<(1<<n);i++)if((i&2)&&!(i&1)){
		int S=i^2;g[i]=pw[cnt[i]];
		for(int j=S&(S-1);;j=(j-1)&S){
			upd(g[i],dalao-1ll*g[j|2]*pw[cnt[S^j]]%dalao);
			if(!j)break;
		}
	}
	int ans=pw[cnt[(1<<n)-1]];
	for(int i=1;i<(1<<n);i++)if((i&1)&&!(i&2)){
		int S=(1<<n)-1,T=S^i;
		for(int j=T;j;j=(j-1)&T)if((j&2)&&cnt[i|j]==cnt[i]+cnt[j])
			upd(ans,dalao-1ll*f[i]%dalao*g[j]%dalao*pw[cnt[S^i]+cnt[S^j]-cnt[S]]%dalao);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 768
N=int(input())
inp=[]

for i in range(N):
    inp.append((input()))

c0=inp.count("AC")
c1=inp.count("WA")
c2=inp.count("TLE")
c3=inp.count("RE")

print("AC x "+str(c0))
print("WA x "+str(c1))
print("TLE x "+str(c2))
print("RE x "+str(c3))

Measured memory_bytes: 16288
s = input()
lst = [i for i in s]
left = "".join([lst[0], lst[1]])
right = "".join([lst[2], lst[3]])
left = int(left)
right = int(right)
if left > 12:
    if right > 12 or right == 0:
        print("NA")
    elif 0<right <13:
        print("YYMM")
elif 0<left<13:
    if right > 12:
        print("MMYY")
    elif 0<right<13:
        print("AMBIGUOUS")
    elif right == 0:
        print("MMYY")
elif left == 0:
    if 0 < right < 13:
        print("YYMM")
    elif right == 0 or right >12:
        print("NA")

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

n = int(input())
count = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}
for _ in range(n):
    s = input()
    count[s] += 1

print('AC x {}'.format(count['AC']))
print('WA x {}'.format(count['WA']))
print('TLE x {}'.format(count['TLE']))
print('RE x {}'.format(count['RE']))


Measured memory_bytes: 9188
import random
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for k in range(D)]

def score(t):
    ret = 0
    last = [0]*26
    for k in range(D):
        last[t[k]-1] = k+1
        ret += s[k][t[k]-1]
        for i in range(26):
            ret -= c[i]*(k+1-last[i])
    return ret

ans = [c.index(max(c))]*D
prev = score(ans)
for k in range(100):
    temp = [random.randint(1,26) for l in range(D)]
    ima = score(temp)
    if ima > prev:
        prev = ima
        ans = temp[::]
print(*ans,sep="\n")


Measured memory_bytes: 79184
#include <stdio.h>
long long n, p, ans;
long long a[5000];
int main() {
	scanf("%lld%lld", &n, &p);
	a[0] = 1;
	for (int i = 0; i < (n - 1) / 2; i++) {
		for (int j = i + 1; j < n; j++) {
			a[j] += a[j - i - 1];
			a[j] %= p;
		}
		for (int j = i + 1; j < n; j++) {
			a[j] += a[j - i - 1];
			a[j] %= p;
		}
	}
	for (int i = 0; i < n; i++) {
		ans += a[i];
	}
	for (int i = 0; i < n / 2; i++) {
		ans += a[i] * (2 - n % 2);
	}
	printf("%lld\n", ans % p);
}

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

int main(){
	int N, i, ans=0;
	cin >> N;
	int a[N];
	for(i=0; i<N; i++) cin >> a[i];
	sort(a, a+N);
	i=N-1;
	for(i=N-1; i>=0; i-=2){
		ans += a[i];
		if(i==0) break;
		ans -= a[i-1];
	}
	cout << ans ;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define PI (acos(-1))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#define MAXN 1123456
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;

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

  int h, n;
  cin >> h >> n;

  const int inf = 1e9;
  vi a(n, inf), b(n);
  rep(i,0,n) cin >> a[i] >> b[i];

  vi dp(h+10005, inf);
  dp[0] = 0;
  rep(i,0,n) {
    rep(j,1,sz(dp)) {
      if (j-a[i] < 0) continue;
      dp[j] = min(dp[j], dp[j-a[i]]+b[i]);
    }
  }
  ll ans = inf;
  rep(i,h,sz(dp)) ans = min(ans,  dp[i]);
  cout << ans << endl;
}

Measured memory_bytes: 384
x,y,z,w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(3)]
for i in range(3) : a[i].sort(reverse=True)
li = []
for i in range(1, x+1):
  for j in range(1, y+1):
    if i*j > w : break
    for k in range(1, z+1):
      if i*j*k > w : break
      li.append(a[0][i-1]+a[1][j-1]+a[2][k-1])
li.sort(reverse=True)
print("\n".join(map(str,li[:w])))

Measured memory_bytes: 8732
#include<bits/stdc++.h>
using namespace std;
int dp[100009],n,k,a[100009];
int main()
{
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i-a[j]<0)break;
            if(dp[i-a[j]]==0)
            {
                dp[i]=1;
                break;
            }
        }
    }
    if(dp[k])cout<<"First";
    else cout<<"Second";
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//UnionFind
//全て添字で扱うこと
struct union_find {
  vll parent;
  vll size;

  void init(ll n) {
    for (ll i = 0; i < n; i++) parent.push_back(i);
    for (ll i = 0; i < n; i++) size.push_back(1);
    return;
  }

  ll root(ll n) {
    if (parent[n] == n) return n;
    return parent[n] = root(parent[n]);
  }

  void unite(ll a, ll b) {
    ll ra = root(a), rb = root(b);
    parent[rb] = ra;
    size[ra] += size[rb];
    return;
  }
};

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

  vll a(m), b(m);
  for (ll i = 0; i < m; i++) cin >> a[i] >> b[i];

  struct union_find uf;
  uf.init(n);

  ll unconv = n * (n - 1) / 2;
  vll ans(1, unconv);

  for (ll i = m - 1; i > 0; i--) {
    ll x = uf.root(a[i] - 1), y = uf.root(b[i] - 1);
    if (x != y) {
      unconv -= uf.size[x] * uf.size[y];
      uf.unite(x, y);
    }
    ans.push_back(unconv);
  }

  for (ll i = 0; i < m; i++) cout << ans[m - 1 - i] << endl;
}

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

int main(void){
    string inp;
    for (int i = 0; i < 1000; ++i) {
        cin>>inp;
        for (int j = 0; j < inp.length()-1; ++j) {
            switch(inp[j]){
                case 'A':
                    if(inp[j+1]=='B'||inp[j+1]=='D')break;
                    else goto end;
                case 'B':
                    if(inp[j+1]=='A'||inp[j+1]=='C'||inp[j+1]=='E')break;
                    else goto end;
                case 'C':
                    if(inp[j+1]=='B'||inp[j+1]=='F')break;
                    else goto end;
                case 'D':
                    if(inp[j+1]=='A'||inp[j+1]=='E'||inp[j+1]=='G')break;
                    else goto end;
                case 'E':
                    if(inp[j+1]=='B'||inp[j+1]=='D'||inp[j+1]=='F'||inp[j+1]=='H')break;
                    else goto end;
                case 'F':
                    if(inp[j+1]=='C'||inp[j+1]=='E'||inp[j+1]=='I')break;
                    else goto end;
                case 'G':
                    if(inp[j+1]=='D'||inp[j+1]=='H')break;
                    else goto end;
                case 'H':
                    if(inp[j+1]=='I'||inp[j+1]=='E'||inp[j+1]=='G')break;
                    else goto end;
                case 'I':
                    if(inp[j+1]=='F'||inp[j+1]=='H')break;
                    else goto end;
            }
        }
        cout<<inp<<endl;
        end:;
    }
    return 0;
}


Measured memory_bytes: 3208
using System;
using System.Linq;

namespace abc096_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Console.WriteLine(x[0] <= x[1] ? x[0] : x[0] - 1);
        }
    }
}

Measured memory_bytes: 11220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class Main {

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


		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = parseInt(line);
			if (n == 0) break;

			int count = 0;
			int steps = 0;

			StringTokenizer st = new StringTokenizer(br.readLine());
			for (int i = 0; i < n; i++) {
				String step = st.nextToken();
				if (step.charAt(0) == 'l') {
					if (step.charAt(1) == 'u') {
						steps += 2;
					} else {
						steps -= 2;
					}
				} else {
					if (step.charAt(1) == 'u') {
						steps += 1;
					} else {
						steps -= 1;
					}
				}
				if (steps == 3) {
					steps = 7;
					count++;
				} else if (steps == 4) {
					steps = 0;
					count++;
				}
			}
			System.out.println(count);
		}
	} //end while
} //end main

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

using namespace std;
typedef long long ll;
const int N = 1e5 + 200;

int n, k, s[N];
ll dp[N];

ll solve(int i) {
    if(i == n-1) return 0;
    ll& res = dp[i];
    if(~res) return res;
    res = 1e10;
    for(int step=1; step<=k; step++) {
        if(i+step < n)
            res = min(res, abs(s[i+step] - s[i]) + solve(i+step));
    }
    return res;
}

int main() {
    memset(dp, -1, sizeof(dp));
    scanf("%d%d", &n, &k);
    for(int i=0; i<n; i++) scanf("%d", &s[i]);
    printf("%I64d\n", solve(0));
    return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
using namespace std;

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  
  int ans=0;
  ans=c-a+b;
  
  if(ans>0)
    cout<<ans<<endl;
  else
    cout<<0<<endl;
  
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline

K = int(input())

st = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(st[K-1])


Measured memory_bytes: 3060
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var a = cin.nextInt();
            var b = cin.nextInt();
            var ab = cin.nextInt();
            var x = cin.nextInt();
            var y = cin.nextInt();

            var ans = new List<int>();
            ans.Add(a * x + b * y);
            var min = Math.Min(x, y);
            var max = Math.Max(x, y);
            if(x > y)
            {
                ans.Add(ab * y * 2 + a * (x - y));
            }
            else
            {
                ans.Add(ab * x * 2 + b * (y-x));
            }
            ans.Add(ab * max * 2);

            Console.WriteLine(ans.Min()); // 7900
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 13268
def main():
    N = int(input())
    B = list(map(int, input().split()))
    ans = []
    while B:
        for i in range(len(B)-1,-1,-1):
            if B[i] == i + 1:
                ans.append(B[i])
                B.pop(i)
                break
        else:
            print(-1)
            exit()
    for i in range(N-1,-1,-1):
        print(ans[i])





if __name__ == "__main__":
    main()

Measured memory_bytes: 63384
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	long long int n,x,i;
	scanf("%lld %lld",&n,&x);
	long long int a = n, b = n-x;
	if(a<b)swap(a,b); 
	while (b!=0)
	{
		long long int x=a; 
		a=b;
		b=x%b;
		if(a<b)swap(a,b);
	}
	printf("%lld",3*(n-a));
}

Measured memory_bytes: 128
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N, M;
  std::cin >> N >> M;

  std::vector<bool> dp(N, false);
  dp[0] = true;
  std::vector<i64> balls(N, 1);
  for (i64 i = 0; i < M; ++i) {
    i64 x_i, y_i;
    std::cin >> x_i >> y_i;
    --x_i;
    --y_i;
    dp[y_i] = dp[y_i] || dp[x_i];
    if (balls[x_i] == 1) {
      dp[x_i] = false;
    }
    --balls[x_i];
    ++balls[y_i];
  }

  std::cout << std::count_if(dp.begin(), dp.end(), [](const bool dp_i) { return dp_i; }) << std::endl;
  return 0;
}

Measured memory_bytes: 1024