akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;++i)
#define MOD (int) 1e9+7

int main(){
    ll n, m;
    cin >> n >> m;
    if(m <= n*2){
        cout << m/2 << endl;
    }else{
        ll  remc = m-n*2;
        cout << n + remc/4 << endl;
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define frn(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define N 2010
#define mod 1000000007
using namespace std;

ll f[N][N],jc[(N+2)*N],ny[(N+2)*N];

inline ll C(ll x,ll y){
	return (((1ll*jc[y]*ny[x]))%mod*ny[y-x])%mod;
}

inline ll ksm(ll a,ll p){
	ll ans=1;
	while(p){
		if(p&1)(ans*=1ll*a)%=mod;
		(a*=1ll*a)%=mod;p/=2;
	}
	return ans;
}

int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	if(m==1){printf("1");return 0;}
	jc[0]=1;
	fr(i,1,n*m)jc[i]=(1ll*jc[i-1]*i)%mod;
	ny[n*m]=ksm(jc[n*m],mod-2);
	frn(i,n*m-1,0)ny[i]=(1ll*ny[i+1]*(i+1))%mod;
	f[0][0]=1;
	fr(i,1,n)
		fr(j,0,i){
			f[i][j]=(1ll*f[i-1][j])%mod;
			if(!j)continue;
			(f[i][j]+=((1ll*f[i][j-1]*(n-j+1))%mod*C(m-2,n*m-i-(j-1)*(m-1)-1))%mod)%=mod;
		}
	printf("%lld",f[n][n]);
	return 0;
}

Measured memory_bytes: 94848
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

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

    int N, A, B;
    cin >> N >> A >> B;
    if ((B - A) % 2 == 0) {
        cout << "Alice" << endl;
    } else {
        cout << "Borys" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#define inf (1<<28)
#define ll long long
#define db double
#define c233 cout<<"233"<<endl
#define mem(s) memset(s,0,sizeof(s))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
const int N=205;
const int M=1050;
using namespace std;

int l[N][N],s[N][N],dp[M][N],way[M];
int n,m,r,ans;

void fre(){
  freopen("in","r",stdin);
  freopen("out","w",stdout);
}

inline int gi(){
  int x=0,res=1;char ch=getchar();
  while(ch>'9'||ch<'0'){if(ch=='-')res*=-1;ch=getchar();}
  while(ch<='9'&&ch>='0')x=(x<<1)+(x<<3)+ch-48,ch=getchar();
  return x*res;
}

void init(){
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      l[i][j]=s[i][j]=inf;
  for(int i=1;i<=n;i++)
    l[i][i]=s[i][i]=0;
  for(int i=1;i<=m;i++){
    int a,b,c;
    char d;
    scanf("%d%d%d %c",&a,&b,&c,&d);
    if(d=='L')l[a][b]=l[b][a]=min(l[a][b],c);
    if(d=='S')s[a][b]=s[b][a]=min(s[a][b],c);
  }
  r=gi();
  for(int i=1;i<=r;i++)
    way[i]=gi();
}

void pre(){
  for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++){
	l[i][j]=min(l[i][j],l[i][k]+l[k][j]);
	s[i][j]=min(s[i][j],s[i][k]+s[k][j]);
      }
  for(int i=1;i<=r;i++)
    for(int j=1;j<=n;j++)
      dp[i][j]=inf;
  ans=inf;
}

void work(){
  dp[1][way[1]]=0;
  for(int i=2;i<=r;i++)
    for(int j=1;j<=n;j++){
      dp[i][j]=min(dp[i][j],dp[i-1][j]+l[way[i-1]][way[i]]);
      for(int k=1;k<=n;k++)
	dp[i][j]=min(dp[i][j],dp[i-1][k]+l[way[i-1]][k]+s[k][j]+l[j][way[i]]);
    }
  for(int i=1;i<=n;i++)
    ans=min(ans,dp[r][i]);
  printf("%d\n",ans);
}

int main(){
  //fre();
  while(1){
    n=gi();m=gi();
    if(n==0&&m==0)break;
    init();
    pre();
    work();
  }
  return 0;
}

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

int main(){

  int H, W, cnt=0;
  cin >> H >> W;

  vector<vector<char>> vec(H,vector<char>(W,0));

  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      cin >> vec.at(i).at(j);
    }
  }
  
  for (int i=0; i<H; i++){
    while (cnt<2){
      for (int j=0; j<W; j++){
        cout << vec.at(i).at(j);
      }
      cout << endl;
      cnt++;
    }
    cnt=0;
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n;
int a[100010];

int main()
{
	read(n);
	for(int i=0; i<n; ++i) read(a[i]), --a[i];
	sort(a, a+n); reverse(a, a+n);
	int p=0;
	while(p+1<n && p+1<=a[p+1]) ++p;
	const char* win="First";
	const char* lose="Second";
	if(a[p]==p && a[p+1]<p){
		puts(lose);
	} else if(a[p]>p && a[p]%2!=p%2){
		puts(win);
	} else {
		int q=p;
		while(a[q+1]>=p && q+1<n) ++q;
		if(p%2!=q%2) puts(win);
		else puts(lose);
	}
	return 0;
}


Measured memory_bytes: 640
h,w = map(int,input().split())
a = []
for i in range(h):
    tmp = list(map(lambda x:int(x)%2,input().split()))
    a.append(tmp)
result = []

for i in range(h):
    for j in range(w-1):
        if a[i][j] == 1:
            #a[i][j] == 0
            a[i][j+1] = 1 ^ a[i][j+1]
            result.append((i+1,j+1,i+1,j+2)) 
for i in range(h-1):
    if a[i][w-1] == 1:
        a[i+1][w-1] = 1 ^ a[i+1][w-1]
        result.append((i+1,w,i+2,w))
print(len(result))
for row in result:
    print("{} {} {} {}".format(row[0],row[1],row[2],row[3])) 

Measured memory_bytes: 26228
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {
        n:usize,k:usize,
        mut a:[i64;n],
    }
    let mut neg = Vec::new();
    let mut pos = Vec::new();
    let mut zeros = 0;
    a.sort_by_key(|x| x.abs());
    for &x in a.iter() {
        if x < 0 {
            neg.push(x);
        } else if x >= 0 {
            pos.push(x);
        }
        if x == 0 {
            zeros += 1;
        }
    }
    if k > n - zeros {
        println!("{}", 0);
        return;
    }

    if k == n {
        let mut ret = 1;
        for x in a.iter() {
            ret *= x;
            ret %= MOD;
            ret = (ret + MOD) % MOD;
        }
        println!("{}", ret);
        return;
    }
    if a.iter().all(|&x| x < 0) && k % 2 == 1 {
        let mut ret = 1i64;
        for x in a.iter().take(k) {
            ret *= x;
            ret %= MOD;
            ret = (ret + MOD) % MOD;
        }
        println!("{}", ret);
        return;
    }
    let mut ret = 1;
    let mut rest = k;
    while rest > 0 {
        if pos.len() >= 1
            && (rest == 1
                || neg.len() < 2
                || pos[pos.len() - 1] * *pos.get(pos.len() - 2).unwrap_or(&&1)
                    >= neg[neg.len() - 1] * neg[neg.len() - 2])
        {
            ret *= pos.pop().unwrap();
            ret %= MOD;
            rest -= 1;
        } else {
            ret *= neg.pop().unwrap();
            ret %= MOD;
            ret *= neg.pop().unwrap();
            ret %= MOD;
            rest -= 2;
        }
    }

    println!("{}", ret);
}

const MOD: i64 = 1000000007;
const MMOD: i64 = MOD * MOD;
const INF: i64 = 1 << 55;


Measured memory_bytes: 8108
def main():
    num = int(input())

    A = 1
    count = 0
    flg = False

    while(True):
        B = 1
        while(True):
            cal = A * B
            if cal < num:
                count += 1
                B += 1
            else:
                if B == 1:
                    flg = True
                break
        if flg:
            break
        A += 1

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
// 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 << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 1000000007;
const ll N = 105;
const ll mm = 1e+18;
void solve()
{
    int n;
    cin>>n;
    map<int,int>mp;
    rep1(i,n){
        int x;
        cin>>x;
        mp[x]++;
    }
    int dp[2]={0};
    for(auto p:mp){
        dp[p.s&1]++;
    }
    cout<<dp[1]+dp[0]-(dp[0]&1);
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}

Measured memory_bytes: 9832
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = [tuple(map(int, input().split())) for _ in range(M)]

ans = min(a) + min(b)
for x, y, d in c:
    ans = min(ans, a[x-1] + b[y-1] - d)

print(ans)


Measured memory_bytes: 29556
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,k;
vector<int>v;
int solve(int l,int r){
	vector<int>t;
	for(int i=0;i<=l;++i)
		t.push_back(v[i]);
	for(int i=r;i<n;++i)
		t.push_back(v[i]);
	sort(t.begin(),t.end());
	int y=k-t.size();
	if(y<0)
		return 0;
	int sum=0;
	for(int i=0;i<t.size();++i)
		if(t[i]<0&&y>0)
			--y;
		else
			sum+=t[i];
	return sum;
}
int main(){
	cin>>n>>k;
	v.resize(n);
	for(int i=0;i<n;++i)
		cin>>v[i];
	int ans=0;
	for(int i=-1;i<n;++i)
		for(int j=i+1;j<=n;++j)
			ans=max(ans,solve(i,j));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
f = open(0)
N, M, L = map(int, f.readline().split())
A = [list(map(int, f.readline().split())) for i in range(N)]
B = [list(map(int, f.readline().split())) for i in range(M)]
C = [[0]*L for i in range(N)]
for i in range(N):
    for j in range(L):
        C[i][j] = str(sum(A[i][k]*B[k][j] for k in range(M)))
for line in C:
    print(*line)


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

#define MAX_V 110
#define INF 1<<29

template <typename T>
struct MaxFlow {
  struct edge { int to, rev; T cap; };

  vector<edge> G[MAX_V];
  int level[MAX_V];
  int iter[MAX_V];
  
  MaxFlow() {}

  void add_edge(int from, int to, T cap) {
    G[from].push_back((edge){to, (int)G[to].size(), cap});
    G[to].push_back((edge){from, (int)G[from].size(), 0});
  }

  void bfs(int source) {
    memset(level, -1, sizeof(level));
    queue<int> que;
    que.push(source);
    level[source] = 0;
    while (!que.empty()) {
      int v = que.front(); que.pop();
      for (int i = 0; i < (int)G[v].size(); i++) {
	edge &e = G[v][i];
	if (e.cap > 0 && level[e.to] < 0) {
	  level[e.to] = level[v] + 1;
	  que.push(e.to);
	}
      }
    }
  }

  T dfs(int v, int sink, T flow) {
    if (v == sink) return flow;
    for (int &i = iter[v]; i < (int)G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
	T d = dfs(e.to, sink, min(e.cap, flow));
	if (d > 0) {
	  e.cap -= d;
	  G[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }

  T dinic(int source, int sink) {
    T flow = 0;
    while (true) {
      bfs(source);
      if (level[sink] < 0) return flow;
      memset(iter, 0, sizeof(iter));
      T f;
      while ((f = dfs(source, sink, INF)) > 0) {
	flow += f;
      }
    }
  }
};


int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int V, E;
  cin >> V >> E;
  MaxFlow<int> mf;
  REP(i, E) {
    int u, v, c;
    cin >> u >> v >> c;
    mf.add_edge(u, v, c);
  }
  cout << mf.dinic(0, V-1) << endl;  
  return 0;
}

Measured memory_bytes: 3292
void main() {
	auto N = readAs!long;
	foreach(h; 1..3501) {
		foreach(n; 1..3501) {
			auto div = 4*h*n - N*h - N*n;
			auto num = N*n*h;
			if(div <= 0) continue;
			if(num % div == 0) {
				writefln("%d %d %d", h, n, num / div);
				return;
			}
		}
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3005,p=1000000007,inv2=(p+1)/2,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int qpow(int x,int k){
	int t=1;
	for (;k;k>>=1){
		if (k&1) t=(ll)t*x%p;
		x=(ll)x*x%p;
	}
	return t;
}
int n,m,ans,a[N],f[N][N];
void check(int &x,int y){if ((x+=y)>=p) x-=p;}
int main(){
	n=read();m=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n;i++)
	for (int j=1;j<=n;j++) f[i][j]=(a[i]>a[j]);
	for (int k=1;k<=m;k++){
		int x=read(),y=read();
		f[x][y]=f[y][x]=(ll)(f[x][y]+f[y][x])*inv2%p;
		for (int i=1;i<=n;i++)
		if ((i!=x)&&(i!=y)){
			f[x][i]=f[y][i]=(ll)(f[x][i]+f[y][i])*inv2%p;
			f[i][x]=f[i][y]=(ll)(f[i][x]+f[i][y])*inv2%p;
		}
	}
	ans=0;
	for (int i=1;i<=n;i++)
	for (int j=i+1;j<=n;j++) check(ans,f[i][j]);
	ans=(ll)ans*qpow(2,m)%p;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 35456
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef std::pair<int,int> P;
using namespace std;
using ll = long long;

vector<pair<string,P>> vec;

int main(){
    int N; cin >> N;
    string s;
    int p;
    rep(i,N){
        cin >> s;
        cin >> p;
        vec.eb(mp(s,mp(-p,i)));
    }
    SORT(vec);
    cout << endl;
    rep(i,N) cout << vec[i].se.se + 1  << endl;
    rn 0;
}


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

int main() {
    while (true)
    {
        int n; cin >> n;
        if(n == 0) break;
        vector<int> train(86410, 0);
        for (int i = 0; i < n; i++)
        {
            string ss, se; cin >> ss >> se;
            int sh = (ss[0] - '0') * 10 + ss[1] - '0';
            int sm = (ss[3] - '0') * 10 + ss[4] - '0';
            int ssec = (ss[6] - '0') * 10 + ss[7] - '0';
            int eh = (se[0] - '0') * 10 + se[1] - '0';
            int em = (se[3] - '0') * 10 + se[4] - '0';
            int esec = (se[6] - '0') * 10 + se[7] - '0';
            train[sh * 3600 + sm * 60 + ssec]++;
            train[eh * 3600 + em * 60 + esec]--;
        }
        for (int i = 0; i < 86400; i++)
        {
            if(i > 0) train[i] += train[i - 1];
        }
        int ans = 0;
        for (int i = 0; i < 86400; i++)
        {
            if(ans < train[i]) ans = train[i];
        }
        cout << ans << endl;
    }

}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int a = n;
	int b = 0;
	while (n > 0)
	{
		b += n%10;
		n /= 10;
	}
	if((a%b) == 0)
	{
		puts("Yes");
	}
	else
	{
		puts("No");
	}
	
}

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

using namespace std;

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

  int n;
  cin >> n;

  string s;
  cin >> s;

  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    v[i] = s[i] == 'R' ? 0 : s[i] == 'G' ? 1 : 2;
  }

  vector<vector<int>> sum(3, vector<int>(n + 2));
  for (int i = 0; i < n; i++) {
    sum[v[i]][i + 1]++;
  }

  for (int i = 0; i < 3; i++) {
    for (int j = 1; j <= n; j++) {
      sum[i][j] += sum[i][j - 1];
    }
  }

  long long ans = 0;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (v[i] != v[j]) {
        for (int k = 0; k < 3; k++) {
          if (k != v[i] && k != v[j]) {
            ans += sum[k][n] - sum[k][j + 1];
            int d = j - i;
            if (j + d < n && v[j + d] == k) {
              ans--;
            }
          }
        }
      }
    }
  }

  cout << ans << "\n";
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int a,b,c,k;
    cin>>a>>b>>c>>k;
    if (k%2==0) {
        long long int ans=a-b;
        if (abs(a-b)>1000000000000000000) {
            cout<<"Unfair"<<endl;
        } else {
            cout<<ans<<endl;
        }
    } else {
        long long int ans=-1*(a-b);
        if (abs(a-b)>1000000000000000000) {
            cout<<"Unfair"<<endl;
        } else {
            cout<<ans<<endl;
        }
    }
}

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

using ll = long long;
using K = long double;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SIZE(a) ((int)(a).size())

const int N = 15;
const int M = 105;

int n = 204, m;
vector<tuple<int,int,int>> edges; 

int a, b, d[N][N];
int used[N][N];
int was[M][M];

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

	cin >> a >> b;
	for (int i = 1; i <= a; ++i) {
		for (int j = 1; j <= b; ++j) {
			cin >> d[i][j];
		}
	}

	for (int r = 0; r <= 100; ++r) {
		for (int x = 0; x <= 100; ++x) {
			for (int y = 0; y <= 100; ++y) {
				if (was[x][y]) continue;
				int failed = 0;
				for (int i = 1; i <= a; ++i) {
					for (int j = 1; j <= b; ++j) {
						if (r + x*i + y*j < d[i][j]) {
							failed = 1;
							goto fin;
						}
					}
				}
			fin:
				if (!failed) {
					edges.emplace_back(2 + x, 103 + y, r);
					was[x][y] = 1;
					for (int i = 1; i <= a; ++i) {
						for (int j = 1; j <= b; ++j) {
							if (r + x*i + y*j == d[i][j]) {
								used[i][j] = 1;
							}
						}
					}
				}
			}
		}
	}

	for (int i = 1; i <= a; ++i) {
		for (int j = 1; j <= b; ++j) {
			if (!used[i][j]) {
				cout << "Impossible\n";
				return 0;
			}
		}
	}

	cout << "Possible\n";

	cout << n << ' ' << SIZE(edges)+202 << '\n';
	cout << 1 << ' ' << 2 << ' ' << 0 << '\n';
	cout << 103 << ' ' << 204 << ' ' << 0 << '\n';
	for (int i = 2; i <= 101; ++i) {
		cout << i << ' ' << i+1 << ' ' << 'X' << '\n';
	}
	for (int i = 103; i <= 202; ++i) {
		cout << i+1 << ' ' << i << ' ' << 'Y' << '\n';
	}
	for (auto& item : edges) {
		int x, y, c;
		tie(x, y, c) = item;
		cout << x << ' ' << y << ' ' << c << '\n';
	}
	cout << 1 << ' ' << 204 << '\n';

	return 0;
}


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





