akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
using namespace std;
int main(){
    int cur=0;
    string row;
    int m;
    cin>>m>>row;
    int n=row.length();
    int cou[n+1],mini=n;
    for(int i=0;i<n;++i){
        cou[i]=cur;
        if(row[i]=='W'){
            ++cur;
        }
    }
    cou[n]=cur;
    for(int i=0;i<n;++i){
        int temp=cou[i]+((n-(i+1))-(cou[n]-cou[i+1]));
        if(mini>temp)
            mini=temp;
    }
    cout<<mini;
}


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

int main(){
	int N, c=0, f=0, i;
	cin >> N;
	int A[N];
	for(i=0; i<N; i++){
		cin >> A[i];
	}
	while(f==0){
		for(i=0; i<N; i++){
			if(A[i]%2!=0){
				cout << c;
				f++;
				break;
			} else {
				A[i] = A[i]/2;
			}
		}
		i=0;
		c++;
	}
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define all(v) (v).begin(),(v).end()
#define chmax(a, b) a = max((a),(b))
#define chmin(a, b) a = min((a),(b))
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;



int main(){
    string a[3]={"Sunny","Cloudy","Rainy"};
    string str;
    cin>>str;
    int ans=0;
    rep(i,3){
        if(a[i]==str){
            ans=i;
        }
    }
    cout<<a[(ans+1)%3]<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define frep(i, m, n) for(int i = m;i < n;i++)
#define frepr(i, m, n) for(int i = m;i >= n;i--)
#define vsort(v) sort(v.begin(),v.end())
#define ll long long
#define inf 999999999
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vst;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef pair<int,P> PP;
typedef pair<ll,LP> LPP;


int main(){
    string s;
    cin >> s;
    int f=0;
    // cout << s << s.size() << endl;
    rep(i,s.size()){
        if(i%2==1){
            // cout<<s[i]<<endl;
            if(s[i]!='L' && s[i]!='U' && s[i]!='D'){
                f=1;
                // cout << "a" << endl;
                break;
            }
        }
        if(i%2==0){
            // cout<<s[i]<<endl;
            if(s[i]!='R' && s[i]!='U' && s[i]!='D'){
                f=1;
                // cout << "n" << endl;
                break;
            }
        }
    }
    if(f)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;

    return 0;
}

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

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

int main() {
  int H, W; cin >> H >> W;
  auto mat = vector<vector<int>>(H, vector<int>(W));
  auto inv = vector<P>(H * W + 1);
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      int x; cin >> x;
      mat[i][j] = x;
      inv[x] = {i, j};
    }
  }

  int ans = 0;
  auto prv = vector<vector<int>>(H, vector<int>(W, -1));
  for (int i = 1; i <= H * W; ++i) {
    int y, x; tie(y, x) = inv[i];
    for (int j = 0; j < 4; ++j) {
      int ny = y + dy[j];
      int nx = x + dx[j];
      if (0 <= ny && ny < H && 0 <= nx && nx < W && mat[ny][nx] < mat[y][x]) {
        if (prv[ny][nx] == 0) {
          prv[y][x] = 0;
        } else if (prv[y][x] == -1) {
          prv[y][x] = prv[ny][nx];
        } else {
          prv[y][x] = (prv[y][x] == prv[ny][nx]) * prv[ny][nx];
        }
      }
    }
    if (prv[y][x] == 0) ++ans;
    if (prv[y][x] == -1) prv[y][x] = mat[y][x];
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 18708
import sys
import re

s = input()
check = len(s)
if ('A' in s[0]) and ('C' in s[2:len(s)-1]):
    if s.count('C') == 1:
        next_s = s.replace('C', '', 1)
        if next_s[1:len(next_s)].islower():
            print('AC')
            sys.exit()
print('WA')

Measured memory_bytes: 3188
def main():
    n, m = map(int, input().split())
    ans = 0
    if m >= 2*n:
        ans += n
        m -= 2*n
        n = 0
    else:
        ans += m // 2
        m -= ans * 2
    ans += m // 4
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9176
#include <stdio.h>
#include <map>
#include <tuple>
#include <vector>
using namespace std;

typedef struct {
	int f;
	int s;
	int c;
} fcs;

fcs out[100000];               // get<0>と結果記録して出力するための箱
vector<vector<fcs*>> nodes;   // ノード（親ノード番号とリスト（子ノード＆連番）をもつ）のリスト
int maxCol = 0;              // 何色使ったか記録用

int main() {
	int N;                // ノード数
	scanf("%d", &N) + 1;
	nodes.resize(N);
	int in1, in2;      // 入力受付用
	for (int i = 0; i < N-1; i++) {
		scanf("%d %d", &in1, &in2) + 1;// 2ノードの入力を受ける
		in1--;
		in2--;

		out[i].f = in1;
		out[i].s = in2;
		out[i].c = 0;
		nodes[in1].push_back(&out[i]);
		nodes[in2].push_back(&out[i]);
	}

	for (int i = 0; i < N; i++) {
		map<int, int> usedC;

		auto itr = nodes[i].begin();
		auto e = nodes[i].end();
		for (; itr != e; itr++) {
			usedC[(*itr)->c] = 1;
		}
		
		int kohoC = 1;

		itr = nodes[i].begin();
		for (; itr != e; itr++) {
			if ((*itr)->c != 0) continue;
			while (usedC.count(kohoC) != 0) kohoC++;

			(*itr)->c = kohoC;
			usedC[kohoC] = 1;
		}
		if (maxCol < kohoC) maxCol = kohoC;
	}

	printf("%d\n", maxCol);
	for (int i = 0; i < N-1; i++) {
		printf("%d\n", out[i].c);
	}

	return 0;
}


Measured memory_bytes: 7680
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

x = int(input())

def sosu(x):
    for i in range(2, x):
        if (x % i == 0):
            return False
    return True

for i in range(x, 100000+5):
    if (sosu(i)):
        print(i)
        exit()




Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


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

  int N, K;
  cin >> N >> K;
  int A[N];
  int maxi = 0, sum = 0;
  rep(i, N){
    cin >> A[i];
    maxi = max(maxi, A[i]);
    sum += A[i];
  }


  vector<int> vec;
  for(int i=1;i*i<=sum;i++){
    if(sum % i == 0){
      vec.push_back(i);
      vec.push_back(sum/i);
    }
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  for(int i=0;i<vec.size();i++){
      int d = vec[i];
      int B[N];
      for(int j=0;j<N;j++){
        B[j] = A[j] % d;
      }
      sort(B, B+N);
      int sum1[N] = {}, sum2[N] = {};
      sum1[0] = B[0];
      if(B[N-1] != 0){
        sum2[N-1] = d - B[N-1];
      }
      else sum2[N-1] = 0;
      for(int j=1;j<N;j++){
        sum1[j] = sum1[j-1] + B[j];
      }
      for(int j=N-2;j>=0;j--){
        if(B[j] != 0){
          sum2[j] = sum2[j+1] + (d - B[j]);
        }
        else sum2[j] = sum2[j+1];
      }
      for(int j=N-2;j>=0;j--){
        if(sum1[j] == sum2[j+1]){
          if(sum1[j] <= K){
            cout << d << endl;
            return 0;
          }
          break;
        }
      }
  
  }
}

Measured memory_bytes: 256
from collections import Counter
n = int(input())
s = list()

for a in range(n):
    s.append(input())

t = list()
m = int(input())

count_s = dict(Counter(s))

for a in range(m):
    t = input()
    if t not in count_s.keys():
        continue
    count_s[t] -= 1

print(max(max(count_s.values()), 0))


Measured memory_bytes: 9468
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		int[] a=sc.Ia;
		var hs=new SortedDictionary<int,int[]>{[0]=new int[]{-1,0}};
		for(int i = 0;i<n;i++) {
			if(!hs.ContainsKey(a[i])){hs.Add(a[i],new int[]{i,1});}
			else{hs[a[i]][1]++;}
		}
		long k=0,m=int.MaxValue,p=0;
		long[] ans=new long[n];
		foreach(KeyValuePair<int,int[]> e in hs.Reverse()){
			if(k!=0){ans[m]+=(k-e.Key)*p;}
			k=e.Key;
			m=Math.Min(m,e.Value[0]);
			p+=e.Value[1];
		}
		Console.WriteLine(String.Join("\n",ans));
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}


Measured memory_bytes: 40312
#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include<cmath>
#include<string>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define deb(x) cerr<<#x<<" "<<x<<"\n"
#define debi cerr<<"hey sparky\n"
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define eps (double)1e-9
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pdbs;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
// look for  all edge cases
//search for a pattern




signed main() {    
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	 
	string s;
	cin >> s;
	int n = s.size();
	int val = 0;
	for(int i =0 ; i < n; i++){
		int temp = s[i] - '0';
		val += temp;
	}
	if(val%9 == 0){
		cout<<"Yes";
	}
	else
		cout<<"No";
	
	 
	return 0;
}


Measured memory_bytes: 3764
// 2019/11/06 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

const int INF = 200000;		// 十分大きな定数

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

	// 累積和
	int sum[21][100001];
	for(int i=1; i<=M; i++){
		sum[i][0] = 0;
	}

	for(int j=1; j<=N; j++){
		for(int i=1; i<=M; i++){
			sum[i][j] = sum[i][j-1];
		}

		int m;
		cin >> m;

		sum[m][j]++;
	}

	// ビットDP
	int dp[1<<20];
	int nS[1<<20];		// 集合Sの個数
	for(int S=0; S<(1<<M); S++){
		dp[S] = INF;
		nS[S] = -1;
	}
	dp[0] = 0;
	nS[0] = 0;

	for(int S=1; S<(1<<M); S++){
		for(int i=1; i<=M; i++){
			if(((S>>(i-1))&1)==1){
				int n = sum[i][N];				// 種類iの個数
				int R = S^(1<<(i-1));				// 種類iが含まれない集合
				int s = sum[i][nS[R]+n]-sum[i][nS[R]];	// 種類iの区間に含まれる個数

				if(dp[S]>dp[R]+(n-s)){
					dp[S] = dp[R]+(n-s);
					nS[S] = nS[R]+n;
				}
			}
		}
	}

	cout << dp[(1<<M)-1] << endl;

	return 0;
}



