akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll h, n;
    cin >> h >> n;
    vl a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    ll n_dp = 2 * 1e4 + 1;
    vector<ll> dp(n_dp, ll_inf);
    dp[0] = 0;
    rep(ih, n_dp) {
        rep(jn, n) {
            if (a[jn] > ih) continue;
            dp[ih] = min(dp[ih], dp[ih - a[jn]] + b[jn]);
        }
    }
    ll ans = ll_inf;
    for (ll i = h; i < n_dp; ++i) {
        ans = min(ans, dp[i]);
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
B = [0] * (N + 1)
for i in reversed(range(1, N + 1)):
    sum_val = 0
    for j in range(i*2, N + 1, i):
        sum_val ^= B[j]
    B[i] = sum_val ^ A[i]

ans = [str(idx) for idx, val in enumerate(B) if val == 1]
print(len(ans))
print(" ".join(ans))


Measured memory_bytes: 17208
// C - 755
#include <bits/stdc++.h>
using namespace std;

int N;//limit value
int Digit;//limit number of digit

int dfs(long long now, int depth,bool is3, bool is5, bool is7){
	if(now > N) return 0;//exceeded value limit?
	int count = is3 && is5 && is7? 1:0;//{3,5,7} all used -> +1
	if(depth >= Digit) return count;//limit of digits?
	count += dfs(now*10+3, depth+1, true, is5, is7);
	count += dfs(now*10+5, depth+1, is3, true, is7);
	count += dfs(now*10+7, depth+1, is3, is5, true);
	return count;
}

int main(){
	cin>>N;
	Digit = ceil(log10(N));
	cout<< dfs(0, 0, false, false, false) <<endl;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
  int i,j=0,k=0,s;
  int N,M,X;
  scanf("%d %d %d",&N,&M,&X);
  int A[M];
  for(i=0;i<M;i++)
    scanf("%d ",&A[i]);
  
  for(i = X;i!=0;i--){
    for(s=0;s<M;s++){
      if(i == A[s])
        j++;
    }
  }
  
  for(i=X;i<=N;i++){
    for(s=0;s<M;s++){
      if(i==A[s])
        k++;
    }
  }
  
  if(j > k)
    printf("%d\n",k);
  else
    printf("%d\n",j);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int s[100005];
int s2[100005];
bool cmp(const int &x,const int &y)
{
	return x>y;
}
int a,b,c,n,m,ans;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		scanf("%d",&s[i]);
	}
	sort(s+1,s+m+1);
	for(int i=1;i<=m-1;i++)
	{
		s2[i]=s[i+1]-s[i];
	}
	sort(s2+1,s2+m,cmp);
	ans=s[m]-s[1];
	for(int i=1;i<=n-1;i++)
	{
		ans-=s2[i];
	}
	printf("%d",ans);
}

Measured memory_bytes: 1024
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

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

x = int(input())
if x == 1:
	print(0)
else:
	print(1)








'''
# Wrap solution for more recursion depth
#submit as python3
import collections,sys,threading
sys.setrecursionlimit(10**9)
threading.stack_size(10**8)



threading.Thread(target=solve).start()
'''


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

int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int dp[n+1];
  dp[0]=0;
  for(int i=1;i<n;i++){
      dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
      for(int j=1;j<=k;j++){
          if(i-j>=0)
          {
              dp[i]=min(dp[i],dp[i-j]+abs(a[i-j]-a[i]));
          }
      }
  }
  cout<<dp[n-1];
  return 0;
}

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

int main(){
  string s;
  cin >>s;
  int l=s.size();
  string z="";
  for(int i=1;i<l;i++){
    if(s[i-1] != s[i]){
      z += s[i-1];
    }
  }
  cout << z.size() << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=3e5+50; 

int n,ans,a[N];
char s[N]; 

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin); 
#endif
	scanf("%d%s",&n,s+1); 
	rep(i,1,n){
		a[i]=a[i-1]+(s[i]=='E');
	}
	rep(i,1,n){
		int l=a[i-1],r=(n-i-(a[n]-a[i]));
		cmax(ans,l+r); 
	}
	printf("%d\n",n-1-ans); 
	return 0;
}


Measured memory_bytes: 1664
N = int(input())
A = list(map(int,input().split()))

f = [0]*N
for i in range(N-1):
    if A[i]<A[i+1]:
        f[i] = 1
    elif A[i]>A[i+1]:
        f[i] = -1

ans = 1000
for s in range(N):
    for t in range(s,N):
        m = 1000%A[s]
        n = 1000//A[s]
        for i in range(s+1,t):
            if f[i]==1:
                n += m//A[i]
                m %= A[i]
            elif f[i]==-1:
                m += A[i]*n
                n = 0
        m += n*A[t]
        ans = max(ans,m)
print(ans)            