typedef long long ll;
#define MOD 1000000007
template<class V, int ME> class BIT { // by kmjp
public:
	V bit[1 << ME], val[1 << ME];
	V total(int e) { V s = 0; e++; while (e) s += bit[e - 1], e -= e&-e; return s; }
	void add(int e, V v) { val[e++] += v; while (e <= 1 << ME) bit[e - 1] += v, e += e&-e; }
	void set(int e, V v) { add(e, v - val[e]); }
};
//-----------------------------------------------------------------
int N; ll A, B; ll S[101010];
BIT<ll, 20> dpx, dpy;
vector<int> vx, vy;
//-----------------------------------------------------------------
int main() {
	cin >> N >> A >> B;
	S[0] = -(1LL<<60);
	rep(i, 1, N + 1) scanf("%lld", &S[i]);
	
	dpx.set(0, 1);
	dpy.set(0, 1);
	vx.push_back(0);
	vy.push_back(0);
	int ix = 0, iy = 0;
	rep(i, 2, N + 1) {
		while (ix < i - 1 && A <= S[i] - S[ix]) ix++;
		while (iy < i - 1 && B <= S[i] - S[iy]) iy++;

		dpx.add(i - 1, dpy.total(iy - 1) % MOD);
		dpy.add(i - 1, dpx.total(ix - 1) % MOD);

		if (S[i] - S[i - 1] < A) {
			for (int j : vy) dpy.set(j, 0);
			vy.clear();
		}

		if (S[i] - S[i - 1] < B) {
			for (int j : vx) dpx.set(j, 0);
			vx.clear();
		}

		vx.push_back(i - 1);
		vy.push_back(i - 1);
	}

	cout << (dpx.total(N) + dpy.total(N)) % MOD << endl;
}