Measured memory_bytes: 19116
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

typedef double P_type;
typedef complex<P_type> P;
const P_type P_eps = 1e-8; //整数の時はゼロ

//内積
double dot(P a, P b) {
  return (a * conj(b)).real();
}

//外積
double cross(P a, P b) {
  return (a * conj(b)).imag();
}

/* 線分abと点cの距離 */
double distanceSP(P a, P b, P c) {
  if ( dot(b-a, c-a) < P_eps ) return abs(c-a);
  if ( dot(a-b, c-b) < P_eps ) return abs(c-b);
  return abs(cross(b-a, c-a)) / abs(b-a);
}


int main(){
  int n;
  int r[SIZE], sx[SIZE], sy[SIZE], gx[SIZE], gy[SIZE];

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    scanf("%d%d%d%d%d",r+i, sx+i, sy+i, gx+i, gy+i);
  }

  int dp[1 << 16];
  int ans = 0;
  
  for(int i=1;i<(1<<n);i++){
    dp[i] = -100;
  }
  dp[0] = 0;
  
  for(int i=0;i<(1<<n);i++){

    for(int j=0;j<n;j++){
      if(i & (1 << j)) continue;

      bool flag = true;
      for(int k=0;k<n;k++){
        if(k == j) continue;
        if(i & (1 << k))
          flag &= distanceSP(P(sx[j],sy[j]),P(gx[j],gy[j]),P(gx[k],gy[k])) > r[j] + r[k] - P_eps;
        else
          flag &= distanceSP(P(sx[j],sy[j]),P(gx[j],gy[j]),P(sx[k],sy[k])) > r[j] + r[k] - P_eps;          
      }

      if(flag){
        dp[i | (1<<j)] = max(dp[i | (1<<j)], dp[i]+1);
        ans = max(dp[i]+1, ans);
      }
    }
  }

  printf("%d\n", ans);
  
  return 0;
}




Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
	ll out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int MAXN=1e5+10;