Measured memory_bytes: 68084
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<cmath>
#include<set>
#include<random>
#include<stdio.h>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109311;
const long double pi = 3.1415926535897932384626433;
typedef pair<int, int> P;
struct edge { int to, cost; };
int a[114];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	int ans = 1145141919;
	int ns = 0;
	rep(i, n) {
		ns += a[i];
		ans = min(ans, ns / (i + 1));
	}
	cout << ans << endl;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VECINT;
typedef vector<ll> VECLL;


struct UnionFind {
  int N;
  vector<int> par,ranc;
  
  UnionFind(int N) : N(N),par(N),ranc(N) { REP(i,N) par[i]=i,ranc[i]=0; }
  
  int root(int s) {
    if (par[s]==s) return s;
    else return root(par[s]);
  }
  
  bool same(int x, int y) { return root(x)==root(y); }
  
  bool connected() {
    int base = root(0);
    REP(i,N) if (root(i)!=base) return false;
    return true;
  }
  
  void merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x==y) return;
    if (ranc[x]>ranc[y]) {
      par[y] = x;
    } else {
      par[x] = y;
      if (ranc[x]==ranc[y]) ranc[y]++;
    }
  }
};

int main() {
  int N,M;cin>>N>>M;
  struct edge { int from,to; };
  vector<edge> es;
  REP(i,M) {
    int a,b;cin>>a>>b;
    a--;b--;
    es.push_back({a,b});
  }

  // 辺を一つずつ無くした場合でUnionFindを実行
  int ans = 0;
  REP(i,M) {
    UnionFind uf(N);
    REP(m,M) {
      if (m==i) continue;

      edge e = es[m];
      uf.merge(e.from,e.to);
    }
    if (!uf.connected()) ans++;
  }
  OUT(ans);

  return 0;
}

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

int main()
{
    long long N, ans = 0, cnt = 1;
    cin >> N;
    vector<string> S(N);

    for (int i = 0; i < N; i++)
    {
        string s;
        cin >> s;

        sort(s.begin(), s.end());
        S[i] = s;
    }

    sort(S.begin(), S.end());

    for (int i = 0; i < N - 1; i++)
    {

        if (S[i] == S[i + 1])
        {
            cnt++;
        }

        else
        {
            ans += cnt * (cnt - 1) / 2;
            cnt = 1;
        }
    }

    ans += cnt * (cnt - 1) / 2;

    cout << ans << endl;
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  int h, a;
  cin >> h >> a;
  
  int ans = 0;
  
  while(h > 0){
    h -= a;
    ans ++;
  }
  
  cout << ans << endl;
  
  return 0;
  
}

Measured memory_bytes: 3584
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>

#define REP(n) for(int i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 1000000005

int main(){

    int a,b;
    cin >> a >> b;

    int ans = (a+b)%24;
    cout << ans << endl;


    return 0;
}

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

#define ll long long int
#define vll vector<ll>

int main() {

    int N;
    cin >> N;

    vll A;
    ll tmp;
    ll sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        A.push_back(tmp);
        if (i%2 == 0) {
            sum += tmp;
        }
        else {
            sum -= tmp;
        }
    }

    ll x = sum/2;
    cout << x*2 << " ";
    for (int i = 0; i < N-1; i++) {
        x = A[i] - x;
        cout << x*2 << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 2164
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
typedef int64_t ll;
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)

#define MAXN (100000)
#define MOD (998244353)

int64_t a[MAXN];

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

    ll x = 0;
    for(int i=0;i<n;i++)
    {
        scanf("%ld",&(a[i]));
        x ^= a[i];
    }
 
    for(int i=0;i<n;i++)
    {
        a[i] &= ~x;
    }

    //掃き出し法
    int r=0;
    for(int i=60;i>=0;i--)
    {
        for(int j=r;j<n;j++)
        {
            if(a[j]&(1L<<i))
            {
                ll t;
                t = a[r];
                a[r] = a[j];
                a[j] = t;
                for(int k=0;k<n;k++)
                {
                    if(k==r) continue;
                    if(a[k]&(1L<<i))
                    {
                        a[k] ^= a[r];
                    }
                }
                r++;
                break;
            }
        }
    }

    ll ans=0;
    for(int i=0;i<n;i++)
    {
        ans ^= a[i];
    }
    ans *= 2;
    ans += x;

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


