akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

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

void printArray(int *A, int n) {
  rep(i, n) {
    std::cout << A[i];
    if (i == n - 1)
      std::cout << '\n';
    else
      std::cout << ' ';
  }
}

int cnt = 0;

void merge(int *A, int n, int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1 + 1], R[n2 + 1];

  for (int i = left; i < mid; ++i)
    L[i - left] = A[i];

  for (int i = mid; i < right; ++i)
    R[i - mid] = A[i];

  L[n1] = R[n2] = (1 << 30);

  int l = 0, r = 0;
  for (int i = left; i < right; ++i) {
    cnt++;
    if (L[l] < R[r]) {
      A[i] = L[l];
      l++;
    } else {
      A[i] = R[r];
      r++;
    }
  }
}

void mergeSort(int *A, int n, int left, int right) {
  if (right - left <= 1)
    return;

  int mid = (left + right) / 2;
  mergeSort(A, n, left, mid);
  mergeSort(A, n, mid, right);
  merge(A, n, left, mid, right);
}

int main() {
  int n;
  std::cin >> n;
  int S[n];
  rep(i, n) std::cin >> S[i];

  mergeSort(S, n, 0, n);
  printArray(S, n);
  std::cout << cnt << '\n';
  return 0;
}



Measured memory_bytes: 6980
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Math;
using static System.Console;
using static exMath;
using static exReadLine;

class Program
{
    static void Main(string[] args)
    {
        int a, b;
        intReadLine(out a, out b);
        WriteLine(a * b);
        //ReadLine();
    }
}

static class exReadLine
{
    public static void intReadLine(out int a)
    {
        a = int.Parse(ReadLine());
    }
    public static void intReadLine(out int a, out int b)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
    }
    public static void intReadLine(out int a, out int b, out int c)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
    }
    public static void intReadLine(out int a, out int b, out int c, out int d)
    {
        int[] input = ReadLine().Split().Select(int.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
        d = input[3];
    }

    public static void longReadLine(out long a)
    {
        a = long.Parse(ReadLine());
    }
    public static void longReadLine(out long a, out long b)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
    }
    public static void longReadLine(out long a, out long b, out long c)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
    }
    public static void longReadLine(out long a, out long b, out long c, out long d)
    {
        long[] input = ReadLine().Split().Select(long.Parse).ToArray();
        a = input[0];
        b = input[1];
        c = input[2];
        d = input[3];
    }
    
    public static void intArrayReadLine(out int[] a)
    {
        a = ReadLine().Split().Select(int.Parse).ToArray();
    }

    public static void longArrayReadLine(out long[] a)
    {
        a = ReadLine().Split().Select(long.Parse).ToArray();
    }

    public static void intListReadLine(out List<int> a)
    {
        a = ReadLine().Split().Select(int.Parse).ToList();
    }

    public static void longListReadLine(out List<long> a)
    {
        a = ReadLine().Split().Select(long.Parse).ToList();
    }
}

static class exMath
{
    // 最大公約数
    public static int Gcd(int a, int b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var r = a % b;
            a = b;
            b = r;
        }
        return a;
    }
    public static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

    // 最小公倍数
    public static long Lcm(int a, int b)
    {
        return BigMul(a, b) / Gcd(a, b);
    }
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }
}

Measured memory_bytes: 28136
#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define LOCAL 1

#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define dbg(...) cout<<#__VA_ARGS__ ": ["; for(auto e: __VA_ARGS__){cout<<e<<", ";} cout<<"]\n"
#define dbg1(...) cout<<#__VA_ARGS__ " "<< __VA_ARGS__ 
#else
#define dbg(...) 1;
#define dbg1(...) 1;
#endif

typedef long long ll;
typedef unsigned long long ull;
constexpr int R=5e6+69, INF=2e9+6969;

int qq;

int main()
{

		int n;
		scanf("%d", &n);
		
		printf("%d\n", (1000-n%1000)%1000);
		
	return 0;
}


Measured memory_bytes: 3792
N, M = map(int,input().split())

s = [0]*M
c = [0]*M
for i in range(M):
  s[i], c[i] = map(int,input().split())

flag = True
for i in range(M):
  if s[i] > N:
    flag = False
    break

flag2 = False