Measured memory_bytes: 5236
s = input()
q = int(input())

x = []
y = []
cnt = 0

for i in range(q):
    a = list(input().split())
    if a[0] == "1":
        x, y = y, x
        cnt += 1
    else:
        if a[1] == "1":
            x.append(a[2])
        else:
            y.append(a[2])

if cnt % 2 == 1:
    s = s[::-1]

s = ''.join(x[::-1]) + s + ''.join(y)

print(s)


Measured memory_bytes: 6268
#include <cstdio>
#include <iostream>
#include <stack>
#include <string>
using namespace std;

int main(){
	while(1){
		int a, b;
		scanf(" %d %d", &a, &b);
		if(a==0) break;
		
		string s;
		int dx[4]={0,1,0,-1}, dy[4]={1,0,-1,0};
		int dir=0;
		int x=1, y=1;
		
		while(getline(cin, s)){
			stack<int> st;
			
			if(s=="STOP") break;
			else if(s[0]=='R') dir=(dir+1)%4;
			else if(s[0]=='L') dir=(dir-1+4)%4;
			else if(s[0]=='F'){
				st.push(s[8]-'0');
				for(int i=9; i<s.size(); ++i){
					int v=st.top();
					st.pop();
					st.push(10*v+s[i]-'0');
				}
				int k=st.top();
				st.pop();
				
				x+=k*dx[dir];
				y+=k*dy[dir];
				
				if(x<1) x=1;
				if(x>a) x=a;
				if(y<1) y=1;
				if(y>b) y=b;
				
			}
			else if(s[0]=='B'){
				st.push(s[9]-'0');
				for(int i=10; i<s.size(); ++i){
					int v=st.top();
					st.pop();
					st.push(10*v+s[i]-'0');		
				}
				int k=st.top();
				st.pop();
				
				x-=k*dx[dir];
				y-=k*dy[dir];

				if(x<1) x=1;
				if(x>a) x=a;
				if(y<1) y=1;
				if(y>b) y=b;
				
			}
		}
		
		printf("%d %d\n", x, y);
	}
}

