akhauriyash/Code-Regression huggingface dataset:
/* be name khoda */

// #define stream_enable
#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl;
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl;
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl;
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl;
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl;
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = (a + (b)) % MOD
#define Mul(a, b) a = (a * (b)) % MOD

stringstream sss;

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

const ll maxn = 100010;

void MAIN() {

    ll a, b;
    cin >> a >> b;
    cout << (a + b - 1) / b << '\n';

}

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

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(

    )";
    MAIN();
    return 0;
}


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

using namespace std;

int main(){

	int N,K,X,Y; cin >> N >> K >> X >> Y;
  	long long res = 0;
  	if(N <= K){
    	res = X*N;
    }
  	else res = K*X + (N-K)*Y;
  	cout << res << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

ll N,A,B;

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

  if(A+B-1>N||A*B<N){
      cout<<-1<<endl;
      return 0;
  }

  int now=min(N-A,B-1);
  vector<int> ans;
  vector<int> used(N+1,0);
  for(int i=N-A+1;i<=N;i++){
      ans.push_back(i);
      used[i]=1;
      for(int j=0;j<B-1;j++){
          if(now-j>=1&&used[now-j]==0){
              used[now-j]=1;
              ans.push_back(now-j);
          }else break;
      }
      now=min(N-A,now+B-1);
  }
  for(int i=0;i<ans.size();i++) cout<<ans[i]<<" ";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 4720
my $N = <STDIN>;
chomp($N);

my $ans = $N - 1;
my $tt = $N - 1;
my $ii = int(sqrt($N));
while ($ii) {
  if ( $N % $ii ){
  } else {
    my $t = $N/$ii;
    $tt = $t + $ii - 2;
    last;
  }
  $ii--;
}
if ($tt < $ans ) {
  $ans = $tt;
}
print $ans;

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

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var x = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray();
            var n = x[0];
            var l = x[1];

            var s = new List<string>();
            for(var i = 0; i < n; i++){
                var c = Console.ReadLine().Trim();
                s.Add(c);
            }

            var o = s.OrderBy(z => z).ToList();
            Console.WriteLine(string.Join("",o));
        }
    }
}


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