Measured memory_bytes: 896
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
double dp[3005][3005];
int main(){
    int n;
    scanf("%d",&n);
    double p[3005];
    for(int i=1;i<=n;i++){
        scanf("%lf",&p[i]);
    }
    dp[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=i;j++){
            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;
    for(int i=n/2+1;i<=n;i++)
    ans+=dp[n][i];
    printf("%.12f\n",ans);
}


Measured memory_bytes: 68992
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N;
ll A[200020];

int main(){
  cin>>N;
  for(int i=0;i<N;i++){
      cin>>A[i];
  }
  bool flag=false;
  for(int i=1;i<N;i++){
      if(A[i]-A[i-1]>1) flag=true;
  }
  if(A[0]!=0||flag){
      cout<<-1<<endl;
      return 0;
  }

  ll ans=0;
  for(int i=1;i<N;i++){
      if(A[i-1]<A[i]) continue;
      else ans+=A[i-1];
  }
  ans+=A[N-1];
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int int64_t
using namespace std;
typedef pair<int, int> P;
const int INF = 100000000;

// グローバル変数


// 関数：


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int A, B, M;
	cin >> A >> B;
	
	if (A == B) {
		M = A + B;
	}
	else if (B > A) {
		M = B;
		M = M + max(B-1, A);
	}
	else {
		M = A;
		M = M + max(B, A-1);
	}
	
	cout << M << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int a, b;
	vector<int> occs(5);
	for (int i = 0; i < 3; ++i) {
		cin >> a >> b;
		++occs[a];
		++occs[b];
	}

	for (int i = 1; i <= 4; ++i) {
		if (occs[i] > 2) {
			cout << "NO\n";
			return 0;
		}
	}

	cout << "YES\n";

	return 0;

}

Measured memory_bytes: 256
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph)
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！

class UNION_FIND(object):
    def __init__(self,n):
        self.parent=[-1 for i in range(n)]
        
    def root(self,x):
        if self.parent[x]<0:
            return x
        else:
            self.parent[x]=self.root(self.parent[x])
            return self.parent[x]
 
    def size(self,x):
        return -self.parent[self.root(x)]
    def union(self,x,y):
        x=self.root(x)
        y=self.root(y)
        if x==y:
            return False
        if self.size(x)<self.size(y):
            x,y=y,x
        self.parent[x]+=self.parent[y]
        self.parent[y]=x
        return True

def compute_mst_kruskal(max_v, edges, flip):
    edges.sort(key=lambda x: x[2],reverse=flip)
    uf = UNION_FIND(max_v)
    mst = []
    for (a,b,c) in edges:
        if uf.root(a)!= uf.root(b):
            uf.union(a,b)
            mst.append(c)
    return mst


def main():
    n=int(input())
    inp=[[i]+list(map(int,input().split()))for i in range(n)]
    inpX=sorted(inp,key=lambda x:x[1])
    inpY=sorted(inp,key=lambda x:x[2])
    edges=[]
    for i in range(1,n):
        a,b,c=inpX[i]
        d,e,f=inpX[i-1]
        edges.append((a,d,min(abs(b-e),abs(c-f))))
        a,b,c=inpY[i]
        d,e,f=inpY[i-1]
        edges.append((a,d,min(abs(b-e),abs(c-f))))
    
    print(sum(compute_mst_kruskal(n, edges, 0)))
        
    
if __name__ == '__main__':
    main()
    
    

Measured memory_bytes: 53020
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b))<EPS)

int n;
double dp[101][30001];
double b,e,v,f;
int r;
int a[1001];
double mem[30000];
const int INF=1000000000;


double dfs(int idx,int runDist){
    if(!EQ(dp[idx][runDist],INF))return dp[idx][runDist];
    if(idx==n)
        return 0;
    double res=INF;
    double cost=0;
    int ndist=a[idx+1]-a[idx];
    res=min(res,dfs(idx+1,ndist)+mem[ndist-1]+b);
    // no change
    if(runDist>=1)
        res=min(res,dfs(idx+1,ndist+runDist)+mem[ndist+runDist-1]-mem[runDist-1]);
    else
        res=min(res,dfs(idx+1,ndist+runDist)+mem[ndist+runDist-1]);
    return dp[idx][runDist]=res;
}

int main(){
    while(cin>>n&&n!=0){
        a[0]=0;
        for(int i = 0; i < n; i++)cin>>a[i+1];
        cin>>b;
        cin>>r>>v>>e>>f;
        for(int i = 0; i < 101; i++)for(int j = 0; j < 30001; j++)dp[i][j]=INF;
        memset(mem,0,sizeof(mem));
        mem[0]=1.0/(v-f*(r));
        for(int i = 1; i < 10001; i++){
            if(i>=r)
                mem[i]=mem[i-1]+1.0/(v-e*(i-r));
            else
                mem[i]=mem[i-1]+1.0/(v-f*(r-i));
        }
        for(int i = 0; i < 30000; i++)
            dp[n][i]=0;
        for(int i = n-1; i >= 0; i--){
            for(int j = 10001; j >= 0; j--){
                int ndist=a[i+1]-a[i];
                dp[i][j]=min(dp[i][j],dp[i+1][ndist]+mem[ndist-1]+b);
                if(j>=1)
                    dp[i][j]=min(dp[i][j],dp[i+1][ndist+j]+mem[ndist+j-1]-mem[j-1]);
                else
                    dp[i][j]=min(dp[i][j],dp[i+1][ndist+j]+mem[ndist+j-1]);
            }
        }
        printf("%.10f\n",dp[0][0]);
    }
    return 0;
}