Measured memory_bytes: 1252
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

n = ini()
p = inl()


def solve():
    ans = 1
    m = p[0]
    for i in range(1, n):
        if p[i] <= m:
            ans += 1
        m = min(m, p[i])
    return ans


print(solve())


Measured memory_bytes: 31040
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;
const ll INF=1e12;
const ll MOD=1000000007;
ll dp[101][100001];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,W;
    cin>>N>>W;
    ll w[N],v[N];
    rep(i,0,N) cin>>w[i]>>v[i];
    rep(i,0,N){
        rep(j,0,100001){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    rep(i,0,N){
        rep(j,0,100001){
            if(j<v[i]) dp[i+1][j]=dp[i][j];
            else dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i]);
        }
    }
    ll ans=0;
    rep(i,1,100001){
        if(W>=dp[N][i]) ans=i;
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 79232
import java.io._
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, K = sc.nextInt()

    val A1 = map(N)(_ => sc.nextLong())
    val A2 = A1.clone()
    rep(N - 1)(i => A1(i + 1) += A1(i))
    A2(0) = max(0, A2(0))
    rep(N - 1)(i => A2(i + 1) = max(0, A2(i + 1)) + A2(i))

    var mx = 0L
    rep(N - K + 1) { i =>
      val l = if (i == 0) 0 else A2(i - 1)
      val m = A1(i + K - 1) - (if (i ==0) 0 else A1(i - 1))
      val r = A2(N - 1) - A2(i + K - 1)
      mx = max(mx, l + max(0, m) + r)
    }

    out.println(mx)
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int)(f: Int => Unit): Unit = {
    var i = 0
    while(i < n) { f(i); i += 1 }
  }
  def rep_r(n: Int)(f: Int => Unit): Unit = {
    var i = n - 1
    while(i >= 0) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}