int n;
ll sum=0,a[MAXN],t[MAXN],x[MAXN];
void pr()
{
	for(int i=1;i<=n;++i)
		printf("%lld ",x[i]);
	puts("");
}
int main()
{
	n=read();
	for(int i=1;i<=n;++i)
		sum+=(a[i]=read());
	for(int i=3;i<=n;i+=2)
	{
		t[i]=a[i-1]-a[i-2];
		t[i]+=t[i-2];
	}
	x[1]=a[n]-t[n];
	for(int i=1;i<=n;i+=2)
		sum-=(x[i]=x[1]+2*(t[i]));
	if(n==3)
	{
		x[2]=sum;
		pr();
		return 0;
	}
	ll tot=0,cnt=1;
	for(int i=4;i<n;i+=2)
	{
		t[i]=2*(a[i-1]-a[i-2]);
		t[i]+=t[i-2];
		tot+=t[i];
		++cnt;
	}
	x[2]=(sum-tot)/(cnt);
	for(int i=4;i<n;i+=2)
		x[i]=x[2]+t[i];
	pr();
	return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#include <limits>
#include <iomanip>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int N,M;
    cin >> N >> M;
    //
    vector<int> a(N);
    vector<int> b(N);
    vector<int> c(M);
    vector<int> d(M);
    for(int i=0;i<N;i++){
        cin >> a[i] >> b[i] ;
    }
    for(int i=0;i<M;i++){
        cin >> c[i] >> d[i] ;
    }
    //
    for(int i=0;i<N;i++){
        ll dist;
        ll min_dist;
        int min_point;
        for(int j=0;j<M;j++){
            dist = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(j==0){
                min_dist = dist;
                min_point = j;
            }
            else{
                if(min_dist > dist){
                    min_dist = dist;
                    min_point = j;
                }
            }
        }
        cout << min_point+1 << endl;
    }
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T iabs(const T& x) { return max(x, -x); }
// #define abs gabs

const i64 mod = 1e9 + 7;
i64 ipow(i64 a, i64 b) {
    i64 x = a, y = 1;
    for (; b > 0; b >>= 1) {
        if (b & 1) (y *= x) %= mod;
        (x *= x) %= mod;
    }
    return y;
}
i64 inv(i64 x) {
    return ipow(x, mod - 2);
}
i64 fact(i64 x) {
    static vector<i64> f;
    if (x >= i64(f.size())) {
        i64 i = f.size();
        f.resize(x + 1);
        for (; i <= x; ++i) {
            f[i] = i == 0 ? 1 : i * f[i - 1] % mod;
        }
    }
    return f[x];
}
i64 perm(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(n - k)) % mod : 0;
}
i64 conb(i64 n, i64 k) {
    return k <= n ? fact(n) * inv(fact(k) * fact(n - k) % mod) % mod : 0;
}