Measured memory_bytes: 24000
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (ll i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << (x) << endl
#define int long long
using namespace std;
using II = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { int n = d.size(); REP (i, n) s << d[i] << " "; return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& dd) { for (vector<T> d: dd) s << d << endl; return s; }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
const int MOD = 1e9 + 7;
class Grid {
  // queryを計算しやすいようにaccの範囲外の値も便宜的に定義
  int point(int i, int j) {
    if (i + j < 0 || H + W - 1 <= i + j) return 0;
    if (i < 0 || j >= W) return 0;
    if (j < 0 && i + j < H) return acc[i + j][0];
    if (i >= H && i + j >= H) return acc[H - 1][i + j - (H - 1)];
    return acc[i][j];
  }
public:
  VVI t; int H, W;
  VVI acc;
  Grid(VVI& tbl) : t(tbl), H(tbl.size()), W(tbl[0].size()) {
    set_acc();
  }
  VI& operator[](int i) {
    return t[i];
  }
  bool exist(int i, int j) {
    return 0 <= i && i < H && 0 <= j && j < W && t[i][j];
  }
  // 左下方向への累積和
  void set_acc() {
    acc = VVI(H, VI(W));
    REP (i, H) {
      REP (j, W) {
        int before = (i == 0 || j == W - 1) ? 0 : acc[i - 1][j + 1];
        acc[i][j] = before + t[i][j];
      }
    }
  }
  // 時計回りに90度回転
  void rotate() {
    VVI t2(W, VI(H));
    REP (i, H) {
      REP (j, W) {
        t2[j][H - i - 1] = t[i][j];
      }
    }
    t = t2;
    swap(H, W);
    set_acc();
  }
  // [i0, i1)の斜めのsum
  int query(int i0, int j0, int i1, int j1) {
    assert(i0 + j0 == i1 + j1);
    assert(i1 > i0);
    return point(i1 - 1, j1 + 1) - point(i0 - 1, j0 + 1);
  }
};

signed main() {
  int H, W; cin >> H >> W;
  VVI t(H, VI(W));
  REP (i, H) {
    REP (j, W) {
      t[i][j] = in<char>() == '#';
    }
  }
  Grid g(t);
  int ans = 0;
  int times = 4;
  while (times--) {
    REP (i, g.H) {
      REP (j, g.W) {
        if (!g.exist(i, j)) continue;
        REPI (k, 1, g.H + g.W - 1) {
          if (!g.exist(i + k, j - k)) continue;
          ans += g.query(i + k, j + k, i + 2 * k, j);
        }
      }
    }
    g.rotate();
  }
  cout << ans << endl;
}


Measured memory_bytes: 3896
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <time.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000001
#define mod 1000000009
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)

int main()
{
    int n;
    cin >> n;
    int a[200000]; 
    int count = 0;
    int flag[200000];
    for(int i = 0;i < n;i++){
        cin >> a[i];
        flag[i] = 0;
    }
    for(int i = 0;i < n;i++){
        int num = a[i] - 1;
        if(a[num] == i + 1 && flag[i] == 0){
            count++;
            flag[i] = 1;
            flag[num] = 1;
        }
    }
    cout << count << endl;
    return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define pll pair <ll , ll>

#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair

#define X first
#define Y second

#define LB(x) (x & -(x))
#define BIT(a,b) ((ll)((a)&(1<<(b)))==0 ? false : true)

const ll MAXN=5e2+10;

ll a[MAXN][MAXN];

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

    ll n,m,w,h,s=0;
    cin>>n>>m>>w>>h;

    if (n%w==0 && m%h==0)
    {
        cout<<"No";
        return 0;
    }

    for (ll i=w;i<=n;i+=w)
    {
        for(ll j=h;j<=m;j+=h)
        {
            a[i][j]=(-((h*w-1)*1000))-1;
        }
    }

    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            if (a[i][j]==0)
            {
                a[i][j]=1000;
            }

            s+=a[i][j];
        }
    }

    cout<<"Yes"<<endl;

    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3584
