akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	int k;
	string s;
	cin >> k >> s;

	int n = s.size();
	string sd = s.substr(0, k);
	string ans = sd + "...";

	if (n <= k) dunk(s);
	else dunk(ans);

	return 0;
}


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

int main(){
  int a=0;
  string s;
  cin >> s;
  
  for(int i=0;i<2;i++){
    if(s.at(0) ==s.at(1)){
      a++;
      break;
    }
    if(s.at(i) == s.at(i+1) || s.at(i+1) == s.at(i+2)){
      a++;
      break;
    }
  }
  if(a == 0)
    cout << "Good" <<endl;
  else
    cout <<"Bad" <<endl;
}

Measured memory_bytes: 256
#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() {
    ll A, B;
    cin >> A >> B;

    if (A + B >= 10) cout << "error" << endl;
    else cout << A + B << endl;
}



Measured memory_bytes: 3576
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    ll N, A, B; cin >> N >> A >> B;
    vector<ll> H(N);
    for(int i=0; i<N; i++) cin >> H[i];

    ll ub = 1e10, lb = 0;
    while(ub - lb > 1) {
        ll mid = (ub + lb) / 2;

        ll cnt = 0;
        for(int i=0; i<N; i++) {
            if(H[i] - mid * B > 0) {
                ll a = H[i] - mid * B, b = A - B;
                cnt += (a + b - 1) / b;
            }
        }

        if(cnt <= mid) ub = mid;
        else lb = mid;
    }
    cout << ub << endl;
    return 0;
}


Measured memory_bytes: 1024
n,q = map(int,input().split())
s = "p" + str(input())
lr = [list(map(int,input().split())) for i in range(q)]
cnt = 0
ans = [0] * (n+1)
for i in range(1,n+1):
    if s[i-1] == "A" and s[i] == "C":
        cnt += 1
    ans[i] = cnt
for i in lr:
    print(ans[i[1]] - ans[i[0]])

Measured memory_bytes: 30688
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
void solve(){
    ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
    int n,k;
    cin>>n>>k;
    vector<int>h(n);
    for(int i=0;i<n;i++) cin>>h[i];
    ll dp[n];
    for(int i=0;i<n;i++) dp[i]=INT_MAX;
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
        for(int j=1;j<=min(k,i);j++){
            dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));
        }
    }
    cout<<dp[n-1];

}
int main(){
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
int main(void){
	int W, H, x, y, r;
	scanf("%d%d%d%d%d\n", &W, &H, &x, &y, &r);
	if (W >=x + r&&x - r>=0 && H >= y + r&&y - r >=0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> dct;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const ll mod = 1e9 + 7;
const ll inf = ll(1e18);
const double PI = acos(-1);

ll modexp(ll x,ll n,ll md){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%md,n/2,md);
    return (x*modexp((x*x)%md,n/2,md))%md;
}

int main(){
    fastio;
    //clock_t tm = clock();
    ll n,x=0,k;
    cin>>n>>k;
    vl a(n);
    f(i,0,n)cin>>a[i];
    sort(all(a),greater<ll>());
    f(i,k,n)x+=a[i];
    cout<<x<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    set<int> graph[10];
    for(int i=0;i<m;++i){
        int a, b;
        cin >> a >> b;
        graph[a].insert(b);
        graph[b].insert(a);
    }
    vector<int> v;
    for(int i=1;i<=n;++i)v.push_back(i);
    int ans = 0;
    do{
        if(v[0] != 1)continue;
        int cnt = 0;
        for(int i=0;i<n-1;++i){
            if(graph[v[i]].count(v[i+1]))cnt++;
        }
        if(cnt == n - 1)ans++;
    }while(next_permutation(v.begin(), v.end()));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		if (M < N) { var t = M; M = N; N = t;}
		
		if(M == N){
			Console.WriteLine( (((FactorialMod(N) * FactorialMod(M) ) % mod) * 2  ) % mod);
			return; 
		}
		if(M == N + 1){
			Console.WriteLine( (((FactorialMod(N) * FactorialMod(M) ) % mod) * 1  ) % mod);
			return; 
		}
		Console.WriteLine(0);
		
	}
	long N,M;
	public Sol(){
		var d = rla();
		N = d[0]; M = d[1];
	}
	
	const long mod = (long) 1e9 + 7;
	long ModPow(long n,long k){
		
		if(k==0)return 1;
		if(n==0)return 0;
		long ret=1;
		long x=n;
		while(k>0){
			if((k&1)==1){ret*=x;ret%=mod;}
			
			x*=x;x%=mod;
			k>>=1;
		}
		return ret;
		
	}
	long[] FM = new long[200010];
	long FactorialMod(long n){
		
		if(FM[(int)n]!=0)return FM[(int)n];

		if(n<2)return FM[(int)n] = 1;
		long ret = n * FactorialMod(n-1);
		ret %= mod;
		return FM[(int)n] = ret;
	}
	
	
	

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 16352
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,sum1,sum2,sum3,sum4,tot;
char a[200];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		if(a[i]=='P')sum1=1;
		if(a[i]=='W')sum2=1;
		if(a[i]=='G')sum3=1;
		if(a[i]=='Y')sum4=1;
	}
	tot=sum1+sum2+sum3+sum4;
	if(tot==3)cout<<"Three";
	if(tot==4)cout<<"Four";
}

Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split(' ')))

