akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


void __print(int 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");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
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


// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;



int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	string s;
	cin >> s;
	string t = s;
	sort(all(t));
	int cnt = 0;
	int r = 0, w = 0;
	zip(i, 0, n)
	{
		if (s[i] == 'R')
			r++;
		else if (s[i] == 'W')
			w++;

		if (s[i] != t[i])
			cnt++;
	}
	int ans = min({r, w, (cnt + 1) / 2});
	cout << ans << en;


	return 0;
}



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

typedef long long ll;

int A, B;

int main() {
    cin >> A >> B;
    string ans = "No";
    for (int i = 1; i <= 3; i++) {
        if ((A * B * i) % 2 == 1) {
            ans = "Yes";
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c, d;
	int n, count;
	
	
	while (scanf("%d", &n) != EOF){
		count = 0;
		for (a = 0; a <= 9; a++){
			for (b = 0; b <= 9; b++){
				for (c = 0; c <= 9; c++){
					for (d = 0; d <= 9; d++){
						if (a + b + c + d == n){
							count++;
						}
					}
				}
			}
		}
		printf("%d\n", count);
	}
	
	return (0);
}

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


def solve(N: int):

    result_set = set()
    for i in range(1, N + 1):
        for j in range(1, N + 1):
            for k in range(1, N + 1):
                result = str(i) + str(j) + str(k)
                result_set.add(result)
    print(len(result_set))

    return


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
    solve(N)


if __name__ == "__main__":
    main()


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

int main() {
int64_t a,b,c,k;
  cin>>a>>b>>c>>k;
  if(k<=a){cout<<k<<endl;}
  else if(a<k&&k<=a+b){cout<<a<<endl;}
  else{cout<<2*a+b-k<<endl;}
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  string s;
  cin>>s;
  int n=s.size();
  
  if(s=="zyxwvutsrqponmlkjihgfedcba"){
    cout<<-1<<endl;
    return 0;
  }
  
  map<int,int> mp;
  REP(i,n){
    mp[s[i]-'a']++;
  }
  bool flag=false;
  char target;
  REP(i,26){
    if(mp[i]==0){
      flag = true;
      target = (char)(i+'a');
      break;
    }
  }
  
  if(flag){
    s += target;
    cout<<s<<endl;
    return 0;
  }
  int index;
  for(int i=n-1;i>=1;i--){
    if(s[i-1]<s[i]){
      index = i-1;
      target = s[i-1];
      break;
    }
  }
  
  char next=target;
  for(int i=index+1;i<n;i++){
    if(s[i]>target){
      next = s[i];
    }
  }
  
  string ans="";
  REP(i,index){
    ans += s[i];
  }
  ans += next;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pair<int,int>>


int main(){
    ios::sync_with_stdio(0);
    int n, r;
    cin >> n >> r;
    if (n >= 10)
        cout << r;
    else
        cout << r + (100*(10-n));
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import static java.lang.Math.*;
import java.text.DecimalFormat;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			long q = sc.nextLong();
			if (q < 0) break;
			double x = q/2.0;
			double e = 0.00001 * q;
			while (abs(pow(x,3) - q) >= e) {
				x = x - (pow(x,3) - q) / (3 * pow(x,2));
			}
			System.out.println(new DecimalFormat("#0.000000").format(x));
		}
	}
}

Measured memory_bytes: 26364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int a[maxn];
int b[maxn];
int main()
{
   int m,n;
    cin>>m>>n;
   for(int i=1;i<=n;i++)
   {
       scanf("%d%d",&a[i],&b[i]);
   }
 int maxs=a[1],mins=b[1];
 for(int i=2;i<=n;i++)
 {
     maxs=max(maxs,a[i]);
     mins=min(mins,b[i]);
 }
 if(maxs>mins)
    cout<<0<<endl;
 else
    cout<<mins-maxs+1<<endl;


    return 0;
}


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

int a[1001][1001] = {0};

int main(){
	int n;
	cin >> n;
	string x;
	string y;
	for ( int i = 0; i < n; i++ ) {
		cin >> x;
		cin >> y;
		for ( int j = 0; j < x.size(); j++ ) {
			int f = 0;
			for ( int k = 0; k < y.size(); k++ ) {
				if ( x[j] == y[k] ) {
					a[j+1][k+1] = a[j][k] + 1;
				}else {
					a[j+1][k+1] = max(a[j+1][k],a[j][k+1]);
				}
			}
		}
		cout << a[x.size()][y.size()] << endl;
	}
	return 0;
}

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

using namespace std;
#define ll long long

ll fun(ll n, ll k)
{
    ll s=1;
    while(k)
    {
        if(k&1)
        {
            s=s*n%1000000007;
        }
        n=n*n%1000000007;
        k=k/2;
    }
    return s;
}

ll C(ll n,ll m)
{
    if(m>n-m)
    {
        m=n-m;
    }
    ll x=1, y=1;
    for(int i=1, j=n;i<=m;i++,j--)
    {
        x=x*j%1000000007;
        y=y*i%1000000007;
    }
    ll z=x*fun(y,1000000007-2)%1000000007;
    return z;
}

int main()
{
    ll n, a, b;
    scanf("%lld%lld%lld",&n,&a,&b);
    ll x=C(n,a);
    ll y=C(n,b);
    ll z=fun(2,n)+2*1000000007-x-y;
    z=z%1000000007;
    cout << z-1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

int main()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 1;
    ll k = 0;
    for(int i = 0; i < n * 2; i++){
        if((s[i] == 'B' && k % 2 == 1) || (s[i] == 'W' && k % 2 == 0)){
            ans = ans * k % MOD;
            k--;
        }
        else k++;
    }
    for(ll i = 1; i <= n; i++) ans = ans * i % MOD;
    if(k) cout << 0 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  while(cin>>s,s[0]!='-'){
    int n,i,b;
    queue<char>a;
    for(i=0;i<s.size();i++)a.push(s[i]);
    cin>>n;
    while(n--){
      cin>>b;
      while(b--){
	a.push(a.front());
	a.pop();
      }
    }
    while(!a.empty()){
      cout<<a.front();
      a.pop();
    }
    cout<<endl;
  }
}


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

UD = {}
LR = {}

RU = {}
DL = {}

UL = {}
RD = {}


for i in range(N):

    X,Y,S = input().split()
    X = int(X)
    Y = int(Y)

    if S == 'U' or S == 'D':
        if X not in UD:
            UD[X] = []
        UD[X].append((Y,S))

    if S == 'L' or S == 'R':
        if Y not in LR:
            LR[Y] = []
        LR[Y].append((X,S))

    if S == 'R' or S == 'U':
        if X+Y not in RU:
            RU[X+Y] = []
        RU[X+Y].append((X,S))

    if S == 'D' or S == 'L':
        if X+Y not in DL:
            DL[X+Y] = []
        DL[X+Y].append((X,S))

    if S == 'U' or S == 'L':
        if X-Y not in UL:
            UL[X-Y] = []
        UL[X-Y].append((Y,S))

    if S == 'R' or S == 'D':
        if X-Y not in RD:
            RD[X-Y] = []
        RD[X-Y].append((Y,S))

ans = float("inf")
for i in UD:
    lasu = float("-inf")
    lis = UD[i]
    lis.sort()
    for t,d in lis:
        if d == "U":
            lasu = t
        else:
            ans = min(ans , (t-lasu))

for i in LR:
    lasu = float("-inf")
    lis = LR[i]
    lis.sort()
    for t,d in lis:
        if d == "R":
            lasu = t
        else:
            ans = min(ans , (t-lasu))

for i in RU:
    lasu = float("-inf")
    lis = RU[i]
    lis.sort()
    for t,d in lis:
        if d == "R":
            lasu = t
        else:
            ans = min(ans , (t-lasu)*2)

for i in DL:
    lasu = float("-inf")
    lis = DL[i]
    lis.sort()
    for t,d in lis:
        if d == "D":
            lasu = t
        else:
            ans = min(ans , (t-lasu)*2)

for i in UL:
    lasu = float("-inf")
    lis = UL[i]
    lis.sort()
    for t,d in lis:
        if d == "U":
            lasu = t
        else:
            ans = min(ans , (t-lasu)*2)

for i in RD:
    lasu = float("-inf")
    lis = RD[i]
    lis.sort()
    for t,d in lis:
        if d == "R":
            lasu = t
        else:
            ans = min(ans , (t-lasu)*2)

if ans == float("inf"):
    print ("SAFE")
else:
    print (ans*5)


Measured memory_bytes: 209972
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  vector<int> A(3);
  rep(i, 3) cin >> A[i];
  sort(A.begin(), A.end());
  A.erase(unique(A.begin(), A.end()), A.end());
  bool bl = (sz(A) == 2);
  if (bl) puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i,n,a,ave,max=0,min=1000,sum=0;
        while(true){
            n = sc.nextInt();
            if(n==0)break;
            for(i=0;i<n;i++){
                a=sc.nextInt();
                if(max<a)max=a;
                if(min>a)min=a;
                sum+=a;
            }
            sum-=max+min;
            ave = sum/(n-2);
            System.out.println(ave);
            max=0;
            min=1000;
            sum=0;
        }
    }
}



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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807
int gcd(int a,int b){if(b==0)return a; return gcd(b,a%b);}
int lcm(int a,int b){return a/gcd(a,b)*b;}

