akhauriyash/Code-Regression huggingface dataset:
using AtCoderBeginnerContest136.Questions;
using AtCoderBeginnerContest136.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest136.Questions
{
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var abc = inputStream.ReadIntArray();
            var a = abc[0];
            var b = abc[1];
            var c = abc[2];

            c -= a - b;
            yield return Math.Max(c, 0);
        }
    }
}

namespace AtCoderBeginnerContest136
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionA();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest136.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest136.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    n*=2;
    int m=sqrt(n);

    bool jud=false;
    for(int i = m; i*(i+1) <= n ; i++) {
        if((i+1)*i==n){
            jud=true;
            m=i+1;
        }
    }
    if(jud==false){
        cout << "No" << "\n";
        return 0;
    }

    int s[m][m];
    int nv=1;
    for(int i = 0; i < m; i++) {
        for(int j = i; j < m; j++) {
            if(i==j) s[i][j]=-1;
            else{
                s[i][j]=nv;
                s[j][i]=nv;
                nv++;
            }
        }
    }

    cout << "Yes" << "\n";
    cout << m << "\n";
    for(int i = 0; i < m; i++) {
        cout << m-1 << " ";
        for(int j = 0; j < m; j++) if(j!=i) cout << s[i][j] << " ";
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 4340
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
  string S;
  cin >> S;
  int cnt = 0;
  for(int i = 0; i < 3; ++i){
    if(S[i] == 'o') cnt++;
  }
  cout << 700 + cnt * 100 << endl;
}


Measured memory_bytes: 764
#include<iostream>
#include<bits/stdc++.h>
#include<string>
#include<set>
#include<vector>
#include<algorithm>
#include<array>