result = 0
for i in range(1, len(p) - 1):
    if p[i - 1] < p[i] < p[i + 1] or p[i + 1] < p[i] < p[i - 1]:
        result += 1

print(result)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

string s;
long long x;

int main(){
	cin >> s;
	cin >> x;
	long long t1 = 0, t2 = 0;
	int last_sign = 0;
	for (int i=0;i<s.length();i+=2){
		if (last_sign){
			if (t1*(s[i]-'0') <= x)
				t1 = t1*(s[i]-'0');
		}else t1 += s[i]-'0';
		if (i+1 != s.length() and s[i+1] == '+') last_sign = 0;
		else last_sign = 1;
	}
	long long current_multiple = 1;
	for (int i=0;i<s.length();i++){
		if (s[i] == '+'){
			t2 += current_multiple;
			current_multiple = 1;
		} else if (s[i] != '*'){
			if (s[i]=='0' or current_multiple <= x)
				current_multiple *= s[i]-'0';
		}
	}
	t2+=current_multiple;
	if (t1 == x and t2!=x){
		cout << "L";
	}
	else if (t1!=x and t2==x){
		cout << "M";
	}
	else if (t1 == x and t2 == x){
		cout << "U";
	}
	else cout << "I";
	cout << "\n";
}

Measured memory_bytes: 3224
var input = require('fs').readFileSync('/dev/stdin', 'utf8');

var lines = (input.trim()).split(/\n/g);
var n = +lines[0].split(' ')[0];
var m = +lines[0].split(' ')[1];

var A = lines.slice(1, n + 1);
var b = lines.slice(n + 1, n + m + 1);

var ans;
for (var i = 0; i < n; i++) {
    ans = 0;
    for (var j = 0; j < m; j++) {
        ans += A[i].split(' ')[j] * b[j];
    }
    console.log(ans);
}

Measured memory_bytes: 18576
a=int(input())
n,m=map(int,input().split())

if a==1:
    print('OK')
else:
    c=0
    b=m-n
    for i in range(b+1):
        if (m-i)%a==0:
            c+=1
            break

    if c==0:
        print('NG')
    else:
        print('OK')


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

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

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

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;
using str = string;

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

long int M = 1e+9+7;
int inf = 1e+9;