int h,w,a[1002][1002],memo[1002][1002],cnt=1;
queue<pair<int,int>> v;

signed main() {
    cin >> h >> w;
    rep1(i,h) rep1(j,w) memo[i][j] = INF;
    rep(i,h+2) a[i][0] = a[i][w+1] = 1;
    rep(i,w+2) a[0][i] = a[h+1][i] = 1;
    rep1(i,h) {
        string s;
        cin >> s;
        rep1(j,w) {
            if (s[j-1] == '.') a[i][j] = 0;
            else a[i][j] = 1,memo[i][j] = 0;
        }
    }
    rep1(i,h) {
        rep1(j,w) {
            int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
            if (a[i][j]) {
                rep(k,4) if (!a[i+dy[k]][j+dx[k]]) {
                    v.push(mp(i+dy[k],j+dx[k]));
                }
            }
        }
    }
    while(!v.empty()) {
        queue<pair<int,int>> tmp;
        while(!v.empty()) {
            int i = v.front().fi, j = v.front().se;v.pop();
            if (a[i][j]) continue;
            a[i][j] = 1;
            memo[i][j] = min(memo[i][j],cnt);
            int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
            rep(k,4) if (!a[i+dy[k]][j+dx[k]]) {
                tmp.push(mp(i+dy[k],j+dx[k]));
            }
        }
        v = tmp;
        cnt++;
    }
    int ans=0;
    rep1(i,h) rep1(j,w) ans = max(ans,memo[i][j]);
    cout << ans << endl;
}