using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    unsigned long int n, ans = 0;
    cin>>n;
    for(int i = 1; i <= n; i++){
        if(i % 3 != 0 && i % 5 != 0){
            ans += i;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
using namespace std;
typedef long long ll;
#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

long long pow_mod(long long n, long long k, long long mod) {
    long long ret = 1, a = n % mod;
    while (k > 0) {
        if (k & 1) ret = (ret * a) % mod;
        a = (a * a) % mod;
        k >>= 1;
    }
    return ret;
}

int main ()
{
    int N; cin >> N;
    ll cnt[100010] = {};
    REP(i,N) {
        int t; cin >> t;
        cnt[t]++;
        if (t == 0 && i != 0) {
            cout << 0 << endl;
            return 0;
        }
    }

    if (cnt[0] != 1) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1LL;
    ll MOD = 998244353LL;

    ll sum = 1;
    for (int i = 1; i < N; i++) {
        if (sum != N && cnt[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
        sum += cnt[i];
        ans *= pow_mod(cnt[i - 1], cnt[i], MOD);
        ans %= MOD;
        if (sum == N) {
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
import math
import sys

def main():
    n = int(sys.stdin.readline())

    total = 0

    for i in range(1,n+1):
        for j in range(1,n+1):
            for k in range(1,n+1):
                total += math.gcd(i, math.gcd(j,k))

    print(total)

main()

Measured memory_bytes: 9088
h,w = map(int,input().split())
s = []
s.append("."*(w+2))
for i in range(h):
    s.append("."+input()+".")
s.append("."*(w+2))

ans = "Yes"
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "#":
            if s[i+1][j] == "." and s[i][j+1] == "." and s[i][j-1] == "." and s[i-1][j] == ".":
                ans = "No"
                break
    if ans == "No":
        break

print(ans)

Measured memory_bytes: 38896
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define INF 0x3f3f3f3f3f
//#define Local
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 20;

int n;
pii a[1 << N];

pii merge(pii A, pii B) {
    if(A.fi < B.fi) swap(A, B);
    pii ans = A;
    if(B.fi > ans.se) ans.se = B.fi;
    return ans;
}

void run() {
    for(int i = 0; i < 1 << n; i++) {
        int x; cin >> x;
        a[i] = MP(x, -INF);
    }
    for(int j = 0; j < n; j++) {
        for(int i = 0; i < 1 << n; i++) {
            if(i >> j & 1) a[i] = merge(a[i], a[i ^ (1 << j)]);
        }
    }
    int ans = 0;
    for(int i = 1; i < 1 << n; i++) {
        ans = max(ans, a[i].fi + a[i].se);
        cout << ans << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
#ifdef Local
    freopen("../input.in", "r", stdin);
    freopen("../output.out", "w", stdout);
#endif
    while(cin >> n) run();
    return 0;
}


Measured memory_bytes: 7168
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
vector<string>a;
int main(){
	string s;
	int k, cnt = 1;
	cin >> s >> k;
	for (int i = 0; i < s.size(); i++) {
		for (int j = 1; j <= min((signed)s.size() - i, 5); j++)a.push_back(s.substr(i, j));
	}
	sort(a.begin(), a.end());
	unique(a.begin(), a.end());
	cout << a[k - 1] << endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
using ll = long long;

int main(){
	//ios::sync_with_stdio(0);cin.tie(0);
	ll x, y, cnt=0;
	cin >> x >> y;
	while(x<=y){
		cnt++;
		x<<=1;
	}
	cout << cnt << "\n";
	return 0;
}

Measured memory_bytes: 256
import fractions
n, m = map(int,input().split())
s = list(map(str,input()))
t = list(map(str,input()))
k = 0
q = fractions.gcd(n, m)
l = n * m // q #lcm(n, m)
p = int(l/n * l/m / fractions.gcd(l/n, l/m)) #lcm(l/n, l/m)
for i in range(0, int(l/p)):
  if s[i * p//(l//n)] != t[i * p//(l//m)]:
    print('-1')
    exit()
print(l)

Measured memory_bytes: 6964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define debug(n) cerr << "[" << #n << " = " << n << "]" << '\n'
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, (b)<(e)?1:-1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define lp(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define each(x, a) for (auto &x: a)
#define pb push_back
template<class A> void read(vector <A>& v);
template<class A, size_t S> void read(array <A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
    read(t...);
}
template<class A> void read(vector<A>& x) {
    each(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    each(a, x)
        read(a);
}

const int di[8] = {0 , 0 , 1 , -1 , 1 , 1 , -1 , -1};
const int dj[8] = {1 , -1 , 0 , 0 , 1 , -1 , 1 , -1};

void Suhaib_Sawalha (){

    int x;
    cin >> x;
    ll ans = (x / 500) * 1000ll;
    x %= 500;
    ans += (x / 5) * 5ll;
    cout << ans;

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
// int _;cin>>_;for(int i=1;i<=_;++i,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}


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

public class Hello
{
    public static void Main()
    {
        string str1=Console.ReadLine();
        char [] str=str1.ToCharArray();
        
        string ans="";
        
        foreach(char let in str)
        {
            
            if((let>='a'&&let<='z')||(let>='A'&&let<='Z')) Console.Write((char)((int)let^0x20));
            else Console.Write(let);
            
        }
        Console.WriteLine();
        
    }
}


Measured memory_bytes: 15852
N = int(raw_input())
P = []
for i in range(N):
	P.append(int(raw_input()))

Q = range(N)

for i in range(N):
	Q[P[i]-1] = i+1

count = 0
max = 0
for i in range(N-1):
	if Q[i]<Q[i+1]:
		count+=1
	else:
		count=0
	
	if max < count:
		max = count

print N-max-1

Measured memory_bytes: 21736
/**********************************
	author:  mariogzsl
**********************************/

#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,b,a) for(int i=b-1;i>=a;i--)
#define f first
#define s second
#define puts(x) cout<<x<<endl
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	int n=(s[0]-'0')*10+(s[1]-'0');
	int m=(s[2]-'0')*10+(s[3]-'0');
	if(n<=12 and m<=12 and n!=0 and m!=0){
		cout<<"AMBIGUOUS"<<endl;
	}else if(n<=12 and n!=0){
		cout<<"MMYY"<<endl;
	}else if(m<=12 and m!=0){
		cout<<"YYMM"<<endl;
	}else{
		cout<<"NA"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
AB = [list(map(int, readline().split())) for _ in range(N)]

LINE = defaultdict(lambda: [0, 0])
for a, b in AB:
    LINE[a][0] += 1
    LINE[b + 1][1] += 1

LINE = list(LINE.items())
LINE.sort()

ans = 0

small = 0
small_able = 0
prevx = -1


if N % 2 == 1:

    mn = 10 ** 10
    mx = 10 ** 10

    flg = False

    for x, p in LINE:
        small_able += p[0]
        small += p[1]

        if small < (N + 1) // 2 and ((N + 1) // 2) <= small_able:
            mn = min(x, mn)

        if (N + 1) // 2 <= small:
            mx = min(mx, x - 1)
            break


else:
    mn_0 = 10 ** 10
    mn_1 = 10 ** 10
    mx_0 = 10 ** 10
    mx_1 = 10 ** 10

    flg_0 = False
    flg_1 = False

    for x, p in LINE:
        small_able += p[0]
        small += p[1]

        if small < N // 2 and (N // 2) <= small_able:
            mn_0 = min(x, mn_0)

        if N // 2 <= small:
            mx_0 = min(mx_0, x - 1)

        if small < (N // 2) + 1 and (N // 2) + 1 <= small_able:
            mn_1 = min(x, mn_1)

        if (N // 2) + 1 <= small:
            mx_1 = min(mx_1, x - 1)
            break

    mn = mn_0 + mn_1
    mx = mx_0 + mx_1


print(mx - mn + 1)


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

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
  
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod=MOD){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)2e5+11;
ll const LG=(ll)log2(N)+1;

void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
       
       cin>>x;
       if(x>=1800){
               cout<<1;
       }else if(x>=1600){
               cout<<2;
       }else if(x>=1400){
               cout<<3;
       }else if(x>=1200){
               cout<<4<<endl;
       }else if(x>=1000){
               cout<<5;
       }else if(x>=800){
               cout<<6;
       }else if(x>=600){
               cout<<7;
       }else cout<<8;
       
        
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        for(ll tc=1;tc<=q;tc++){
                // cout<<"Case #"<<tc<<": ";
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
long double pi=3.14159265358979323846L;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n;cin>>n;
    ll ans=(n/11)*2;
    n%=11;
    if(n==0)ans=ans;
    else if(n<=6)ans++;
    else ans+=2;
    cout<<ans<<endl;
}



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

int main() {
  int a, b, c, k;
  int max_, kmax, out;
  cin >> a >> b >> c;
  cin >> k;
  max_ = max(a, b);
  max_ = max(max_, c);
  kmax = max_ * pow(2, k);
  out = kmax + a + b + c - max_;
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 256
a,b,c,d = map(int,input().split())
s = []
s += ["U"]*(d-b)+["R"]*(c-a)+["D"]*(d-b)+["L"]*(c-a)
s += ["L"]+ ["U"]*(d-b+1)+["R"]*(c-a+1)+["D"]+["R"]
s += ["D"]*(d-b+1)+["L"]*(c-a+1)+["U"]
print("".join(s))

Measured memory_bytes: 3316
#include<iostream>
#include<string>

using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int a[200000];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin>>n;
    REP(i,n)cin>>a[i];
    int b=0;REP(i,n)b^=a[i];
    string ans="";
    REP(i,n){cout<<(a[i]^b)<<endl;}
    return 0;
}

Measured memory_bytes: 4400
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		while(true){
			String line = std.nextLine();

			if(line.equals("-")){break;}

			int n = Integer.parseInt(std.nextLine());
			for(int i=0; i<n; i++){
				int index = Integer.parseInt(std.nextLine());
				String newline = line.substring(index, line.length());
				newline += line.substring(0,index);
				line = newline;
			}
			System.out.println(line);
		}
	}
}

Measured memory_bytes: 26388
A = input()
B = input()
C = input()
next = "a"
while True:  
  if next == "a":
    if not A:
      print("A")
      quit()
    next = A[0]
    A = A[1:]
  elif next == "b":
    if not B:
      print("B")
      quit()
    next = B[0]
    B = B[1:]
  elif next == "c":
    if not C:
      print("C")
      quit()
    next = C[0]
    C = C[1:]

Measured memory_bytes: 3064
#include<cstdio>

#define MAXN 1000000

int list[MAXN];
int main(){
	int n;
	scanf("%d",&n);
	int same=0,tot=0,x;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		if(list[x]==0){
			list[x]=1;
			tot++;
		}
		else {
			same++;//相同的数量 
		}
	}
	//每次消都是减去两个数 
	if(same%2==1){//如果多出来的是奇数，那么需要一个数和这些数一起牺牲，成偶数，所以类数就减1 
		printf("%d",tot-1);
	}
	else {//如果多出来的数是偶数，刚好多出来的数消掉 
		printf("%d",tot);
	}
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int gcd(int p,int q){while(q){int t=p%q;p=q;q=t;}return p;}

int main(){
	int n;
	scanf("%d",&n);
	int ans=0;
	for(int i=0;i<n;i++){
		int t;
		scanf("%d",&t);
		ans=gcd(ans,t);
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
// D - Widespread
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define rp(i,n) for(int i=0;i<(n);++i)
#define roundup(a,b) (((a)+(b)-1)/(b))

int main(){
	int N,A,B; cin>>N>>A>>B;
	A -= B;//A: additional damage, B: basic damage
	vector<int> H(N);
	int maxh = 0;
	rp(i, N){
		cin>>H[i];
		maxh = max(maxh, H[i]);
	}
	int ans = INT_MAX;
	int L = 0, R = maxh/B+1;//[L,R), R: answer
	while(L < R){
		int t = (L + R)/2;//mid, number of basic attacks
		LL tb = (LL)t * B;
		LL at = 0;//number of additional atacks
		rp(i, N) if(H[i] > tb) at += roundup(H[i] - tb, A);
		if(t >= at) R = t;//mid
		else L = t + 1;//mid+1
	}
	cout<< R <<endl;
}

Measured memory_bytes: 640
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long m = Long.parseLong(sc.next());
        sc.close();
        long ans = 0;
        if (n * 2 >= m) {
            ans = m / 2;
        } else {
            ans = n;
            m -= n * 2;
            ans += m / 4;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
def z_algo(s):
    z = [0]*len(s)
    n = len(s)
    L = 0
    R = 0
    for i in range(1, n):
        if i > R:
            L = i
            R = i
            l = 0
            while l + L < n and s[l] == s[l + i]:
                l += 1
            z[i] = l
            if l > 0:
                R = L + l - 1
        else:
            k = i - L
            right_len = R - i + 1
            if z[k] < right_len:
                z[i] = z[k]
            else:
                L = i
                l = R + 1
                while l < n and s[l - L] == s[l]:
                        l += 1
                z[i] = l - L
                R = l - 1
    return z

ans = 0
N = int(input())
S = input()

for i in range(N):
    LCP = z_algo(S[i:])
    for j, l in enumerate(LCP):
        tmp = min(l, j)
        ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 52700
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"
#include "string"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (n); i++)

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int& x : a) cin >> x;
	sort(a.rbegin(), a.rend());
	int t = n - 1;
	ll ans = 0;
	rep(i, n) {
		if (t == 0) break;
		if (i == 0) {
			ans += a[i];
			--t;
			continue;
		}
		ans += a[i];
		--t;
		if (t == 0) break;
		ans += a[i];
		--t;
	}
	cout << ans << endl;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, A, B;
    ll count = 0;
    ll prev;
    cin >> N >> A >> B;
    cin >> prev;
    rep(i, N - 1) {
        ll temp;
        cin >> temp;
        count += min(B, A * (temp - prev));
        prev = temp;
    }
    cout << count << endl;
    return 0;
}


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

using namespace std;


int main(){
    int n,a,b;
    scanf("%d %d %d",&n,&a,&b);
    printf("%d %d\n",min(a,b),max(a+b-n,0));

    return 0;
    
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPR2(i, m, n) for (int i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REP(i, a.size()) cin >> a[i];
#define INPUTP(a) REP(i, a.size()) cin >> a[i].first >> a[i].second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(i, n) a[idx][i] = v[i]; idx++; PER = a;} while(next_permutation(ALL(v)));} while(0); // int fact(), VVI PERを宣言しておく
#define ENDL cout << endl;
using namespace std;
using LL = long long;
using LD = long double;
using PII = pair<int, int>;
using VPII = vector<PII>;
using PLL = pair<LL, LL>;
using VPLL = vector<PLL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
using VD = vector<double>;
const int INF = 1e9;
const LL MOD = 1e9 + 7;

template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}

void END(){cout << 1 << endl; exit(0);}

int fact(int n)
{
  if (n == 0) return 1;
  return n * fact(n-1);
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<VB> G(n, VB(n, false));
  REP(i, m)
  {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a][b] = true;
    G[b][a] = true;
  }
  VVI PER;
  MAKE_PERMUTATION(n-1);
  int ans = 0;
  REPx(x, PER)
  {
    if (!G[0][x[0]]) continue;
    bool flg = true;
    REP(i, n-2)
    {
      if (!G[x[i]][x[i+1]])
      {
        flg = false;
        break;
      }
    }
    if (flg) ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;
string S;
int N,Q,ans=0,counter=0,num[100000+10]={},tmp=0;
signed main(){
  cin >> N >> Q >> S;
  for(int i=1;i<N;i++){
    if(S[i-1]=='A' && S[i]=='C'){
      tmp++;
      num[i]=tmp;
    }
    else num[i]=num[i-1];
  }
  for(int i=0;i<Q;i++){
    int l,r;
    cin >> l >> r;
    cout << num[r-1]-num[l-1] << endl;
  }
  return 0;
}


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

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

	vector<int> d(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i];	
	}
	sort(d.begin(), d.end());

	//for (int i = 0; i < n; i++) cout << d[i] <<endl;
	cout << d[n / 2] - d[n / 2 - 1] << endl;
	return 0;
}

Measured memory_bytes: 640
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    S = str(input())

    if S[1] == "S":
        if S[2] =="R" or S[0] =="R":
            print(1)
        else:
            print(0)
    else:
        if S[2] =="R" or S[0] =="R":
            if S[2] =="R" and S[0] =="R":
                print(3)
            else:
                print(2)
        else:
            print(1)

    

if __name__ == "__main__":
	main()

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

typedef long long ll;

const ll mod = 1e9 + 7;

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

    vector<ll> sequences (k+1);
    for (ll x = k; x >= 1; x--) {
        ll c = 1;
        ll p = n;
        ll base = k/x;

        while (p > 0) {
            if (p % 2 == 1) {
                c = (c * base) % mod;
            }

            p /= 2;
            base = (base * base) % mod;
        }

        for (ll i = x+x; i <= k; i += x) {
            c = (c - sequences[i] + mod) % mod;
        }

        sequences[x] = c;
    }

    ll s = 0;
    for (ll i = 1; i <= k; i++) {
        s = (s + (i*sequences[i]) % mod) % mod;
    }
    cout << s << "\n";
}

Measured memory_bytes: 4056
/*
                            Author: Ankit Kaul
*******Code Belongs to Respective Author Only*************
*/
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
/*freopen("input.txt", "rt", stdin);
freopen("output.txt", "wt", stdout);
*/
#include <bits/stdc++.h>
#define endl       '\n'
#define PI          3.141592653589
#define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M           1000000007
#define int         long long int
#define inf         INT_MAX
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
using namespace std;
int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
        {   if(n % 2 ==1)
            result=(result * x)%M;
            x=(x*x)%M;
            n=n/2;
        }
    return result%M;
}
bool isPrime(int n)
    {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    return true;
    }
int inv(int a,int m)
{   return power(a,m-2);
}   
int lcm(int a,int b)
{   return a*b/(gcd(a,b));
}
signed main()
{   jaldi  
    int n;
    cin>>n;
    int count=0;
    for(int i=1;i<=n;i++)
    {   for(int j=1;j<=n;j++)
        {   if(n-(i*j)>0)
            count++;
            else
            break;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3648
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
using namespace std;
using ll = long long;

int main(){
    ll A,B,M;
    cin>>A>>B>>M;
    vector<ll> a(A),b(B);
    ll x[M],y[M],c[M];
    for(ll i=0;i<A;i++){
        cin>>a[i];
        a[i];
    }
    for(ll i=0;i<B;i++){
        cin>>b[i];
        b[i];
    }
    for(ll i=0;i<M;i++){
        cin>>x[i]>>y[i]>>c[i];
        x[i]--;y[i]--;
    }
    ll _min = 999999999999;
    for(ll i=0;i<M;i++){
        _min = min(_min,a[x[i]]+b[y[i]]-c[i]);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    _min = min(_min,a[0]+b[0]);
    cout<<_min<<endl;

}
 

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define pb push_back

template<typename T> T DUP(T x, T y) { return (x + y - 1) / y; };
template <typename A, size_t N, typename T>
void arrayFill(A(&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using setint = unordered_set<int32_t>;
using setstr = unordered_set<string>;
using qint = queue<int32_t>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main() {
    int a, b;
    cin >> a >> b;
    int ans = max(a - b * 2, 0);
    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 892
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
string s;
int a[1000010];
int main()
{
	int n,i,j,sum=0,k;
	cin>>s;
	n=s.size();
    for(i=1;i<=n;i++) 
	a[i]=(s[n-i]-'0')*9;
    for(i=1;i<=n;i++)
	{
        a[i+1]+=a[i]/10;
		a[i]%=10;
    }
    if(a[n+1]) 
	n++;
    for(i=1;i<=n;i++) 
	sum+=a[i];
    for(k=1;k<=n*10;k++)
	{
        a[1]+=9;
		sum+=9;
        j=1;
        while(j<=n)
		{
            if(a[j]<10) 
			break;
            sum-=10;
			a[j]-=10;
            sum++;
			a[j+1]++;
            j++;
            if(j==n and a[j+1]) 
			n++;
        }
        if(sum<=9*k)
		{
            cout<<k<<endl;
			return 0;
        }
    }
}

Measured memory_bytes: 2820
#include<stdio.h>
#include<string.h>
int S,D,M,K[105],W[105][55],P[105][55],F,N[51][301],i,j,k,l,w,p,dp[305];
int main()
{
	for(;~scanf("%d%d%d",&S,&D,&M);)
	{
		memset(dp,-1,sizeof(dp));
		memset(N,0,sizeof(N));
		dp[0]=0;
		for(i=0;i<S;i++)
			for(scanf("%d",&K[i]),j=0;j<K[i];j++)
				scanf("%d%d",&W[i][j],&P[i][j]);
		for(i=0;i<D;i++)
		{
			scanf("%d",&F);
			for(j=0;j<K[F];j++)
				N[W[F][j]][P[F][j]]++;
		}
		for(i=0;i<51;i++)
			for(j=0;j<=M;j++)
				if(N[i][j]>0)
					for(k=M;k>=0;k--)
						if(dp[k]>=0)
							for(l=1;l<=N[i][j]&&k+j*l<=M;l++)
							{
								if(j==0)dp[k+j*l]=dp[k+j*l]<dp[k]+i?dp[k]+i:dp[k+j*l];
								else dp[k+j*l]=dp[k+j*l]<dp[k]+i*l?dp[k]+i*l:dp[k+j*l];
							}
		for(i=w=p=0;i<=M;i++)
			if(w<dp[i])
			{
				w=dp[i];
				p=i;
			}
		printf("%d %d\n",w,p);
	}
	return 0;
}

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

#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)

using namespace std;



int main()
{
	typedef vector<char> VC;
	VC p={0,1,2,3,4,5,6,7};
	map<VC, int> mp;
	mp[p] = 0;
	
	int dr[]={0,1,0,-1,0};
	int ct=0;
	queue< VC > que;
	que.push(p);
	while(!que.empty()){
		auto cr = que.front(); que.pop();
		int zps = -1;
		rep(i,8) if(cr[i]==0){zps = i; break;}
		int cy = zps/4, cx = zps%4;
		rep(i,4){
			int ny=cy+dr[i], nx=cx+dr[i+1];
			if(ny<0 || ny>=2 || nx<0 || nx>=4) continue;
			auto wv=cr;
			swap(wv[zps], wv[ny*4+nx]);
			if(mp.count(wv)) continue;
			mp[wv] = mp[cr]+1;
			que.push(wv);
		}
		//printf("%d::%d\n", ct++, mp.size());
	}


	int su;
	while(cin >> su){
		VC ba(8);
		ba[0]=su;
		rep(i,7){ cin >> su; ba[i+1]=su;} 
		
		cout << mp[ba] << endl;
	
	}
	
	return 0;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()
#define PI acos(-1)

// code starts
vector<complex<double>> dft(vector<complex<double>> f, int n)
{
  if(n == 1)return f; // value of f(1) = c_i
  else
  {
    vector<complex<double>> f0(n/2);
    vector<complex<double>> f1(n/2);
    int i;
    rep(i,n/2)
    {
      f0[i] = f[2*i];
      f1[i] = f[2*i+1];
    }
    f0 = dft(f0, n/2);
    f1 = dft(f1, n/2);
    complex<double> zeta = complex<double>(cos(2*PI/n), sin(2*PI/n));
    complex<double> pow_zeta = complex<double>(1.0, 0.0);
    rep(i,n)
    {
      f[i] = (f0[i%(n/2)]+pow_zeta*f1[i%(n/2)]);
      pow_zeta *= zeta;
    }
    return f;
  }
}

vector<complex<double>> inv_dft(vector<complex<double>> f, int n, int nf)
{
  if(n==1)return f;
  else
  {
    vector<complex<double>> f0(n/2);
    vector<complex<double>> f1(n/2);
    int i;
    rep(i,n/2)
    {
      f0[i] = f[2*i];
      f1[i] = f[2*i+1];
    }
    f0 = inv_dft(f0, n/2, nf);
    f1 = inv_dft(f1, n/2, nf);
    complex<double> zeta = complex<double>(cos(-2*PI/n), sin(-2*PI/n));
    complex<double> pow_zeta = complex<double>(1.0, 0.0);
    rep(i,n)
    {
      f[i] = (f0[i%(n/2)]+pow_zeta*f1[i%(n/2)]);
      pow_zeta *= zeta;
    }
    if(n==nf)
    {
      rep(i,n) f[i] /= n;
    }
    return f;
  }
}

vector<ll> fft(vector<int> a, vector<int> b) //a,b: count array
{
  int n = a.size(); // |a|=|b|=|ans|/2
  vector<int> ka(n+1, 0);
  vector<int> kb(n+1, 0);
  int i;
  rep(i,n)
  {
    ka[i+1] = a[i];
    kb[i+1] = b[i]; 
  }
  int n2 = 1;
  while(n2 <= n*2) n2 *= 2;
  vector<complex<double>> g(n2, (0.0, 0.0));
  vector<complex<double>> h(n2, (0.0, 0.0));
  rep(i,n+1) g[i] = complex<double>(ka[i], 0);
  g = dft(g, n2);
  rep(i,n+1) h[i] = complex<double>(kb[i], 0);
  h = dft(h, n2);
  vector<complex<double>> gh(n2, (0,0));
  rep(i,n2) gh[i] = g[i]*h[i];
  vector<complex<double>> kans(n2, 0);
  kans = inv_dft(gh, n2, n2);
  vector<ll> ans(n*2+1, 0);
  for(i=1;i<=n*2;i++) ans[i] = (ll)round(kans[i].real())+0;
  return ans;
}

int main()
{
  int n;
  ll m;
  cin >> n >> m;
  vector<int> a(n);
  int i;
  rep(i,n) cin >> a[i];
  int maxs = 0;
  rep(i,n) maxs = max(maxs,a[i]);
  vector<int> count(maxs,0);
  rep(i,n)
  {
    count[a[i]-1]++;
  }
  vector<ll> vals(maxs*2+1, 0);
  vals = fft(count,count);
  ll times = 0;
  ll ans = 0;
  ll now = maxs*2;
  while(times < m)
  {
    ll take = min(m-times, (ll)vals[now]);
    times += take;
    ans += take*now;
    now--;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 40496
h,w = gets.chomp.split.map(&:to_i)
s = []
h.times do |i|
  s[i] = gets.chomp
end

flag = true
(0...h).each do |y|
  (0...w).each do |x|
    next if s[y][x] == "."
    next if x<w-1 && s[y][x+1] == "#"
    next if y<h-1 && s[y+1][x] == "#"
    next if x>0   && s[y][x-1] == "#"
    next if y>0   && s[y-1][x] == "#"
    flag = false
  end
  break if !flag
end

printf("%s\n",(flag ? "Yes" : "No"))

Measured memory_bytes: 1788
#include<bits/stdc++.h>
typedef long long ll;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f;
const int N=2e5+5;
using namespace std;
vector<ll> v;
int boom[N];
int a[N];
int main()
{
    ll n,k;cin>>n>>k;k++;
    for(int i=1;i<=n;i++) cin>>a[i];
    v.push_back(1);
    boom[1]=1;
    int i=1;
    while(!boom[a[i]])
    {
        v.push_back(a[i]);
        boom[a[i]]=1;
        i=a[i];
    }
    int t=inf;
    for(int j=0;j<v.size();j++)
    {
        if(v[j]==a[i])
        {
            t=j;break;
        }
    }
    int len=v.size()-t;
    if(k<=t) cout<<v[k-1]<<endl;
    else
    {
        cout<<v[(t+(((k-t)%len==0)?len:((k-t)%len))-1)];
    }
    return 0;
}


Measured memory_bytes: 6824
#include <stdio.h>
int n; long long dp[301][18];
int main() {
	while(~scanf("%d", &n), n) {
		for(int i = 0; i <= n; i++) {
			for(int j = 0; j <= 17; j++) dp[i][j] = 0;
		}
		dp[0][0] = 1;
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j * j <= i; j++) {
				for(int k = 0; k <= j; k++) dp[i][j] += dp[i - j * j][k];
			}
		}
		long long ret = 0;
		for(int i = 0; i <= 17; i++) ret += dp[n][i];
		printf("%lld\n", ret);
	}
	return 0;
}

Measured memory_bytes: 2640
n, w = map(int, input().split())
W, V = [], []
for i in range(n):
    wi, vi = map(int, input().split())
    W.append(wi)
    V.append(vi)

max_sumv = sum(V) 
# Dp[i][sum_v] := i-1 番目までの品物から価値がsum_v以上を達成するように選んだときの、重さの総和の最小値小値
dp = [[10 ** 9] * (max_sumv + 1) for _ in range(n+1)]

dp[0][0] = 0

for i in range(n):
    for sum_v in range(max_sumv + 1):
        # i番目の商品を選ぶ場合
        if sum_v - V[i] >= 0:
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - V[i]] + W[i])
        # i番目の商品を選ばない場合
        dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v])
ans = 0
for i in range(max_sumv + 1):
    if dp[n][i] <= w:
        ans = i
print(ans)

Measured memory_bytes: 120812
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(RALL(a));
    ll ans = a[0];
    int cnt = 0, now = 1;
    for(int i = 2; i < n; i++) {
        if(cnt == 2) {
            now++;
            cnt = 0;
        }
        ans += a[now];
        cnt++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4764
a, b, c, k = map(int, input().split())
sum = 0

if a < k:
    sum += a
    k -= a
else:
    sum += k
    k = 0

if 0 < k:
    if b < k:
        k -= b
    else:
        k = 0

if 0 < k:
    sum -= k
    k = 0

print(sum - k)


Measured memory_bytes: 9200
#include <iostream>
#include <vector>
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < 1000000; i++) {
		if (i * (i + 1) / 2 >= n) {
			printf("%d\n", i);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



vector<long long> divisor(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n%i == 0LL) {
            res.push_back(i);
            long long temp = n/i;
            if (i != temp) res.push_back(temp);
        }
    }
    return res;
}

int n;

int main() {
    while (cin >> n) {
        if (n == 0) break;
        
        vll div = divisor(n);
        sort(ALL(div));
        ll res = 0;
        for (int i = 0; i < div.size()-1; ++i) res += div[i];
        if (res > n) cout << "abundant number" << endl;
        else if (res == n) cout << "perfect number" << endl;
        else cout << "deficient number" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1208
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	s := wordScanner()
	n, h := scanNAndIntSlice(s)

	for i := n - 1; i > 0; i-- {
		if h[i] == h[i-1]-1 {
			h[i-1]--
		} else if h[i] < h[i-1] {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}

func wordScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func scanNAndIntSlice(s *bufio.Scanner) (int, []int) {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n, scanIntSlice(s, n)
}

func scanIntSlice(s *bufio.Scanner, n int) []int {
	vals := make([]int, n)
	for i := range vals {
		s.Scan()
		m, _ := strconv.Atoi(s.Text())
		vals[i] = m
	}
	return vals
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,c=0;
  string a;
  cin>>n;
  cin>>a;
  int i=0,j=n-1;
  while(i<=j){
    if(a[i]=='W'&& a[j]=='R'){
        swap(a[i],a[j]);
        c++;
        i++;
        j--;
    }

    else{
        if(a[i]!='W')
        i++;
        if(a[j]!='R')
        j--;
    }
  }
  cout<<c;

}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
int n,maxim;
string s;
map <string,int> mp;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>s;
        mp[s]++;
    }
    for(auto it: mp)
        maxim=max(maxim,it.second);
    for(auto it : mp)
    {
        if(it.second==maxim)
            cout<<it.first<<"\n";
    }
    return 0;
}

Measured memory_bytes: 23808
n = int(raw_input())
a = map(int, raw_input().split())
print " ".join(map(str, a))
for j in range(1,n):
    key = a[j]
    i = j-1
    while i >= 0 and a[i] > key:
        a[i+1] = a[i]
        i = i - 1
    a[i+1] = key
    print " ".join(map(str, a))

Measured memory_bytes: 4220
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
using namespace std;

 
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	int n, m;
	
	cin >> n >> m;
	
	map<int, int> mp;
	
	int val;
	for(int i = 0; i < m; i++){
		cin >> val;
		mp[val] = 1;
	}
	
	int dp[n+5] = {0};
	dp[0] = 1;
	
	for(int i = 0; i <= n; i++){
		if(mp[i+1] == 0) dp[i+1] = ((dp[i+1]%MOD) + (dp[i]%MOD)) % MOD;
		if(mp[i+2] == 0) dp[i+2] = ((dp[i+2]%MOD) + (dp[i]%MOD)) % MOD;
	}
	
	
	cout << dp[n] << "\n";
	
	return 0;
}


Measured memory_bytes: 5376
package main

import "fmt"

func main() {
	var n, m int
	var arr1 [100][100]int
	var arr2 [100]int

	fmt.Scan(&n, &m)

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Scan(&arr1[i][j])
		}
	}
	
	for i := 0; i < m; i++ {
		fmt.Scan(&arr2[i])
	}

	for i := 0; i < n; i++ {
		tmp := 0
		for j := 0; j < m; j++ {
			tmp += arr1[i][j] * arr2[j]
		}
		fmt.Println(tmp)
	}
}



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

int main()
{
   int x,k=0,i,n,z=0,v[200],m;
   cin>>n;
   for(i=1;i<=n;i++)
   {
       cin>>x;
       while(x%2==0)
       {
           x=x/2;
           k++;
       }
      v[i]=k;
      k=0;
   }
   m=v[1];
   for(i=2;i<=n;i++)
    if(m>v[i])
        m=v[i];
cout<<m;
return 0;
}

Measured memory_bytes: 256