if flag is True:
  if N ==1:
    start = 0
  else:
    start = 10**(N-1)
  end = 10**N

  for n in range(start,end):
    flag3 = [0]*M

    for i in range(M):
      if str(n)[s[i]-1] == str(c[i]):
        flag3[i] = 1
    if sum(flag3) == M:
      num = n
      flag2 = True
      break
      
if flag2 is True:
  print(num)
else:
  print("-1")


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

int main(){
  char c11, c12, c13, c21, c22, c23;
  cin >> c11 >> c12 >> c13 >> c21 >> c22 >> c23;
  if(c11==c23 && c12==c22 && c13==c21){
    cout << "YES" << endl;
    return 0;
  }
  cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main(){
    char c;
    cin >> c;
    char ans = c + 1;
    cout << ans << endl;
}

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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  int num[n];
  REP(i,n) {
    cin >> num[i];
  }
  unordered_map<int, int> occur_in_even_of;
  unordered_map<int, int> occur_in_odd_of;
  REP(i,n) {
    if(i%2) {
      ++occur_in_odd_of[num[i]];
    } else {
      ++occur_in_even_of[num[i]];
    }
  }
  int mode_in_even = 0, second_mode_in_even = 0;
  int mode_in_odd = 0, second_mode_in_odd = 0;
  REPOBJ(itr, occur_in_even_of) {
    if(itr->second >= occur_in_even_of[mode_in_even]) {
      second_mode_in_even = mode_in_even;
      mode_in_even = itr->first;
      continue;
    }
    if(itr->second >= occur_in_even_of[second_mode_in_even]) {
      second_mode_in_even = itr->first;
    }
  }
  REPOBJ(itr, occur_in_odd_of) {
    if(itr->second >= occur_in_odd_of[mode_in_odd]) {
      second_mode_in_odd = mode_in_odd;
      mode_in_odd = itr->first;
      continue;
    }
    if(itr->second >= occur_in_odd_of[second_mode_in_odd]) {
      second_mode_in_odd = itr->first;
    }
  }
  if(mode_in_even != mode_in_odd) {
    cout << n - occur_in_even_of[mode_in_even] - occur_in_odd_of[mode_in_odd] << endl;
    return 0;
  }
  int ans = n - occur_in_even_of[mode_in_even] - occur_in_odd_of[second_mode_in_odd];
  int ans2 = n - occur_in_even_of[second_mode_in_even] - occur_in_odd_of[mode_in_odd];
  cout << min(ans, ans2) << endl;
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 5144
#include <cstdio>

int testcase_ends() {
  int N;
  scanf("%d", &N);
  if (N == 0) return 1;

  int res = 0;
  for (int i = 1; i < N; ++i) {
    int a = i;
    for (int j = i+1; j < N; ++j) {
      a += j;
      if (a >= N) break;
    }
    if (a == N) ++res;
  }
  printf("%d\n", res);
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2752
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N,A;cin>>N>>A;
    N%=500;
    if(N<=A){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


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

int main(){
	map<int,int> mp;
	int n;
	cin >> n;
	int a[n+1];
	for(int i=1; i<=n; i++){
		cin >> a[i];
		mp[a[i]]++;
	}
	map<int, int>::iterator it=mp.begin();
	
	int s=0;
	for( ;it!=mp.end(); it++){
		if((*it).second==(*it).first) continue;
		else if((*it).second>(*it).first) s+=(*it).second-(*it).first;
		else s+=(*it).second;
	} 
	cout << s;
	return 0;
}

Measured memory_bytes: 5120
//copied code
#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long
 
signed main(void)
{
	int n, k; cin >> n >> k;
	int p[5005], c[5005];
	reps (i, 1, n + 1) cin >> p[i];
	reps (i, 1, n + 1) cin >> c[i];
	int a[5005] = {0}, r[2][3000], rn = 0, rp;
	reps (i, 1, n + 1)
	{
		if (a[i]) continue;
		rp = i;
		r[1][rn] = 0;
		while (1)
		{
			r[1][rn]++;
			a[rp] = rn;
			r[0][rn] += c[rp];
			rp = p[rp];
			if (rp == i) break;
		}
		rn++;
	}
	rn--;
	//reps (i, 1, n + 1) cout << a[i];
	//cout << endl;
	int ans = -2000000000;
	reps (i, 1, n + 1)
	{
		int ans2 = 0, k2 = k;
		int tmp = k / r[1][a[i]] - 1;
		if (r[0][a[i]] > 0)
		{
			if (tmp > 0)
			{
				ans2 = r[0][a[i]] * tmp, k2 -= tmp * r[1][a[i]];
				if (ans2 > ans) ans = ans2;
			}
		}
		else
		{
			k2 = 5005;
		}
		int q = i;
		rep (j, k2)
		{
			q = p[q];
			ans2 += c[q];
			if (ans2 > ans) ans = ans2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3756
t = input().split()
n = int(t[0])
m = int(t[1])

low = 0
high = n
for i in range(0, m):
  tmp = input().split()
  if int(tmp[0]) > low:
    low = int(tmp[0])
  if int(tmp[1]) < high:
    high = int(tmp[1])

if (high-low)<0:
  num = 0
else:
  num = high-low+1
print(num)

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

typedef long long ll;
using namespace std;
 
int main (){
  int n,x = 0,ans = 0;
  string s;
  cin >> n >> s;

  rep(i,0,s.length()){
    if(s[i] == 'I'){
      x++;
    }
    if(s[i] == 'D'){
      x--;
    }
    ans = max(ans,x);
  }

  pout(ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ri register int
const long double PI=3.141592653589793238462643383279;
const int N=500005,M=998244353;
int n,i,m,s[N],d,j,head[100005],Next[200005],adj[200005],l,r,c,leng[200005],k;
long long lazy[N*4];
void modify(int i,int l,int r,int ll,int rr,long long y)
{
	if(l>=ll&&r<=rr)
	{
		lazy[i]=min(lazy[i],y);
		return;
	}
	int mid=l+r>>1;
	if(mid>=ll)
		modify(i<<1,l,mid,ll,rr,y);
	if(mid<rr)
		modify(i<<1|1,mid+1,r,ll,rr,y);
}
long long Query(int i,int l,int r,int x)
{
	if(l==r)
		return lazy[i];
	int mid=l+r>>1;
	if(mid>=x)
		return min(Query(i<<1,l,mid,x),lazy[i]);
	else
		return min(Query(i<<1|1,mid+1,r,x),lazy[i]);
}
void Push(int u,int v,int c)
{
	Next[++k]=head[u];
	head[u]=k;
	adj[k]=v;
	leng[k]=c;
}
int main()
{
	scanf("%d %d",&n,&m);
	for(i=0;i<N;++i)
		lazy[i]=100000000000000000ll;
	modify(1,1,n,1,1,0);
	for(i=1;i<=m;++i)
	{
		scanf("%d %d %d",&l,&r,&c);
		Push(l,r,c);
	}
	for(i=1;i<n;++i)
	{
		long long u=Query(1,1,n,i); 
		for(j=head[i];j!=0;j=Next[j])
			modify(1,1,n,i+1,adj[j],u+leng[j]);
	}
	long long u=Query(1,1,n,n);
	if(u>=100000000000000000ll)
		puts("-1");
	else
		cout<<u;
}


Measured memory_bytes: 8448
#include<stdio.h>

int main(){

int X;
scanf("%d",&X);

if (X < 100)
{
  puts("0");
}else if(X>=2000){
  puts("1");
}else{
  X%100 <= ((X%10000)/100)*5 ? puts("1") : puts("0");
}

return 0;

}

Measured memory_bytes: 1656
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define LONG_INF 1000000000000000
int wow[200000] = {};
int moduloed[200000] = {};
int used[200000] = {};
int main() {
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	for (int i = 0;i < n;++i) {
		int tmp;
		cin >> tmp;
		wow[tmp%m]++;
		used[tmp]++;
	}
	for (int i = 0;i < 110000;++i) {
		moduloed[i%m] += used[i] / 2;
	}
	int ans = 0;
	for (int i = 1;i < m;++i) {
		if (i != (m - i)) {
			int hoge = min(wow[i], wow[m - i]);
			ans += hoge;
			wow[i] -= hoge;
			wow[m - i] -= hoge;
			if (wow[i] == 0) {
				ans += min(wow[m - i] / 2, moduloed[m - i]);
			}
			else {
				ans += min(wow[i] / 2, moduloed[i]);
			}
			wow[m - i] = 0;
			wow[i] = 0;
			moduloed[m - i] = 0;
			moduloed[i] = 0;
		}
	}
	if (m % 2 == 0) {
		ans += wow[m / 2] / 2;
	}
	ans += wow[0] / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1408
from bisect import bisect
H,W=map(int,input().split())
S=[input() for i in range(H)]
sec_x=[[-1] for i in range(H)]
sec_y=[[-1] for i in range(W)]
for y in range(H):
  for x in range(W):
    if S[y][x]=="#": 
      sec_x[y].append(x)
  sec_x[y].append(W)
for x in range(W):
  for y in range(H):
    if S[y][x]=="#": 
      sec_y[x].append(y)
  sec_y[x].append(H)

ans=0
#print(sec_x)
#print(sec_y)
for y in range(H):
  l=1
  for x in range(W):
    if S[y][x]=="#":
      l+=1
    else:
      b=bisect(sec_y[x],y)
      #print(x,y,l,b,sec_x[y][l]-sec_x[y][l-1]+sec_y[x][b]-sec_y[x][b-1]-3)
      ans=max(ans,sec_x[y][l]-sec_x[y][l-1]+sec_y[x][b]-sec_y[x][b-1]-3)
print(ans)    
          
    

Measured memory_bytes: 125016
#include "bits/stdc++.h"

using namespace std;

int mp[400][400];
int vis[400];


int n, m;


int slove() {
    int cnt[350];
    memset(cnt, 0, sizeof(cnt));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (!vis[mp[i][j]]) {
                cnt[mp[i][j]]++;
                break;
            }
        }
    }
    int maxx = 0, pos = 0;
    for (int i = 1; i <= m; i++) {
        if (cnt[i] > maxx) {
            maxx = cnt[i];
            pos = i;
        }
    }
    return pos;
}

int b[500];

int main() {
    int n, m, c;
    cin >> n >> m >> c;
    int ans = 0;
    for (int i = 1; i <= m; i++) {
        cin >> b[i];
    }
    int temp, x;
    for (int i = 1; i <= n; i++) {
        temp = 0;
        for (int j = 1; j <= m; j++) {
            cin >> x;
            temp += x * b[j];
        }
        if (temp + c > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define MOD 1000000007
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//               When something is important enough, you do it even if the odds are not in your favor.
LLI dp[3004][3004];
LI a[3004];
void solve(LI l,LI r,bool f){
  if(l==r) {
    if(f) dp[l][r]=a[l];
    else dp[l][r]=0;
    return;
  }
  if(dp[l][r]==-1){
    if(dp[l][r-1]==-1) solve(l,r-1,f);
    if(dp[l+1][r]==-1) solve(l+1,r,f);
    if(f==(r-l+1)%2) dp[l][r]=max(a[r]+dp[l][r-1],a[l]+dp[l+1][r]);
    else dp[l][r]=min(dp[l][r-1],dp[l+1][r]);
  }
}
int main(){   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LI n,i;cin>>n;
      LLI sum=0;
      memset(dp,-1,sizeof(dp));
      fo(i,0,n){ cin>>a[i];sum+=a[i];}
      bool f;
      if(n%2) f=1;
      else f=0; 
      solve(0,n-1,f);//cout<<dp[0][n-1];
      cout<<2*dp[0][n-1]-sum;
    }
    return 0;
}

Measured memory_bytes: 70912
#include<bits/stdc++.h>
 
using namespace std;
 
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=200002;

void solve(){
	int n;
	cin>>n;
	vi a(n),b(n),c(n-1);
	cin>>a>>b>>c;
	ll ans=0;
	for(int i=0;i<n;i++){
		if(i){
			ans+=b[a[i]-1];
			if((a[i]-a[i-1])==1){
				ans+=(c[a[i-1]-1]);
			}
		}
		else{
			ans+=b[a[i]-1];
		}
	}
	cout<<ans;
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}
 



Measured memory_bytes: 256
// 基本テンプレート
 
#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>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int 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;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int mod_pow(int n, int k) {
    int ret = 1;
    for(; k>0; k>>=1) {
        if(k & 1) (ret *= n) %= MOD;
        (n *= n) %= MOD;
    }
    return ret;
}
 
const int S = 200000;
int A[100010], cnt[100010], fact[S+10], finv[S+10];

int comb(int n, int r) {
    if(n < r or r < 0) return 0;
    return fact[n] * finv[n-r] % MOD * finv[r] % MOD;
}

signed main() {
    fact[0] = 1;
    for(int i=1; i<=S; i++) {
        fact[i] = (fact[i-1] * i) % MOD;
    }
    finv[S] = mod_pow(fact[S], MOD-2);
    for(int i=S-1; i>=0; i--) {
        finv[i] = (finv[i+1] * (i+1)) % MOD;
    }

    int N, dbl = -1; cin >> N; N++;
    for(int i=0; i<N; i++) {
        cin >> A[i];
        if(++cnt[ A[i] ] >= 2) dbl = A[i];
    }

    int mi = INF, ma = -1;
    for(int i=0; i<N; i++) {
        if(A[i] == dbl) {
            chmin(mi, i);
            chmax(ma, i);
        }
    }
    int width = ma - mi - 1;

    cout << N-1 << endl;
    for(int d=2; d<=N; d++) {
        int ans = 0;

        // dbl 以外から選ぶ
        (ans += comb(N-2, d)) %= MOD;

        // dbl を 2 つとも選ぶ
        (ans += comb(N-2, d-2)) %= MOD;

        // dbl を 1 つだけ選ぶ
        // 左をつかう
        (ans += comb(N-2, d-1)) %= MOD;
         ans = (ans - comb(N-2-width, d-1) + MOD) % MOD; // dbl の間にあるものを使わない

        // 右をつかう
        (ans += comb(N-2, d-1)) %= MOD;
        //  ans = (ans - comb(N-1-width, d-1) + MOD) % MOD; // dbl の間にあるものを使わない

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

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = (a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (a); i <= (long long)(n); i++)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<double> v_double;
typedef std::vector<std::vector<double> > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int a,b,k;

    cin >> k >> a >> b;

    irep2(i, a, b) {
        if(i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    
    return 0;
}
/** atcoder **/


Measured memory_bytes: 3636
D,G = map(int,input().split())
questions = [list(map(int,input().split())) for _ in range(D)]
ans = float('inf')
for bit in range(1 << D):
  count = 0
  score = 0
  max_zero_index = 0
  for i in range(D):
    if (bit >> i) & 1:
      score += questions[i][0]*100*(i+1)+questions[i][1]
      count += questions[i][0]
    else:
      max_zero_index = i
  if score >= G:
    ans = min(count,ans)
  else:
    for _ in range(1,questions[max_zero_index][0]):
      count +=1
      score += 100*(max_zero_index+1)
      if score >= G:
        ans = min(count,ans)
print(ans)

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

using namespace std;

int main()
{
	string a, b;
    cin >> a >> b;
    string c = (a + b);
    long long x = 0;
    for(int i = 0; i < (int)c.size(); i ++){
   		x = x * 10 + (c[i] - '0');
    }
    long long y = 1;
    while(y * y < x) y ++;
    if(y * y == x) cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;

#define MAX_N 200000

ll N, K;
priority_queue<ll> que;

void solve() {
    ll cnt = 0;

    for (ll i = 0; i < K; ++i) {
        que.pop();
    }

    ll h;
    while(!que.empty()) {
        h = que.top(); que.pop();
        cnt += h;
    }

    printf("%lld\n", cnt);
}

int main() {
    scanf("%lld %lld", &N, &K);

    ll h;
    for (ll i = 0; i < N; ++i) {
        scanf("%lld",&h);
        que.push(h);
    }

    if (K >= N) {
        printf("0\n");
        return 0;
    }

    solve();

    return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
string s;

int r_sum[4005];
int g_sum[4005];
int b_sum[4005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> s;

  int r = 0, g = 0, b = 0;
  REP(i, n) {
    if(s[i] == 'R') r++;
    else if(s[i] == 'G') g++;
    else b++;

    r_sum[i] = r;
    g_sum[i] = g;
    b_sum[i] = b;
  }

  ll ans = 0;
  REP(i, n) {
    FOR(j, i + 1, n) {
      if(s[i] == s[j]) continue;
      if(s[i] == 'R') {
        if(s[j] == 'G') {
          ans += b_sum[n - 1] - b_sum[j];
          if(j + (j - i) < n && s[j + (j - i)] == 'B') ans--;
        } else {
          ans += g_sum[n - 1] - g_sum[j];
          if(j + (j - i) < n && s[j + (j - i)] == 'G') ans--;
        }
      } else if(s[i] == 'G') {
        if(s[j] == 'R') {
          ans += b_sum[n - 1] - b_sum[j];
          if(j + (j - i) < n && s[j + (j - i)] == 'B') ans--;
        } else {
          ans += r_sum[n - 1] - r_sum[j];
          if(j + (j - i) < n && s[j + (j - i)] == 'R') ans--;
        }
      } else {
        if(s[j] == 'R') {
          ans += g_sum[n - 1] - g_sum[j];
          if(j + (j - i) < n && s[j + (j - i)] == 'G') ans--;
        } else {
          ans += r_sum[n - 1] - r_sum[j];
          if(j + (j - i) < n && s[j + (j - i)] == 'R') ans--;
        }
      }
    }
  }

  cout << ans << endl;
}


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

#define N 100000

char primeTable[N] = {0};
int a[N] = {0};

int main()
{
	int q;
	int l, r;
	int cnt;

	primeTable[0] = 1;
	primeTable[1] = 1;
	for( int i = 2; i * i < N; i++ ) {
		if( primeTable[i] ) {
			continue;
		}
		for( int j = i + i; j < N; j += i ) {
 			primeTable[j] = 1;
		}
	}

	cnt = 0;
	for( int i = 0; i < N; i++ ) {
		if( primeTable[i] == 0 && primeTable[( i + 1) / 2] == 0 ) {
			cnt++;
		}
		a[i] = cnt;
	}

	cin >> q;
	for( int i = 0; i < q; i++ ) {
		cin >> l >> r;
		cnt = a[r] - a[l-1];
		cout << cnt << endl;
	}


	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 10000000000

int main() {
	int x, n, ans;
	cin >> x >> n;
	vector<int> p(n);
	vector<bool> table(102, true);
	for (int i = 0; i < n; i++) {
		cin >> p.at(i);
		table[p[i]] = false;
	}

	for (int i = 0;; i++) {
		if (table[x - i]) {
			ans = x - i;
			break;
		}
		if (table[x + i]) {
			ans = x + i;
			break;
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3596
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

#define eps 1e-6
#define pi 3.141592653589793
using namespace std;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

int main(int argc, char* argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin>>s;
	stringstream ss(s);
	while(getline(ss,s,','))
    cout<<s<<' ';
	return 0;
}

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

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void print_case(int tn) {cout<<"Case #"<<tn<<": ";}

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;
/*----------------------------------------------------------------------*/

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    clock_t clk = clock();

    int n; cin>>n;
    vi arr(n);
    FOR(i, 0, n) cin>>arr[i];
    sort(all(arr));
    int res = 0;
    FOR(i, 0, n) {
        FOR(j, i+1, n) {
            int lo = max(arr[i]-arr[j], arr[j]-arr[i]);
            int hi = arr[i] + arr[j];
            
            auto up = lower_bound(arr.begin() + j, arr.end(), hi);
            --up;

            res += distance(arr.begin() + j, up);
        }
    }
    cout<<res;
    cerr << endl << "Time (in ms): " << double(clock() - clk) * 1000.0 / cps << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
//ミスがあったのでもう一度一応試すよ...ver.3
bool check_int(double b){
	if(abs(b-(int)b)<0.0000000001){
		return true;
	}
	return false;
}
int main(){
	int N;
	cin>>N;
	for(int h=1;h<=3500;h++){
		for(int w=1;w<=3500;w++){
			double tmp=4.0/N-1.0/h-1.0/w;
			if(tmp>0&&check_int(1.0/tmp)){
				cout<<h<<" "<<(int)(1.0/tmp)<<" "<<w<<endl;
				return 0;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 256
N, T = map(int, input().split())
dp = [[0 for _ in range(T)] for _ in range(N+1)]
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort()
for i in range(1, N+1):
    A, B = AB[i-1]
    for j in range(T):
        dp[i][j] = max(dp[i][j], dp[i-1][j])
        if j >= A:
            dp[i][j] = max(dp[i][j], dp[i-1][j-A] + B)
AB.append((0, 0))
ans = [x[T-1] + AB[i][1] for i, x in enumerate(dp)]
print(max(ans))

Measured memory_bytes: 119388
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int n, m;
	cin >> n >> m;
	map<int,int> ma;
	bool canConsist = true;
	for (int i = 0;i < m;i++) {
		int s, c;
		cin >> s >> c;
		if (ma.find(s) != ma.end() && ma[s] != c) {
			canConsist = false;
			break;
		}
		ma[s] = c;
	}

	
	int ans = 0;
	for (int i = 1; i <=n;i++) {
		if (ma.find(i) == ma.end()) {
			if (i == 1 && n != 1) {
				ans = ans * 10 + 1;
			}
			else {
				ans = ans * 10 + 0;
			}
			continue;
		}
		ans = ans * 10 + ma[i];

	}

	if (ma.find(1) != ma.end() &&ma[1] == 0 && n != 1) {
		canConsist = false;
	}

	if (canConsist) {
		cout << ans << endl;
	}
	else {
		cout << -1 << endl;
	}
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n;
	long s=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		char c;
		int d;
		scanf(" %c %d",&c,&d);
		switch(c){
			case 'S':d+=13*0;break;
			case 'H':d+=13*1;break;
			case 'C':d+=13*2;break;
			case 'D':d+=13*3;break;
		}
		s|=1L<<--d;
	}
	for(int i=0;i<52;i++)if(~s>>i&1)printf("%c %d\n","SHCD"[i/13],i%13+1);
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
typedef long long ll;
const int N = 305;

inline void up(int &x, int y) { x < y ? x = y : 0; }
inline void down(int &x, int y) { x > y ? x = y : 0; }
inline int max(const int x, const int y) { return x > y ? x : y; }
inline int min(const int x, const int y) { return x < y ? x : y; }

int n;
ll a[N], XOR, AND, ans;
int main() {
    std::ios::sync_with_stdio(false), std::cin.tie(0);
    std::cin >> n;
    for (int i = 1; i <= n; ++i) std::cin >> a[i];
    for (int i = 3; i <= n; ++i) XOR ^= a[i];
    AND = a[1] + a[2] - XOR;
    
    if (AND < 0 || AND & 1) return std::cout << -1 << '\n', 0;
    ans = (AND >>= 1);

    for (int i = 63; ~i; --i) {
    	ll A = (AND >> i) & 1, X = (XOR >> i) & 1;
		if (X == 1 && A == 1) return std::cout << -1 << '\n', 0;
    	if (X == 1 && A == 0) {
    		if (ans + (1ll << i) <= a[1]) ans += (1ll << i);
    	}
	}
	ans = a[1] - ans;
	if (! (ans >= 0 && ans < a[1] )) ans = -1;
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define in              insert
#define pb              push_back
#define mp              make_pair
#define lb              lower_bound
#define ub              upper_bound
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n]
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int32_t main()
{
	FIO;
	int n; cin >> n;
	double p[n + 1];
	for (int i = 1; i <= n; i++)
		cin >> p[i];

	double dp[n + 1][n + 1];

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (i == 0 && j == 0)
				dp[i][j] = 1.0;
			else if (i == 0)
				dp[i][j] = 0.0;
			else if (j == 0)
				dp[i][j] = dp[i - 1][j] * (1 - p[i]);
			else
				dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i];
		}
	}

	double ans = 0.0;

	for (int i = n / 2 + 1; i <= n; i++)
		ans += dp[n][i];

	cout << ps(ans, 9) << endl;

	return 0;
}

Measured memory_bytes: 74024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#include<map>
#define R(i, n) for(int i = 0;i < n; i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SL2(a, b) scanf("%lld%lld", &a, &b)
#define SL3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define SAL(i, n, a) R(i, n) scanf("%lld", a + i)
#define SC(a) scanf("%c", &a);
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
#define PY printf("Yes");
#define PN printf("No");
#define Py printf("yes");
#define Pn printf("no");
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;

int N;
string s;

int main() {
	S(N);
	cin >> s;
	if (s.length() <= N) {
		printf("%s", s.c_str());
	}
	else {
		string st = "...";
		string str = s.substr(0, N) + st;
		printf("%s", str.c_str());
	}
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
    ll n,m;
    cin>>n>>m;
    n = n % m;
    ll p = m - n;
    cout<<min(n,p)<<endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}

			int[] dp = new int[n + 1];
			dp[1] = 1;
			if (2 <= n) dp[2] = 2;
			if (3 <= n) dp[3] = 4;
			for (int i = 4; i <= n; i++) {
				dp[i] = dp[i - 1] + dp[i - 2] + dp[i - 3];
			}

			int d = ((dp[n]-1) / 10) + 1;
			System.out.println((d-1)/365 + 1);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>PII;
typedef vector<PII>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>MP;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
const int mod=1e9+7;
const int sze=1e5+2;
signed main(){
 string str;
 cin>>str;
 int len=str.length();
 string ans="";
 int i=0;
 stack<char>st;
 while(i<len){
	if(str[i]!='B')st.push(str[i]);
	else if(!st.empty()) st.pop();
	i++;
 }
 vector<char>ch;
 while(!st.empty()){
	 char chh=st.top();
	 ch.pb(chh);
	 st.pop();
 }
 reverse(ch.begin(),ch.end());
 for(auto it:ch)cout<<it;
 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  ll n,a[333],p=998244353;
  cin>>n;
  ll ans=1;
  ll suma=0;
  for(int i=0;i<n;i++){
	 cin>>a[i];
	 suma+=a[i];
	 ans*=3;
	 ans%=p;
  }
  ll dp[90310]={};
  dp[0]=1;
  for(int i=0;i<n;i++){
    for(int j=suma;j>=0;j--){
	 dp[j+a[i]]+=dp[j];
	 dp[j+a[i]]%=p;
	 dp[j]*=2;
	 dp[j]%=p;
    }
  }
  for(int i=suma;i*2>=suma;i--){
    ans-=dp[i]*3%p;
    ans+=p;
    ans%=p;
  }
  if(suma%2==0){
    fill_n(dp,90310,0);
    dp[0]=1;
    for(int i=0;i<n;i++){
	 for(int j=suma;j>=0;j--){
	   dp[j+a[i]]+=dp[j];
	   dp[j+a[i]]%=p;
	 }
    }
    ans+=dp[suma/2]*3%p;
    ans%=p;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 896
<?="1
1.5
2.12
2.76
3.37
4
4.62
5.24
5.86
6.48
7.1
7.72
8.35
8.97
9.6
10.21
10.83
11.45
12.07
12.7
13.32
13.94
14.56
15.18
15.8
16.42
17.05
17.67
18.3
18.91
19.53
20.15
20.77
21.4
22.02
22.64
23.26
23.88
24.5
25.12
25.75
26.37
27
27.61
28.23
28.85
29.47
30.1
30.72
31.34
31.96
61.8
62.41
63.03
63.65
483.13
620.47
621.09
621.71
622.33
622.96
932.44
6212.86
6213.5
6214.11
6214.73
62143.02
62143.65
62144.27
62144.9"?>


Measured memory_bytes: 9088
#include<iostream>
#include<functional>
#include<algorithm>
using namespace std;

int main(){
  int W[10],K[10];
  int ans_W=0,ans_K=0;
  for(int i=0;i<10;i++){
    cin >> W[i];
  }
  for(int i=0;i<10;i++){
    cin >> K[i];
  }
  sort(W,W+10,greater<int>());
  sort(K,K+10,greater<int>());
  for(int i=0;i<3;i++){
    ans_W += W[i];
    ans_K += K[i];
  }
  cout << ans_W << " " << ans_K << endl;
}

  

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

using namespace std;

typedef long long ll;
const ll mod = 1e9+7;

template<typename T> ostream& operator << (ostream& os, vector<T> v) {
  for (auto& i : v) os << i << " "; return os; 
}
template<typename T> istream& operator >> (istream& is, vector<T>& v) {
  for (auto& i : v) is >> i; return is;
}
template<typename K, typename V> ostream& operator << (ostream& os, unordered_map<K, V> m) {
  for (auto& i : m) os << i.first << ":" << i.second << endl; return os;
}
template<typename T> inline bool chmin(T& x, T y) {
  if (x > y) {
    x = y;
    return true;
  }
  return false;
}
template<typename T> inline bool chmax(T& x, T y) {
  if (x < y) {
    x = y;
    return true;
  }
  return false;
}

int main() {
  string s;
  cin >> s;
  unordered_map<char, int> um;
  for (auto& c : s) {
    um[c] += 1;
  }
  if (um.size() == 2) {
    for (auto& e : um) {
      if (e.second != 2) {
        cout << "No" << endl;
        return 0;
      }
    }
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           ((ll)x.size())
#define hell            (1000000007)
#define inf             ((ll)5e18 + 5)
#define PI              ((double)3.14159265358979323844)
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define bitcount(a)     (ll)__builtin_popcount(a)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    ll a,b,c;
    cin>>a>>b>>c;
    if (a%c==0 && b%c==0){
        cout<<b/c-a/c+1<<endl;
        return;
    }
    cout<<b/c-a/c<<endl; 
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 3600