Measured memory_bytes: 42896
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define UNIQUE(v) v.erase(unique(all(v)),v.end());
#define fill(a,x) memset(a,x,sizeof(a))
#define zero(a) fill(a,0)
#define minus(a) fill(a,-1)
#define dbg(x) cout << #x"=" << x << endl

const int INF=INT_MAX/3;
const int LIMIT=100;

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

ll x,y,z;
string s;
int ans;

int main(){
    cin>>x>>y>>z;
    FOR(i,1,x){
        if(i*y+(i+1)*z<=x)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int d[1005][1<<12],a[1005],b[1005];
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++){
        int x;
        scanf("%d %d",&a[i],&x);
        for(int j=0;j<x;j++){
            int y;
            scanf("%d",&y);
            b[i]=b[i]|(1<<(y-1));
        }
    }
    d[1][b[1]]=a[1];
    for(int i=1;i<m;i++)for(int j=0;j<(1<<n);j++){
        if(j==0||d[i][j]){
            d[i+1][j|b[i+1]]=(d[i+1][j|b[i+1]]?min(d[i+1][j|b[i+1]],d[i][j]+a[i+1]):d[i][j]+a[i+1]);
            d[i+1][j]=(d[i+1][j]?min(d[i+1][j],d[i][j]):d[i][j]);
        }
    }
    if(d[m][(1<<n)-1])printf("%d",d[m][(1<<n)-1]);
    else printf("-1");
}

Measured memory_bytes: 14336
//B - Making Triangle
//Hiia
#include <stdio.h>
#include <stdlib.h>//rannsuu, zettaichi(absolute)
#include <time.h>
//srand((unsigned int) time(0));
#include <math.h>//koudona keisann
#include <string.h>//hairetsu
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
typedef long long ll;
//#define N 998244353
#define pi 3.1415926535897932384626433832

int gcd(int m,int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
int lcm(int m,int n){if((0==m)||(0==n))return 0;return(m*n/gcd(m, n));}
int fact(int x){if(x==1) return(x);else return(x*fact(x-1));}//Kaijou x!
int ruijou(int base,int exponent){int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

long long int llgcd(long long int m,long long int n){if((0==m)||(0==n))return 0;while(m!=n)if(m>n)m=m-n;else n=n-m;return m;}
long long int lllcm(long long int m,long long int n){if((0==m)||(0==n))return 0;return(m*n/llgcd(m, n));}
long long int llfact(long long int x){if(x==1) return(x);else return(x*llfact(x-1));}//Kaijou
int llruijou(long long int base,long long int exponent){long long int i,answer=1;i=exponent;while(i!=0){answer=answer*base;--i;}return answer;}//ruijou base^exponent

int main()
{
  ll n,x[101],i,j,k,ans=0;
  scanf("%lld", &n);
  for(i = 1; i <= n; i++) {
    scanf("%lld", &x[i]);
  }

  if(n<=2){
    printf("0\n");
  }
  else{
    for(i = 1; i <= n-2; i++) {
      for(j = i+1; j <= n-1; j++) {
        for(k = j+1; k <= n; k++) {
          if(x[i]!=x[j] && x[j]!=x[k] && x[k]!=x[i] && x[i]+x[j]>x[k] && x[k]+x[i]>x[j] && x[j]+x[k]>x[i]){
            ans++;
          }
        }
      }
    }
    printf("%lld\n", ans);
  }

  return 0;
}


Measured memory_bytes: 1732
import sys
# input = sys.stdin.buffer.readline
def main():
    x, y = map(int, input().split())
    for i1 in range(x + 1):
        if i1 * 2 + (x - i1) * 4 == y:
            print('Yes')
            sys.exit()
    print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 9168
n = input()
R = []
for i in range(n):
   R.append(int(raw_input()))

maxv = R[1] - R[0]
minv = R[0]

for v in range(1, n):
   if minv > R[v]:
      minv = R[v]
   elif maxv < R[v] - minv:
      maxv = R[v] - minv
print maxv   

Measured memory_bytes: 18888
def f(a,b,c):
    mx = max(a,b,c)
    mn = min(a,b,c)
    if mx == b or mn == b:
        return False
    else:
        return True

n = int(input())
p = list(map(int,input().split()))
cnt = 0
for i in range(n-2):
    if f(p[i],p[i+1],p[i+2]):
        cnt += 1
print(cnt)

Measured memory_bytes: 9224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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

const ll mod = 1e9+7;




int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll x,k,d;
    cin >> x >> k >> d;
    if(x < 0) x = -x;
    ll mod = x/d,dist = x%d;
    ll ans;
    if(k < mod){
        ans = x-k*d;
        cout << ans << endl;
        return 0;
    } 
    k -= mod;
    if(k%2 == 0){
        cout << dist << endl;
    }else{
        cout << abs(dist-d) << endl;
    }
    return 0;


}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int A,B,C;
  cin>>A>>B;
  C=A+B;
  if(C%2==1){
  cout<<"IMPOSSIBLE"<<endl;
  }else{
  cout<<C/2<<endl;
  }
}

