akhauriyash/Code-Regression huggingface dataset:
S=str(input())
s=list(S)
x,y=map(int,input().split())
fora=0
side=[]
updw=[]
while s[0]=="F":
  fora+=1
  s.pop(0)
  if len(s)==0:break
flag=1#1のとき横向き、-1のときたて向き
step=0
while s:
  if s[0]=="T":
    s.pop(0)
    if step:
      if flag==-1: updw+=[step]
      else: side+=[step]
    flag=flag*(-1)
    step=0
  else:
    s.pop(0)
    step+=1
    if len(s)==0:
      if flag==-1: updw+=[step]
      else: side+=[step]
ypossi=len(side)
tpossi=len(updw)
X=sum(side)+fora+abs(x)
Y=sum(updw)+abs(y)
xdp=[[0 for i in range(2*X+1)] for j in range(ypossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
xdp[0][fora+X]=1 
for i in range(ypossi):
  for j in range(2*X+1):
    if j-side[i]>=0:
      if xdp[i][j-side[i]]==1:xdp[i+1][j]=1
    if j+side[i]<2*X+1:
      if xdp[i][j+side[i]]==1:xdp[i+1][j]=1

ydp=[[0 for i in range(2*Y+1)] for j in range(tpossi+1)]
#dp[i][j] i個文字使ったときにj+len(s)は達成できるか
ydp[0][Y]=1 
for i in range(tpossi):
  for j in range(2*Y+1):
    if j-updw[i]>=0:
      if ydp[i][j-updw[i]]==1:ydp[i+1][j]=1
    if j+updw[i]<2*Y+1:
      if ydp[i][j+updw[i]]==1:ydp[i+1][j]=1
if xdp[ypossi][x+X]==1 and ydp[tpossi][y+Y]==1:
  print("Yes")
else: print("No")

Measured memory_bytes: 308360
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = sorted(list(li()))

print(sum(a[n:3*n:2]))

Measured memory_bytes: 37084
N = gets.to_i
Hs = gets.split.map(&:to_i)

def cut(hs, acc)
  i, a = hs.minmax
  return acc if a.zero?
  return cut(hs.map{|h| h - i}, acc + i) if i > 0
  hs.chunk(&:positive?).select(&:first).map(&:last).inject(acc){|s, a| s + cut(a, 0)}
end

puts cut(Hs, 0)

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

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i,h) cin >> s[i]; 
    //ビット演算で実装すると良い
    //ビット全探索問題
    int ans=0;
    rep(is,1<<h)rep(js,1<<w){ //左シフトで行，列ごとに全列挙　&& 消す行列全探索
        int cnt=0;
        rep(i,h)rep(j,w){ //マス目全検索
            if(is>>i&1) continue; //行が消されてるなら抜ける
            if(js>>j&1) continue; //列が消されてるなら抜ける
            if(s[i][j]=='#') cnt++; //消されず黒ならインクリメント
        }
        if(cnt==k) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include<stdio.h>
int main(void)
{
	int i,j,x[100],y[100],a,b,c,d,e;
	while(1){
		scanf("%d %d",&a,&b);
		if(a==0||b==0) break;
		c=1000;
		for(i=0;i<4;i++){
			x[i]=0;
			x[i]=a/c;
			a=a-x[i]*c;
			c=c/10;
		}
		c=1000;
		for(j=0;j<4;j++){
			y[j]=0;
			y[j]=b/c;
			b=b-y[j]*c;
			c=c/10;
		}
		d=0; e=0;
		for(i=0;i<4;i++){
			for(j=0;j<4;j++){
				if(x[i]==y[i]){
					d++;
					break;
				}
				else if(x[i]==y[j]){
					e++;
				}
			}
		}
		printf("%d %d\n",d,e);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll  long long int
#define pb push_back
#define fe first
#define se second
#define endl "\n"
#define pii pair<int,int>

#define PI  3.14159265358979323846
const int  N=2e5+10;

int n;
double sum;

void solve(){
	 cin>>n;
	 for(int i=0;i<n;i++){
		   double x;
		   string s;
		   cin>>x>>s;
		   if(s=="JPY")
		     sum+=x;
		   else if(s=="BTC"){
			     x=x*380000.0;
			     sum+=x;
			   }
		 
		 }
		 cout<<fixed<<setprecision(8)<<sum;
	  
	

	}
	
	
 


int main(){
  cool;
   int t=1;
   while(t--)   
     solve(); 

  return 0; 
}



  


  


Measured memory_bytes: 256
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  long long P = 1000000007;
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long dp[n + 1][n + 1];
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= n; j++)
      dp[i][j] = 0;
  for (int i = 0; i < n; i++)
    dp[0][i] = 1;
  for (int i = 0; i < n - 1; i++) {
    long long sdp[30303] = {0};
    sdp[0] = 0;
    for (int j = 0; j < n; j++) {
      sdp[j + 1] = (sdp[j] + dp[i][j]) % P;
    }
    for (int j = 0; j < n - i - 1; j++) {
      if (s[i] == '<') {
        dp[i + 1][j] = (sdp[n] - sdp[j + 1] + P) % P;
      } else {
        dp[i + 1][j] = sdp[j + 1];
      }
    }
  }
  cout << dp[n - 1][0] << endl;
  return 0;
}


Measured memory_bytes: 70912
/*
 * Task_A.cxx
 * 
 * Copyright 2020 Dell <Dell@HP>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 * 
 */


#include <iostream>
#include <stdio.h>
using namespace std;

int main(int argc, char **argv)
{	
	int k, a, b;
	scanf("%d%d%d", &k, &a, &b);
	int rem = b % k;
	if(b - rem >= a){
		cout<<"OK"<<endl;
	}
	else{
		cout<<"NG"<<endl;
	}
	return 0;
}



Measured memory_bytes: 3688
X = int(input())
mod = X % 100
q = int(X //100)
sum = 0
ans = 0
if q >= 100:
    ans = 1
else:
    for i in range (0,q+1):
        for j in range (0,q+1-i):
            for k in range (0,q+1-i-j):
                for l in range (0,q+1-i-k-j):
                    for m in range (0,q+1-i-j-k-l):
                        sum = i+(2*j)+(3*k)+(4*l)+(5*m)
                        if sum == mod:
                            ans = 1
print(ans)


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, k, q; cin >> n >> k >> q;
  vi a(n);
  vi mi(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  int ans = INF;
  for(int i=0;i<n;++i) {
    vector<int> tmp;
    vector<int> v;
    for(int j=0;j<n;++j) {
      if(a[j] < a[i]) {
        sort(v.begin(), v.end());
        for(int l=0;l<SZ(v)-k+1;++l) {
          tmp.push_back(v[l]);
        }
        v.clear();
      } else {
        v.push_back(a[j]);
      }
    }
    sort(v.begin(), v.end());
    for(int j=0;j<SZ(v)-k+1;++j) {
      tmp.push_back(v[j]);
    }
    sort(tmp.begin(), tmp.end());
    //cout << i << endl;
    //printv(tmp);
    if(SZ(tmp) >= q) {
      ans = min(ans, tmp[q-1] - tmp[0]);
    }
  }
  cout << ans << endl;

}


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


void c_xys_triplets(void) {
	int n;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		if (i < 6) {
			cout << 0 << endl;
			continue;
		}
		int max = (i+3) / 6;
		int cnt = 0;
		for (int a = 1; a <= max; a++) {
			if (a * a > i) break;
			for (int b = 1; b <= max; b++) {
				if ((a * a +b*b) > i) break;
				//for (int c = 1; c <= max; c++) {
				//	if (a *a + b*b + c*c + a * b + b * c + c * a == i) {
				//		cnt++;
				//		break;
				//	}
				//}
				int remain = i - a * a - a * b - b * b;
				if (remain<0)break;
				int l = int(sqrt(double(remain)));
				for (int c = 1; c <= l; c++) {
					if (c * c + a * c + b * c == remain) {
						cnt++;
						break;
					}
				}

			}
		}
		cout << cnt << endl;
	}

}

int main()
{
	c_xys_triplets();
    return 0;
}

Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
int main (){
  int N,L;
  cin>>N>>L;
  vector<string> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  string s="";
  for(int i=0;i<N;i++){
    s+=a[i];
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
typedef long long ll;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int n,ans = 0,t = 0;
    cin >> n;
    for(int i = 0;i < n; ++i){
        cin >> a[i];
    }
    for(int i = 0;i < n-1; ++i){
        if(a[i] >= a[i+1]){
            t++;
            //cout << a[i] <<" " << a[i+1] << " " << t << endl;
        }
        else {
            ans = max(t,ans);
            t = 0;
        }
    }
    cout << max(ans,t) ;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int N;
	bool flag = true;
	cin >> N;
	vector<int> A(N);
	for (int count = 0; count < N; count++)
	{
		cin >> A.at(count);
	}
	for (int count = 0; count < N; count++)
	{
		if (A.at(count) % 2 == 0)
		{
			flag = false;
			if (A.at(count) % 3 == 0 || A.at(count) % 5 == 0)
			{
				flag = true;
			}
			else
			{
				break;
			}
		}
	}
	if (flag)
	{
		cout << "APPROVED" << endl;
	}
	else
	{
		cout << "DENIED" << endl;
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
int main()
{
	string str = "ABCDE";
	while(1)
	{
		int v=-1,n;
		for(int i=0;i<5;i++)
		{
			int a,b;
			cin >> a >> b;
			if(a==0&&b==0)goto end;
			if(v<a+b)
			{
				v = a+b;
				n = i;
			}
		}
		cout << str[n] << ' ' << v << endl;
	}
	end:;
	return 0;
}

Measured memory_bytes: 1204
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>  
#include<memory.h> 
#include<sstream>
#include<time.h>
#include<iomanip>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const int MOD=1000000007;
const long long LMOD=998244353;
//const long long LMOD=1000000007;
#define Fi first
#define Se second
#define P2 pair
#define Pii pair<int,int>
#define Cb make_pair
#define Ll long long
#define Ull unsigned long long
#define Snf scanf
#define Prf printf
#define Pb push_back
#define Stc stack
#define Vct vector
#define Ret return
#define Sz size
#define Ins insert
int n,m;
set<int>s;
int a[100005];
int main()
{
	Snf("%d%d",&n,&m);
	int t;
	for(int i=1;i<=m;i++)
	{
		Snf("%d",&t);
		s.Ins(t);
	}
	a[0]=1;
	if(!s.count(1))a[1]+=a[0];
	for(int i=2;i<=n;i++)
	{
		if(s.count(i))continue;
		a[i]+=a[i-1]+a[i-2];
		a[i]%=MOD;
	}
	Prf("%d",a[n]);
	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

int main(void) {

  int n;
  scanf("%d", &n);
  int d1,d2,count = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &d1, &d2);
    if (d1 == d2) {
      count++;
    } else {
      count = 0;
    }
    if (count == 3) {
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");

  return 0;
}

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = NK[0];
            var K = NK[1];
            var AList = Console.ReadLine().Split(' ').Select(int.Parse);

            var dict = new Dictionary<int, int>();
            foreach (var A in AList)
            {
                if (!dict.ContainsKey(A))
                {
                    dict.Add(A, 0);
                }

                dict[A]++;
            }

            var m = dict.Count - K;

            if (m <= 0)
            {
                Console.WriteLine(0);
                return;
            }

            var ordered = dict.OrderBy(p => p.Value);
            var output = 0;
            foreach (var d in ordered)
            {
                m--;
                output += d.Value;

                if (m <= 0)
                {
                    Console.WriteLine(output);
                    return;
                }
            }
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 38260
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll mod=998244353;
const int maxn=(1e6)+5;
int n,cnt[maxn];
ll s,g[maxn],s2,iv[maxn],ans;
ll ksm(ll x,ll y) {
	ll res=1;
	while (y) {
		if (y&1) res=res*x%mod;
		x=x*x%mod; y>>=1;
	} return res;
}
void update(ll &x,ll y) {
	x+=y; if (x>=mod) x-=mod;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n); int x;
	for (int i=1;i<=n;i++) read(x),cnt[x]++;
	iv[0]=iv[1]=1;
	for (int i=2;i<maxn;i++) iv[i]=(mod-mod/i)*iv[mod%i]%mod;
	for (int i=1;i<maxn;i++) {
		s=s2=0;
		for (int j=i;j<maxn;j+=i)
			s+=(ll)cnt[j]*j,
			update(s2,(ll)cnt[j]*j%mod*j%mod);
		s%=mod;
		g[i]=(s*s%mod-s2+mod)*iv[2]%mod;
	}
	for (int i=maxn-1;i>=1;i--) {
		for (int j=i*2;j<maxn;j+=i)
			update(g[i],mod-g[j]);
		update(ans,g[i]*iv[i]%mod);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 19712
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

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

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    ll W, H;
    ll X, Y;
    cin >> W >> H >> X >> Y;
    cout << fixed;
    cout.precision(15);
    cout << W*H/2.0 << " " << ((2*X == W && 2*Y == H) ? 1 : 0) << endl;

    return 0;
}


Measured memory_bytes: 256
H, N = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

dp = [[10 ** 9] * (H + 1) for _ in range(N + 1)]
dp[0][0] = 0
X.sort(key=lambda x: -x[-1])

for i, (a, b) in enumerate(X):
    for j in range(H + 1):
        if j == 0:
            dp[i + 1][j] = 0
        if j + a < H:
            dp[i + 1][j + a] = min(dp[i][j + a], dp[i][j] + b, dp[i + 1][j] + b)
        else:
            dp[i + 1][-1] = min(dp[i][-1], dp[i + 1][-1], dp[i][j] + b, dp[i + 1][j] + b)            
            
print(dp[-1][-1])


Measured memory_bytes: 120412
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define rep(i, l, r) for(int i = (l); i <= (r); i++)
#define per(i, r, l) for(int i = (r); i >= (l); i--)
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree <int, null_type, less <int>, rb_tree_tag, tree_order_statistics_node_update> os;

int B, A, C;
int main(){
  int n; scanf("%d", &n);
  int cnt = 0;
  rep(i, 1, n) {
    int p = i;
    int digit = 0;
    while(p) {
      digit++;
      p /= 10;
    }
    if(digit % 2 == 1) ++cnt;
  }
  cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
S = input()
lct_A = 0
lct_q = 0
rct_C = S.count("C")
rct_q = S.count("?")

MOD = 10**9 + 7

ans = 0
for s in S:
  if s == "C":
    rct_C -= 1
  elif s == "?":
    rct_q -= 1
  #print(s, lct_A, lct_q, rct_C, rct_q)
    
  if s == "B" or s == "?":
    ans += (lct_A * rct_C * pow(3, lct_q+rct_q, MOD)) % MOD
    if lct_q > 0:
      ans += (lct_q * rct_C * pow(3, lct_q+rct_q-1, MOD) ) % MOD
    if rct_q > 0:
      ans += (rct_q * lct_A * pow(3, lct_q+rct_q-1, MOD) ) % MOD
    if lct_q > 0 and rct_q > 0:
      ans += (lct_q * rct_q * pow(3, lct_q+rct_q-2, MOD) ) % MOD   
    ans %= MOD
    #print(" ", ans)
    
  if s == "A":
    lct_A += 1
  elif s == "?":
    lct_q += 1
    
print(ans % MOD)

Measured memory_bytes: 73116
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))




signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	vector<P>tmp;
	rep(i, n) {
		int a, b; cin >> a >> b;
		tmp.push_back(make_pair(a, b));
	}
	sort(tmp.begin(), tmp.end());
	int ans = 0;
	int now = 0;
	rep(i, n) {
		if (now +tmp[i].second< m) {
			ans += tmp[i].first*tmp[i].second;
		}
		else {
			ans += tmp[i].first*(m - now);
			cout << ans << endl; return 0;
		}
		now += tmp[i].second;
	}
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define LAST(i,n) if(i==n-1)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

typedef long lint;
typedef pair<lint, lint> P;

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

    vector<lint> A;

    REP(_, N) {
      lint a; cin >> a; A.push_back(a);
    }

    SORT(A);

    lint res = 0;

    if(N == 2) {
      PRINT(A[1]-A[0]);
      return 0;
    }

    if(N%2 == 0) {
      REP(i, N) {
        if(i >= N/2) {
          if(i == N/2) {
            res += A[i];
          }
          else {
            res += 2*A[i];
          }
        }
        else {
          if(i==N/2-1) {
            res -= A[i];
          }
          else {
            res -= 2*A[i];
          }
        }
      }
    }
    else {
      REP(i, N) {
        if(i > N/2) {
          res += 2*A[i];
        }
        else {
          if(i== N/2 || i== N/2-1) {
            res -= A[i];
          }else {
            res -= 2*A[i];
          }
        }

      }
      lint res2 = 0;

      REP(i, N) {
        if(i >= N/2) {
          if(i == N/2 || i==N/2+1) {
            res2 += A[i];
          }
          else {
            res2 += 2*A[i];
          }
        }
        else {
          res2 -= 2*A[i];
        }
        res = max(res, res2);
      }
    }
    
    

    

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll unsigned long long int
const int mx = 1e7 + 7;
int arr[mx];
void solve()
{
	ll n;
	ll ans = 1;
	cin>>n;
//	clock_t start, end; 
//	start = clock();
	for(ll i=2; i<=n; i++)
	{
//		cout<<arr[i]<<"\n";
		arr[i]++;
		for(ll j=i; j<=n; j+=i)
		{
			arr[j]++;
		}
//		cout<<arr[i]<<"\n";
		ans+=(i*arr[i]);
	}
	cout<<ans<<"\n";
//	end = clock(); 
//	double time_taken = double(end - start) / double(CLOCKS_PER_SEC); 
//    cout << "Time taken by program is : " << fixed  
//         << time_taken << setprecision(5); 
//    cout << " sec " << endl; 
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		memset(arr, 0, sizeof(arr));
		solve();
	}
	return 0;
}

Measured memory_bytes: 42700
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

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


Measured memory_bytes: 256
program ABC103A
    implicit none
    integer(8)::i
    integer(8),dimension(3)::A
    
    read(5,*)(A(i),i=1,3)

    print'(i0)',max(max(A(1),A(2)),A(3))-min(min(A(1),A(2)),A(3))
end program ABC103A

Measured memory_bytes: 512
(defun app ()
    (let ((a3*3 (make-array '(3 3) :initial-element 0))
        (b3*3 (make-array '(3 3) :initial-element NIL))
        (ans "No"))

        (dotimes (i 3)
            (dotimes (j 3)
                (setf (aref a3*3 i j) (read))
            ))
        (let ((n (read))
            (num 0))
            
            (loop for k below n do
                (setq num (read))
            (loop named a for i below 3 do
                (loop for j below 3 do
                    (if (= (aref a3*3 i j) num)
                        (progn
                        (setf (aref b3*3 i j) T)
                        (return-from a))
                    )
                )
            )

            )
        )

        (dotimes (i 3)
            (if (and (eq (aref b3*3 i 0) T) (eq (aref b3*3 i 1) T) (eq (aref b3*3 i 2) T))
                (setf ans "Yes")
            )
            (if (and (eq (aref b3*3 0 i) T) (eq (aref b3*3 1 i) T) (eq (aref b3*3 2 i) T))
                (setf ans "Yes")
            )
        )
        (if (eq (aref b3*3 1 1) T)
            (progn
            (if (and (eq (aref b3*3 0 0) T) (eq (aref b3*3 2 2) T))
                (setf ans "Yes")
            )
            (if (and (eq (aref b3*3 0 2) T) (eq (aref b3*3 2 0) T))
                (setf ans "Yes")
            )
            )
        )    
        (format t "~A~%" ans)
    )
)
(app)

Measured memory_bytes: 23676
#include <iostream>

using namespace std;
const int LEN = 2e5 + 10;
int Arr[LEN] = {0};

int main() {
    int N, m;
    cin >> N;
    for (int i = 1; i < N; i++) {
        cin >> m;
        Arr[m] += 1;
    }
    for (int i = 1; i <= N; i++) {
        cout << Arr[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4300
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int mod = 1e9 + 7;

const int N = 2e5 + 5;

int n, m;
int par[N];

int fs(int x)
{
  return x == par[x] ? x : par[x] = fs(par[x]);
}

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

  while(m--){
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    --a, --b;
    a = fs(a);
    b = fs(b);
    if(a != b)
      par[a] = b;
  }

  int ans = 0;
  for(int i = 0 ; i < n ; i++)
    ans += fs(i) == i;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1152
#include "bits/stdc++.h"
using namespace std;

#define db(x) //cerr << #x << " == " << x << endl
#define all(container) container.begin(), container.end()
#define mp(i,j) make_pair(i,j)
#define pb push_back

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

template<typename T>
void print_vector_debug(const T& t) {
	cout << "[DEBUG] VECTOR:";
	for (auto i = t.cbegin(); i != t.cend(); ++i) {
		if ((i + 1) != t.cend()) {
			cout << *i << " ";
		} else {
			cout << *i << endl;
		}
	}
}

#define MAXN 105
#define MAXV 100005
#define INF (ll)20000000000000000LL

ll N, W;
ll v[MAXN], w[MAXN];
int vis[MAXN][MAXV];
ll dp[MAXN][MAXV];

ll solve_dp(int idx, ll r)
{
	if (idx == N)
	{
		return r <= 0 ? 0:INF;
	}
	
	if (r <= 0)
	{
		return 0;
	}
	
	if (vis[idx][r])
	{
		return dp[idx][r];
	}
	vis[idx][r] = 1;
	
	ll res = min(solve_dp(idx + 1, r), solve_dp(idx + 1, r - v[idx]) + w[idx]);
	dp[idx][r] = res;
	
	return res;
}

ll solve()
{
	ll upper = MAXV - 1;
	ll lower = 0;
	ll mid, best;
	
	while (lower <= upper)
	{
		mid = lower + (upper - lower) / 2;
		
		db(upper);
		db(lower);
		db(mid);
		
		if (solve_dp(0, mid) <= W)
		{
			db("possible");
			best = mid;
			lower = mid + 1;
		}
		else
		{
			db("impossible");
			upper = mid - 1;
		}
	}
	
	return best;
}

int main() 
{
	scanf("%lld%lld", &N, &W);
	
	for (int i = 0; i < N; i++)
	{
		scanf("%lld%lld", &w[i], &v[i]);
	}
	
	printf("%lld\n", solve());
	
	return 0;
}


Measured memory_bytes: 119168
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 0;										/* デバッグプリント 提出時は0 */

int main()
{
	int		i=0,m=0,f=0,r=0;
	char	a[50];

	while(1) {
		scanf("%d %d %d", &m, &f, &r);
		if ((m==-1)&&(f==-1)&&(r==-1)) break;
		if ((m==-1)||(f==-1)) a[i] = 'F';
		else if (m+f>=80) a[i] = 'A';
		else if (m+f>=65) a[i] = 'B';
		else if (m+f>=50) a[i] = 'C';
		else if (m+f>=30) {
			if (r>=50) a[i] = 'C';
			else a[i] = 'D';
		} else a[i] = 'F';
		i++;
	}

	for(m=0;m<i;m++) {
		printf("%c\n",a[m]);
	}

	return 0;
}



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

int main(){
  string S;
  cin>>S;
  if(S.at(0)==S.at(1)||S.at(1)==S.at(2)||S.at(2)==S.at(3))
    cout<<"Bad"<<endl;
  else
    cout<<"Good"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int N = sc.nextInt();
        int[][] tasks = new int[N][3];

        for (int i = 0; i < N; i++) {
            tasks[i][0] = sc.nextInt();
            tasks[i][1] = sc.nextInt();
            tasks[i][2] = sc.nextInt();
        }

        int[] dp = new int[3];

        for(int day = 0; day < N; day++) {
            int[] temp = new int[3];
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    if (i != j) {
                        temp[i] = Math.max(temp[i], dp[j] + tasks[day][i]);
                    }
                }
            }
            dp = temp;
        }
        System.out.println(Math.max(dp[0], Math.max(dp[1], dp[2])));
    }
}


Measured memory_bytes: 98288
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = input()
    t = input()
    if t in s:
        print(0)
        sys.exit()
    if len(s) == 1 and len(t) == 1:
        if t != s:
            print(1)
            sys.exit()
    lens = len(s)
    lent = len(t)
    res = set()
    for i1 in range(lens - lent + 1):
        tmp1 = sum([c1 == c2 for c1, c2 in zip(t, s[i1:i1+lent])])
        res.add(lent - tmp1)
        #print(s[i1:i1+lent], res)
    if res:
        r = min(res)
        print(r)
    else:
        print(lent)

if __name__ == '__main__':
    main()


Measured memory_bytes: 67628
#include <iostream>
#include <algorithm>

using namespace std;

long long t[200005];

int main() {
    long long N, T;
    long long ans = 0;

    cin >> N >> T;

    for (int i = 0; i < N; i++) {
        cin >> t[i];
    }
    for (int i = 0; i < N; i++) {
        if (i == N-1) { ans += T; }
        else {
            ans += min(T, t[i+1]-t[i]);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
package main

import (
        "fmt"
        "sort"
)

func solution(n, k int, p []int) int {
        sort.Ints(p)

        sum := 0
        for i := 0; i < k; i++ {
                sum += p[i]
        }
        return sum
}

func main() {
        var n, k int
        fmt.Scan(&n, &k)
        p := make([]int, n)
        for i := range p {
                fmt.Scan(&p[i])
        }
        fmt.Println(solution(n, k, p))
}

Measured memory_bytes: 1888
#112B
N,T=map(int,input().split())
c,t,L=[0]*N,[0]*N,[]
for i in range(N):
    c[i],t[i]=map(int,input().split())
    if t[i]<=T:L.append((c[i],t[i]))
if len(L)==0:
    print('TLE')
else:
    L.sort()
    print(L[0][0])

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author varunvats32
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ARemainingBalls solver = new ARemainingBalls();
        solver.solve(1, in, out);
        out.close();
    }

    static class ARemainingBalls {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String l = in.nextLine();
            String[] balls = l.split(" ");
            String n = in.nextLine();
            String[] nums = n.split(" ");
            String u = in.nextLine();

            int s = Integer.parseInt(nums[0]);
            int t = Integer.parseInt(nums[1]);

            if (u.equals(balls[0])) {
                s--;
            } else {
                t--;
            }

            out.println(s + " " + t);
        }

    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
long long ccc;
long long n;
long long check(long long num){
    bool ok3=false,ok5=false,ok7=false;
    string s=to_string(num);
    for(int i=0;i<s.size();i++){
        if(s[i]=='3') {ok3=true; continue;}
        if(s[i]=='5') {ok5=true; continue;}
        if(s[i]=='7') {ok7=true; continue;}
    }
    if(ok3&&ok5&&ok7) return 1;
        else return 0;
    }
bool checky(vector <long long> alp,int num){
    for(int i=0;i<alp.size();i++){
        if(alp[i]==num) return 1;
    }
    return 0;
} 
long long makenum(long long num,vector <long long> alp){
    if(checky(alp,num)) return 0;
    alp.push_back(num);
    if(num>n) return 0;
    if(num>100) ccc+=check(num);
    makenum(num*10+3,alp);
    makenum(num*10+5,alp);
    makenum(num*10+7,alp);
    return 0;
}
int main(void){
    cin>>n;
    ccc=0;
    vector <long long> alp;
    makenum(3,alp);
    makenum(5,alp);
    makenum(7,alp);
    cout<<ccc<<endl;
}

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

int main()
{
   ll n;

   cin>>n;

   ll a[n],b[n],c[n],d[n],ans=0;

   for(int i=0;i<n;i++) cin>>a[i]>>b[i];

   for(int i=0;i<n;i++) cin>>c[i]>>d[i];

   pair <ll , ll> red[n],blue[n];

   for(int i=0;i<n;i++)
   {
     red[i].first=b[i];
     red[i].second=a[i];
     blue[i].first=c[i];
     blue[i].second=d[i];
   }

   sort(red,red+n);
   sort(blue,blue+n);

   ll ch[111]={0};

   for(int i=0;i<n;i++)
   {
       for(int j=n-1;j>=0;j--)
       {
           if(red[j].second<blue[i].first && red[j].first<blue[i].second && ch[j]==0 )
           {
               ans++;
               ch[j]++;
               break;
           }
       }
   }

  cout<<ans;
    return 0;
}


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

int main()
{
    int n;
    cin >> n;
    map<int, int> map1, map2;
    rep(i, n)
    {
        int x;
        cin >> x;
        if (i % 2 == 0)
            map2[x]++;
        else
            map1[x]++;
    }
    vector<pair<int, int>> v1, v2;
    for (auto e : map1)
        v1.push_back(make_pair(e.second, e.first));
    for (auto e : map2)
        v2.push_back(make_pair(e.second, e.first));
    sort(v1.begin(), v1.end(), greater<pair<int, int>>());
    sort(v2.begin(), v2.end(), greater<pair<int, int>>());
    if (v1[0].second != v2[0].second)
        cout << n - v1[0].first - v2[0].first << endl;
    else
        cout << n - max(v1[0].first + v2[1].first, v1[1].first + v2[0].first) << endl;
    return 0;
}


Measured memory_bytes: 6136
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 1e5 + 10;

int row , col , n ,top , f [ maxn ] , x_1 , y_1 , x_2 , y_2;
bool vis [ maxn ];
vector < pair < int , int > > v [ 4 ];

inline bool check ( int a , int b )
{
	if ( a == 0 || a == row || b == 0 || b == col ) {
		return true;
	} 
	return false;
}

inline int read ( )
{
	int s = 0 , t = 1; char ch = getchar ( );
	while ( ch < '0' || ch > '9' ) { if ( ch == '-' ) t = -1; ch = getchar ( ); }
	while ( ch >= '0' && ch <= '9' ) { s = s * 10 + ch - '0'; ch = getchar ( ); }
	return s * t;
}

void get_in ( int Row , int Col , int flag )
{
	if ( !Row ) {
		v [ 0 ].emplace_back ( make_pair ( Col , flag ) );
	} else if ( col == Col ) {
		v [ 1 ].emplace_back ( make_pair ( Row , flag ) );
	} else if ( row == Row ) {
		v [ 2 ].emplace_back ( make_pair ( col - Col , flag ) );
	} else {
		v [ 3 ].emplace_back ( make_pair ( row - Row , flag ) );
	}
} 

int main ( void )
{
	row = read ( ); col = read ( ); n = read ( );
	for ( int i = 1 ; i <= n ; i++ ) {
		x_1 = read ( ); y_1 = read ( ); x_2 = read ( ); y_2 = read ( );
		if ( check ( x_1 , y_1 ) && check ( x_2 , y_2 ) ) {
			get_in ( x_1 , y_1 , i );
			get_in ( x_2 , y_2 , i );
		}
	}
	for ( int i = 0 ; i < 4 ; i++ ) {
		sort ( v [ i ].begin ( ) , v [ i ].end ( ) );
		for ( vector < pair < int , int > >::iterator x = v [ i ].begin ( ) ; x != v [ i ].end ( ) ; x++ ) {
			int flag = x->second;
			if ( !vis [ flag ] ) {
				f [ ++top ] = flag;
				vis [ flag ] = 1;
			} else if ( !top || f [ top ] != flag ) {
				puts ( "NO" );
				return 0;
			} else {
				--top;
			}
		}
	}
	puts ( "YES" );
	return 0;
}


		

Measured memory_bytes: 2520
# Prime Numbers
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_C&lang=jp

import math
def isPrime(c):
    if (c == 2 ):
        return True
    if (c % 2 == 0 ):
        return False
    len = int(math.sqrt(c)) + 1
    for i  in range (3,len+1,2):
        if ( c % i == 0):
            return False  
    return True

cnt = 0
n = int(input())
while ( n > 0):
    n = n -1
    s = int(input())
    if ( isPrime(s) == True ):
        cnt += 1
print (cnt)


Measured memory_bytes: 5676
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
  int N;
  string s;
  cin >> N;
  cin >> s;
  int ans = 0;
  for (int i=0; i<N-1; i++){
    if(s[i]!=s[i+1]){
      ans++;
    }
  }
  cout << ans+1 << endl;
}

Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<cstring>
#include<bitset>
#define mp(a,b) make_pair(a,b)
using namespace std;
bitset<10010> can[2010];
pair<int,int> vis[2][10010];
char s[2010][10010],ans[1000010];
int len[2010],n,k,cnt,ncnt;
int main()
{
    scanf("%d%d",&n,&k);
    for (int i=1;i<=n;i++) scanf("%s",s[i]),len[i]=strlen(s[i]);
    can[n+1][0]=1;
    for (int i=n;i>=1;i--)
        can[i]=can[i+1]|(can[i+1]<<len[i]);
    for (int i=1;i<=n;i++)
        if (can[i+1][k-len[i]]) vis[0][++cnt]=mp(i,0);
    int ii=0;
    for (int i=0;i<k;i++)
    {
        char minc='z';
        for (int j=1;j<=cnt;j++) minc=min(minc,s[vis[ii][j].first][vis[ii][j].second]);
        ans[i]=minc;
        int minid=n+1;
        ncnt=0;
        for (int j=1;j<=cnt;j++)
        {
            int nid=vis[ii][j].first,nlen=vis[ii][j].second;
            if (s[nid][nlen]!=minc) continue;
            if (nlen+1==len[nid]) minid=min(minid,nid);
            else vis[ii^1][++ncnt]=mp(nid,nlen+1);
        }
        for (int j=minid+1;j<=n;j++)
            if (k-len[j]-i-1>=0&&can[j+1][k-len[j]-i-1]) vis[ii^1][++ncnt]=mp(j,0);
        ii^=1;
        cnt=ncnt;
    }
    printf("%s",ans);
}

Measured memory_bytes: 22016
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>
#include<random>
#include<set>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007

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; }

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}


long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}


long long int absmax(vector<int> a, long long int b) {
	int max = -100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (max < abs(a.at(i) - b)) {
			max = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

void haerobatya(int start, int end, char level) {
	if (start > end) swap(start, end);
	for (int i = start; i <= end; i++) {
		if (i < 100) {
			cout << "https://atcoder.jp/contests/abc0" << i << "/tasks/abc0" << i << "_" << level << endl;
		}
		else {
			cout << "https://atcoder.jp/contests/abc" << i << "/tasks/abc" << i << "_" << level << endl;
		}
	}
}

long long int cntmod(long long int warareru, long long int mod) {
	long long int i = 0;
	for (i = 0;true; i++) {
		if (warareru % mod == 0 && warareru >= mod) {
			warareru /= mod;
		}
		else {
			return i;
		}
	}
}

//ここまでライブラリ
//ここから本文

long long int tpimin(vector<int> a) {
	int MIN = 1000000000;
	int number = 0;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
		number = i;
	}
	return number;
}
int main() {
	vector<int> a(27);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		a.at(s.at(i) - 'a')++;
	}
	for (int i = 0; i < 26; i++) {
		if (a.at(i) == 0) {
			cout << (char)(i + 'a') << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	int data[4][2];
	memset(data,0,sizeof(data));
	double a[2];
	while(cin>>a[0]>>a[1]){
		for(int i=0;i<2;i++){
			if(1.1<=a[i])data[0][i]++;
			else if(0.6<=a[i])data[1][i]++;
			else if(0.2<=a[i])data[2][i]++;
			else data[3][i]++;
		}
	}
	for(int i=0;i<4;i++){
		cout<<data[i][0]<<" "<<data[i][1]<<endl;
	}
}

Measured memory_bytes: 1220
#include<iostream>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (b <= c) { cout << 0 << endl; return 0; }
	if (a <= c && c <= b && b <= d) { cout << b - c << endl; return 0; }
	if (a <= c && d <= b) { cout << d - c << endl; return 0; }
	if (c <= a && b <= d) { cout << b - a << endl; return 0; }
	if (c <= a && a <= d && d <= b) {
		cout << d - a << endl; return 0;
}
	if (d <= a)cout << 0 << endl;
}

Measured memory_bytes: 3632
import Control.Applicative

main = do
  [a, b] <- map read . words <$> getLine
  putStrLn $ solve a b

solve :: Int -> Int -> String
solve a b
  | a == 1 && b == 1 = "Draw"
  | a == 1           = "Alice"
  | b == 1           = "Bob"
  | a > b            = "Alice"
  | a < b            = "Bob"
  | otherwise        = "Draw"

Measured memory_bytes: 508
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll N,X;
string S;
vector<ll> vec;

void solve() {
	cin >> N >> X;
	ll ans = 0;
	ll pos = 0;
	rep(i, N) {
		if (pos <= X) ans++;
		ll input;
		cin >> input;
		pos += input;
	}
	if (pos <= X) ans++;

	cout << ans;

}

int main() {
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

int N,M;
int num[100010];
bool redValid[100010];

int main(){
    cin>>N>>M;
    for(int i=1;i<=N;i++){
        num[i]=1;
        redValid[i]=false;
    }
    redValid[1]=true;
    for(int i=0;i<M;i++){
        int x,y;
        cin>>x>>y;
        if(num[x]!=0){
            if(redValid[x]){
                if(num[x]==1){
                    redValid[x]=false;
                }
                redValid[y]=true;
            }
            num[x]--;
            num[y]++;
        }
    }
    int ans=0;
    for(int i=1;i<=N;i++){
        if(redValid[i]){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;
const int MAX_N = 500;

int main() {
    int a, b; cin >> a >> b;
    cout << (b-a)*(b-a+1)/2-b << endl;
}

Measured memory_bytes: 256
x1,y1,x2,y2 = map(int,input().split())
a = x2-x1
b = -(y2-y1)
x3 = x2+b
y3 = y2+a
x4 = x3-a
y4 = y3+b
print(x3,y3,x4,y4)

Measured memory_bytes: 3060
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n) cin >> h.at(i);
  vector<int> a(m), b(m);
  rep(i, m) cin >> a.at(i) >> b.at(i);

  vector<int> count(n, 0);
  rep(i, m) {
    if (h.at(a.at(i) - 1) > h.at(b.at(i) - 1)) {  //小さければ＋する
      count.at(b.at(i) - 1)++;
    } else if (h.at(a.at(i) - 1) < h.at(b.at(i) - 1)) {  //同じく
      count.at(a.at(i) - 1)++;
    } else if (h.at(a.at(i) - 1) == h.at(b.at(i) - 1)) {
      count.at(a.at(i) - 1)++;
      count.at(b.at(i) - 1)++;
    }
  }
  int res = 0;
  rep(i, n) {
    // cout << count.at(i) << " ";
    if (count.at(i) == 0) res++;
  }
  cout << res;
  return 0;
}


Measured memory_bytes: 4792
#include<bits/stdc++.h>
using namespace std;
const int limit = 50;
int n, m;
int a[limit], b[limit];
bool graph[limit][limit];
bool visited[limit];
void dfs(int v) {
  visited[v] = true;
  for (int v2 = 0; v2 < n; ++v2) {
    if (graph[v][v2] == false) continue;
    if (visited[v2] == true) continue;
    dfs(v2);
  }
}

int main(){
  cin>>n>>m;
  for (int i = 0; i < m; ++i) {
    cin>>a[i]>>b[i];
    a[i]--, b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }
  int ans = 0;
  for (int i = 0; i < m; ++i) {
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
    for (int j = 0; j < n; ++j)
      visited[j] = false;
    dfs(0);
    bool bridge = false;
    for (int j = 0; j < n; ++j)
      if (visited[j] == false)
        bridge = true;
    if (bridge)
      ans += 1;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int kansu(int a,int b,int c)
{
  if((a<b&&b<=c)||(a>=b&&b>c))
    return 1;
  else
    return 0;
}
int main(void)
{
  int n;
  int p[20];
  int ans=0;
  int i;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&p[i]);
  
  for(i=0;i<n-2;i++)
  {
    ans += kansu(p[i],p[i+1],p[i+2]);
  }
  printf("%d",ans);

  return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  FOR(i, 0, n) { cin >> vec[i]; }
  int cnt = 0;
  int index = 1;
  FOR(i, 0, n) {
    if (vec[i] == index) {
      index++;
    } else {
      cnt++;
    }
  }
  if (cnt == n) {
    cout << -1 << endl;
  } else {
    cout << cnt << endl;
  }
  return 0;
}

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

#define Fast            ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define fWrite          freopen ("out.txt","w",stdout);
#define TC              int t;cin >> t;FOR(tc,1,t)
#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define all(a)          a.begin(),a.end()
#define MEM(a,x)        memset(a,x,sizeof(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)

#define Make(x,p)       (x  (1<<p))
#define DeMake(x,p)     (x & ~(1<<p))
#define Check(x,p)      (x & (1<<p))
#define popcount(x)     __builtin_popcount(x)

int main()
{
    Fast
    LL x;
    cin >> x;
    LL a=x/500;
    x=x%500;
    LL b=x/5;
    cout << a*1000+b*5;
}


Measured memory_bytes: 256