int main() {
    i64 n, k;
    cin >> n >> k;
    vector<i64> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    sort(begin(a), end(a));
 
    i64 y[2] = {};
    for (int j = 0; j < 2; ++j) {
        for (int i = n - 1; i >= 0; --i) {
            i64 x = conb(i, k - 1) % mod * (a[i] + mod) % mod;
            (y[j] += x) %= mod;
        }
        reverse(begin(a), end(a));
    }
 
    cout << (y[0] - y[1] + mod) % mod << endl;
    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<map>
#include<algorithm>
#include<queue>
using namespace std;
int n,m;
map<string,priority_queue<int,vector<int>,greater<int> > >M;
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string s;int a;cin>>s>>a;
		M[s].push(a);
	}
	cin>>m;
	int now=0;
	for(;m--;)
	{
		string s;cin>>s;
		while(M[s].size()>0&&M[s].top()<=now)M[s].pop();
		if(M[s].size()>0)
		{
			now=M[s].top();
			M[s].pop();
		}
		else
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}



Measured memory_bytes: 21936
n,k = map(int,input().split())
p = [(int(i)+1)/2 for i in input().split()] #期待値にして格納

#累積和を求める
for i in range(1,n):
    p[i]=p[i-1]+p[i]
mx = p[k-1]
for i in range(k,n):
    a = p[i] - p[i-k]
    if a > mx:
        mx = a
        
print(mx)

Measured memory_bytes: 71792
N, W = map(int, input().split())
items = [tuple(map(int, input().split())) for i in range(N)]

memo = [{} for i in range(N + 1)]

memo[0] = {0: 0}
for i, (wi, vi) in enumerate(items):
    for w, v in memo[i].items():

        if w + wi <= W:
            memo[i + 1][w + wi] = max(memo[i + 1].get(w + wi, 0), v + vi)

        memo[i + 1][w] = max(memo[i + 1].get(w, 0), v)

print(max(memo[N].values()))


Measured memory_bytes: 12004
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
# from math import *
import math
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

######################################

N, K = In.ints()
MOD = 10**9+7

ans = 0
for k in range(K, N+2):
    firstRow = (N-(k-1))+1
    restRows = (k-1)*(firstRow-1)
    
    ans += firstRow+restRows
    ans %= MOD

Out.int(ans)

######################################

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

Measured memory_bytes: 68252
from collections import defaultdict


def main():
    N = int(input())
    S = input()
    if N < 4:
        print(0)
        exit(0)
    rgb_cnt = defaultdict(int)
    for c in S:
        rgb_cnt[c] += 1
    # Caclulate cases that first condition is satisfied but second condision not,
    # then remove this cases from first condition cases finally.
    cnt = 0
    for center in range(N):
        cc = S[center]
        for w in range(1, N + 1):
            left = center - w
            right = center + w
            if left < 0 or right > N - 1:
                continue
            cl = S[left]
            cr = S[right]
            if cl != cc and cc != cr and cr != cl:
                cnt += 1
    answer = rgb_cnt['R'] * rgb_cnt['G'] * rgb_cnt['B'] - cnt
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9468
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end() //使うときはsort(all())という感じで
using ll = long long;
#define PI 3.14159265359