#include <iostream>
using namespace std;
int main(){
    int n;
    int d[50];
    int ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> d[i];
        for(int j = i-1; j >= 0;j--){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input());

dic = {};
count = 0;
for i in range(N):
  chars = list(input());
  chars.sort();
  sorted_str = "".join(chars);
  # print(sorted_str);
  
  if sorted_str in dic:
    dic[sorted_str] += 1;
    count += dic[sorted_str];
  else:
    dic[sorted_str] = 0;
  
print(count);

Measured memory_bytes: 22256
import itertools

N = int(input())

data = []
min_value_0 = 0
for _ in range(N):
	X, Y, P = town = tuple(map(int, input().split()))
	data.append(town)
	min_value_0 += min(abs(X), abs(Y)) * P

print(min_value_0)

B = 2 ** N
table_h = []
table_v = []

for b in range(B):
	towns = []
	i = 0
	x = b
	while x > 0:
		if x % 2 == 1:
			towns.append(i)
		x //= 2
		i += 1
	dists_h = []
	dists_v = []
	for i in range(N):
		X0, Y0, P0 = data[i]
		d_h = abs(X0)
		d_v = abs(Y0)
		for j in towns:
			X1, Y1, P1 = data[j]
			d_h = min(d_h, abs(X1 - X0))
			d_v = min(d_v, abs(Y1 - Y0))
		dists_h.append(d_h * P0)
		dists_v.append(d_v * P0)
	table_h.append(dists_h)
	table_v.append(dists_v)
#	print(f"{{:0{N}b}}".format(b), dist_h, dist_v)

table = [min_value_0] * (N + 1)

import sys

stack = [0] * N
i = 0
c = 0
b0 = 0
b1 = 0
b = 1
while True:
	if i == N:
		value = 0
		t1 = table_h[b0]
		t2 = table_v[b1]
		for j in range(N):
			value += min(t1[j], t2[j])
		if table[c] > value:
			table[c] = value
		i -= 1
		b //= 2
	else:
		s = stack[i]
		if s == 3:
			if i == 0:
				break
			else:
				stack[i] = 0
				i -= 1
				b //= 2
		else:
			if s == 0:
				b0 += b
				c += 1
			elif s == 1:
				b0 -= b
				b1 += b
			else:
				b1 -= b
				c -= 1
			stack[i] = s + 1
			i += 1
			b *= 2

for i in range(1, N):
	print(table[i])

print(0)


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

int main() {
  int L, R, d;
  int cnt = 0;
  cin >> L >> R >> d;
  for(int i=L;i<=R;i++) {
    if(i % d == 0) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;
import java.util.Arrays;

public class Main {

public static void main(String [] args){


        int H,W,D;
        int count =0;
        Scanner input = new Scanner(System.in);
        String Ans = "Yes";
        int [][] arr = new int[4][4];

        for (int i=1; i<=3; i++ ) {
                for (int j=1; j<=3; j++ ) {
                        arr[i][j] = input.nextInt();
                }
        }

        if (arr[1][1]-arr[2][1] != arr[1][2]-arr[2][2] || arr[1][2]-arr[2][2] != arr[1][3]-arr[2][3]) {
                //a1 - a2
                Ans = "No";
        }else if (arr[2][1]-arr[3][1] != arr[2][2]-arr[3][2] || arr[2][2]-arr[3][2] != arr[2][3]-arr[3][3]) {
                //a2 - a3
                Ans = "No";
        }else if (arr[3][1]-arr[1][1] != arr[3][2]-arr[1][2] || arr[3][2]-arr[1][2] != arr[3][3]-arr[1][3]) {
                //a3 - a1
                Ans = "No";
        }else if (arr[1][1]-arr[1][2] != arr[2][1]-arr[2][2] || arr[2][1]-arr[2][2] != arr[3][1]-arr[3][2]) {
                //b1 - b2
                Ans = "No";
        }else if (arr[1][2]-arr[1][3] != arr[2][2]-arr[2][3] || arr[2][2]-arr[2][3] != arr[3][2]-arr[3][3]) {
                //b2 - b3
                Ans = "No";
        }else if (arr[1][3]-arr[1][1] != arr[2][3]-arr[2][1] || arr[2][3]-arr[2][1] != arr[3][3]-arr[3][1]) {
                //b3 - b1
                Ans = "No";
        }

        System.out.println(Ans);
}
}


Measured memory_bytes: 23764
def CountingSort(A, B, k):
    C = [0]*(k+1)

    for j in A:
        C[j] += 1

    for i in range(1, k+1):
        C[i] = C[i] + C[i-1]

    for j in A[::-1]:
        B[C[j]-1] = j
        C[j] -= 1


n = int(input())
inlst = list(map(int, input().split()))
k = max(inlst)
outlst = [0]*n
CountingSort(inlst, outlst, k)
print(*outlst)


Measured memory_bytes: 224376
import numpy as np
ans = 'Yes'
x, y = map(int, input().split())
A = np.matrix([[1, 1], [2, 4]])
Y = np.matrix([[x], [y]])
calc = np.array(np.linalg.solve(A,Y))
for i in calc:
  if i[0] < 0 or i[0].is_integer() is False:
    ans = 'No'
    break
print(ans)

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c << endl;

    return 0;
}

Measured memory_bytes: 256
def shrink(s, char):
    while len(set(s)) > 1:
        temp = ''
        for i in range(len(s) - 1):
            if s[i] == char or s[i+1] == char:
                temp += char
            else:
                temp += s[i]
        s = temp
    return s

S = input()
ans = 10 ** 9
for c in set(S):
    ans = min(ans, len(S) - len(shrink(S, c)))
print(ans)

Measured memory_bytes: 3064
def main():
    examA()

def examA():
    N, C, K = LI()
    T = [I()for _ in range(N)]
    T.sort()
    cnt = 1
    customer = 1
    start = T[0]
    for i in range(1,N):
        t = T[i]
        if start+K<t:
            cnt += 1
            customer = 1
            start = t
        else:
            if customer==C:
                customer = 1
                start = t
                cnt += 1
            else:
                customer += 1
    ans = cnt
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

def test():
    i = I()
    li = LI()
    lsi = LSI()
    si = LS()
    print(i)
    print(li)
    print(lsi)
    print(si)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,alphabet_convert,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 1<<31
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    main()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 91252
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

ll f(ll b, ll n) {
	if (n < b) { return n; }
	return f(b, n / b) + n % b;
}


int main() {

	ll N, A;
	cin >> N >> A;

	ll dp[51][51][3000] = {};
	dp[0][0][0] = 1;

	repn(i, N) {
		ll x;
		cin >> x;

		dp[i][0][0] = 1;

		repn(j, N) {

			rep(k, 3000) {
				if (k < x) { dp[i][j][k] = dp[i - 1][j][k]; }
				else { dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x]; }
			}
		}
	}

	ll ans = 0;

	repn(i, N) {
		ans += dp[N][i][i*A];
	}
	cout << ans;

	system("PAUSE");
}


Measured memory_bytes: 61432
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
int mod = 1000000007;
long long dp[100005];

int main() {
  int n;
  cin >> n;
  
  int a[n+1],b[n];
  for(int i = 0;i< n+1;i++){
    cin >> a[i];
  }
  for(int i = 0;i< n;i++){
    cin >> b[i];
  }
  long long c = 0;
  for(int i = 0;i< n;i++){
    if(b[i] <= a[i]){
      c += b[i];
    }else if(b[i] <= a[i] + a[i+1]){
      c+= b[i];
      a[i+1] -= (b[i] -a[i]);
    }else if(b[i] >a[i] + a[i+1]){
      c += (a[i]+a[i+1]);
      a[i+1] = 0;
    }
  }
  
  cout << c;
  
}


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

int main(){
	int n;
	cin >> n;
	string g[n];
	for(int i = 0; i < n; i++){
		cin >> g[i];
	}
	int ans = 0;
	for(int j = 0; j < n; j++){
		string a[n];
		for(int i = 0; i < n; i++){
			a[i] = g[(i+j)%n];
		}
		int ok = 1;
		for(int c = 0; c < n; c++){
			for(int d = 0; d < n; d++){
				if(a[c][d] != a[d][c]) ok = 0;
			}
		}
		ans += ok;
	}
	cout << ans * n << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    while (1)
    {
        cin >> n;
        if (n == 0)
            break;
        int a[30][30] = {};
        rep(i, n)
        {
            int x, y;
            cin >> x >> y;
            a[x][y] = 1;
        }
        int x = 10, y = 10;
        int m;
        cin >> m;
        int b[30][30] = {};
        b[x][y] = 1;
        rep(i, m)
        {
            char c;
            int d;
            cin >> c >> d;
            if (c == 'N')
            {
                rep(j, d)
                {
                    y++;
                    b[x][y] = 1;
                }
            }
            else if (c == 'S')
            {
                rep(j, d)
                {
                    y--;
                    b[x][y] = 1;
                }
            }
            else if (c == 'E')
            {
                rep(j, d)
                {
                    x++;
                    b[x][y] = 1;
                }
            }
            else
            {
                rep(j, d)
                {
                    x--;
                    b[x][y] = 1;
                }
            }
        }
        bool f = true;
        rep(i, 30) rep(j, 30) if (a[i][j] == 1 && b[i][j] == 0) f = false;
        cout << (f ? "Yes" : "No") << endl;
    }
}


Measured memory_bytes: 3232
#include<iostream>
#include<stack>
#include<cstdio>
#include<vector>
using namespace std;
int a;


int main(int argc, char *argv[])
{
  stack<int> s;
  vector<int> m;
  while(cin>>a){
    if(a == 0){
      m.push_back(s.top());
      s.pop();
    }else{
    s.push(a);
	}
  }
  int S = m.size();
  for(int i= 0;i < S;i++){
    cout<<m[i]<< endl;
  }
  return 0;
}

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

using namespace std;

void Solve(){
    string s;
    cin>>s;
    string t = s;
    bool good = true;
    reverse(t.begin(), t.end());
    if(t != s) good = false;
    t = "";
    for(int i = 0; i < (s.size() - 1) / 2; i++){
        t += s[i];
    }
    string k = t;
    reverse(t.begin(), t.end());
    if(t != k) good = false;
    t = "";
    for(int i = s.size() - 1; i > (s.size() + 3) / 2; i--){
        t += s[i];
    }
    k = t;
    reverse(t.begin(), t.end());
    if(k != k) good = false;
    if(good) cout<<"Yes\n";
    else cout<<"No\n";
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int q = 1;
    //cin>>q;
    while(q--){
    	Solve();
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main()

{

    int a, b;

    scanf("%d %d", &a, &b);

    if (a >= 13)

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

    if (a <= 12 && a >= 6)

        printf("%d\n", b / 2);

    if (a < 6)

        printf("0\n");

    return 0;

}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		int multiple = scan.nextInt();
		int minus = scan.nextInt();
		int gram = scan.nextInt();
		
		int ans = 0;
		for (int i = 0; i < 10; i++) {
			if (i == 0) {				
				ans = multiple * gram - minus;
			} else {
				ans = ans * multiple - minus;
			}
			System.out.println(ans);
		}
	}	
}

Measured memory_bytes: 21844
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

A, B, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = INF
for i in range(M):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    now = A[x] + B[y] - c
    ans = min(now, ans)
min_a = min(A)
min_b = min(B)
ans = min(ans, min_a + min_b)
print(ans)

Measured memory_bytes: 25648
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
char m[111][111];
int d[111][111];
int main()
{
	int mx, my;
	scanf("%d%d", &mx, &my);
	for (int i = 0; i < mx; i++)for (int j = 0; j < my; j++)scanf(" %c", &m[i][j]);
	for (int i = 0; i <= mx; i++)for (int j = 0; j <= my; j++)d[i][j] = 1000000000;
	d[0][0] = (m[0][0] == '#');
	for (int i = 0; i < mx; i++)
	{
		for (int j = 0; j < my; j++)
		{
			d[i + 1][j] = min(d[i + 1][j], d[i][j] + (m[i][j] != m[i + 1][j]));
			d[i][j + 1] = min(d[i][j + 1], d[i][j] + (m[i][j] != m[i][j + 1]));
			//printf("%d %d %d %c\n", i,j,d[i][j],m[i][j]);
		}
	}
	d[mx - 1][my - 1] += (m[mx - 1][my - 1] == '#');
	printf("%d\n", d[mx - 1][my - 1] / 2);
}

Measured memory_bytes: 256
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

x = int(input())
now = 100
ans = 0
while True:
    if now >= x:
        print(ans)
        break
    ans += 1
    now = floor(now * 1.01)

Measured memory_bytes: 10424
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int T = scanner.nextInt();
		double s = 0;
		int num = 0;
		
		s = (T + 0.5) / A;
		int si = (int)s;
		num = si * B;
		
		System.out.println(num);
	}
}