Measured memory_bytes: 256
s = list(input())
total = 0
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        if s[i+1] == '0':
            s[i+1] = '1'
        else:
            s[i+1] = '0'
        total = total + 1
print(total)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define INF 1000000000
#define MOD 1000000007
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define p_q priority_queue

#define FOR(i, a, b) for (int i=(a); i<=(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 200005
int q;
ll sm;
int n;
int nv;
ll ai[MN];
ll bi[MN]; //MOD MOD if q 2

ll tree[MN*3][2];
void upd(int node, int a, int b, int i, int j, ll val, int tp){
    if(a > j || b < i || b < a) return;
    
    if(a == b){
        if(tp == 0){
            tree[node][0]++;
        } else{
            tree[node][1] += val;
        }
        return;
    }

    upd(node*2, a, (a+b)/2, i, j, val, tp);
    upd(node*2+1, 1+(a+b)/2, b, i, j, val, tp);
    tree[node][tp] = tree[node*2][tp]+tree[node*2+1][tp];
}
ll que(int node, int a, int b, int i, int j, int tp){
    if(a > j || b < i || b < a || i > j) return 0;

    if(i <= a && b <= j){
        return tree[node][tp];
    }

    ll q1 = que(node*2, a, (a+b)/2, i, j, tp);
    ll q2 = que(node*2+1, 1+(a+b)/2, b, i, j, tp);
    return q1+q2;
}

vll vals;

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

    cin >> q;
    F0R(i, q){
        int x;
        cin >> x;
        if(x == 2){
            ai[i] = MOD;
        } else{
            cin >> ai[i] >> bi[i];
            vals.pb(ai[i]);
        }
    }
    sort(vals.begin(), vals.end());
    vll::iterator it = unique(vals.begin(), vals.end());
    vals.resize(distance(vals.begin(), it));

    nv = vals.size();

    F0R(i, q){
        int x = 1;
        if(ai[i] == MOD) x = 2;
        
        if(x == 1){
            n++;
            ll a = ai[i];
            ll b = bi[i];
            sm = sm+b;
            int loc = lower_bound(vals.begin(), vals.end(), a) - vals.begin();
            upd(1, 1, nv, loc+1, loc+1, 1, 0);
            upd(1, 1, nv, loc+1, loc+1, a, 1);
        } else{
            int tg = (n+1)/2;
            
            int l = 0;
            int r = nv;
            while(l+1 < r){
                int mid = (l+r)/2;
                ll cnt = que(1, 1, nv, 1, mid, 0);

                if(cnt >= tg){
                    r = mid;
                } else{
                    l = mid;
                }
            }
            
            int loc = r;
            ll cv = vals[r-1];
            ll lct = que(1, 1, nv, 1, r, 0);
            ll rct = que(1, 1, nv, r+1, nv, 0);
            ll lsm = que(1, 1, nv, 1, r, 1);
            ll rsm = que(1, 1, nv, r+1, nv, 1);

            ll tot = lct*cv-lsm + rsm-rct*cv + sm;
            //cout << lct << " " << rct << " " << lsm << " " << rsm << " " << sm << "\n";
            cout << cv << " " << tot << "\n";
        }
    }

    return 0;
}