int main(){
  double d;
  double l;
  cin>>l;
  d=l/3;
  cout<<setprecision(16)<<d*d*d<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mo 1000000007
int n , k; int a[100005]; int dp[100005];
int main()
{
	ios_base:: sync_with_stdio(false);cin.tie(NULL);
	cin>>n>>k; 
	
	for(int i = 0 ; i<n; i++)
	cin>>a[i];
	
	sort(a,a+n);
	
    dp[0]= 0;
	
	for(int i = 1; i<=k ;i++)
	{
		int num =0 ; int flag = 1 ; 
		while(num<n&&a[num]<=i)
		{
			if(dp[i-a[num]]==0)
			{
				dp[i]= 1; 
				flag = 0 ; 
				break ; 
			}
			num++;
		}
		if(flag)
		dp[i]= 0 ; 
	}
	
	if(dp[k])
	cout<<"First";
	else
	cout<<"Second";
		return(0);
	}



Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
int main() {
	int out=0;
	
	std::string a;
	
	
	std::cin >> a;
	
	for (int j = 0; j < a.size(); j++) {
		for (int i = 0; i < a.size(); i++) {

			if (a[i] == a[j]) {
				out++;
			}

		}
	}
	
	if (out == a.size()) {
		std::cout << "yes" << std::endl;
	}
	else {
		std::cout << "no" << std::endl;
	}
}

Measured memory_bytes: 256
# E

N = int(input())

ab = []

for i in range(N):
  ab.append(tuple(map(int,input().split())))

ab.sort()
  
import statistics
import math

am = statistics.median([i[0] for i in ab])
bm = statistics.median([i[1] for i in ab])

if N%2 != 0:
  print(bm-am+1)
else:
  print(int((bm-am)*2+1))


Measured memory_bytes: 41468
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int P = 1e9 + 7;
inline int add(int a, int b) {if((a += b) >= P) a -= P; return a;}
inline int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
inline int mul(int a, int b) {return 1ll * a * b % P;}
inline int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
int T;
int a, b;
int main(){
	scanf("%d", &T);
	rep(cas, 0, T) {
		scanf("%d%d", &a, &b);
		ll ab = 1ll * a * b, sq = sqrt(ab);
		if(a > b) swap(a, b);
		ll ans = (a - 1) * 2, len = max(0ll, b - a - 1ll);
		if(sq * sq < ab) {
			if((sq + 1) * sq < ab) {
				ll t = (sq - a) * 2;
				ans += t;
				ans += t < len;
			//	de(1);
			} else {
				ll t = max(0ll, (sq - a - 1) * 2 + 1);
				//dd(sq), de(a);
				ans += t;
				ans += t < len;
		//		de(2);
			}
		} else {
			ll t = max(0ll, (sq - a - 1) * 2);
			ans += t;
			ans += t < len;
		//	de(3);
		}
		printf("%lld\n", ans);
	}
	return 0;
}
/*
1
314159265 358979323
*/

Measured memory_bytes: 256
//  ######    ##   ######    ##   ##    ##
//  ##  ##   ###   ##  ##   ###   ###   ##
//  ######  ####   ######  ####   ##### ##
//  ##     ## ##   ##     ## ##   ## #####
//  ##    ##  ##   ##    ##  ##   ##   ###
#include<bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(b);i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(d);j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRvl(c) for (vl::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvll(c) for (vll::iterator it = (c).begin(); it != (c).end(); it++)
#define mod 1000000007
#define gc getchar_unlocked
#define pc putchar_unlocked3
#define pb(a) push_back((a))
 


void solve()
{
   
    double x[10];
    double y[10];
    double n;
    cin>>n;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i];
    double m=1;
    double k = n;
    double ans=0;
    k--;

    while(k){m*=k;k--;}
    //cout<<m<<endl;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            double d = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
            //cout<<i<<' '<<j<<' '<<d<<endl;
            ans+=d*m*2;
        }
    }
    double d=1;
    while(n)
    {
        d*=n;n--;
    }
    //cout<<d<<endl;
    printf("%0.15f",ans/d);

}


int main()
{
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    */
    
    lo t;
    //cin>>t;
    //while(t--)
        solve();




}


Measured memory_bytes: 256
M, D = [int(x) for x in input().split()]

count = 0
for m in range(1, M+1):
    for d in range(1, D+1):
        d1 = d % 10
        d10 = d // 10
        if d1 > 1 and d10 > 1 and d1 * d10 == m:
            count += 1
print(count)


Measured memory_bytes: 38896
N, Q = gets.split.map(&:to_i)
 
nodes = []
 
class Node
  attr_accessor :parent, :count
 
  def initialize(id)
    @id = id
    @count = 0
    @count_all = nil
    @parent = nil
  end
 
  def calc
    return @count_all if @count_all
    return @count if parent.nil?
 
    @count_all = parent.calc + @count
  end
end
 
# N個分のノードを作る
N.times { |i| nodes << Node.new(i + 1) }
 
# ノード間の関係を作る
(N - 1).times do |i|
  a, b = gets.split.map(&:to_i)
  nodes[b - 1].parent = nodes[a - 1]
end
 
Q.times do
  p, x = gets.split.map(&:to_i)
  nodes[p - 1].count += x
end
 
puts nodes.map { |node| node.calc }

Measured memory_bytes: 29436
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}


	vector<pair<int, int> > X(M);

	for (int i = 0; i < M; i++) {
		cin >> X[i].second >> X[i].first;
	}
	sort(X.rbegin(), X.rend());

	sort(A.begin(), A.end());
	int cur = 0;
	for (int i = 0; i < M; i++) {
		for (int j = cur; j < min(N, X[i].second + cur); j++) {
			if (A[j] < X[i].first) {
				A[j] = X[i].first;
			}
		}
		cur += X[i].second;
	}
	for (int i = 0; i < N; i++) {
		res += A[i];
	}

	cout << res << endl;
}

Measured memory_bytes: 2560
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program
{
    public static Scanner cin;
    static void Main()
    {
        cin = new Scanner();
        var nq = cin.arrayInt(2);
        int n = nq[0];
        int q = nq[1];
        string s = ReadLine();
        int[][] lrArray = new int[q][];
        for(int a = 0; a < q; a++)
        {
            lrArray[a] = cin.arrayInt(2);
        }

        var hits = new List<int>();
        int count = 0;
        for(int a = 0; a < s.Length+1; a++)
        {
            if (a>=2&&s[a - 2] == "A"[0] && s[a-1] == "C"[0])
            {
                count++;
            }
            hits.Add(count);
        }
        for(int a = 0; a < lrArray.Length; a++)
        {
            int left = lrArray[a][0];
            int right = lrArray[a][1];

            WriteLine(hits[right]-hits[left-1+1]);
        }
        
        //WriteLine(string.Join(",",lrArray[0]));
        ReadLine();

    }
}