Measured memory_bytes: 21716
import java.util.*;

public class Main {
    private static final long MOD = 1000000007;
    long modKai[] = new long[100002];
    long modKaiInv[] = new long[100002];

    public void main(Scanner sc) {
        int n = sc.nextInt();
        LinkedList<Integer> list = new LinkedList<>();
        long sum = 0;
        for (int i = 0; i <= n; i++) {
            int a = sc.nextInt();
            list.add(a);
            sum += a;
        }

        init(n + 1);
        int d = (int) (sum - sigma(n));
        int p = list.indexOf(d);
        int lp = n - list.lastIndexOf(d);
        for (int i = 1; i <= n + 1; i++) {
            if (i <= p + lp + 1) {
                System.out.println((MOD + comb(n + 1, i) - comb(p + lp, i - 1)) % MOD);
            } else {
                System.out.println(comb(n + 1, i));
            }
        }
    }

    private long sigma(int n) {
        long res = n;
        return res * (res + 1) / 2;
    }

    private void init(int n) {
        modKai[0] = 1;
        for (int i = 1; i <= n; i++) {
            modKai[i] = (modKai[i - 1] * i) % MOD;
        }

        modKaiInv[n] = inv(modKai[n], MOD - 2);
        for (int i = n; i >= 1; i--) {
            modKaiInv[i - 1] = (modKaiInv[i] * i) % MOD;
        }
    }