int main() {
	// your code goes here
	int n,k;
	cin >> n >> k;
	int arr[n], sum = 0;
	for(int i = 0 ; i < n ; i++){
	    cin >> arr[i];
	    sum += arr[i];
	}
	int c = 0;
	for(int i = 0 ; i < n ; i++){
	    if(arr[i]*4*k >= sum)c++;
	}
	if(c >= k)cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  int sum=0;
  for(int i=0; i<N; i++){
    cin >> a.at(i);
    sum+=a.at(i);
  }
  if(sum%N>N/2) sum=sum/N+1;
  else sum = sum/N;
  
  int ans=0;
  for(int i=0; i<N; i++){
    ans+=(sum-a.at(i))*(sum-a.at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e3+2;
const int inf=1e12;
int n,m;
int price[N];
int unlock[N];
//int ans=inf;
int dp[N][1<<13];
int rec(int i,int mask)
{
	
	if(mask==0) return 0;
	if(i==m) return inf;
	int mask2=mask;
	//cout<<i<<" "<<unlock[i]<<endl;
	if(dp[i][mask]!=-1) return dp[i][mask];
	for(int k=0;k<n;k++)
	{
		if((unlock[i]&(1<<k))&&(mask2&(1<<k)))
		{
		  // cout<<mask2<<endl;
			mask2=mask2^((1<<k));
		//	cout<<mask2<<endl;
		}
	}
//	cout<<endl;
	//cout<<mask<<" "<<mask2<<endl;
	return dp[i][mask]=min(rec(i+1,mask),rec(i+1,mask2)+price[i]);
}

int32_t main()
{
//	int n,m;
    memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	int x;
	for(int i=0;i<m;i++)
	{
		cin>>price[i];
	
		cin>>x;
		int un=0;
		int c;
		for(int i=0;i<x;i++)
		{
			
			cin>>c;
			un|=(1<<(c-1));
			
		}
		unlock[i]=un;
	//	cout<<i<<" "<<un<<endl;
	}
	int ans=rec(0,(1<<n)-1);
	if(ans>=inf) cout<<-1;
	else cout<<ans;
}

Measured memory_bytes: 64512
#include <iostream>
#include <cstdio>
using namespace std;
long long a[505][4];
int main() {
    int n;
    cin>>n;
    for(int i=1;i<n;i++)
        cin>>a[i][1]>>a[i][2]>>a[i][3];
    for(int i=1;i<n;i++)
    {
        long long s=0;
        for(int j=i;j<n;j++)
        {
            if(s<=a[j][2])
                s=a[j][2];
            else if(s>a[j][2]&&(s-a[j][2])%a[j][3]!=0)
                s=a[j][2]+(s-a[j][2])/a[j][3]*a[j][3]+a[j][3];
            s+=a[j][1];
        }
        cout<<s<<endl;
    }
    cout<<0<<endl;
    // insert code here...
    //std::cout << "Hello, World!\n";
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

void bomb(int x,int y);

int m[9][9];

int main(void){
	int n,i,l,j,x,y;
	char a[10];
	
	scanf("%d",&n);
	
	for(i=0;i<9;i++){
		for(l=0;l<9;l++){
			m[i][l]=0;
		}
	}
	
	for(i=0;i<n;i++){
		for(l=0;l<8;l++){
			for(j=0;j<10;j++)a[j]=NULL;
			scanf("%s",a);
			for(j=0;j<8;j++){
				if(a[j]=='0')
				m[j][l]=0;
				else
				m[j][l]=1;
			}
		}
		scanf("%d %d",&x,&y);
		
		bomb(x-1,y-1);
		
		printf("Data %d:\n",i+1);
		for(l=0;l<8;l++){
			for(j=0;j<8;j++){
				printf("%d",m[j][l]);
			}
			printf("\n");
		}
	}
	return 0;
}

void bomb(int x,int y){
	int i;
	
	m[x][y]=0;
	
	for(i=-3;i<=3;i++){
		if(i==0)continue;
		
		if(x+i>=0 && x+i<8){
			if(m[x+i][y]==1)bomb(x+i,y);
		}
		
		if(y+i>=0 && y+i<8){
			if(m[x][y+i]==1)bomb(x,y+i);
		}
	}
	
	return;
}
		

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
vector<pair<int,int>>e[N];
int co[N];
void dfs(int u,int f)
{
	for(int i=0;i<e[u].size();i++)
	{
		int v=e[u][i].first,w=e[u][i].second;
		if(v==f)
			continue;
		if(w%2)
			co[v]=co[u]^1;
		else
			co[v]=co[u];
		dfs(v,u);
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		e[u].push_back(make_pair(v,w));
		e[v].push_back(make_pair(u,w));
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)
		printf("%d\n",co[i]);
	return 0;
}


Measured memory_bytes: 9088
N = int(input()) - 1
rst = ''
for i in range(1, 10 ** 15):
    if N >= 26 ** i:
        N -= 26 ** i
        continue
    for j in range(i):
        rst += chr(ord('a') + N % 26)
        N //= 26
    print(rst[::-1])
    break

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

int main(){
	int n;
	int area[11][11];
	while(cin >> n){
		if(n == 0) break;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cin >> area[i][j];
			}
		}
		for(int i = 0; i < n; i++){
			int count = 0;
			for(int j = 0; j < n; j++){
				count += area[i][j];
			}
			area[i][n] = count;
		}
		for(int j = 0; j <= n; j++){
			int count = 0;
			for(int i = 0; i < n; i++){
				count += area[i][j];
			}
			area[n][j] = count;
		}
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= n; j++){
				cout << setw(5) << area[i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
int main(void)
{
	int a,i;
	i=2;
	scanf("%d",&a);
	while(1){
		i=i*2;
		if(i>a){
			i=i/2;
			break;
		}
		else if(i==a){
			break;
		}
	}
	printf("%d\n",i);
	return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O3")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 

template <typename T> 
void DEBUG_ARR(vt<T> a,char c)
{
	f(i,0,a.size())cout<<a[i]<<c;
	cout<<"\n";
}

lli tmod(lli x,lli m=mod){return (x%m+m)%m;}//USE AT YOUR OWN RISK
lli power(lli x, lli y) 
{
    lli res = 1;  
   
    while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1; 
        x = (x*x)%mod;  
    }
    if(res<0)
       res+=mod; 
    return res; 
}
// lli fact[2000009];
// lli ncr(lli n,lli r){
//     lli ans=fact[n];
//     if(r>n)return 0;
//     ans=(ans*power(fact[n-r],mod-2))%mod;
//     ans=(ans*power(fact[r],mod-2))%mod;
//     return ans;
// }

int main() 
{ 
    // fact[0]=1;
    // f(i,1,2000001)fact[i]=(i*fact[i-1])%mod;
    fastio;
    int t;
    // cin>>t;	
    t=1;
	while(t--){
        int mat[3][3];f(i,0,3)f(j,0,3)cin>>mat[i][j];
        int n;cin>>n;
        int b[n];f(i,0,n)cin>>b[i];
        int x[3][3];
        memset(x,0,sizeof x);
        f(i,0,3)f(j,0,3)f(k,0,n)if(b[k]==mat[i][j])x[i][j]=1;
        f(i,0,3){
            int sum=0,sum2=0;
            f(j,0,3){
                sum+=x[i][j];
                sum2+=x[j][i];
            }
            if(sum==3 || sum2==3){
                cout<<"Yes\n";
                return 0;
            }
        }
        int sum=max(x[0][0]+x[1][1]+x[2][2],x[2][0]+x[1][1]+x[0][2]);
        if(sum==3){
            cout<<"Yes\n";
            return 0;
        }
        cout<<"No\n";
	}

    return 0; 	
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, h: "List[int]"):
    dp = [float('inf')] * (N+2)
    h.extend([0, 0])
    dp[0] = 0
    for i in range(N):
        dp[i+1] = min(dp[i+1], dp[i] + abs(h[i]-h[i+1]))
        dp[i+2] = min(dp[i+2], dp[i] + abs(h[i]-h[i+2]))
    return dp[N-1]

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, h))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 18064
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int N=105,P=1e9+7;
int n,h[N];
int fpow(int k1,int k2){
	int k3=1;
	for(;k2;k2>>=1,k1=1LL*k1*k1%P)if(k2&1)k3=1LL*k3*k1%P;
	return k3;
}
pair<int,int>sol(int l,int r,int bs){
	int mn=*min_element(h+l,h+r+1),coef=1,all=1,num=0;
	for(int i=l;i<=r;){
		if(h[i]!=mn){
			int j=i+1;
			while(j<=r&&h[j]!=mn)++j;
			pair<int,int>val(sol(i,j-1,mn));
			coef=1LL*coef*val.fi%P;
			all=1LL*all*(val.fi+val.se)%P;
			i=j;
		}else{
			++num,++i;
		}
	}
	return make_pair(1LL*coef*fpow(2,mn-bs)%P,(1LL*all*fpow(2,num)%P+1LL*coef*(fpow(2,mn-bs)+P-2)%P)%P);
}
int main(){
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",h+i);
	printf("%d\n",sol(1,n,0).se);
	return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in(),M = in();
    int sum = 0;
    REP(i,M)sum += in();
    cout << max(N - sum , -1) << "\n";
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
typedef long long ll;

struct Edge{
    int to, id;
    Edge(int to, int id): to(to), id(id) {}
};
vector<vector<Edge>> a(50);

/* 目的地までの経路を返す */
bool fds(int parent, int to, int from, vector<int>& root){
    if (from == to){
        return true;
    }
    for (auto edge : a[from])
    {
        if (parent == edge.to) continue;
        if (fds(from, to, edge.to, root)){
            root.push_back(edge.id);
            return true;
        }
    }
    
    return false;
}

int main()
{
    int n;
    cin >> n;
    rep(i, n-1){ 
        int tmp1, tmp2; cin >> tmp1 >> tmp2; 
        tmp1--; tmp2--;
        a[tmp1].emplace_back(tmp2, i);
        a[tmp2].emplace_back(tmp1, i);
    }
    int m;
    cin >> m;
    vector<pair<int, int>> u;
    rep(i, m){
        int tmp1, tmp2; cin >> tmp1 >> tmp2; 
        tmp1--; tmp2--;
        u.emplace_back(tmp1, tmp2);
    }

    // for(auto l: u){
    //     cout << l.first << l.second << endl;
    // }
    vector<ll> eset(m);
    rep(i, m){
        vector<int> root;
        fds(-1, u[i].first, u[i].second, root);
        //show(root);
        for (auto node: root){
            eset[i] |= 1ll<<node;
        }
    }

    ll ans = 0;
    //i bitでどの条件の集合をとるかを表す
    rep(i, 1<<m){
        ll mask = 0;
        //複数条件の積集合のカバー範囲を記載
        rep(j, m){
            if ((i>>j)&1 == 1){
                mask |= eset[j];
            }
        }
        int white = __builtin_popcountll(mask);
        ll now = 1ll<<(n-1-white);
        //cout << white << " "<< now << endl;
        if (__builtin_popcountll(i)%2 ==0) {
            ans += now;
        } else {
            ans -= now;
        }
    }
    cout << ans << endl;
    //show(root);
    //for(auto i: root){cout << i+1 << " ";}
}



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

using namespace std;

int main()
{
  long long K, N;
  cin >> K >> N;
  
  vector<int> A(N);
  for (int i = 0; i < N; ++i) cin >> A[i];

  int max = 0;
  int ans = 0;
  for (int i = 0; i < N; ++i)
  {
    int diff;
    if (i == N - 1) diff = K+A[0] -A[i];
    else            diff = A[i + 1] - A[i];
    
    ans += diff;
    if (max < diff) max = diff;
  }

  ans -= max;
  cout << ans << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <cstdint>
#include <sys/time.h>

typedef std::int_fast32_t  s32;
typedef std::uint_fast32_t u32;
typedef std::int_fast64_t  s64;
typedef std::uint_fast64_t u64;

int main(void) {

  for(;;) {
    int N, A, B, C, X;
    std::cin >> N >> A >> B >> C >> X;
    if( N == 0 and A == 0 and B == 0 and C == 0 and X == 0 ) break;

    int Y[128];
    for(int i = 0; i < N; ++i) {
      std::cin >> Y[i];
    }

    int R[16384];
    R[0] = X;
    for(int i = 1; i < 10010; ++i) {
      R[i] = (A * R[i - 1] + B) % C;
    }

    int i;
    int p = 0;
    for(i = 0; i < N; ++i) {
      for(; p <= 10100; ++p) {
        if( Y[i] == R[p] ) {
          p += 1;
          break;
        }
      }
    }
    p -= 1;
    std::cout << (p <= 10000 ? p : -1) << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 1204
n=int(input())

total=0

for i in range(n):
  #print(f'i+1={i+1}')
  j=i
  while j<n:
    #print(f'j+1={j+1}')
    k=j
    while k<n:
      #print(f'k+1={k+1}')
      kouho=min(i+1,j+1,k+1)
      while True:
        #kouhoが最大公約数の時
        if (i+1)%kouho==0 and (j+1)%kouho==0 and (k+1)%kouho==0:
          #３つとも同じ数字
          if i==j and j==k:
            total+=kouho
          #２つのみ同じ数字
          elif i==j or j==k or k==i:
            total+=kouho*3
          #同じ数字がない時
          else:
            total+=kouho*6
          break
        else:
          kouho -= 1
      k+=1
    j+=1
          
print(total)

Measured memory_bytes: 73832
def solve():
  n, k = map(int,input().split())
  group_num = 10
  
  book_map = [[] for i in range(group_num)]
  acc_map = [[0] for i in range(group_num)]

  for i in range(n):
    c, g = map(int,input().split())
    book_map[g - 1].append(c)

  for i in range(group_num):
    bmi = book_map[i]
    bmi.sort(reverse=True)
    ami = acc_map[i]
    acc = 0
    for j in range(len(bmi)):
      acc += (bmi[j] + j * 2)
      ami.append(acc)
  
  dp = [[0] * (k + 1) for i in range(group_num + 1)]
  for y in range(1, k + 1):
    for x in range(1, group_num + 1):
      accs = acc_map[x - 1]
      dp_pre = dp[x - 1]
      dp[x][y] = max([dp_pre[y - z] + accs[z] for z in range(min(y + 1, len(accs)))])
  
  print(dp[group_num][k])
solve()



Measured memory_bytes: 6324
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define UM unordered_map
#define MP map
#define ST set
#define US unordered_set
#define V vector
#define S string
#define D deque
#define L list
#define Q queue
#define PQ priority_queue
#define DB double
#define LDB long double
#define FOR(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define FFOR(i, n) for (int(i) = 0; (i) <= (n); ++(i))
#define RFOR(i, n) for (int(i) = (n)-1; (i) >= 0; --(i))
#define all(v) (v).begin(), (v).end()

const int dr[] = {0, 1, 0, -1};
const int dc[] = {1, 0, -1, 0};

int nxt()
{
    int n;
    cin >> n;
    return n;
}

LL llnxt()
{
    LL l;
    cin >> l;
    return l;
}

LDB ldbnxt()
{
    LDB n;
    cin >> n;
    return n;
}

DB dbnxt()
{
    DB n;
    cin >> n;
    return n;
}

void bfs(VVI &graph, int start)
{
    int n = graph.size();
    Q<int> q;
    V<bool> visited(n);
    q.push(start);
    visited[start] = true;
    while (not q.empty())
    {
        auto curr = q.front();
        q.pop();
        for (auto i : graph[curr])
        {
            if (not visited[i])
            {
                q.push(i);
                visited[i] = true;
            }
        }
    }
}
LL pow5(LL i)
{
    return i * i * i * i * i;
}
int main()
{
    int x;
    cin >> x;
    FOR(i, 5000)
    {
        LL a = pow5(i);
        int l = -5000, r = 5000;
        // cout << i << "\n";
        while (l <= r)
        {
            int m = (l + r) / 2;
            // cout << m << " " << pow5(m) << "\n";
            if (a - pow5(m) == x)
            {
                cout << i << " " << m;
                return 0;
            }
            if (a - pow5(m) < x)
            {
                r = m - 1;
            }
            else
            {
                l = m + 1;
            }
        }
        }
}

Measured memory_bytes: 3644
x,y = input().split()
X = int(x)
Y = int(y)

A = []
now_num = X
next_num = X*2
while(now_num <= Y):
	A.append(now_num)
	now_num = int(next_num)
	next_num = int(now_num*2)
print(len(A))

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

using namespace std;

int main() {
	int i, m[10];

	for(i=0; i<10; i++) {
			cin >> m[i];
	}

	sort(m, m+10);

	for(i=9; i>6; i--) {
		cout << m[i] << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> A(200100);
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        A[a+b]++;
    }
    for (int i = 0; i < 200099; ++i) {
        A[i+1] += A[i]/2;
        A[i] &= 1;
    }
    for (int i = 0; i < 200100; ++i) {
        if(A[i]) printf("%d %d\n", i, 0);
    }
    return 0;
}


Measured memory_bytes: 3620
//#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const int maxn = 5e2 + 33, mod = 998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
ll tot = 0;
vi a;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	a.pb(0);
	for(int t, i = 0; i < n; i++) cin >> t, a.pb(t);
	a.pb(0);
	for(int i =0; i <= n; i++) tot += abs(a[i]-a[i+1]);
	for(int i = 1; i <= n; i++) {
		cout << tot - abs(a[i]-a[i-1]) - abs(a[i]-a[i+1]) + abs(a[i-1]-a[i+1]) << '\n';
	}
}


Measured memory_bytes: 2164
/*    特徴    */

/*    教訓    */

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

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

#define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

// -------- template end - //


// - library ------------- //



// --------- library end - //


int main(){

  ll A, V;
  cin >> A >> V;

  ll B, W;
  cin >> B >> W;

  ll T = il();

  if (V > W && T*abs(V-W)>=abs(A-B)) cout << "YES" << endl;
  else cout << "NO" << endl; 
  
}

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

int main(){
  int x1, x2, y1, y2, x3, x4, y3, y4;
  cin >> x1 >> y1 >> x2 >> y2;

  int t1 = x2-x1;
  int t2 = y2-y1;

  x3 = x2-t2;
  y3 = y2+t1;

  t1 = x3-x2;
  t2 = y3-y2;

  x4 = x3-t2;
  y4 = y3+t1;

  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;
using qul = queue<ll>;

int binary_search(ll x, vel a) {
    auto ite = lower_bound(ALL(a), x);
    if(ite != a.end() && *ite == x) {
        return ite - a.begin();
    } else {
        return -1;
    }
}

ll modpow(ll a, ll n, ll mod) {
    if(n == 0)
        return 1;
    if(n == 1)
        return a % mod;
    if(n % 2 == 1)
        return (a * modpow(a, n - 1, mod)) % mod;
    ll t = modpow(a, n / 2, mod);
    return (t * t) % mod;
}

int main() {
    ll N,num,ans = 0;
    cin >> N;
    vel a(N);
    REP(i, N) cin >> a[i];
    REP(i,N){
        num = a[i];
        if((i+3) % 2 == 1 && (num + 2) % 2 == 1) ans++; 
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <iostream>

using namespace std;
int main(void){

int inputA=0;
int inputB=0;
int loopT=0;
int sum[200]={};
int output=0;

for(int i=0;i<200;i++){
	inputA=0;
	inputB=0;
	cin >>inputA >>inputB;
	if(inputA+inputB!=0){
	sum[i]=inputA+inputB;
	}else{
	loopT=i;	
	i=200;
	}
}


for(int i=0;i<loopT;i++){
	output=1;
		for(int j=0;j<100;j++){
			sum[i]=sum[i]/10;
			if(sum[i]>0){
				
				output++;
			}else{
			cout <<output <<endl;
			j=100;
			}
		}
}

}

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

using namespace std;

int main(){
	int K;
	string S;
	cin >> K >> S;

	if(S.size() <= K){
		cout << S << endl;
	} else {
		cout << S.substr(0, K) << "..." << endl;
	}
	return 0;
}


Measured memory_bytes: 3616
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <vector>

using namespace std;

// #define DEBUG 1
#define DFILE "t1.1"

int main() {
  string s;
  int n;
  int i, j;

#ifdef DEBUG
#define cin fin
  fstream fin(DFILE);
#endif

  cin >> n;
  int ab = 0;
  int start_b = 0;
  int end_a = 0;
  int only_ab = 0;
  int n_ba = 0;
  for (i = 0; i < n; i++) {
    cin >> s;
    for (j = 0; j < s.length() - 1; j++) {
      if (s[j] == 'A' && s[j + 1] == 'B') {
        ab++;
      }
    }
    if (s[0] == 'B') start_b++;
    if (s[s.length() - 1] == 'A') end_a++;
    if (s[0] == 'B' || s[s.length() - 1] == 'A') n_ba++;
  }
  // cout << ab << endl;
  // cout << start_b << endl;
  // cout << end_a << endl;
  // cout << only_ab << endl;
  if (0 < n_ba) ab += min(min(start_b, end_a), n_ba - 1);
  cout << ab << endl;
  return 0;
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long

static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const ll INF = 1e18;

int main() {

    int N;
    cin >> N;
    vector<string> W(N);
    map<string, int> str;
    vector<char> start(N), end(N);
    REP(i, N){
        cin >> W[i];
        str[W[i]]++;
        start[i] = W[i][0];
        end[i] = W[i][W[i].length()-1];
    }
    REP1(i, N){
        // cout << start[i] << " " << end[i-1] << endl;
        if(start[i] != end[i-1]){
            cout << "No" << endl;
            return 0;
        }
    }
    for(auto itr = str.begin(); itr != str.end(); itr++){
        if(itr->second != 1){
            cout << "No" << endl;
            return 0;         
        }
    }

    cout << "Yes" << endl;
    return 0;  
 

}

/*
みんな、くるくるぱーにな〜れ
　∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/



Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
// g++ hoge.cpp -std=c++17 -I . でコンパイルできる
// -fsanitize=undefinedでオーバーフロー検出
#include <bits/stdc++.h>
//#include <atcoder/all>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
//using namespace atcoder;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    cin>>n;
    ll v[n];
    rep(i,n)cin>>v[i];
    rep(i,n) sum+=v[i];
    ll local=0;
    rep(i,n-1){
        local+=v[i];
        sum-=v[i];
        mini=min(mini,max(sum-local,local-sum));
    }
    cout<<mini<<endl;
    return 0;
}


Measured memory_bytes: 5180
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

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

#define MAX 1000

#define INF 111111111111
ll a[MAX][MAX];

void floyd() {
  FOR(k, 1, n + 1) {
	FOR(i, 1, n + 1) {
	  if (a[i][k] == INF) continue;
	  FOR(j, 1, n + 1) {
		if (a[k][j] == INF) continue;
		a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
	  }
	}
  }
}

int main(void) {
  ll x;
  vll r;
  cin >> n >> m >> x;

  FOR(i, 0, x) {
	cin >> temp;
	r.push_back(temp);
  }

  FOR(i, 0, n + 1) {
	FOR(j, 0, n + 1) {
	  i == j ? a[i][j] = 0 : a[i][j] = INF;
	}
  }

  ll ai, bi, c;
  FOR(i, 0, m) {
	cin >> ai >> bi >> c;
	a[ai][bi] = c;
	a[bi][ai] = c;
  }

  floyd();

  sort(ALL(r));

  ans = INF;

  do {
	sum = 0;
	FOR(i, 0, r.size() - 1) {
	  sum += a[r[i]][r[i + 1]];
	}
	ans = min(ans, sum);
  } while (next_permutation(ALL(r)));

  cout << ans << endl;

}

Measured memory_bytes: 1408
n, q = map(int, input().split())
s = input()
t = [0] * (n + 1)
for i in range(n):
    if s[i : i + 2] == "AC":
        t[i + 1] = t[i] + 1
    else:
        t[i + 1] = t[i]

for i in range(q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])


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

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

    int n, k;
    while(cin >> n >> k){
        if(n == 0 and k == 0) break;
        vector<int> A(n), B(n + 1, 0);
        for(int i = 0; i < n; i++){
            cin >> A[i];
            B[i + 1] += B[i] + (i > 0 ? A[i - 1] : 0);
        }

        int maxi = -1e9;
        for(int i = k; i < n + 1; i++){
            maxi = max(maxi, B[i] - B[i - k]);
        }
        cout << maxi << endl;
    }

    return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <utility> 
using namespace std; 
//  long long arr[1000000000000] = { 0 };
 
long carcal(long n){
    // if(arr[n]!=0){
        // return arr[n];
    // }
    if(n==1){
        return 1;
    }
    else{
        // arr[n] = 1+ carcal(n/2)*2;
        return(1+ carcal(n/2)*2);
    }
}
int main(){
    long num;
    // arr[1] = 1;
    scanf("%ld",&num);
    printf("%ld",carcal(num));
    
}

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

const int MAX_LEN = 3005;

int dp[MAX_LEN][MAX_LEN];
pair<int, int> mov[MAX_LEN][MAX_LEN];

int main(void) {
    string s, t;

    cin >> s >> t;
    for (int i = 1; i <= (int)s.size(); i++) {
        for (int j = 1; j <= (int)t.size(); j++) {
            dp[i][j] = dp[i - 1][j];
            mov[i][j] = {-1, 0};

            if (dp[i][j - 1] > dp[i][j]) {
                dp[i][j] = dp[i][j - 1];
                mov[i][j] = {0, -1};
            }
            if (s[i - 1] == t[j - 1] && 1 + dp[i - 1][j - 1] > dp[i][j]) {
                dp[i][j] = 1 + dp[i - 1][j - 1];
                mov[i][j] = {-1, -1};
            }
        }
    }

    int a = (int)s.size();
    int b = (int)t.size();
    string ans = "";
    while(a > 0 && b > 0) {
        int da = mov[a][b].first;
        int db = mov[a][b].second;
        if (da + db == -2) {
            ans += s[a - 1];
        }
        a += da;
        b += db;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 105984
#include <iostream>
using namespace std;
int main(){
    int N,i;
     
    cin >> N;
     
    int a[N];
     
    for(i=0;i<N;i++){
        cin >> a[i];
    }
     
    for(i=N-1;i>=0;i--){
    	if(i==0){
    	cout << a[i];
    	}
    	else{
    	cout << a[i]<< " ";
    	}
    }
    cout << endl;
    return 0;
}
	

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

bool binary_reseach(vector<int> a,int key){//二分探索でaにkeyが含まれるかどうか判定する関数
  int left = 0, right = (int)a.size() - 1; // 配列 a の左端と右端
    while (right >= left) {
        int mid = left + (right - left) / 2; // 区間の真ん中
        if (a[mid] == key) return true;
        else if (a[mid] > key) right = mid - 1;
        else if (a[mid] < key) left = mid + 1;
    }
  return false;
}

int main() {

  int n,q;  cin >> n;

  vector<int> S(n);
  rep(i,n) cin >> S[i];

  cin >> q ;

  vector<int> T(q);
  rep(i,q) cin >> T[i];//入力終了

  int ans=0;
  
  rep(i,q){
    if(binary_reseach(S,T[i])) ans++;
  }
  
  cout << ans << endl;
  

  return 0;
}


Measured memory_bytes: 3872
def main():
    H, W = map(int, input().split())
    A = [[int(x) for x in input().split()] for _ in range(H)]

    ans = []
    for r, row in enumerate(A):
        for c, cell in enumerate(row):
            if c == W - 1:
                if cell & 1 and r != H - 1:
                    A[r + 1][c] += 1
                    ans.append((r, c, r + 1, c))
            else:
                if cell & 1:
                    A[r][c + 1] += 1
                    ans.append((r, c, r, c + 1))
    print(len(ans))
    for opr in ans:
        print(*map(lambda x: x + 1, opr))


if __name__ == '__main__':
    main()


Measured memory_bytes: 24096
{-# LANGUAGE OverloadedStrings #-}
import Data.Maybe
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU

main :: IO()
main = do
  [sx, sy, tx, ty] <- getIntList
  let (x, y) = (tx - sx, ty- sy)
  putStrLn . concat $ zipWith replicate [x, y+1, x+1, y+1, 1, 1, x+1, y+1, x+1, y] ['R', 'U', 'L', 'D', 'R', 'D', 'R', 'U', 'L', 'D']
    
-- IO
readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

getInt :: IO Int
getInt = readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getIntVec :: Int -> IO (VU.Vector Int)
getIntVec n = VU.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

Measured memory_bytes: 1020
#B
from operator import itemgetter
n = int(input())
sp=[]
for i in range(n):
    s,p=map(str,input().split())
    sp.append([s, int(p), i + 1])
# print(sp)
#itemgetter:呼び出し可能なオブジェクトを返す　ex…f=itemgetter(2) f(a)>>a[2]
# sp = sorted(sp, key=lambda f: f[1], reverse=True)
# sp = sorted(sp, key=lambda f: f[0])
# print(sp)
sp.sort(key=itemgetter(1), reverse=True)
sp.sort(key=itemgetter(0))
# print(sp)
for i in range(n):
    print(sp[i][2])

Measured memory_bytes: 3064
n=int(input())
s=[]
for i in range(n):
    s.append(input())
m=int(input())
for i in range(m):
    a=input()
    if(a in s):s.remove(a)
d=set(s)
ans=0
for i in d:
    ans=max(ans,s.count(i))
print(ans)

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

int main()
{
    long X, K, D;
    cin >> X >> K >> D;
    int rem;
    if (X >= 0) {
        rem = 1;
    }else {
        rem = -1;
    }
    long N = X*rem / D;
    if (N > K) {
      	X = X*rem - D*K;
    }else {
        X = X*rem - D*N;
        if ((K - N)%2 == 1){
            X -= D;
        }
    }
    if (X < 0) {
        X *= -1;
    }
    cout << X << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  int n;
  cin>>n;
  vector<int> a(3*n);
  rep(i,3*n) cin>>a[i];
  sort(all(a));
  reverse(all(a));
  ll ans=0;
  for(int i=1;i<2*n;i+=2){
    ans+=a[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4216
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/

double a,b,x;

int main(){
    scanf("%lf%lf%lf",&a,&b,&x);
    //cin>>a>>b>>x;
    x/=a;
    //printf("x=%lf\n",x);
    double s=a*b-x,s2=x;
    double y=s*2/a,y2=s2*2/a;
    //printf("y=%lf,a=%lf\n",y,a);
    double ans=atan(y/a)*180/M_PI;
    double ag2=atan(y2/a)*180/M_PI;
    //printf("ag2=%lf\n",ag2);
    if(ag2<ans){
        y2=s2*2/b;
        ans=atan(b/y2)*180/M_PI;
        printf("%.10lf",ans);
    }
    else printf("%.10lf",ans);
    return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;
const ll inf = 1e18;

template<typename T> struct segtree {
    
    T merge(T x, T y) {
	return max(x,y);
    }
    int n;
    vector<ll> t;
    void init(int n) {
	n += 10;
	this->n = n;
	t.resize(n*4);
    }

    void upd(int v, int tl, int tr, int i, T dx) {
	if (tl == tr) {
	    t[v] = merge(t[v], dx);
	} else {
	    int tm = (tl+tr)/2;
	    if (i<=tm) {
		upd(2*v,tl,tm,i,dx);
	    } else {
		upd(2*v+1,tm+1,tr,i,dx);
	    }
	    t[v] = merge(t[2*v], t[2*v+1]);
	}
    }

    T qry(int v, int tl, int tr, int l, int r) {
	if (l>tr || r<tl) {
	    return -inf;
	}
	if (l <= tl && tr <= r) {
	    return t[v];
	}
	int tm = (tl+tr)/2;
	return merge(qry(2*v,tl,tm,l,r), qry(2*v+1,tm+1,tr,l,r));
    }
};



const int maxn = 6e3;
const int maxm = 222;

int n, m;

ll a[maxn];
ll b[maxn][maxm];

segtree<ll> t[maxm];

ll qry(int l, int r) {
    ll walk = a[r-1]-a[l-1];
    ll res = 0;
    for (int i=1; i<=m; i++) {
	res += t[i].qry(1,1,n,l,r);
    }
    return res - walk;
}




// As we increase end loc i, starting loc j does not decrease.

ll dp[maxn]; // dp[i]: max value if we end at loc i
// compute dp[tl],dp[tl+1]...dp[tr], assuming optimal starting loc is in [ql,qr]
void solve(int tl, int tr, int ql, int qr) {
    if (tl>tr) return;
    int tm = (tl+tr)/2;

    int opt = 0;
    ll best = -inf;

    // compute dp[tm]
    for (int i=ql; i<=min(tm, qr); i++) {
	dp[tm] = max(dp[tm], qry(i, tm));
	if (dp[tm] > best) {
	    best = dp[tm];
	    opt = i;
	}
    }

    solve(tl,tm-1,ql,opt); // no point in going past opt, [tl,tm-1] < tm, and tm didn't find something past opt useful
    solve(tm+1,tr,opt,qr); // no point in trying to start before opt, tm < [tm+1,tr], and start loc doesn't decrease after end loc increases.
}


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


    cin>>n>>m;
    for (int j=1; j<=m; j++) {
	t[j].init(n+10);
    }

    for (int i=1; i<=n-1; i++) {
	cin>>a[i];
	a[i] += a[i-1];
    }

    for (int i=1; i<=n; i++) {
	for (int j=1; j<=m; j++) {
	    cin>>b[i][j];
	    t[j].upd(1,1,n,i,b[i][j]);
	}
    }


    solve(1,n,1,n);
    ll res = 0;
    for (int i=1; i<=n; i++) {
	res = max(res, dp[i]);
    }

    cout<<res<<endl;    
    return 0;
}


Measured memory_bytes: 44132
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
vector<P> L;
vector<P> R;
ll N,M,K,ans,X;
string S[1000001];
ll total;

bool check(vector<P> A){
    bool found = true;
    int plus=0;
    for(int i=0;i<A.size();i++){
        if(plus+A[i].first<0){
            found = false;
            break;
        }
        plus += A[i].second;
    }
    return found;
}
int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> S[i];
    }
    for(int j=0;j<N;j++){
        ll lmin = 0;
        ll l = 0;
        for(ll i=0;i<S[j].size();i++){
            if(S[j][i]=='('){
                l += 1;
                total += 1;
            }else{
                l -= 1;
                total -= 1;
            }
            if(lmin>l){
                lmin = l;
            }
        }
        if(l>0){
            L.push_back(P(lmin,l));
        }else{
            R.push_back(P(lmin-l,-l));
        }
    
    }
    sort(L.rbegin(),L.rend());
    sort(R.rbegin(),R.rend());
    
    if(check(L)&&check(R)&&total==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}




Measured memory_bytes: 65808
# 中心に1をおき、(1,2),(1,3),(1,4)...を結んだグラフを作ると
# ペアの数は(N-1)C2できてこれが最大（これを超えるKの場合-1）
# ここから条件に合わせるためには、1を含まない要素のペアを直接結んでいけばよい。
# 全部結んだ場合でNC2になり、O(N^2)で10000 (実際5000弱)

N,K = map(int,input().split())

maxval = ((N-1)*(N-2)) // 2
if maxval < K:
  print(-1)
  exit(0)
  
ans = []

# まず1と各頂点を結んだグラフを構成する
for i in range(2,N+1):
  ans.append((1,i))
  
# そこから減らすべき頂点数
goal = maxval - K
cnt = 0
import itertools
for comb in itertools.combinations(range(2,N+1),2):
  if goal == cnt:
    break
  ans.append(comb)
  cnt += 1
  
print(len(ans))
for a in ans:
  print(*a)

Measured memory_bytes: 3992
#include <stdio.h>

int main(void) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a <= 5) {
        printf("0\n");
    } else if (a >= 6 && a <= 12) {
        printf("%d\n", b / 2);
    } else {
        printf("%d\n", b);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <string>
#include <climits>
using namespace std;

#define REP(i,a,n) for(i=(a); i<(int)(n); ++i)
#define rep(i,n) REP(i,0,n)
#define DEB 0

int add(int x, int y){ return max(x,y); }
int imul(int x, int y){ return min(x,y); }
int inv(int x){ return 2-x; }

int p,q,r;

int parse(string in){

  //printf("init:%s\n",in.c_str());

  switch(in[0]){
  case '0': case '1': case '2':
    return in[0]-'0';
  case 'P': return p;
  case 'Q': return q;
  case 'R': return r;
  case '-': return inv(parse(in.substr(1)));
  case '(':
    int x=0;
    int idx=1;
    for(;idx<in.size();idx++){
      if( in[idx]=='(' )x++;
      if( in[idx]==')' )x--;
      if( x==0 && (in[idx]=='*' || in[idx]=='+') )break;
    }
    //printf("idx:%d\n",idx);
    if( in[idx]=='*' ){
      //printf("%d\n",idx);
      return imul(parse(in.substr(1,idx-1)), parse(in.substr(idx+1)));
    }else{
      return add(parse(in.substr(1,idx-1)), parse(in.substr(idx+1)));
    }
  }
}

int main(){
  string in;
  while(cin>>in, in!="."){
    int ans = 0;
    for(p=0; p<=2; p++){
      for(q=0; q<=2; q++){
	for(r=0; r<=2; r++){
	  if( parse(in)==2 )ans++;
	}
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

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

int main() {
    int n; cin >> n;
    vector<long long> v(n);
    bool flag = false;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        if (v[i] % 2) flag = true;
    }
    if (flag) cout << "first" << endl;
    else cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int x[100005];
int y[100005];

int main(){
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  memset(x,-1,sizeof(x));
  memset(y,-1,sizeof(y));
  
  int ans=0;
  for(int i=0;i<n;i++){
    int p=i,c=0;
    while(x[p]==-1){
      x[p]=c++;
      y[p]=i;
      p=(p+a[p])%n;
    }
    if(y[p]==i)ans+=(c-x[p]);
  }

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

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

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

    if(n <= k) 
    {
        cout << 0 << endl;
        return 0;
    }
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    
    sort(h.rbegin(), h.rend());

    rep(i,k) h[i] = 0;

    ll ans = 0;
    rep(i,n) ans += h[i];

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int k,a[100005];
ll ans,Ans;
ll calc(ll x){
	for (int i=1;i<=k;i++)
		x-=x%a[i];
	return x;
}
int main(){
	scanf("%d",&k);
	for (int i=1;i<=k;i++)
		scanf("%d",&a[i]);
	ll l=1,r=8e18,ans;
	while (l<=r){
		ll mid=(l+r)/2;
		if (calc(mid)<=2)
			ans=mid,l=mid+1;
		else r=mid-1;
	}
	if (calc(ans)!=2) return puts("-1"),0;
	l=1,r=8e18;
	while (l<=r){
		ll mid=(l+r)/2;
		if (calc(mid)>=2)
			Ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%lld %lld\n",Ans,ans);
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		int ans=0;
		for(int i=105;i<=N;i+=2){
			int a=0;
			for(int j=1;j<=i;j++){
				if(i%j==0)
					a++;
			}
			if(a==8)
				ans++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716