class Scanner
{
    string[] s;
    int i;

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

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

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

    public int inputInt()
    {
        return int.Parse(input());
    }
    public int[] arrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = inputInt() + add;
        }
        return Array;
    }

    public long inputLong()
    {
        return long.Parse(input());
    }

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

    public double inputDouble()
    {
        return double.Parse(input());
    }


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

Measured memory_bytes: 23876
#include <bits/stdc++.h> 
using namespace std;
int main() {
int n,ans=0;
cin>>n;
int b[100005];
for(int i=0;i<n-1;i++){
    cin>>b[i];
}
ans=b[0]+b[n-2];
for(int i=0;i<n-1;i++){
    ans=ans+min(b[i],b[i+1]);
}
cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]

dp = [[0]*3 for _ in range(n+1)]

for i in range(n):
    dp[i+1][0] = max(dp[i][1], dp[i][2]) + abc[i][0]
    dp[i+1][1] = max(dp[i][0], dp[i][2]) + abc[i][1]
    dp[i+1][2] = max(dp[i][0], dp[i][1]) + abc[i][2]

print(max(dp[n]))


Measured memory_bytes: 47364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
#define fi first
#define se second
#define pi pair<ll,ll>
#define pii pair<ll,pi>
#define pb push_back
#define mk make_pair
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<ll>v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	vector<ll>got;
	sort(v.begin(), v.end(), greater<ll>());
	for (int i = 0; i < n - 1; ) {
		if (v[i + 1] == v[i]) {
			got.pb(v[i]);
			i += 2;
			if (got.size() == 2)break;
		}
		else
			i++;
	}
	if (got.size() <= 1) {
		cout << "0" << endl;
	}
	else {
		cout << got[0]*got[1] << endl;
	}
}

Measured memory_bytes: 3972
reverseFlag = False

S = input()
Q = int(input())
S_mae = ''
S_ato = ''

for i in range(Q):
    TFC = input().split(' ')
    if TFC[0] == '1':
        reverseFlag = not reverseFlag
    else:
        if TFC[1] == '1':
            if reverseFlag:
                S_ato = S_ato + TFC[2]
            else:
                S_mae = TFC[2] + S_mae
        else:
            if reverseFlag:
                S_mae = TFC[2] + S_mae
            else:
                S_ato = S_ato + TFC[2]
if reverseFlag:
    print(S_ato[::-1] + S[::-1] + S_mae[::-1])
else:
    print(S_mae + S + S_ato)

Measured memory_bytes: 4432
N, M = map(int, input().split())
H = list(map(int, input().split()))
a = [True] * N
for i in range(M):
  ai, bi = map(int, input().split())
  if H[ai-1] <= H[bi-1] :
    a[ai-1] = False
  if H[ai-1] >= H[bi-1]:
    a[bi-1] = False
print(sum(a))    
  

Measured memory_bytes: 20156
package main

import (
	"fmt"
)