Measured memory_bytes: 44996
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
typedef pair<LL, LL> pii;
#define x first
#define y second
const int N = 2e5 + 10, mod = 1e9 + 7;
map<LL, int> val;
int n;
pii a[N], range[N];
LL b[N];
int s[N];

void add(int x, int d) { for(;x < N; x += (-x) & x) (s[x] += d) %= mod; }
int sum(int x) { int ans = 0; for(;x; x -= (-x) & x) (ans += s[x]) %= mod; return ans; }

int main() {
	scanf("%d",&n);
	rep(i,1,n) scanf("%lld%lld",&a[i].x,&a[i].y), b[i] = a[i].y;
	sort(a + 1, a + n + 1), sort(b + 1, b + n + 1);
	rep(i,1,n) val[b[i]] = i; rep(i,1,n) a[i].y = val[a[i].y];
	LL mx = 0;
	rep(i,1,n) mx = max(mx, a[i].y), range[i].y = mx;
	LL mn = n;
	dep(i,n,1) mn = min(mn, a[i].y), range[i].x = mn;
	sort(range + 1, range + n + 1);
	add(1, 1); int ans = 0;
	rep(i,1,n) {
		int F = (sum(N - 1) - sum(range[i].x - 1)) % mod;
		add(range[i].y + 1, F);
		if (range[i].y == n) (ans += F) %= mod;
	}
	if (ans < 0) ans += mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 21376
#include<iostream>
using namespace std;
int turi(int n,int i,int j,int k,int l){
	int sum=0;
	if(n<0)return -1;
	while(n>=500){if(l!=0)return -1;n-=500;sum++;}
	while(n>=100){if(k!=0)return -1;n-=100;sum++;}
	while(n>=50){if(j!=0)return -1;n-=50;sum++;}
	while(n>=10){if(i!=0)return -1;n-=10;sum++;}
	return sum;
}

int main(){
	int n;
	bool f=1;
	while(true){
				
		cin>>n;
			
		if(n==0)break;
	if(!f)cout<<endl;//データセットを処理する2番目以降のみ改行
	f=0;
		int ans[4]={0};
		int table[4]={500,100,50,10};//高い順のテーブル
		int have[4];
		for(int i=0;i<4;i++)cin>>have[i];
		int goke=have[0]+have[1]+have[2]+have[3];
		bool first=1;
		for(int i=0;i<=have[0];i++){
			for(int j=0;j<=have[1];j++){
				for(int k=0;k<=have[2];k++){
					for(int l=0;l<=have[3];l++){
						int now=0;
						if(first==1) now=goke-(ans[0]+ans[1]+ans[2]+ans[3])+turi(ans[0]*10+ans[1]*50+ans[2]*100+ans[3]*500-n,ans[0],ans[1],ans[2],ans[3]);
						else  now=1000000000;
						first=0;
						int nextsum=i*10+j*50+k*100+l*500;
						int next=goke-(i+j+k+l);
						if(nextsum<n)continue;
						if(turi(nextsum-n,i,j,k,l)==-1)continue;
						next+=turi(nextsum-n,i,j,k,l);
						if(next<now){ans[0]=i;ans[1]=j;ans[2]=k;ans[3]=l;}
					}
				}
			}
		}
		for(int i=0;i<4;i++){
		if(ans[i]!=0)cout<<table[3-i]<<' '<<ans[i]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, x, a[30]; bool dp[1000001], prime[1000001];
int main() {
	prime[0] = true, prime[2] = true;
	for(int i = 3; i <= 1000000; i += 2) prime[i] = true;
	for(int i = 3; i <= 1000; i += 2) {
		if(!prime[i]) continue;
		for(int j = i * i; j <= 1000000; j += i * 2) prime[j] = false;
	}
	while(scanf("%d%d", &n, &x), n) {
		for(int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n);
		for(int i = 0; i < x; i++) dp[i + 1] = false; dp[0] = true;
		for(int i = 1; i <= x; i++) {
			for(int j = 0; j < n && i >= a[j]; j++) {
				if(dp[i - a[j]]) {
					dp[i] = true; break;
				}
			}
		}
		for(int i = x; i >= 0; i--) {
			if(dp[i] && prime[i]) {
				printf(i ? "%d\n" : "NA\n", i); break;
			}
		}
	}
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
#define Rep(i,n) for(int i = 0; i < (n); i++)
#define For(i,start,end) for(i64 i = start; i < end; i++)
inline void nl(){std::cout<<std::endl;}
using namespace std;
typedef long long ll;
typedef unsigned long ul;

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ui = uint64_t;

//----------------library in this time--------------------------------
template <class T>
T gcd(const T a,const T b) {
    return (b == 0) ? a : gcd (b, a % b);
}
template <class T>
T lcm(const T a, const T b) {
    return a * b / gcd(a,b);
}
template <class T>
inline T ave(const T a, const T b) {
    return (a + b) / 2.0f;
}

long long squareTwo(const long long a,const long long b) {
    return (b == 1) ? a : squareTwo(a * 2, b - 1);
}

template<class T> inline bool UpdateMin(T& a, T b) {
    if (a > b) { a = b; return 1; } return 0;
}

template<class T> inline bool UpdateMax(T& a, T b) {
    if (a < b) { a = b; return 1; } return 0;
}

//------------------------main function-------------------------------
void Main(){
    int n;
    cin >> n;
    vector<int> L(n);
    Rep(i,n) cin >> L[i];
    sort(L.begin(), L.end());
    //for(int i:L) cout << i << " ";
    //nl();
    int ans = 0;
    Rep(b,n){
       // nl();
        Rep(a,b) {
            //cout << "a = "<< a<< "; b = "<<  b <<  endl;
        int ab = L[a]+L[b];
        int r = lower_bound(L.begin(), L.end(), ab)- L.begin();
        int l = b + 1;
            //cout << "ab = " << ab << "; r = "<< r <<"; l = "<< l << endl;
        // c = [l,r)
        ans += max(0,r-l);
    }}
    cout << ans << endl;
    /*
    int n;
    cin >> n;
    vector<int> L(n);
    Rep(i,n) cin >> L[i];
    sort(L.begin(), L.end());
    int ans = 0;
    Rep(b,n) {
        int r = b+1;
        Rep(a,b) {
            int ab = L[a]+L[b];
            while (r < n && L[r] < ab) ++r;
            int l = b+1;
            ans += max(0,r-l);
        }
    }
    cout << ans << endl;
     */
}
//--------------------------------------------------------------------
int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(10);
    
    Main();
    return 0;
}

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

using namespace std;

const int maxn = 200100;

int n,a[maxn];
map<int,int> num;

int main() {
  //  freopen("in.txt","r",stdin);
    cin>>n;
    int m=0;
    for (int i=1;i<=n;i++) {
        int x;
        cin>>x;
        num[x]++;
        if (num[x]==1) a[++m]=x;
    }
    int cnt = 0;
    for (int i=1;i<=m;i++) {
       // cout<<a[i]<<" "<<num[a[i]]<<endl;
        if (num[a[i]] >= a[i]) cnt+=num[a[i]] -a[i];
        else cnt+=num[a[i]];
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 5120
L = 50

def get_binary_str(n: int) -> str:
    binary = bin(n)[2:]
    padding_length = L - len(binary)
    return '0' * padding_length + binary

def get_first_one_pos(s: str) -> int:
    i = 0
    while i < len(s) and s[i] == '0':
        i += 1
    return i

def xor(x: int, y: int) -> int:
    if x == y:
        return 0
    else:
        return 1

def calc_xor(i: int, x: int, binary_As) -> int:
    ret = 0
    for binary_A in binary_As:
        ret += xor(x, int(binary_A[i]))
    return ret


N, K = list(map(int, input().split(' ')))
As = list(map(int, input().split(' ')))

binary_As = [get_binary_str(A) for A in As]
binary_K = get_binary_str(K)
one_pos = get_first_one_pos(binary_K)

i = 0
ret = 0
while i < one_pos:
    ret += calc_xor(i, 0, binary_As) * 2**(L-i-1)
    i += 1

flag = False
while i < L:
    a = calc_xor(i, 0, binary_As)
    b = N - a
    if flag:
        ret += a * 2**(L-i-1) if a > b else b * 2**(L-i-1)
    else:
        if binary_K[i] == '1':
            if a > b:
                flag = True
            ret += a * 2**(L-i-1) if a > b else b * 2**(L-i-1)
        else:
            ret += a * 2**(L-i-1)

    i += 1

print(ret)


Measured memory_bytes: 18844
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	k <- readInt
	s <- getLine
	let
		l = length s
		res = if l <= k
			then s
			else take k s ++ "..."
	putStrLn res

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

int main(){
    int n,max; cin>>n>>max;
    int ans=1;
    for(int i=1; i<n; i++) {
        int h; cin>>h;
        if(max<=h) {
            ans++;
            max=h;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

void change(char *str){
	int len=strlen(str);
	int i;
	for(i=0;i<len;i++){
		if('a'<=str[i] && 'z'>=str[i]) str[i]-=32;
	}
}

int main(){
	char t[1000];
	char key[1000];
	char eot[]={"END_OF_TEXT"};
	int ans=0;
	
	scanf("%s",key);
	change(key);
	
	while(1){
		scanf("%s",t);
		if(strcmp(t,eot)==0) break;
		change(t);
		if(strcmp(t,key)==0) ans++;
	}
	printf("%d\n",ans);
}
	


Measured memory_bytes: 2080
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <map>
using namespace std;
typedef long long lint;

int main() {
    lint n, k;
    cin>>n>>k;
    lint r=n%k;
    lint ans=min(r,k-r);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int N,answer;
    char S[51];
    
    answer=0;
    scanf("%d",&N);
    scanf("%s",&S);
    for(int i=0;i<N-2;i++){
        
        if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
            answer++;
        }
        
    }

    printf("%d\n",answer);

   
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl0

ll modpow(ll x, ll y, ll m){
    if(y==0) return 1;
    ll res = modpow(x,y/2,m);
    return res * res % m * (y&1 ? x : 1) % m;
}

int h,w,n,k;

int ask(int a, int b, int c, int d){
    printf("? %d %d %d %d\n", a, b, c-1, d-1);
    fflush(stdout);
    int p;
    cin >> p;
    return p;
}

int ans[50][50];

void solve(int i1, int j1, int i2, int j2, int n){
    int h = i2 - i1;
    int w = j2 - j1;
    if(n == 0 || n == h*w){
        for(int i = i1; i < i2; ++i){
            for(int j = j1; j < j2; ++j){
                ans[i][j] = n == 0 ? 0 : 1;
            }
        }
    } else {
        if(h > w){
            int x = ask(i1, j1, i1 + h/2, j2);
            solve(i1, j1, i1 + h/2, j2, x);
            solve(i1 + h/2, j1, i2, j2, n - x);
        } else {
            int x = ask(i1, j1, i2, j1 + w/2);
            solve(i1, j1, i2, j1 + w/2, x);
            solve(i1, j1 + w/2, i2, j2, n - x);
        }
    }
}

int main(){
    cin >> h >> w >> n >> k;
    memset(ans, -1, sizeof ans);
    solve(0, 0, h, w, n);

    // rep(i,h){
    //     rep(j,w){
    //         cerr << ans[i][j];
    //     }
    //     cerr << endl;
    // }

    ll sigma = 0;
    rep(i,h)rep(j,w){
        sigma += ans[i][j] * modpow(2, i*w + j, k);
        sigma %= k;
    }
    cout << "! " << sigma << endl;
}


Measured memory_bytes: 720
import sys
input = sys.stdin.readline

N = int(input())
L = [[int(v) for v in input().split()] for _ in range(N - 1)]

for i in range(N - 1):
    time = L[i][0] + L[i][1]
    
    for j in range(i + 1, N - 1):
        time = max(time, L[j][1])
        t = time - L[j][1]
        if t % L[j][2] == 0:
            time += L[j][0]
        else:
            time += L[j][0] + (L[j][2] - t % L[j][2])
        
    print(time)

print(0)

Measured memory_bytes: 3188
n = int(input())
list = [0]*n
if n ==1:
  m = 1
else:
  m = int((n-2)**0.5)
for i in range(1, m):
  for j in range(i, m):
    for k in range(j, m):
      if i*i + j*j + k*k + i*j + j*k + k*i <= n:
        if i==j and j == k:
          list[i*i + j*j + k*k + i*j + j*k + k*i-1] += 1
        elif i == j or j == k:
          list[i*i + j*j + k*k + i*j + j*k + k*i-1] += 3
        else:
          list[i*i + j*j + k*k + i*j + j*k + k*i-1] += 6
      else:
        break
for i in range(n):
  print(list[i])

Measured memory_bytes: 9436
S = raw_input()
T = raw_input()

s_c_list = []
t_c_list = []

new_S = ""
new_T = ""

for i in range(len(S)):
    if not S[i] in s_c_list:
        new_S+=str(len(s_c_list))
        s_c_list.append(S[i])
    else:
        new_S+=str(s_c_list.index(S[i]))
    if not T[i] in t_c_list:
        new_T+=str(len(t_c_list))
        t_c_list.append(T[i])
    else:
        new_T+=str(t_c_list.index(T[i]))

if new_S==new_T:
    print "Yes"
else:
    print "No"

Measured memory_bytes: 10236
N = int(input())
L = list(map(int, input().split()))

L.sort()
MAX = L[-1]
num = [0 for _ in range(MAX+1)]
index = 0
for l in L:
    if index == l:
        num[index] += 1
    else:
        num[l] += 1
        for i in range(index+1, l+1):
            num[i] += num[i-1]
        index = l

ans = 0
# print(num)
for i in range(N):
    for j in range(i+1, N):
        # print("{0} and {1}".format(L[i], L[j]))
        max_rest = min(MAX, L[i]+L[j]-1)
        # print(max_rest)
        # print(max(0, max_rest - j - 1))
        ans += max(0, num[max_rest] - j - 1)
print(ans)

Measured memory_bytes: 3316
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll A, B, C;
  cin >> A >> B >> C;

  REP(i, 1, 1000) {
    if ((A * i) % B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }





int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    
    
    int a, b;
    cin >> a >> b;
    
    if ((ll)a * b <= 0) {
        cout << "Zero" << endl;
    } else if (a > 0) {
        cout << "Positive" << endl;
    } else {
        if ((b - a + 1) % 2) cout << "Negative" << endl;
        else cout << "Positive" << endl;
    }
    
}


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

int main(){
  int a, b, c; cin >> a >> b >> c;
  
  for(int i=1; i<b; i++) {
    if(a*i%b==c) {
      cout << "YES" << endl;
      return 0;
    }
  }

  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 3576
n, k = gets.split.map(&:to_i)
xx = gets.split.map(&:to_i)
if k == 0
    puts xx.reduce(:+)
else
    a = 0
    y = 1
    loop do
        break if k < (y << 1)
        y <<= 1
    end
    loop do
        break if y <= 0
        if xx.count{ |x| x & y == 0 } > n / 2
            a += y if a + y <= k
        end
        y >>= 1
    end
    puts xx.map{ |x| x ^ a }.reduce(:+)
end



Measured memory_bytes: 10780
fun main() {
    val MOD = 1_000_000_007L
    var res = 0L
    var sumj = 0L

    val n = nextInt()
    val a = nextLongList()

    (n.minus(1) downTo 1).forEach { j ->
        sumj = sumj.plus(a[j]).rem(MOD)
        res = res.plus(sumj.times(a[j - 1]).rem(MOD)).rem(MOD)
    }

    println(res)
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

Measured memory_bytes: 64932