    private long inv(long n, long x) {
        if (x == 0) {
            return 1;
        } else if (x % 2 == 0) {
            return inv(n * n % MOD, x / 2);
        } else {
            return (n * inv(n, x - 1)) % MOD;
        }
    }

    private long comb(int n, int r) {
        return (((modKai[n] * modKaiInv[r]) % MOD) * modKaiInv[n - r]) % MOD;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}


Measured memory_bytes: 68264
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int n,m;
	cin>>n>>m;
	vi to[300100];

	loop(m){
		int u,v;
		cin>>u>>v;
		u--;v--;
		to[3*u].pb(3*v+1);
		to[3*u+1].pb(3*v+2);
		to[3*u+2].pb(3*v);
	}
	int s,t;
	cin>>s>>t;
	s--;t--;

	queue<int> que;
	vi dist(3*n,INF);
	dist[3*s]=0;
	que.push(3*s);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(auto p:to[v]){
			if(dist[p]<INF){
				continue;
			}
			dist[p]=dist[v]+1;
			que.push(p);
		}

	}
	if(dist[3*t]<INF)cout<<dist[3*t]/3<<endl;
	else cout<<-1<<endl;

	return 0;
}



Measured memory_bytes: 21940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String[] array = br.readLine().split(" ");
			int N = Integer.parseInt(array[0]);
			int C = Integer.parseInt(array[1]);

			int[] channels = new int[N];
			int[] starts = new int[N];
			int[] ends = new int[N];
			for (int i = 0; i < N; i++) {
				String[] tmp = br.readLine().split(" ");

				starts[i] = Integer.parseInt(tmp[0]);
				ends[i] = Integer.parseInt(tmp[1]);
				channels[i] = Integer.parseInt(tmp[2]);
			}
			final int[] table = new int[2 * 100_001];
			final boolean[] tmp = new boolean[2 * 100_001];
			// boolean updated = false;
			for (int channel = 1; channel <= C; channel++) {
				// if (updated) {
				for (int i = 0; i < tmp.length; i++) {
					tmp[i] = false;
				}
				// updated = false;
				// }

				for (int index = 0; index < N; index++) {
					if (channels[index] == channel) {
						for (int i = starts[index] * 2 - 1; i <= ends[index] * 2; i++) {
							tmp[i] = true;
						}
						// updated = true;
					}
				}

				for (int i = 0; i < table.length; i++) {
					if (tmp[i]) {
						table[i]++;
					}
				}
			}

			int max = Integer.MIN_VALUE;
			for (int i = 0; i < table.length; i++) {
				max = Math.max(max, table[i]);
			}

			System.out.println(max);
		}
	}
}


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