Measured memory_bytes: 13940
object Main extends App {
    val n:Int = scala.io.StdIn.readLine().toInt
    val Array(t, a) = scala.io.StdIn.readLine().split("\\s").map(_.toInt)
    val h = scala.io.StdIn.readLine().split("\\s").map(_.toInt)

    var diff:Double = Math.pow(10,15)
    var result:Int = 0

    for (i <- 1 to n) {
      val tmp_h = h(i-1)
      val tmp_t = t - tmp_h * 0.006
      val tmp_diff = Math.abs(a - tmp_t)
      if (diff > tmp_diff) {
        diff = tmp_diff
        result = i
      }
    }

    println(result)
}

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

int main(){

    string s;
    cin>>s;

    int rpointer=s.size();
    rpointer--;
    int lpointer=0;
    int changed=0;




    while(lpointer<rpointer ){
        if(s[lpointer]!=s[rpointer]){
            changed++;

        }
        lpointer++;
        rpointer--;
        

    }
    cout<<changed;




}

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

int main(){
    double a,b;
    int d;
    cin >> a >> b;
    double c;
    d = (a+b)/2;
    c = (a+b)/2 - d;
    if(c!=0){
        cout << d+1 << endl;
    }
    else{
        cout << d << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n,a,b = gets.split.map(&:to_i)
total = 0

(0..n).each do |n|
  sum = 0
  nb = n #ここで代数に入れておかないとtotalを出すときにn==0が入ってしまう。メソッド化するのもあり。
  until nb == 0
    sum += nb % 10
    nb /= 10 # n/10としないように
  end
  total += n if a <= sum && sum <= b
end

puts total

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define debug(x) cerr << #x " = " << (x) << endl;
#define P(x) cerr << #x << endl;    
typedef long long ll;
//#define int long long
//#define int unsigned long long
const int mod = 1000000007;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    
    
    int months, days;
    cin >> months >> days;
    int count = 0;
    for(int i = 1; i <= months; ++ i)
    {
        for(int j = 22; j <= days; ++ j)
        {
            int copy = j;
            int ones = copy % 10;
            copy /= 10;
            int tens = copy % 10;
            
            if(tens * ones == i && tens >= 2 && ones >= 2)
            {
                ++ count;
            }
        }
    }
    
    cout << count << endl;
    
    return 0;
}






Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>

int main(void) {
	long long k, a, b;
	long long turn;
	long long ans1 = 0, ans2 = 0;

	scanf("%lld %lld %lld", &k, &a, &b);
	ans1 = 1 + k;
	turn = k - (a - 1);
	if (turn%2) 	ans2 = b + (b - a) * (turn / 2 - 1) + 1;
	else ans2 = b + (b - a) * (turn / 2 - 1);

	if (ans1 > ans2 || b <= a) printf("%lld", ans1);
	else printf("%lld", ans2);
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		if (a >= b)
			System.out.println("delicious");
		else if (b - a <= x)
			System.out.println("safe");
		else
			System.out.println("dangerous");
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}

priority_queue<int, vector<int>, greater<int>> pq;
vector<int> v;

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

    while (n) {
        if (n % 10 == 7) return !printf("Yes\n");
        n /= 10;
    }
    printf("No");
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	sort(ALL(v), greater<>());
	ll ans = 0;
	rep(i,n-1) {
		ans += v[(i + 1) / 2];
	}
	cout << ans << endl;
}

Measured memory_bytes: 4064
N, L = map(int,input().split())
lisu = [L+i-1 for i in range(1,N+1)]
abs_l = [abs(i) for i in lisu]
mii = min(abs_l)
auu = sum(lisu)
ans = auu - lisu[abs_l.index(mii)]
print(ans)

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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

// index が条件を満たすかどうか
template <typename T>
bool isOK(const ll &a, ll b, T key) {
  if (a * b < key)
    return true;
  else
    return false;
}

// 汎用的な二分探索のテンプレ
template <typename T>
ll binary_search(const ll &a, T key) {
  ll ng = 1000000;  //「index = 0」が条件を満たすこともあるので、初期値は -1
  ll ok = 0;        // 「index = a.size()-1」
                    // が条件を満たさないこともあるので、初期値は a.size()

  /* ok と ng のどちらが大きいかわからないことを考慮 */
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;

    if (isOK(a, mid, key)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }
  return ok;
}