func main() {
	var x, y int
	fmt.Scanf("%d", &x)
	fmt.Scanf("%d", &y)

	if 2 * x <= y && 4 * x >= y && y % 2 == 0 {
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}


Measured memory_bytes: 1832
from itertools import combinations

class Solver:
    def __init__(self, N, M, X, C, A):
        self.N = N
        self.M = M
        self.X = X
        self.C = C
        self.A = A

    def is_achievable(self, A):
        result = [0] * self.M
        for a_row in A:
            for i, a in enumerate(a_row):
                result[i] += a

        for n in result:
            if n < self.X:
                return False
        return True

    def solve(self):
        if not self.is_achievable(self.A):
            print(-1)
            return

        min_cost = 10 ** 10
        index_C = [ i for i in range(N) ]
        for i in range(len(index_C)+1):
            for comb in combinations(index_C, i):
                cur_A = []
                cur_cost = 0
                for i in comb:
                    cur_A.append(self.A[i])
                    cur_cost += C[i]
                if self.is_achievable(cur_A):
                    min_cost = min(min_cost, cur_cost)

        print(min_cost)

N, M, X = map(int, input().split())

C = [0] * N
A = []

for i in range(N):
    query = list(map(int, input().split()))
    C[i] = query[0]
    A.append(query[1:])

solver = Solver(N, M, X, C, A)
solver.solve()



Measured memory_bytes: 74024
import java.util.Scanner;

public class Main {
    public static void main(String []args){
        Scanner in = new  Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
        int x = in.nextInt();
        int count = 0;
        for(int i = 0; i <= a; i++){
            for(int j = 0; j <= b; j++){
                for(int k = 0; k <= c; k++){
                    if((i * 500 + j * 100 + k * 50) == x){
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 23892
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  if(d<=a)printf("%d",d);
  else if(d<=a+b)printf("%d",a);
  else printf("%d",(2*a+b-d));
  return 0;
}

Measured memory_bytes: 3828
n,*l=map(int,open(0).read().split())
from heapq import *
l.sort()
hq=[-l.pop()]
heapify(hq)
a=0
for _ in range(n-1):
  m=heappop(hq)
  a-=m
  t=-l.pop()
  heappush(hq,t)
  heappush(hq,t)
print(a)

Measured memory_bytes: 31612
#include<stdio.h>
#include<string.h>
int main() {

	
	char s[101], u[101], t[101] = {'0'};
	int i, j,k,n,cnt=0,ans=0;
	scanf("%s%s", s,u);
	n = strlen(s);
	for (i = 0; i<n; i++) {
		for (j = 0; j < n; j++) {
			if ((j + i) >= n)t[j + i - n] = s[j];
			else t[j + i] = s[j];
		}
		cnt = 0;
		for (k = 0; k < n; k++) {
			if (u[k] == t[k])cnt++;
		}
		if (cnt == n)ans++;
	}

	if (ans == 0)puts("No");
	else puts("Yes");

	return 0;

}

Measured memory_bytes: 128
function Main(input) {
	var s = input.trim();
	var sum = 0;
	for(var i=0;i<s.length;i++){
		if(s[i] == '-'){
			sum--;
		} else {
			sum++;
		}
	}
	console.log(sum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
    string s; cin >> s;
    ll po[26] = {};
    for(ll i = 0; i < s.size(); ++i) ++po[s[i] - 'a'];
    ll ans = s.size() * (s.size() - 1) / 2;
    for(ll i = 0; i < 26; ++i) ans -= po[i] * (po[i] - 1) / 2;
    cout << ans + 1 << endl;
    return 0;
}

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

int main(){
    int n, m, total = 0;
    std::priority_queue<int> pq;
    std::cin >> n >> m;
    for(int i = 0; i < n; i++){
        int a;
        std::cin >> a;
        pq.push(a);
        total += a;
    }
    bool flag = true;
    int threshold = total/(4*m);
    for(int i = 0; i < m; i++){
        int t = pq.top(); pq.pop();
        if(total % 4*m){
            if(t<=threshold){
                flag = false;
            }
        }else{
            if(t<threshold){
                flag = false;
            }
        }
    }
    std::cout << (flag ? "Yes" : "No") << std::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();
    String S = sc.next();
    char[] ans = S.toCharArray();
    for (int i = 0; i < ans.length; i++) {
      ans[i] = (char) ((((ans[i] - 'A') + N) % 26) + 'A');
    }
    System.out.println(new String(ans));
  }
}


Measured memory_bytes: 23508
import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        int m=sc.nextInt(),e=m;
        int sz=100101;
        long fr[]=new long[sz];
        long inv[]=new long[sz];

        fr[0]=inv[0] = 1;
        fr[1]=inv[1] = 1;
        int mod=1000000007;

        for (int i = 2; i <sz; ++i){
            inv[i] = inv[mod % i] * (mod - mod / i) % mod ;
        }

        for (int i = 2; i <sz; ++i){
            fr[i]=fr[i-1]*i %mod;
            inv[i]=inv[i-1]*inv[i] %mod;
        }
        n--;
        long ans=1;
        int c=0,i=0;
        long s=0;
        for(i=2; i*i<=e; i++) {
            c=0;
            s=0;
            while(m%i==0){c++;m/=i;}
            if(c>0){
                s=(fr[n+c]*inv[c])%mod;
                s*=inv[n];
                s%=mod;
                ans*=s;
                ans%=mod;
            }
        }
        if(m>1){
            s=0;
            c=1;
            s=(fr[n+c]*inv[c])%mod;
            s*=inv[n];
            s%=mod;
            ans*=s;
            ans%=mod;
        }


    
        out.println(ans);
        out.flush();
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  

    static long gcd(long a, long b){
        if(min(a,b) == 0)return max(a,b);
        return gcd(max(a,b) % min(a,b),min(a,b));
    }
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 25172
/**
*    author:  souzai32
*    created: 15.08.2020 21:15:42
**/

#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
typedef long long ll;
using namespace std;

int main() {

    ll x,k,d;
    cin >> x >> k >> d;
    ll ans;


    if(abs(x)/k>=d) ans=abs(x)-k*d;
    else if((k-(x/d))%2) ans=d-abs(x)%d;
    else ans=abs(x)%d;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <algorithm>
#include <utility>
using namespace std;
int main() {
	long long int A, B, C; 
	cin >> A >> B >> C; 
	if(C <= A + B + 1){cout << B + C << endl;}
	else{cout << B + (A + B + 1) << endl;}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>

typedef long long ll;
typedef long double ld;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;
const ld pi = acos(-1);

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

  ll x1, y1, x2, y2;
  std::cin >> x1 >> y1 >> x2 >> y2;

  ll vx = x2 - x1;
  ll vy = y2 - y1;

  ld theta = pi / 2.0;

  ld x4 = cos(theta) * vx - sin(theta) * vy + x1;
  ld y4 = sin(theta) * vx + cos(theta) * vy + y1;

  vx *= -1;
  vy *= -1;
  theta *= -1.0;

  ld x3 = cos(theta) * vx - sin(theta) * vy + x2;
  ld y3 = sin(theta) * vx + cos(theta) * vy + y2;

  std::cout << (ll)round(x3) << " " << (ll)round(y3) << " " << (ll)round(x4) << " " << (ll)round(y4) << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a,b,c,p=0;
  cin>>a>>b>>c;
  for(int i=1;i<=1000000;i++){
    p=p+a;
    if(i%7==0){
      p=p+b;
    }
    if(p>=c){
      p=i;
      break;
    }
  }
  cout<<p<<'\n';
  return(0);
}



Measured memory_bytes: 3112
n,m,x=map(int,input().split())
a = list(map(int,input().split()))

cnt_lower=0
cnt_higher=0

for i in a:
    if i>x:
        cnt_lower+=1
    elif i<x:
        cnt_higher+=1
    else:
        continue
        
ans = min(cnt_lower, cnt_higher)
print(ans)

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

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

    int n, m;
    cin >> n >> m;

    bool F[n][n];
    REP(i, n) REP(j, n) F[i][j] = false;

    REP(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        F[a][b] = true;
        F[b][a] = true;
    }

    vector<int> B(n - 1);
    REP(i, n - 1) B[i] = i + 1;
    sort(B.begin(), B.end());

    int ans = 0;
    do{
        int tmp = 0;
        bool f = true;
        REP(i, n - 1){
            if(F[tmp][B[i]] == false){
                f = false;
                break;
            }
            tmp = B[i];
        }
        if(f == true) ans++;
    }while(next_permutation(B.begin(), B.end()));

    cout << ans << endl;

    return 0;
}

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

signed main(void)
{
	int n;
	cin >> n;
	int a[n];
	int cnt, ans;
	rep(i, n) cin >> a[i];
	ans = 0;
	cnt = 1;
	for(int i = 0; i < n; i++)
	{
		if (a[i] != a[i + 1])
		{
			ans += cnt / 2;
			cnt = 1;
		}
		else
			cnt++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#ABC096 C - Grid Repainting 2
I = raw_input().split(" ")
H = int(I[0])
W = int(I[1])
A = [list(raw_input()) for i in range(H)]
ans = 0
for X in range(H):
    for Y in range(W):
        counter = 0
        if A[X][Y] == "#":
            if X != 0 and A[X][Y] == A[X - 1][Y]:
                counter += 1
            if X != H - 1 and A[X][Y] == A[X + 1][Y]:
                counter += 1
            if Y != 0 and A[X][Y] == A[X][Y - 1]:
                counter += 1
            if Y != W - 1 and A[X][Y] == A[X][Y + 1]:
                counter += 1
            if counter == 0:
                ans += 1
if ans == 0:
    print "Yes"
else:
    print "No"

Measured memory_bytes: 2820
#include<iostream>

using namespace std;


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

    int a[n];

    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int s=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++)
        s+=a[i]*a[j];
    }
    cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 256
s = list(input())
c = 0
if s[0] != "A":
    print("WA")
    
else:
    for a in s[2:-1]:
        if a == "C":
            c += 1
            t = a
    if c == 1:
        s.remove(s[0])
        s.remove(t)
        if "".join(s).islower():
            print("AC")
        else:
            print("WA")
    else:
        print("WA")

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long ll;

string s;

int main(int argc, char const *argv[])
{
	cin >> s;
	for (int i = 0; i < 4; i++) cout << s[i];
	cout << " ";
	for (int i = 4; i < s.length(); i++) cout << s[i];
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
char s[20];
int n;
int main()
{
	scanf("%s", s);
	n = strlen(s);
	if (n & 1)
	{
		puts("No");
		return 0;
	}
	for (int i = 0; i < n; i += 2)
		if (s[i] != 'h' || s[i + 1] != 'i')
		{
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}

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

void test()
{
    for (int i = 0; i < 5; i++)
    {
        int val;
        cin >> val;
        if (val == 0)

        {
            cout << i+1 << endl;
            return;
        }
    }
}
int32_t main()
{

    int t = 1;
    // cin >> t;
    while (t--)
    {
        test();
    }

    return 0;
}

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

int main() {
    int a = 0, b = 1000000007, N;
    cin >> N;
    for (int i = 0; i < N; i++){
        int c;
        cin >> c;
        a = max(a,c);
        b = min(b,c);
    }
    cout << a - b << endl;
}


Measured memory_bytes: 256