int n;
int ten7 = 1e7;
ll solve(){
    ll ans=0;
    vl sc(n+1,1);
    ssrep(i,2,n){
        for(int j=i; j<=n; j+=i){
            sc[j]++;
        }
    }

    for(ll i=1; i <= n; i++){
        ans += sc[i] * i;
    }
    return ans;
}

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

    while(cin >> n){
        cout << solve() << endl;
        //cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 81336
from collections import deque
n, q = map(int, input().split())
f = lambda a, b: (a, int(b))
dq = deque(f(*input().split()) for _ in range(n))
ans = 0
li = []
while dq:
    s, t = dq.popleft()
    if t <= q:
        ans += t
        li.append(s + " " + str(ans))
    else:
        ans += q
        dq.append((s, t - q))
print(*li, sep="\n")



Measured memory_bytes: 13388
import math

l = [int(input()) for i in range(5)]
c = [l[i] % 10 for i in range(5)]
index = 0
minimum = 10
for i in range(5):
    if c[i] != 0 and c[i] < minimum:
        minimum = c[i]
        index = i
a = [10 * math.ceil(l[i] / 10) for i in range(5)]
ans = sum(a) - a[index] + l[index]
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, M;
    cin >> N;
    vector<string> blue(N);
    for (int i = 0; i < N; i++){
        cin >> blue[i];
    }
    cin >> M;
    vector<string> red(M);
    for (int i = 0; i < M; i++){
        cin >> red[i];
    }

    int ans = 0;
    int b_num, r_num;
    int money;
    for (int i = 0; i < N; i++){
        b_num = count(blue.begin(), blue.end(), blue[i]);
        r_num = count(red.begin(), red.end(), blue[i]);
        money = b_num - r_num;
        ans = max(ans, money);
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#pragma 03
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
typedef pair<int,int> ii ;
typedef vector<int> vi ;

#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ll long long
#define rep(i,a,n) for(int i = a ; i <= n ; i++ )
#define REP(i,a,n) for(int i = n ; i >= a ; i-- )
#define fi first 
#define se second
#define int ll 
const int N = 1e5+1 ;
const int mod = 1e9+7 ;

int n,m,t,vis[N] ; 
ll h[N] ; 
vector<vector<pair<int,ll>>> G ; 
void dfs(int u , int fa ) {
	vis[u] = 1 ; 
	for( auto p : G[u] ) {
		int v = p.fi , w = p.se ; 
		if (v==fa) continue ; 
		else if (vis[v]==1) {
			if ( h[u]+w != h[v] ) {
				cout << "No" ; 
				exit(0) ; 
			}
		}
		else if (vis[v]==0) {
			h[v] = h[u]+w ; 
			dfs(v,u) ; 
		}
	}
}
signed main() {
	//freopen("BIGNUM.inp","r",stdin);
	//freopen("BIGNUM.out","w",stdout);
	int u,v,w;  
	cin >> n >> m ; 
	G.resize(n+1) ; 
	rep(i,1,m) {
		cin >> u >> v >> w ; 
		G[u].push_back(ii(v,w)) ; 
		G[v].push_back(ii(u,-w)) ; 
	}
	rep(i,1,n) {
		if(!vis[i]) dfs(i,0) ; 
	}
	cout << "Yes" ;  
}



Measured memory_bytes: 21052
A = int(input())
B = int(input())
C = int(input())
X = int(input())
pattern = 0

for i in range(A+1):
    for j in range(B+1):
        goukei = 500*i+100*j
        if 0 <= (X-goukei)/50 <= C:
            pattern+=1
print(pattern)

Measured memory_bytes: 40176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()


int main(){
  ll N,M;cin>>N>>M;
  vll A(N);rep(i,N)cin>>A[i];
  vll cumsum(N+1,0);
  cumsum[0]=0;
  rep(i,N){
    cumsum[i+1]=cumsum[i]+A[i];
  }
  map<int,int> m;
  rep(i,N+1){
    m[cumsum[i]%M]++;
  }
  ll ans=0;
  for(auto& x:m){
    ans += ll(x.second)*ll(x.second-1)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4736
n=int(input())
a=list(map(int,input().split()))
z=[0]
p=0
b=[0]
for x in a:
  b.append(x)
b.append(0)
for i in range(n+1):
  z.append(z[i]+abs(b[i+1]-b[i]))
for i in range(1,n+1):
  print(z[i-1]+z[n+1]-z[i+1]+abs(b[i+1]-b[i-1]))

Measured memory_bytes: 13920
# coding: utf-8

CAKE = 4
DONUT = 7
UPPER_LIMIT = 100
flg = False

n = int(input())

for i in range(UPPER_LIMIT // CAKE + 1):
    if CAKE * i > n:
        break
    
    if (n - CAKE * i) % 7 == 0:
        flg = True
        break

print('Yes' if flg else 'No')


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

int main(){
    int x, y;
    cin >> x >> y;
    for(int i = 0; i <= y/2; i++){
        int z = 2*i;
        if(y-z >= 0 && (y-z)%4==0 && (y-z)/4+i==x){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<vector>
#include<algorithm>

int bubblesort(int n, std::vector<int> &a){
    int number_of_swap = 0;
    
    for(int i = 0; i < n; i++){
        for(int j = n-1; j >= i+1; j--){
            if(a[j-1] > a[j]) {
                std::swap(a[j-1], a[j]);
                number_of_swap++;
            }
        }
    }
    
    return number_of_swap;
}

int main(){
    int n;
    std::cin >> n;
    
    std::vector<int> a(n);
    for(int i = 0; i < n; i++) std::cin >> a[i];
    
    int number_of_swap = bubblesort(n, a);
    
    for(int i = 0; i < n; i++){
        if(i) std::cout << " ";
        std::cout << a[i];
    }
    std::cout << std::endl;
    
    std::cout << number_of_swap << std::endl;
    return 0;
}




Measured memory_bytes: 3080
import java.math.BigDecimal;
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        long T = sc.nextLong();

        long currentStart = sc.nextLong();
        long currentEnd = currentStart + T;
        long sum = 0;
        for (int i = 1; i < N; i++) {
            long t = sc.nextLong();

            if (t <= currentEnd) {
                currentEnd = t + T;
            } else {
                sum += currentEnd - currentStart;
                currentStart = t;
                currentEnd = t + T;
            }
        }
        sum += currentEnd - currentStart;
        System.out.println(sum);
    }
}

Measured memory_bytes: 62076
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
#define clr(a) memset(a,0,sizeof(a))
#define umap unordered_map
#define uset unordered_set
#define fr first
#define sc second
#define pb push_back
#define M int(1e9+7)
#define endl '\n'

using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;


int main(){
	fast_io; cout_precision;
	int n;	cin >> n;
  int count=0;
  int x;	cin >> x;
  for(int i=1; i<=n; i++){
	int y;	cin >> y;	if(y>=x)	count++;
  }
	cout<<count;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+13;
int a[maxn];
int main()
{
   int n;
   ll ans=0;
   scanf("%d",&n);
   for(int i=1;i<=n;i++) scanf("%d",&a[i]);
   sort(a+1,a+n+1,greater<int>());
   int now=n-2;
   int t=2;
   ans+=1ll*a[1];
   if(n==2)
   {
   	return printf("%d",ans),0;
   }
   while(now)
   {
   	if(now==1)
	   {
	   	ans+=1ll*a[t];
	   	break;
		}
	ans+=2*1ll*a[t++];
	now-=2;
   }
   printf("%lld",ans);
}

Measured memory_bytes: 4588
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const ll INF = 1LL<<60;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vi x(n);
    rep(i, n) cin >> x[i];
    if (k == 1) {
        cout << abs(x[0]) << endl;
        return 0;
    }
    ll ans = INF;
    rep(i, n-k+1) {
        ll sx = x[i];
        ll fx = x[i+k-1];
        if (sx >= 0 && fx >= 0) {
            chmin(ans, fx);
        } else if (sx <= 0 && fx <= 0) {
            chmin(ans, -sx);
        } else {
            chmin(ans, fx - sx + min(abs(sx), abs(fx)));
        }
    }
    cout << ans << endl;
}

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

bool box[100010];
int cou[100010];
int n;
int m;

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

	fill(box,box + 100010,false);
	fill(cou,cou + 100010,1);
	box[1] = true;

	for(int i = 0;i < m;i++)
	{
		int x,y;
		cin >> x >> y;
		cou[y]++;
		cou[x]--;
		if(box[x])
		{
			box[y] = true;
			if(cou[x] == 0)
			{
				box[x] = false;
			}
		}

	}

	int result = 0;

	for(int i = 1;i <= n;i++)
	{

		if(box[i]) result += 1;
	}

	cout << result << endl;
}




Measured memory_bytes: 768
/*
g++ -std=c++14 C.cpp && ./a.out <<< "3
1
2 1
1
1 1
1
2 0"
*/

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

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

// Source: https://codeforces.com/blog/entry/62393
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int n; cin >> n;
    vector<vector<int>> Hon(n);
    vector<vector<int>> Unk(n);

    rep(i, 0, n) {
        int a;
        cin >> a;
        rep(j, 0, a) {
            int x, y; cin >> x >> y;
            x--;
            if (y == 1) Hon[i].push_back(x);
            else Unk[i].push_back(x);
        }
    }

    int ans = 0;

    for (int b = 0; b < (1 << n); b++) {
// printf("b = %d\n", b);

        vector<bool> True(n, false);
        int cnt = 0;
        rep(i, 0, n) {
            if ((b & (1 << i)) != 0) {
                True[i] = true;
                cnt++;
            }
        }

        bool ok = true;
        rep(i, 0, n)
            if (True[i]) {
                trav(h, Hon[i])
                    if (!True[h]) {
                        ok = false;
                        break;
                    }
                trav(h, Unk[i])
                    if (True[h]) {
                        ok = false;
                        break;
                    }
            }

        if (ok) {
// printf("yay cnt = %d\n", cnt);
            ans = max(ans, cnt);
        }
    }

    cout << ans << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  int sum = 0;
  vector<int> A(N);
  for (auto&& e : A) {
    cin >> e;
    sum += e;
  }
  vector<int> D;
  for (int i = 1; i * i < sum + 1; i++) {
    if (sum % i == 0) {
      D.emplace_back(i);
      D.emplace_back(sum / i);
    }
  }
  int res = 0;
  for (int d : D) {
    vector<int> R;
    for (const auto& e : A) {
      R.emplace_back(e % d);
    }
    sort(R.begin(), R.end());
    vector<int64_t> ACC = {0}, BCC = {0};
    for (const auto& e : R) {
      ACC.emplace_back(ACC.back() + e);
      BCC.emplace_back(BCC.back() + ((2 * d - e) % d));
    }
    for (int i = 0; i < N + 1; i++) {
      if (ACC[i] == BCC.back() - BCC[i] && ACC[i] <= K) {
        res = max(res, d);
      }
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 3700
#include <cstdio>
#include <algorithm>

#define MAX_N 100010

using namespace std;

int main() {
    int n, k;
    scanf("%d %d\n", &n, &k);
    int j = 0, ans = 0, change[MAX_N];
    char prev = '0';
    for (int i=0; i<n; i++) {
        char c;
        scanf("%c", &c);
        if (c != prev) {
            prev = c;
            change[j] = i;
            j++;
        }
        if (c == '1')
            ans = max(i+1 - (j>=2*k+1 ? change[j-2*k-1] : 0), ans);
        else if (k > 0)
            ans = max(i+1 - (j>=2*k ? change[j-2*k] : 0), ans);
    }
    printf("%d\n", ans);
    return 0;
}




Measured memory_bytes: 512
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	template<class T>constexpr T pow(T val, std::uint64_t p)
	{
		auto ret = T(1);
		for (auto i : boost::irange(0, 63))
		{
			if (p & (1ULL << i))
			{
				ret *= val;
			}
			val *= val;
		}
		return ret;
	}
	template<std::uint64_t Mod>class modnum :
		private boost::addable<modnum<Mod>>,
		private boost::subtractable<modnum<Mod>>,
		private boost::multipliable<modnum<Mod>>,
		private boost::dividable<modnum<Mod>>
	{
		std::uint64_t val;
		void clamp()
		{
			val %= Mod;
		}
	public:
		modnum() = default;
		modnum(std::int64_t v) :val()
		{
			if (v < 0)
			{
				v += (std::abs(v) / Mod + 1) * Mod;
			}
			val = v;
			clamp();
		}
		modnum(std::uint64_t v) :val(v)
		{
			clamp();
		}
		modnum(std::int32_t v) :modnum(static_cast<std::int64_t>(v))
		{

		}
		modnum(std::uint32_t v) :modnum(static_cast<std::uint64_t>(v))
		{

		}
		friend std::ostream& operator<<(std::ostream& os, modnum const& num)
		{
			return os << num.val;
		}
		auto& operator+=(modnum const& rhs)
		{
			val += rhs.val;
			clamp();
			return *this;
		}
		auto& operator-=(modnum const& rhs)
		{
			val += Mod - rhs.val;
			clamp();
			return *this;
		}
		auto& operator*=(modnum const& rhs)
		{
			val *= rhs.val;
			clamp();
			return *this;
		}
		auto& operator/=(modnum const& rhs)
		{
			val *= pow(rhs, Mod - 2).val;
			clamp();
			return *this;
		}
		auto const& operator*()const
		{
			return val;
		}
	};
}
using mod_t = lib::modnum<1000000007>;

void Main()
{
	mod_t result = 1;
	int r = 0, g = 0, b = 0;
	int N;
	std::cin >> N;
	for (auto i : boost::irange(0, N))
	{
		int v;
		std::cin >> v;
		int c = 0;
		if (r == v)
		{
			++c;
		}
		if (g == v)
		{
			++c;
		}
		if (b == v)
		{
			++c;
		}
		result *= c;
		if (r == v)
		{
			++r;
		}
		else if (g == v)
		{
			++g;
		}
		else if (b == v)
		{
			++b;
		}
	}
	std::cout << result << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

long long gcd(long long a,long long b){
    while(b){
        swap(a%=b,b);
    }
    return a;
}
long long lcm(long long a,long long b){
    return a/gcd(a,b)*b;
}

signed main(){
    int a,b;
    cin>>a>>b;
    cout<<lcm(a,b)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (LL i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (LL i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

LL const MOD = 1e9+7;
LL const MaxSize = 3e5 + 5;
//LL const MOD = 998244353;

/*

#https://atcoder.jp/contests/abc147/tasks/abc147_d
#Xor Sum 4
"""
iterate over bits
1. calculate how many bits we have on that position
2. for each 1, we need to add num 0s * num 1s * 2s
3. sum them up

1. python version gets TLE due to the IO
2. in c++ version, all needs to be LL
 */


LL N;
string S;

int main() {
        ios_base::sync_with_stdio(false);
        //freopen("/Users/georgeli/A_1.in", "r", stdin);

        cin >> N >> S;

        int ans = 0;
        LP(fd, 0, 10){
        	int fi = -1;
        	LP(i, 0, N){
        		if(S[i] - '0' == fd){
        			fi = i;
        			break;
        		}
        	}

        	if(fi < 0)
        		continue;

        	LP(sd, 0, 10){
        		int si = -1;
        		LP(i, fi+ 1, N){
        			if(S[i] - '0' == sd){
        				si = i;
        				break;
        			}
        		}
        		if(si < 0)
        			continue;

        		LP(td, 0, 10){
        			LP(i, si + 1, N){
        				if(S[i] - '0' == td)
        				{
        					ans++;
        					break;
        				}

        			}
        		}
        	}
        }

        cout << ans;
        return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

#pragma warning(disable:4996)

#define H_MAX 1000
#define W_MAX 1000

int masu[H_MAX][W_MAX];
int newb[2][H_MAX * W_MAX];

int dir[4][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };

int main(void) {
	int h, w;
	int sum = 0;


	scanf("%d %d", &h, &w);
	
	char s[1024];

	int bcnt[] = { 0, 0 };
	int flip = 0;
	for (int j = 0; j < h; ++j) {
		scanf("%s", &s[0]);
		for (int i = 0; i < w; ++i) {
			masu[j][i] = s[i] == '.' ? 0 : 1;
			if (masu[j][i] == 1) {
				newb[flip][bcnt[flip]++] = j * w + i;
			}
		}
	}
	while (true) {
		int next = (flip + 1) % 2;
		bcnt[next] = 0;
		for (int i = 0; i < bcnt[flip]; ++i) {
			int ox = newb[flip][i] % w;
			int oy = newb[flip][i] / w;
			for (int k = 0; k < 4; ++k) {
				int nx = ox + dir[k][0];
				int ny = oy + dir[k][1];
				if ((nx < 0) || (nx >= w)) continue;
				if ((ny < 0) || (ny >= h)) continue;
				if (masu[ny][nx] == 0) {
					newb[next][bcnt[next]++] = ny * w + nx;
					masu[ny][nx] = 1;
				}
			}
		}
		if (bcnt[next] == 0) break;
		++sum;

		flip = next;
		
	}

	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 11648
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    vector<double> a(n);
    
    for ( ll i = 0; i < n; i++ ) cin >> a[i];
    
    double ans = 0;
    for ( ll i = 0; i < n; i++ ) ans += 1/a[i];
    
    cout << setprecision(12) << 1/ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
#include <string.h>
#include <set>
using namespace std;

#define N 100005
#define mod 1000000007

int p[N];
int lmini[N],lmaxi[N];
int rmini[N],rmaxi[N];
bool hasLeft[N],hasRight[N];
void solve() {
  int n;scanf("%d ",&n);
  vector<pair<int,int> >in;
  for(int i=1;i<=n;++i) {
    scanf("%d ",&p[i]);
    in.push_back(make_pair(p[i],i));
  }
  sort(in.begin(),in.end());
  set<int> s;

  for(int i=n-1;i>=0;--i) {
    int ind = in[i].second;
    s.insert(ind);
    set<int>::iterator it = s.find(ind);
    if(it== s.begin()) {
      hasLeft[ind] = false;
      lmini[ind] = ind;
    } else {
      hasLeft[ind] = true;
      --it;
      lmini[ind] = ind - *it;
      if(it!=s.begin()) {
        --it;
        lmaxi[ind] = ind - *it;
      } else {
        lmaxi[ind] = ind;
      }
    }
    it = s.find(ind);
    ++it;
    if(it==s.end()) {
      hasRight[ind] = false;
      rmini[ind] = n+1 - ind;
    } else {
      hasRight[ind] =true;
      rmini[ind] = *it - ind;
      ++it;
      if(it==s.end()) {
        rmaxi[ind] = n+1 - ind;
      } else {
        rmaxi[ind] = *it - ind;
      }
    }
  }
  long long ret = 0;
  for(int i=1;i<=n;++i) {
    if(p[i]==n) continue;
    long long tmp = 0;
    if(hasLeft[i]) {
      tmp = (long long)(lmaxi[i]-lmini[i])*rmini[i];
    }
    if(hasRight[i]) {
      tmp += (long long)(rmaxi[i] - rmini[i])*lmini[i];
    }
    tmp *= p[i];
    ret += tmp;
  }
  printf("%lld\n", ret);
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


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

int main(){
  int n,L;
  cin >> n >> L;
  vector<int> a(n);
  rep(i,n){
    a[i] = L+i;
  }
  int goukei = 0;
  rep(i,n){
    goukei += a[i];
  }
  int ans = 1e9;
  rep(i,n){
    int goukei1 = goukei - a[i];
    if(abs(goukei-goukei1)<abs(goukei-ans)) ans = goukei1;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define TREE_SIZE 512
#define NIL -2e9+1

using namespace std;

int main()
{
    int h, tree[TREE_SIZE];
    cin >> h;

    for(int i = 0; i < TREE_SIZE; i++){
        tree[i] = NIL;
    }

    for(int i = 1; i <= h; i++){
        cin >> tree[i];
    }

    for(int i = 1; i <= h; i++){
        printf("node %d: ", i);
        printf("key = %d, ", tree[i]);
        if(i/2 >= 1){ printf("parent key = %d, ", tree[i/2]); }
        if(tree[2*i] != NIL){ printf("left key = %d, ", tree[2*i]); }
        if(tree[2*i+1] != NIL){ printf("right key = %d, ", tree[2*i+1]); }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 3208
/*
解説として拝見した記事
http://drken1215.hatenablog.com/entry/2018/07/21/224200
https://creep06.hatenablog.com/entry/2018/07/21/232414
http://tutuz.hateblo.jp/entry/2018/07/22/084326
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

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

int main(){
    int N,M,ans=0;
    cin>>N>>M;
    vector<pair<int,int> > AB(M);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        a--,b--;
        AB[i]=make_pair(b,a);
    }
    sort(AB.begin(),AB.end());
    int end=0;//右端がどこかをメモる
    for(int i=0;i<M;i++){
        if(AB[i].second>=end)ans++,end=AB[i].first;
        //橋を無くす島の区間で右端の位置と、AB[i]のaを比較して、aが右端よりも左にあればそれは区間が被っていることと同義である。
        //そのため、end(橋をなくす区間の右端)よりも、右側に橋をなくさねばならない区間が来たら二つを同じ橋を無くして要望を満たすことはできない。
    }
    cout<<ans<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 1024
s = input()
arr = [0]*len(s)
tmp_r = 0
tmp_l = 0
flg = -1
for i in range(len(s)-1):
  if s[i:i+2] == 'RL':
    if flg != -1:
      arr[flg] += (tmp_l + 1)//2
      arr[flg+1] += tmp_l//2
      tmp_l = 0
    arr[i] = tmp_r//2 + 1
    arr[i+1] = (tmp_r+1)//2 + 1
    tmp_r = 0
    flg = i
  elif s[i] == 'R':
    tmp_r += 1
  elif s[i] == 'L':
    if s[i-1] == 'L':
      tmp_l += 1
if s[-2] == 'L':
  tmp_l += 1
arr[flg] += (tmp_l+1)//2
arr[flg+1] += tmp_l//2
print(*arr)

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

int main() {
	string s,t;
	cin>>s>>t;
	int m=s.length(),n=t.length();
	int dp[m+1][n+1];
	for(int i=0;i<=m;i++)
	{
	    for(int j=0;j<=n;j++)
	    {
	        if(i==0 || j==0)
	            dp[i][j]=0;
	        else if(s[i-1]==t[j-1])
	            dp[i][j]=1+dp[i-1][j-1];
	       else
	            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	    }
	}
	int index=dp[m][n];
	char res[index+1];
	res[index]='\0';
	index--;
	int i=m,j=n;
	while(i>0 && j>0)
	{
	    if(s[i-1]==t[j-1])
	    {
	        res[index]=s[i-1];
	        index--;
	        i--;
	        j--;
	    }
	    else if(dp[i-1][j]>dp[i][j-1])
	        i--;
	   else
	        j--;
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 38800
function main(input) {
  input = input.trim();
  const n = Number(input);
  let result = 0;
  for (let i = 1; i <= n; i++) {
    if (("" + i).length%2 === 1) result++;
  }
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++){
    s.at(i) += n;
    if (s.at(i) > 90) s.at(i) -= 26;
  }
  cout << s << endl;
  return 0;
}

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

  int n,a,b,c,x,i,d=0;
  int y[101]={};

  for(;;){
    scanf("%d %d %d %d %d",&n,&a,&b,&c,&x);
    if(n==0&&a==0&&b==0&&c==0&&x==0){
      break;
    }
    
    for(i=1;i<=n;i++){
      scanf("%d",&y[i]);
    }


    i=1;
    for(;;){
 
      if(x==y[i]){
	i++;
      }
      if(i==(n+1)){
	break;
      }

      x=(a*x+b)%c;
      d++;
      if(d>10000){
	break;
      }
    }
    if(d<=10000){
    printf("%d\n",d);
    }
    else {
      printf("-1\n");
    }
    d=0;
    for(i=1;i<=100;i++){
      y[i]=0;
    }
  }
  return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/
 
 
 
 




int N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;

    int ans = 1;
    int x = 1, y = 1;
    rep(i, 0, 30) {
        x = x * 2 + 1; y++;
        if (x <= N) ans = y;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3220
// D - Pair Cards.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <numeric>


using lolo=long long;
using namespace std;
using vec=vector<lolo>;
using vvec=vector<vec>;
using vecb=vector<bool>;
#define FOR(i,n) for (lolo i=0; i<n; ++i)
#define FORN(i,a,b) for (lolo i=a; i<b; ++i)
#define REV(i,a,b) for (lolo i=a; i>b; --i)
#define ALL(x) x.begin(), x.end()

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

int main()
{
	lolo N, M;
	cin >> N >> M;
	vec X(N);
	lolo mmax = 0;
	FOR(i, N) {
		cin >> X[i];
		chmax(mmax, X[i]);
	}

	vector< map<lolo, lolo> > POOL(M, map<lolo, lolo>{});
	//vec S(mmax + 1, 0);
	vec S(M, 0);
	
	FOR(i, N) {
		S[X[i] % M ] += 1;
		//POOL[X[i] % M].push_back(X[i]);
		POOL[X[i] % M][X[i]] += 1;
	}

	//int i = 1; int j = (M - i) % M;
	int i = 0; int j = 0;
	lolo ans = 0;
	//ans += S[0] / 2;
	while (i <= j) {
		// i == j になるのは、Mが偶数の時
		if (i != j) {
			ans += min(S[i], S[j]);
			
			lolo ones = 0;
			lolo pairs = 0;
			if (S[i] > S[j]) {
				for (auto mv : POOL[ i % M]) {
					ones += (mv.second % 2 == 1) ? 1 : 0;
					pairs += mv.second / 2;
				}
			}
			else {
				for (auto mv : POOL[ j % M]) {
					ones += (mv.second % 2 == 1) ? 1 : 0;
					pairs += mv.second / 2;
				}
			}

			lolo rem = min(S[i], S[j]) - ones;
			if (rem > 0) {// ones が足りないとき
				pairs -= (rem + 1) / 2;
			}
			ans += pairs ;

			
		}
		else if ( i == j and i == 0) {
			lolo ones = 0, pairs = 0;
			for (auto mv : POOL[j  % M]) {
				ones += (mv.second % 2 == 1) ? 1 : 0;
				pairs += mv.second / 2;
			}
			//lolo rem = max(S[i], S[j]) - min(S[i], S[j]);
			//ans += pairs / 2;
			ans += S[i] / 2;
		}
		else {
			//lolo rem = max(S[i], S[j]) - min(S[i], S[j]);
			ans += S[i] / 2;

		}
		
		i += 1;
		(j = (j + M) - 1) %= M;
	}
	cout << ans << endl;

}



Measured memory_bytes: 12800
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int A = scn.nextInt();
		int B = scn.nextInt();
		boolean ans = (A <10) && (0 < A) && (0 < B) && (B<10);

		System.out.println(ans?A*B:-1);
	}

}


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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	for (int N; cin >> N&&N;) {
		string m; cin >> m;
		vector<int> a(N), b(N); rep(i, 0, N) { cin >> a[i] >> b[i]; a[i]--, b[i]--; }
		rrep(i, 0, N) {
			int diff = abs(a[i] - b[i]);
			m[a[i]] = (m[a[i]] - 'a' + diff) % 26 + 'a';
			m[b[i]] = (m[b[i]] - 'a' + diff) % 26 + 'a';
			swap(m[a[i]], m[b[i]]);
		}
		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 2968
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (ll i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

int N;
int A[2000];

int main ()
{
    cin >> N;
    REP(i,N) cin >> A[i];

    bitset<4000010> inst;
    inst.set(0);

    REP(i,N) {
        bitset<4000010> inst_t = inst;
        inst_t <<= A[i];
        inst |= inst_t;
    }

    int sum = 0;
    REP(i,N) sum += A[i];
    sum = sum / 2 + sum % 2;

    REP(i,4000010) {
        if (inst[i] && sum <= i) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include  <cassert>
#include <fstream>
#include <codecvt>

using namespace std;
using ll = long long int;
using ullong = unsigned long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define int ll
const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };



signed main() {
	ios::sync_with_stdio(true);
	
	string s;
	cin >> s;
	int ans = 0;
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - i - 1]) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char x,y;
	scanf("%c %c",&x,&y);
	if((int)x<(int)y){
		printf("<\n");
	}else if((int)x>(int)y){
		printf(">\n");
	}else if((int)x==(int)y){
		printf("=");
	}
}

Measured memory_bytes: 128
//#include "pch.h"
//#include "stdafx.h"
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#include <cstring>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define INF				2e9
#define MOD				(1000 * 1000 * 1000 + 7)
#define MIN(a, b)		((a) < (b) ? a : b)
#define MAX(a, b)		((a) > (b) ? a : b)
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)		/* 奇数 */
#define IsEven(x)		(!IsOdd((x)))					/* 偶数 */
#define ArrayLength(x)	(sizeof(x) / sizeof(x[0]))
#define DWORD_MAX		(0xFFFFFFFF)

typedef short SWORD;
typedef unsigned short WORD;
typedef long SDWORD;
typedef unsigned long DWORD;
typedef long long int QWORD;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
QWORD w[100];
QWORD v[100];
QWORD dp[100 + 1][1000 * 100 + 1000 + 1];
int N, W;

/* メイン */
int main()
{
	cin >> N >> W;
	REP(x, N) cin >> w[x] >> v[x];
	REP(x, ArrayLength(dp)) REP(y, ArrayLength(dp[0])) dp[x][y] = -1;

	dp[0][0] = W;
	int i, j;
	for (i = 0; i < N; i++) {
		for (j = 0; j < ArrayLength(dp[0]); j++) {
			if (0 <= dp[i][j]) {
				dp[i + 1][j] = MAX(dp[i + 1][j], dp[i][j]);
				if (w[i] <= dp[i][j]) {
					dp[i + 1][j + v[i]] = MAX(dp[i + 1][j + v[i]], dp[i][j] - w[i]);
				}
			}
		}
	}

	for (j = ArrayLength(dp[0]) - 1; 0 <= j; j--) {
		if (0 <= dp[N][j]) {
			cout << j;
			break;
		}
	}

	cout << endl;
	return 0;
}



Measured memory_bytes: 80000
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  a=list(map(int,input().split()))
  l=[x+i for i in range(101)]
  s=[x-i for i in range(101)]
  m=min(len(l),min(s))
  mada=1
  k=0
  while mada:
    if s[k] not in a:
      ans=s[k]
      mada=0
      break
    elif l[k] not in a:
      ans=l[k]
      mada=0
      break
    else:
      k+=1
  print(ans)


Measured memory_bytes: 9204
n = int(input())
_s = input()
q = int(input())
query = [input() for _ in range(q)]

def bitsum(_bit, i):
    s = 0
    while i > 0:
        s += _bit[i]
        i -= i & (-i)
    return s

def bitadd(_bit, i, x):
    while i <= n:
        _bit[i] += x
        i += i & (-i)
    return _bit

al = [chr(ord('a') + i) for i in range(26)]
al_to_idx = dict()
for i in range(26):
    al_to_idx[al[i]] = i

s = list(_s)

# init
import math
n_ = int(math.log(n) / math.log(2)) + 1
bit = [[0] * (2 ** n_ + 1) for _ in range(26)]
for i in range(n):
    idx = al_to_idx[s[i]]
    bit[idx] = bitadd(bit[idx], i + 1, 1)
# print(bit)

for i in range(q):
    _query = query[i].split(' ')
    if _query[0] == '1':
        # decrement old
        idx = al_to_idx[s[int(_query[1]) - 1]]
        bit[idx] = bitadd(bit[idx], int(_query[1]), -1)

        s[int(_query[1]) - 1] = _query[2]
        # print(s)

        # increment
        idx = al_to_idx[_query[2]]
        bit[idx] = bitadd(bit[idx], int(_query[1]), 1)

    else:
        _ans = 0
        for idx in range(26):
            _bit = bit[idx]
            c = bitsum(_bit, int(_query[2])) - bitsum(_bit, int(_query[1]) - 1)
            if c != 0:
                _ans += 1
        print(_ans)


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

int main() {
	int s,w;
	cin>>s>>w;
	if(w>=s)cout<<"unsafe"<<endl;
	else cout<<"safe"<<endl;
}


Measured memory_bytes: 3636