int main() {
  long N,K;
  cin >> N>>K;
  
    cout<<min(N%K,K-N%K)<<endl;
  
  
}





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

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
// using namespace __gnu_pbds;

#define int long long int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()

// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
  
	int n, w, val = 0;
	cin>>n>>w;
	pair<int, int> item[n+1];

	for(int i=1;i<=n;i++) {
		cin>>item[i].ff;
		cin>>item[i].ss;
		val += item[i].ss;
	}

	int dp[n+1][val+1];
	memset(dp, 0, sizeof(dp));
	// for(int j=0; j<=val; j++) {
	// 	dp[0][j] = INT_MAX;
	// }

	for(int i=1; i<=n; i++) {
		for(int j=1; j<=val; j++) {
			if(item[i].ss == j) {
				if(dp[i-1][j] && dp[i-1][j-item[i].ss])
					dp[i][j] = min(item[i].ff + dp[i-1][j-item[i].ss], dp[i-1][j]);
				else if(dp[i-1][j])
					dp[i][j] = min(item[i].ff, dp[i-1][j]);
				else if(dp[i-1][j-item[i].ss])
					dp[i][j] = item[i].ff + dp[i-1][j-item[i].ss];
				else
					dp[i][j] = item[i].ff;
			}
			else if(item[i].ss < j) {
				if(dp[i-1][j] && dp[i-1][j-item[i].ss])
					dp[i][j] = min(item[i].ff + dp[i-1][j-item[i].ss], dp[i-1][j]);
				else if(dp[i-1][j])
					dp[i][j] = dp[i-1][j];
				else if(dp[i-1][j-item[i].ss])
					dp[i][j] = item[i].ff + dp[i-1][j-item[i].ss];
			} else {
				dp[i][j] = dp[i-1][j];
			}
			// cout<<dp[i][j]<<" ";
		}
		// cout<<endl;
	}

	int i = 0;
	for(int z=1;z<=val;z++) {
		if(dp[n][z]!=0 && dp[n][z]<=w)
			i = z;
	}

	cout<<i;

	return 0;
}

Measured memory_bytes: 79232
N = int(input())
A = list(map(int, input().split()))

ans = [] * (N)
temp = (A[1] - A[0])*2
for i in range(N)[2:]:
    temp = A[i]*2 - temp
a = int(temp/2)
ans.append(str(a))

temp = a
for i in range(N-1):
    temp = A[i]*2 - temp
    ans.append(str(temp))

print(' '.join(ans))

Measured memory_bytes: 74212
#include<iostream>
using namespace std;
int main(){
    int H,W,i,j;
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0){
            break;
        }
        
        for(i=0;i<H;i++){
            if(i == 0 || i == H-1){
                for(j=0;j<W;j++){
                    cout << "#";
                }
            }else{
                for(j=0;j<W;j++){
                    if(j == 0 || j == W-1){
                        cout << "#";
                    }else{
                        cout << ".";
                    }
                }
            }
            cout << endl;
        }
        cout << endl;
        
    }
    
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
#include <vector>
#include <limits.h>
#include <stack>
#include <queue>

using namespace std;

#define PI 3.14159265359
#define INF LLONG_MAX


const long long mod = 1000000007;

long long fac(long long n) {
    if (n == 0) {
        return 1;
    }

    long long p = 1;
    for (long long i = 1; i <= n; ++i) {
        p = (p % mod) * i;
    }

    return (p % mod);
}


int main(int argc, char const *argv[])
{
    int N, M;
    cin >> N >> M;

    if (N < M) {
        swap(N, M);
    }

    long long x;
    if (N - M > 1) {
        x = 0;
    } else if(N == M) {
        x = ((fac(N) * fac(M)) * 2) % mod;
    } else {
        x = (fac(N) * fac(M)) % mod;
    }

    cout << x << endl;
    return 0;
}

Measured memory_bytes: 760