void solve(long long N) {
  ll ans = 0;
  FOR(a, 1, 1000000) {
    ll b = binary_search<ll>(a, N);
    ans += b;
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 3760
#include "bits/stdc++.h"
using namespace std;
#define MODULO 1000000007
#define PI 3.14159265359
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
     int l,r,d;
     cin>>l>>r>>d;
     int x=r/d;
     int y=l/d;
     int ans=x-y;
     if(l%d==0)
     ans=ans+1;
     cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3596
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=200001;


int main(){
  int n;
  cin>>n;
  P a[51];
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    a[i]=P(tmp,i);
  }
  sort(a,a+n);
  int mini=a[0].first,maxi=a[n-1].first;
  if(mini<=0 and maxi<=0){
    cout<<n-1<<endl;
    for(int i=n-1;i!=0;i--){
      cout<<i+1<<" "<<i<<endl;
    }
  }
  else if(mini>=0 and maxi>=0){
     cout<<n-1<<endl;
     for(int i=0;i<n-1;i++){
        cout<<i+1<<" "<<i+2<<endl;
      }
  }
  else{
    cout<<2*n-1<<endl;
    if(abs(mini)<=abs(maxi)){

      for(int i=0;i<n;i++){
        cout<<a[n-1].second+1<<" "<<a[i].second+1<<endl;
      }
      for(int i=0;i<n-1;i++){
        cout<<i+1<<" "<<i+2<<endl;
        
      }
    }
    else{
      for(int i=0;i<n;i++){
        cout<<a[0].second+1<<" "<<a[i].second+1<<endl;
      }
      for(int i=n-1;i!=0;i--){
        cout<<i+1<<" "<<i<<endl;
      }
    }
  }
  

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define lld long long double
#define pb push_back
#define mp make_pair
#define M 1000000007
using namespace std;

int f(int a[][3], int n) {
	int dp[n][3];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 3; j++)
			dp[i][j] = INT_MIN;
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			for (int p = 0; p < 3; p++) {
				if (j != p) {
					dp[i][j] = max(dp[i][j], dp[i - 1][p] + a[i][j]);
				}
			}
		}
	}
	return max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int n;
	cin >> n;
	int a[n][3];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 3; j++)
			cin >> a[i][j];
	cout << f(a, n);
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main () {
  int n;
  long long a;
  long long minValue = 1000000;
  long long maxValue = -1000000;
  long long sum = 0;
  cin >> n;
  for ( int m = 0; m < n; m++){
    cin >> a;
    if ( a < minValue ) minValue = a;
    if ( a > maxValue ) maxValue = a;
    sum += a;
  }
  cout << minValue << " " << maxValue << " " << sum << endl;
  return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int h,w;
	while(1){
		cin>>h>>w;
		if(h==0&&w==0)	break;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cout<<"#";
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}
	


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
#define INF 200000000000
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()

bool compare(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
// 入力



int main() {
    ll N;
    string S;
    cin >>N>>S;
    
    rep(i,S.size()){
        rep(j,N){
            if(S[i] == 'Z'){
                S[i] = 'A';
            }else{
                S[i]++;
            }
        }
    }
    cout << S << endl;


    return 0;
    

}

Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
namespace ProCon
{
    class Program
    {

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int r = int.Parse(input[0]);
            int g = int.Parse(input[1]);
            int b = int.Parse(input[2]);
            if( (r*100+g*10+b)%4 == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }

        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
	const int MAXN = 2 * 100000;
	int N;

	//int P[MAXN];
	int pos[MAXN];

	cin >> N;

	for (int i = 0; i < N; i++)
	{
		int P;
		cin >> P;
		pos[P-1] = i;
	}

	int best = 0;
	int current = 1;

	for (int i = 0; i < N-1; i++)
	{
		if (pos[i + 1] > pos[i])
		{
			current++;
		}
		else
		{
			if (current > best)
				best = current;
			current = 1;
		}
	}
	if (current > best)
		best = current;

	cout << N - best;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  //input
  int N;
  long long int W;
  cin >> N >> W;
  long long int w[N];
  long long v[N];
  long long int totalw;
  for(int i=0; i<N; i++){cin >> w[i] >> v[i];}
  
  //main
  int INF = 1e9;
  long long memo[N+1][W+1];
  
  //DPtable i番目(0~N)まででjの重さ
  for(int i=0; i<N+1; i++){
    for(int j=0; j<W+1; j++){
      //if(i==0) memo[i][j] = 0;
      memo[i][j] = 0;
    }
  }
  
  for(int i=0; i<N; i++){
    for(int sum=0; sum<W+1; sum++){
      if(sum - w[i] >= 0){chmax(memo[i+1][sum], memo[i][sum-w[i]]+v[i]);}
      chmax(memo[i+1][sum], memo[i][sum]);
    }
  }
  
  //output  
  cout << memo[N][W] << endl;
}

Measured memory_bytes: 79104
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 500000
struct Node {
  int key;
  struct Node *pa,*l,*r;/*parents left child right child*/
};
struct Node *root,*NIL;
void insert(int k){/*挿入　挿入するキー*/
  struct Node *y=NIL;
  struct Node *x=root;
  struct Node *z;
  z=(struct Node *)malloc(sizeof(struct Node));/*zノードのメモリを動的に確保*/
  z->key=k;/*zのキーをkとする*/
  z->l=NIL;
  z->r=NIL;
  while(x!=NIL){/*x　rootから*/
    y=x;/*yののーどをxとおなじものにする（最初はroot）*/
    if(z->key < y->key){/*zのキーがyのキーより小さい時*/
      x=x->l;/*xをxのleft child とする*/
    }
    else x=x->r;/*zのキーがyのキー以上の時　xをxのright child とする*/

  }
  z->pa=y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key < y->key){
      y->l = z;
    }else{
      y->r = z;
    }
  }
}

void inorder(struct Node *u){
  if(u==NIL)return;
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}

void preorder(struct Node *u){
  if(u ==NIL)return;
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
}
int main(){
  int str1 = 0, str2 = 0;
  int i,n,v;
  char C1[10], C2[10]="insert", C3[10]="print";
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%s",C1);
    if(strcmp(C1,C2)== 0)str1= 1;
    if(strcmp(C1,C3)== 0)str2= 1;
    if(str1== 1){
      scanf("%d",&v);
      insert(v);
      str1 = 0;
    }
    else if(str2 == 1){
      str2 = 0;
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



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

int main() {
  int n, q;
  string s;
  cin >> n >> s >> q;
  vector<set<int>> is(26);
  rep(i,n) is[s[i]-'a'].insert(i);
  rep(qi,q) {
    int ty;
    cin >> ty;
    if (ty == 1) {
      int i; char c;
      cin >> i >> c;
      --i;
      is[s[i]-'a'].erase(i);
      s[i] = c;
      is[s[i]-'a'].insert(i);
    } else {
      int l, r;
      cin >> l >> r;
      --l;
      int ans = 0;
      rep(i,26) {
        auto it = is[i].lower_bound(l);
        if (it != is[i].end() && *it < r) ++ans;
      }
      printf("%d\n", ans);
    }
  }
  return 0;
}


Measured memory_bytes: 24196
#include<bits/stdc++.h>
using namespace std;
int pos[2][2005],c[4005],dp[2005][2005],w,n;
void add(int x,int p){
	for(int i=x;i<=w;i+=i&-i)c[i]+=p;
}
int sum(int x){
	int ans=0;
	for(int i=x;i>=1;i-=i&-i)ans+=c[i];
	return ans;
}
int main(){
	scanf("%d",&n);
	w=2*n;
	for(int i=1;i<=w;i++){
		char s[2];int x;
		scanf("%s%d",s,&x);
		pos[s[0]=='W'][x]=i;
		add(i,1);
	}
	pos[0][0]=pos[1][0]=w+1;
	for(int i=0;i<=n;i++){
		add(pos[0][i],-1);
		for(int j=0;j<=n;j++){
			add(pos[1][j],-1);
			if(i||j){
				dp[i][j]=1e9;
				if(i)dp[i][j]=min(dp[i][j],dp[i-1][j]+sum(pos[0][i]-1));
				if(j)dp[i][j]=min(dp[i][j],dp[i][j-1]+sum(pos[1][j]-1));	
			}
		}
		for(int j=0;j<=n;j++)add(pos[1][j],1);
	}
	printf("%d\n",dp[n][n]);
}

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

int main()
{
	int a,b,c,n=0;
	cin>>a>>b>>c;
	for(int i=a;i<=b;i++)
	{
		if(c%i==0)
		{
			n++;
			
		}
	}
	cout<<n<<endl;

	return 0;
}


Measured memory_bytes: 3088
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(A: int, B: int, C: int, K: int):
    ss = sorted([A, B, C])
    return ss[0] + ss[1] + ss[2] * 2 ** K


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    result = solve(A, B, C, K)
    if isinstance(result, Iterable):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


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

int DP[101][2<<15];
int W[2<<15];

int main(){
    int N,M;
    while(cin>>N>>M,N){
        vector<int> S(N);
        vector<int> D(M);
        for(auto &s:S)cin>>s;
        for(auto &d:D)cin>>d;
        sort(S.begin(), S.end());
        sort(D.begin(), D.end());
        fill(DP[0],DP[M+1],200000000);
        fill(DP[0],DP[1],0);
        for(int b=0;b<(1<<N);b++){
            W[b]=0;
            for(int n=0;n<N;n++){
                if(b&(1<<n))W[b]+=S[n];
            }
        }
        for(int i=1;i<=M;i++){
            for(int b=0;b<(1<<N);b++){
                DP[i][b]=min(DP[i][b],abs(W[b]-D[i-1])+DP[i-1][b]);
                for(int n=0;n<N;n++){
                    if(b&(1<<n))
                        DP[i][b]=min(DP[i][b],DP[i][b^(1<<n)]);
                }
            }
        }
        int ans=200000000;
        for(int b=0;b<(1<<N);b++){
            ans = min(DP[M][b],ans);
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 29148
#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;
int N;
vector < vector<int> >X;
int ca = 0;
int cb = 0;
bool f = true;
vector<int> v;
vector<int> col;
void dfs(int a, int c) {
	if (c == 0) {
		ca++;
	}
	else {
		cb++;
	}
	col[a] = c;
	v[a] = 1;
	//cerr <<"a=" <<  a << endl;

	for (int i = 0; i < N; i++) {
		//cerr << "X[a][i]" << X[a][i] << endl;
		if (X[a][i] == 1) {
			if (v[i] == 0) {
				dfs(i, 1 - c);
			}
			else {
				if (col[i] == c) {
					f = false;
				}
			}
		}
	}
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int M;
	cin >> N >> M;
	X.resize(N, vector<int>(N, 1));
	v.resize(N, 0);
	col.resize(N, -1);
	for (int i = 0; i < N; i++) {
		X[i][i] = 0;
	}
	int res = 0;
	int a, b;
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		a--;
		b--;
		X[a][b] = 0;
		X[b][a] = 0;
	}
	vector<int> dp(N + 1, 0);
	vector<int> ndp(N + 1, 0);
	dp[0] = 1;
	for (int i = 0; i < N; i++) {
		if (v[i] == 0) {
			ca = 0;
			cb = 0;
			dfs(i, 0);
			//cerr << ca << " " << cb << endl;
			for (int j = N; j >= 0; j--) {
				ndp[j] = 0;
			}
			for (int j = N; j >= 0; j--) {
				if (dp[j] == 1) {
					if (j + ca <= N) {
						ndp[j + ca] = 1;
					}
					if (j + cb <= N) {
						ndp[j + cb] = 1;
					}
				}
			}
			dp = ndp;
		}
	}
	if (!f) {
		cout << -1 << endl;
	}
	else {
		res = (int)1 << 60;
		for (int i = 0; i <= N; i++) {
			if (dp[i] == 1) {
				res = min(res, (i*(i - 1) / 2) + ((N - i)*(N - i - 1) / 2));
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};



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

	ll x, y;
	cin >> x >> y;
	int cnt = 0;
	while(true){
		if(x>y){break;}
		cnt++;
		x *= 2;
	}
	cout << cnt << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int q,t,f;
  bool flag;
  flag=false;
  string s;
  cin>>s;
  cin>>q;
  deque<string> fr;
  deque<string> ba;
  string c;
  rep(i,q){
    cin>>t;
    if(t==1){
      if(flag){
        flag=false;
      }
      else{
        flag=true;
      }
    }
    else{
      cin>>f>>c;
      if(f==1){
        if(flag){
          ba.push_front(c);
        }
        else{
          fr.push_front(c);
        }
      }
      else{
        if(flag){
          fr.push_front(c);
        }
        else{
          ba.push_front(c);
        }
      }
    }
  }
  if(flag){
    reverse(all(s));
    int si=ba.size();
    rep(i,si){
      cout<<ba.front();
      ba.pop_front();
    }
    cout<<s;
    si=fr.size();
    rep(i,si){
      cout<<fr.back();
      fr.pop_back();
    }
  }
  else{
    int si=fr.size();
    rep(i,si){
      cout<<fr.front();
      fr.pop_front();
    }
    cout<<s;
    si=ba.size();
    rep(i,si){
      cout<<ba.back();
      ba.pop_back();
    }
  }
  return(0);
}


Measured memory_bytes: 11728
#include<bits/stdc++.h>
#define ULL unsigned long long
#define LL long long
#define Max 100005
#define mem(a,b) memset(a,b,sizeof(a));
#define pb push_back
#define mp make_pair
const LL mod=1e9+7;
const ULL base=131;
const LL LL_MAX=9223372036854775807;
using namespace std;
LL a[Max],sum[Max],b[Max];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
        sum[i]=sum[i-1]+a[i];
    }
    LL ans=sum[n]/2;
    int i=1,j=n-1;
    for(i=1,j=n-1;i<j;i++,j--){
        ans=(sum[j]-sum[i-1])-ans;
    }
    b[i]=ans;
    b[i-1]=a[i-1]-b[i];
    for(int t=i-2;t>=1;t--){
        b[t]=a[t]-b[t+1];
    }
    b[i+1]=a[i]-b[i];
    for(int t=i+2;t<=n;t++){
        b[t]=a[t-1]-b[t-1];
    }
    for(int i=1;i<=n;i++)
        printf("%lld ",b[i]*2);
    printf("\n");
    return 0;
}


Measured memory_bytes: 3712
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        String num[] = str.split("/");
        int year = Integer.parseInt(num[0]);
        int month = Integer.parseInt(num[1]);
        int day = Integer.parseInt(num[2]);
        if(year > 2019){
            System.out.println("TBD");
            return;
        }
        if(year == 2019 && month > 4){
            System.out.println("TBD");
            return;
        }
        System.out.println("Heisei");

    }
}

Measured memory_bytes: 21844