akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
struct edge{
    int to, cost;
    edge(int a = 0, int b = 0) : to(a), cost(b) {}
};
vector<pii> dijkstra(int s, vector<vector<edge>> &g,const int L){
    int n = (int)g.size();
    vector<pii> dist(n);
    rep(i,n)dist[i] = {n * 10, 0};
    using ll_i = pair<pii, int>;
//    priority_queue<ll_i,vector<ll_i>,greater<ll_i>>pq;
    queue<ll_i> pq;
    dist[s] = {0,-L};
    pq.push({dist[s], s});
    while(!pq.empty()){
        auto a = pq.front();
        pq.pop();
        int v = a.second;
        if(a.first > dist[v])continue;
        for(auto &x:g[v]){
            int num = a.first.first;
            int ren = -a.first.second;
            if(x.cost > L)continue;
            if(x.cost > ren){
                num++;
                ren = L;
            }
            ren -= x.cost;
            if(dist[x.to] > pii(num, -ren)){
                dist[x.to] = pii(num, -ren);
                pq.push({dist[x.to], x.to});
            }
        }
    }
    return dist;
}
//ll dist[300][300];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int m;
    cin >> m;
    int L;
    cin >> L;
//    rep(i,n)rep(j,n)dist[i][j] = 1LL<<60;
    vector<vector<edge>>g(n);
    rep(i,m){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        a--,b--;
        if(c > L)continue;
//        dist[a][b] = min(dist[a][b], c);
//        dist[b][a] = min(dist[b][a], c);
        g[a].emplace_back(b, c);
        g[b].emplace_back(a, c);
    }
//    rep(k,n)rep(i,n)rep(j,n)dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    int q;
    cin >> q;
    vector<vector<pii>> dist(n);
    rep(i,n)dist[i] = dijkstra(i, g, L);
//    rep(i,n)show(i, dist[i]);
    while(q--){
        int s, t;
        cin >> s >> t;
        s--, t--;
//        show(dist[s][t]);
        if(dist[s][t].first > n){
            cout << -1 << "\n";
        }else{
            cout << dist[s][t].first << "\n";
        }
    }
}



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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

int N;
vector<vector<int>> G;
vector<vector<ll>> dp;

void rec(int parent, int current) {
    if (G[current].size() == 1 && G[current][0] == parent) {
        dp[current][0] = 1;
        dp[current][1] = 1;
    }

    if (G[current].size() == 0) {
        dp[current][0] = 1;
        dp[current][1] = 1;
    }

    for (int i = 0; i < G[current].size(); i++) {
        int next = G[current][i];
        if (next == parent) continue;
        rec(current, next);
    }
    if (parent == -1 ) return;
    dp[parent][0] *= dp[current][1];
    dp[parent][0] %= mod;
    dp[parent][1] *= (dp[current][1] + dp[current][0])%mod;
    dp[parent][1] %= mod;
    return;
}

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

    cin >> N;
    G.assign(N, vector<int>());

    for (int i = 0; i < N - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    dp.assign(N + 1, vector<ll>(2, 1));

    rec(-1, 0);

    cout << (dp[0][0] + dp[0][1]) % mod << endl;
    
    return 0;
}

Measured memory_bytes: 18048
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;

int main() {
  int n,k,x,y;
  cin>>n>>k>>x>>y;
  cout << x * min(n,k) + y * max(0, n-k) << endl;
}

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

using namespace std;

typedef long long ll;

int main() {
  int n;
  cin>>n;
  ll minv = 1e10;
  ll maxv = 0;
  for (int i = 0; i < n; i++) {
    ll tmp;
    cin>>tmp;
    minv = min(minv,tmp);
    maxv = max(maxv,tmp);
  }
  cout<<(maxv-minv)<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    
    int N = Integer.parseInt(sc.next());
    int Ma = Integer.parseInt(sc.next());
    int Mb = Integer.parseInt(sc.next());
    
    int a[] = new int[N];
    int b[] = new int[N];
    int c[] = new int[N];
    int sub[] = new int[N];
    for (int i = 0; i < N; i++) {
      a[i] = Integer.parseInt(sc.next());
      b[i] = Integer.parseInt(sc.next());
      c[i] = Integer.parseInt(sc.next());
      sub[i] = Mb * a[i] - Ma * b[i];
    }
    
    int origin = 10 * 10 * N;
    int length = origin * 2 + 1;
    int dp[][] = new int[N + 1][length];
    int maxSumCost = 100 * N + 1000;
    for (int i = 0; i < N + 1; i++) {
      for (int j = 0; j < length; j++) {
        dp[i][j] = maxSumCost;
      }
    }
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < length; j++) {
        if (dp[i][j] < maxSumCost) {
          dp[i + 1][j] = Math.min(dp[i][j], dp[i + 1][j]);
          dp[i + 1][j + sub[i]] = Math.min(dp[i][j] + c[i], dp[i + 1][j + sub[i]]);
        }
        if (j == origin) {
          dp[i + 1][origin + sub[i]] = Math.min(c[i], dp[i][origin + sub[i]]);
        }
      }
    }
    if (dp[N][origin] == maxSumCost) {
      System.out.println(-1);
    } else {
      System.out.println(dp[N][origin]);
    }
  }
}

Measured memory_bytes: 23380
import java.util.*;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        
        UnionFind uf = new UnionFind(n);
        
        for(int i=0; i<m; i++){
            int x = Integer.parseInt(sc.next())-1;
            int y = Integer.parseInt(sc.next())-1;
            int z = Integer.parseInt(sc.next());
            uf.unite(x,y);
        }
        
        Set<Integer> s = new HashSet<>();
        for(int i=0; i<n; i++){
            s.add(uf.find(i));
        }
        
        System.out.println(s.size());
    }
}

class UnionFind{
    int[] par;
    int[] size;
    
    public UnionFind(int n){
        par = new int[n];
        for(int i=0; i<n; i++){
            par[i] = i;
        }
        size = new int[n];
        Arrays.fill(size, 1);
    }
    
    public int find(int x){
        if(par[x] == x){
            return x;
        }else{
            par[x] = find(par[x]);
            return par[x];
        }
    }
    
    public boolean unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x==y) return false;
        
        if(size[x]<size[y]){
            int tmp = x;
            x = y;
            y = tmp;
        }
        size[x] += size[y];
        par[y] = x;
        return true;
    }
    
    public boolean same(int x, int y){
        return find(x)==find(y);
    }
    
    public int size(int x){
        return size[find(x)];
    }
}


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(10);
    /*start*/
    ll n, k;
    cin >> n >> k;
    ll sum = 1;
    while (n / k != 0)
    {
        sum++;
        n = n / k;
    }
    c(sum);
    return 0;
}

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

int main(){
    int N, B[110], ans = 0;
    cin >> N;
    for (int i = 0; i < N-1; ++i){
        cin >> B[i];
    }
    
    ans += B[0];
    for (int i = 0; i < N-2; ++i){
        ans += min(B[i], B[i+1]);
    }
    ans += B[N-2];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
          ,     \    /      ,
         / \    )\__/(     / \
        /   \  (_\  /_)   /   \
   ____/_____\__\@  @/___/_____\____
  |             |\../|              |
  |              \VV/               |
  |        ------hoi-------         |
  |_________________________________|
   |    /\ /      \\       \ /\    |
   |  /   V        ))       V   \  |
   |/     `       //        '     \|
   `              V                '
*/

#include <bits/stdc++.h>

#define ld long double
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define f first
#define se second
#define Speedforce boost();
#define fop(s1, s2) freopen(s1, "r", stdin);freopen(s2, "w", stdout);

using namespace std;

void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const int N = 1e6;
const ll inf = 1e9 + 9;
const ld PI = acos(-1);

ll bin_pow(ll x, ll y){
    ll res = 1, base = x;
    while(y){
        if(y & 1){
            res *= base;
            res %= inf;
        }
        base *= base;
        base %= inf;
        y /= 2;
    }
    return res;
}

ll n;
int a[N], suf[N];

int main(){
    Speedforce
    //fop("", "")
    cin >> n;
    cout << n * (n - 1) / 2;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
    int maxx=101010;
    vector<int> is_prime(maxx, 1);
    is_prime[0]=0;is_prime[1]=0;
    for(int i=2;i<maxx;i++){
        if(!is_prime[i])continue;
        for(int j=i*2;j<maxx;j+=i)is_prime[j]=0;
    }
    vector<int> a(maxx);
    for (int i=1;i<maxx;i+=2){
        if(is_prime[i]&&is_prime[(i+1)/2])a[i]=1;
    }
    vector<int> sum(maxx+1);
    for (int i=0;i<maxx;i++){
        sum[i+1]=sum[i]+a[i];
    }
    int q;
	cin>>q;
    for(int i=0;i<q;i++){
        int l,r;
		cin>>l>>r;
        r++;
        cout<<sum[r]-sum[l]<<endl;
    }
}


Measured memory_bytes: 4448
#include <iostream>
#include <cmath>
#include <string.h>
using namespace std;

int n, tp = 1, tq = 1;
int p[8], q[8];
bool f[8], g[8];

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> p[i];

	for (int i = 0; i < n; i++)
		cin >> q[i];

	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= n; j++) {
			if (p[i] == j) {
				f[j - 1] = 1;
				break;
			}
			else if(!f[j - 1]){
				int k = 1;
				for (int w = 1; w < n - i; w++)
					k *= w;

				tp += k;
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= n; j++) {
			if (q[i] == j) {
				g[j - 1] = 1;
				break;
			}
			else if(!g[j - 1]){
				int k = 1;
				for (int w = 1; w < n - i; w++)
					k *= w;

				tq += k;
			}
		}
	}

	cout << abs(tp - tq) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int n;
double pi = acos(-1);
void koch(double xl, double yl, double xr, double yr, int depth) {
	if(depth == n) {
		printf("%.8lf %.8lf\n", xr, yr);
		return;
	}
	double px =(xr-xl)/3+xl, py = (yr-yl)/3+yl;
	double qx =(xr-xl)*2/3+xl, qy = (yr-yl)*2/3+yl;
	double len = sqrt(pow(xr-xl,2.0) + pow(yr-yl,2.0))/3.0;
	double rad = atan2(yr-yl,xr-xl);
	koch(xl,yl,px,py,depth+1);
	koch(px,py,len*cos((pi/3)+rad)+px,len*sin((pi/3)+rad)+py,depth+1);
	koch(len*cos((pi/3)+rad)+px,len*sin((pi/3)+rad)+py,qx,qy,depth+1);
	koch(qx,qy,xr,yr,depth+1);
}
int main() {
	cin >> n;
	printf("%.8lf %.8lf\n",0,0);
	koch(0,0,100,0,0);
	return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  char O;
  cin >> H >> W;
  vector<char> out = vector<char>(W+2,'#');
  for(int i=0;i<W+2;i++) cout << out[i];
  cout << endl;
  for(int i=0;i<H;i++){
    cout << '#';
    for(int j=0;j<W;j++){
      cin >> O;
      cout << O;
    }
    cout << '#' << endl;
  }
  for(int i=0;i<W+2;i++) cout << out[i];
}

Measured memory_bytes: 256
def solve():
	unknownDate = input()
	datePre = int(unknownDate[:2])
	datePos = int(unknownDate[2:])
	
	isPreMightMonth = (0 < datePre <= 12)
	isPostMightMonth = (0 < datePos <= 12)
	
	if isPreMightMonth and isPostMightMonth:
		print('AMBIGUOUS')
	elif isPreMightMonth and (not isPostMightMonth):
		print('MMYY')
	elif (not isPreMightMonth) and isPostMightMonth:
		print('YYMM')
	else:
		print('NA')
solve()


Measured memory_bytes: 38256
/**********************************
	author:  mariogzsl
**********************************/

#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,b,a) for(int i=b-1;i>=a;i--)
#define f first
#define s second
#define puts(x) cout<<x<<endl
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
#define MOD 1000000007

ll dp[120][10][10][10];
int n;
ll dfs(int i, int p0, int p1, int p2){
    if(i==n) return 1;
    if(dp[i][p0][p1][p2]!=-1)return dp[i][p0][p1][p2];
    ll ans = 0;
	FOR(j,1,5){
        if(p0==1 && p1==2 && j==3)continue;
        if(p0==1 && p2==2 && j==3)continue;
        if(p1==1 && p2==2 && j==3)continue;
        if(p1==2 && p2==1 && j==3)continue;
        if(p1==1 && p2==3 && j==2)continue;
        ans = (ans+dfs(i+1, p1, p2, j))%MOD;
    }
 
    return dp[i][p0][p1][p2] = ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	memset(dp, -1, sizeof(dp));
	cout << dfs(0, 0, 0, 0) << endl;
	return 0;
} 


Measured memory_bytes: 1152
/*
      HET PAGHADAR
      DA-IICT
      @HET262
*/
 
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define oos tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds; 
typedef long double ld;
typedef long long ll;
typedef vector<ll> vec; 
#define inf LLONG_MAX
#define bp __builtin_popcountll
#define pb push_back
#define F first
#define S second
#define P pair<ll,ll>
#define N 1000005
#define mod 1000000007
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAX 1000005
#define MOD 1000000007

ll d, x, y;
void extendedEuclid(ll A, ll B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        ll temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}
ll modInverse(ll A)
{
    extendedEuclid(A,MOD);
    return (x%MOD+MOD)%MOD;   
}

int prime[MAX]; 
unordered_map<int, int> max_map; 

ll n,ar[10005];
  
// Function to return a^n 
int power(int a, int n) 
{ 
    if (n == 0) 
        return 1; 
    int p = power(a, n / 2) % mod; 
    p = (p * p) % mod; 
    if (n & 1) 
        p = (p * a) % mod; 
    return p; 
} 
  
// Function to find the smallest prime factors 
// of numbers upto MAX 
void sieve() 
{ 
    prime[0] = prime[1] = 1; 
    for (int i = 2; i < MAX; i++) { 
        if (prime[i] == 0) { 
            for (int j = i * 2; j < MAX; j += i) { 
                if (prime[j] == 0) { 
                    prime[j] = i; 
                } 
            } 
            prime[i] = i; 
        } 
    } 
} 
  
// Function to return the LCM modulo M 
ll lcmModuloM() 
{ 
  
    for (int i = 0; i < n; i++) { 
        int num = ar[i]; 
        unordered_map<int, int> temp; 
  
        // Temp stores mapping of prime factor to 
        // its power for the current element 
        while (num > 1) { 
  
            // Factor is the smallest prime factor of num 
            int factor = prime[num]; 
  
            // Increase count of factor in temp 
            temp[factor]++; 
  
            // Reduce num by its prime factor 
            num /= factor; 
        } 
  
        for (auto it : temp) { 
  
            // Store the highest power of every prime 
            // found till now in a new map max_map 
            max_map[it.first] = max(max_map[it.first], it.second); 
        } 
    } 
  
    ll ans = 1; 
  
    for (auto it : max_map) { 
  
        // LCM is product of primes to their highest powers modulo M 
        ans = (ans * power(it.F, it.S)) % mod; 
    } 
  
    return ans; 
} 


int32_t main()
{
      
      FAST;
      
      sieve();
      cin>>n;
      
      ll a[n+1];
      
      for(int i=0;i<n;i++)
            cin>>ar[i];
            
      ll ans=lcmModuloM();
      
      ll aa=0;
      
      for(int i=0;i<n;i++)
      {
            ll t1=modInverse(ar[i]);
            aa=(aa+(ans*t1)%mod)%mod;
            
      }
      
      cout<<aa;
      
}


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

typedef long long ll;
typedef pair<int, int> ii;

ll a, b, k;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> a >> b >> k;
  if (k >= a + b)
    cout << 0 << ' ' << 0 << endl;
  else {
    if (k > a)
      cout << 0 << ' ' << b - (k - a) << endl;
    else
      cout << a - k << ' ' << b << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
n = int(input())
d = []

renzoku_count = 0
max_renzoku_count = 0
for _ in range(n):
    d1, d2 = input().split()
    # print(d1, d2)
    if d1 == d2:
        renzoku_count += 1
    else:
        renzoku_count = 0
    max_renzoku_count = max(max_renzoku_count, renzoku_count)
    
# print(max_renzoku_count)
if max_renzoku_count >= 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9168
N, Y = map(int, input().split())

for i in range(0, N + 1):
    for j in range(i, N + 1):
        if Y == 10000 * i + 5000 * (j - i) + 1000 * (N - j):
            print(i, j - i, N - j)
            exit()

print(-1, -1, -1)


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
#define ll              long long int
#define w(x)            ll X; cin>>X; while(X--)
#define fast            std::ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb              push_back
#define vec             vector
#define inf				1e9
int main()
{
  fast 

  ll d,s,t; cin>>d>>s>>t;
  if(d>s*t)
  	cout<<"No"<<endl;
  else
  	cout<<"Yes"<<endl;


  return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>

using namespace std;
 
int main(){
    int N;
    vector<int> A;
  
    cin >> N;

    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        A.push_back(a);
    }

    int next = 1;
    int now = 0;

    for(int i = 0; i < N; i++){
        next = A[next-1];
        A[now] = 0;
        now = next-1;

        if(A[next-1] == 0){
            cout << -1 << endl;
            exit(0);
        }

        if(next == 2){
            cout << i+1 << endl;
            exit(0);
        }
    }

    return 0;
}


Measured memory_bytes: 892
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <complex>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include "fstream"
using namespace std;
#define PI acos(-1)
#define MOD (ll)1000000007
#define pii pair<long long ,long long >
#define ll  long long int
#define loop(i,n) for(ll i=0;i<n;i++)
#define loop2(i,n) for(ll i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define EPS 1e-8
inline ll gcd(ll a, ll b){ ll t; while (b){ a = a%b; t = a; a = b; b = t; }return a; }
using namespace std;

// JAI SHREE KRISHNA

// 1.25H Dude!!! 1.25 H

//!!!C***

//Remember the Past,Play the Future

vector<pii>v1;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    v1.clear();
    ll n;
    cin>>n;
   loop(i,n)
    {
        ll a,b;
        cin>>a>>b;
        v1.push_back({a,b});
    }
    ll ans  =0  ;
    ll curr = 0 ;
    for(ll j = v1.size()-1;j>=0;j-=1)
    {
        v1[j].first+=curr;
        if(v1[j].first%v1[j].second==0)
            continue;
        ll x = v1[j].first/v1[j].second;
        curr+=(((x+1)*v1[j].second)-v1[j].first);
        ans+=(((x+1)*v1[j].second)-v1[j].first);
    }
    cout<<ans<<endl;
    
    
    
    
      return 0;
}

Measured memory_bytes: 2420
/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
using namespace std;
string s;
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> s;
	cout << (s == "ABC" ? "ARC" : "ABC");
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;

class b {
    static void Main(){
        
        List<int> input = new List<int>();
        for(int i=0; i<10; i++){
            input.Add(int.Parse(Console.ReadLine()));
        }

        input.Sort((a, b) => b - a);

        Console.WriteLine(input[0]);
        Console.WriteLine(input[1]);
        Console.WriteLine(input[2]);
    }
}

Measured memory_bytes: 9200
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';
int mod = 1e9 + 7;
ll inf = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int v[21], c[21];
    rep(i, n) cin >> v[i];
    rep(i, n) cin >> c[i];
    int sum = 0;
    rep(i,n){
        if(v[i]-c[i]>=0){
            sum += v[i] - c[i];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;

void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], x = tmp[1];
    int[] l = readln.split.to!(int[]);
    int d, cnt = 1;
    foreach (i; 0 .. n) {
        d += l[i];
        if (d > x) break;
        ++cnt;
    }
    cnt.writeln;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

inline int cut(string in,int mask){
	int res=0,cur=0;
	int n=in.size();
	rep(i,n){
		cur=cur*10+(in[i]-'0');
		if(mask&(1<<i))
			res+=cur,cur=0;
	}
	return res+cur;
}

void output(string in,int mask){
	int n=in.size();
	rep(i,n){
		cout << in[i];
		if(mask&(1<<i))
			cout << " ";
	}
	cout << endl;
	return;
}

int main(void){
	int t;
	string in;
	while(cin >> t >> in){
		if(t==0)
			break;
		int n=in.size();
		int cmax=0;
		int num=0;
		int ans=0;
		rep(mask,1<<(n-1)){
			int cur=cut(in,mask);
			if(cur>t)
				continue;
			if(cur>cmax)
				ans=mask,cmax=cur,num=1;
			else if(cur==cmax)
				num++;
		}
		if(num>=2)
			puts("rejected");
		else if(num==1){
			cout << cmax << " ";
			output(in,ans);
		}else
			puts("error");
	}
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b,n,sum=0;
    cin>>n>>a>>b;
    
    for(int i=1;i<=n;i++){
        int x=0,vl=i;
        while(vl!=0){
            x+=vl%10;
            vl=vl/10;
        }
        if(a<=x && x<=b) sum+=i;
    }
    
    cout<<sum<<endl;
}


Measured memory_bytes: 256
def read():
    N = int(input())
    S, T = (input().split())

    return N, S, T


def solve(N, S, T):
    s = ""
    for i in range(N):
        s += S[i]
        s += T[i]
    return s


if __name__ == '__main__':
    N, S, T = read()
    print("%s" % solve(N, S, T))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<string> S(N);
  int wa = 0, ac = 0, tle = 0, re = 0;
  for(int i = 0; i < N; i++) {
    cin >> S.at(i);
    if(S.at(i) == "WA") {
      wa++;
    }
    else if(S.at(i) == "AC") {
      ac++;
    }
    else if(S.at(i) == "TLE") {
      tle++;
    }
    else{
      re++;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

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

int main() {
    int n, k;
    std::cin >> n >> k;
    std::vector<int> h(n);
    for (int i = 0; i < n; i++) {
        std::cin >> h[i];
    }

    std::sort(h.begin(), h.end());
    int64_t ans = 0;
    for (int i = 0; i < n - k; i++) {
        ans += h[i];
    }
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1024
using System;
using static System.Console;
using System.Linq;
namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int A = tmp[0];
            int B = tmp[1];
            int C = tmp[2];
            WriteLine(
                (A == B && C == A) || (A != B && B!= C && C != A)
                ? "No" : "Yes"
                );
        }
    }
}

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

int main() {
    int N;
    cin >> N;
    int res = 0, cntA = 0, cntB = 0, cntAB = 0;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < s.size() - 1; j++) {
            if (s[j] == 'A' && s[j + 1] == 'B') res++;
        }
        if (s[0] == 'B' && s[s.size() - 1] == 'A') cntAB++;
        else if (s[0] == 'B') cntB++;
        else if (s[s.size() - 1] == 'A') cntA++;
    }

    if (cntAB == 0) {
        cout << res + min(cntA, cntB) << endl;
    } else if (cntA + cntB > 0) {
        cout << res + cntAB + min(cntA, cntB) << endl;
    } else {
        cout << res + cntAB - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int (input())
work = []
work_time = 0
flag = 0

for i in range(N):
    work.append(list(map(int , input().split())))
#print(work)
work = sorted(work , key = lambda x: x[1])
#work.sort()
#sort(work)
#print()
#print("sorting ... ")
#print()
#print(work)
for i in range(N):
    work_time += work[i][0]
    if work_time > work[i][1]:
        flag = 1
        break

if flag == 1:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 55256
#include <bits/stdc++.h>
using namespace std;
int main(){
  double n;
  cin >> n;
  bool ok=false;
  for(long long a=-20000;a<=20000;a++){
    for(long long b=-20000;b<=20000;b++){
      if(n/(a-b)==(a*a*a+b*b*b)*(a+b)+a*a*b*b){
        ok=true;
        cout << a <<" "<<b <<endl;
      }
      if(ok)break;
  }
    if(ok)break;
  }
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

int main() {
	int N;
	cin >> N;

	cout << ((N + 1000 - 1) / 1000) * 1000 - N << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
	int v, e;
	cin >> v >> e;
	vector<vector<int>> elist(v);
	vector<int> indeg(v);
	for(int i=0; i<e; ++i){
		int s, t;
		cin >> s >> t;
		elist[s].push_back(t);
		++indeg[t];
	}
	queue<int> zeroq;
	for(int i=0; i<v; ++i){
		if(indeg[i]==0) zeroq.push(i);
	}
	vector<int> result;
	while(!zeroq.empty()){
		int u=zeroq.front();
		zeroq.pop();

		result.push_back(u);
		for(int i : elist[u]){
			--indeg[i];
			if(indeg[i]==0) zeroq.push(i);
		}
	}

	for(int i : result) cout << i << endl;
}


Measured memory_bytes: 3680
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<cmath>
#include<sstream>
#include<iomanip>

//const int64_t cc = pow( 10, 9 ) + 7;

bool sort_pair( std::pair< char, int64_t > origin, std::pair< char, int64_t > another )
{
    return origin.second > another.second;
}


int main()
{
   int64_t a,b,c,d;
   std::cin>> a;
   std::cin>> b;

   std::string word;
   std::cin>> word;

   std::vector< std::pair< int64_t, int64_t > > list;
   std::pair< int64_t, int64_t > instance;
   std::vector< int64_t > check_list( a, 0 ); 

   for( int i = 0; i < b; i++ )
   {
       std::cin>> instance.first;
       std::cin>> instance.second;
       list.push_back( instance );
   }

   char s = word[0];
   int64_t count = 0;
   
   for( int i = 1; i < a; i++ )
   {
       if( s == 'A'
           && word[i] == 'C' )
       {
           count += 1;
       }
       
       check_list[i] = count;
       s = word[i];
   }

   std::vector< int64_t > result;
   for( int i = 0; i < list.size(); i++ )
   {
       result.push_back( check_list[ list[i].second - 1 ] - check_list[ list[i].first - 1 ] );
   }

   for( int i = 0; i < result.size(); i++ )
   {
       std::cout<< result[i] <<"\n";
   }
}


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

int main() {
    long long a;
    long long b;
    long long c;
    long long d;
    cin >> a >> b >> c >> d;
    long long e = a * c;
    long long f = a * d;
    long long g = b * c;
    long long h = b * d;
    cout << max({e,f,g,h}) << endl;

}


Measured memory_bytes: 3632
info = [int(i) for i in input().split(' ')]
K = info[0]
S = info[1]

count = 0
for x in range(K+1):
    for y in range(K+1):
        z = S - x - y
        if (0<=z)&(z<=K):
          count += 1
                
print(count)


Measured memory_bytes: 2940
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var n = Read().Long();
            var r = ReadSplit();
            var hl = new long[n];
            var l1 = new long[n];
            var l2 = new long[n];
            var ansl = new long[600000];
            for (int i = 0; i < n; i++)
            {
                var h = r[i].Long();
                hl[i] = h;
                l1[i] = i + 1 + h;
                if (l1[i] > 600000) continue;
                ansl[l1[i]] += 1;
                l2[i] = i + 1 - h;
            }
            long ans = 0;
            for (int i = 0; i < n; i++)
            {
                var tmp = l2[i];
                if (tmp < 0) continue;
                ans += ansl[tmp];
            }
            WriteRead(ans);
        }
        
        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 44408
#include <iostream>
using namespace std;
int main() {
	int N, M, array[51] = { 0 };
	int n1,n2;
	cin >> N >> M;
	
	for (int i = 0;i < M;i++) {
		cin >> n1 >> n2;
		array[n1]++;
		array[n2]++;
	}

	for (int i = 1;i <= N;i++) {
		cout << array[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import numpy as np

P = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
M = {}

for i in P:
	M[i] = 0

N = int(input())
for p in P:
	i = 1
	s = 0
	while(True):
		t = int(N/(p**i))
		if t == 0:
			break
		s += t
		i+=1
	M[p] = s

k2 = 0
k4 = 0
k14 = 0
k24 = 0
k74 = 0

for i in M.values():
	if 74 <= i:
		k74+=1
	if 24 <= i:
		k24+=1
	if 14 <= i:
		k14+=1
	if 4 <= i:
		k4+=1
	if 2 <= i:
		k2+=1

print(int(k74 + k24*(k2-1) + k14*(k4-1)+ (k2-2)*k4*(k4-1)/2))






Measured memory_bytes: 21408
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>

int main(void){
    std::string s;

    std::cin >> s;

    for(int i = 0; i < s.size(); i++){
        if(i%2 ==0){
            std::cout << s[i];
        }
    }
    return 0;
}




Measured memory_bytes: 576
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef complex<ld> Point;
const ll mod = 1000000007;
const ll INF = mod * mod;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

void solve() {
	int x, y, z; cin >> x >> y >> z;
	int k; cin >> k;
	vector<ll> a(x), b(y), c(z);
	rep(i, x)cin >> a[i];
	rep(i, y)cin >> b[i];
	rep(i, z)cin >> c[i];
	sort(a.begin(), a.end(), greater<ll>()); 
	sort(b.begin(), b.end(), greater<ll>());
	sort(c.begin(), c.end(), greater<ll>());
	vector<ll> v;
	rep(i, x) {
		int len = min(y, k / (i + 1));
		rep(j, len) {
			v.push_back(a[i] + b[j]);
		}
	}
	sort(v.begin(), v.end(),greater<ll>());
	vector<ll> ans;
	rep(i, v.size()) {
		int len = min(z, k / (i + 1));
		rep(j, len) {
			ans.push_back(v[i] + c[j]);
		}
	}
	sort(ans.begin(), ans.end(), greater<ll>());
	rep(i, k) {
		cout << ans[i] << endl;
	}
}
int main() {
	solve();
	//stop
	return 0;
}


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

int main(){
  int d;
  int c[27];
  int s[400][27];
  int t[400];
  static int last[27];//最後の開催日
  int ans = 0;
  int kotae[100005];

  cin >> d;
  rep(i, 26)cin >> c[i+1];
  rep(i, d){
    rep(j, 26){
      cin >> s[i+1][j+1];
    }
  }

  rep(i, d){
    cin >> t[i+1];
  }

  int m;
  cin >> m;
  rep(k, m){
    int a, b;
    cin >> a >> b;
    t[a]=b;
    //初期化
    ans = 0;
    rep(i, 26)last[i+1]=0;
    for(int i=1;i<=d;i++){
      ans += s[i][t[i]];
      last[t[i]]=i;
      for(int j=1;j<=26;j++)ans-=(i-last[j])*c[j];

    }
    kotae[k] = ans;
  }

  rep(i, m)cout << kotae[i] << endl;
  return 0;
}


Measured memory_bytes: 3952
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 2 - 170;

int main() {
    string s;
    cin >> s;
    int p = 0, q = 0;
    for (char i : s) {
        if(i == 'S') p++;
        else {
            if(p > 0) {
                p--;
                q++;
            }
        }
    }
    cout << s.length()-q*2 << "\n";
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main()
{
	int N,d,i,num[101]={},count=0;
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d",&d);
		num[d]++;
	}
	
	for(i=1;i<=100;i++)
	{
		if(num[i]>=1) count++;
	}
	
	printf("%d\n",count);
	return 0;
}	 

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0; i<(n);i++)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
	int n, m;
	vector<pair<int, int>> key;
	cin >> n >> m;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		int s = 0;
		rep(j, b) {
			int c;
			cin >> c;
			--c;
			s |= 1 << c;
		}
		key.emplace_back(s, a);
	}
	vector<int> dp(1 << n,INF);
	dp[0] = 0;
	rep(s, 1 << n) {
		rep(i, m) {
			int t = s | key[i].first;
			int cost = dp[s] + key[i].second;
			dp[t] = min(dp[t], cost);
		}
	}
	int ans = dp.back();
	if (ans == INF) ans = -1;
	cout << ans << endl;
	return 0;

}

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

struct a {
	int data;
	struct a *next,*prev;
};
typedef struct a *NP;

NP make1node(int, NP,NP);
NP find(int);
NP del(int);
NP insert(int);
void print(void);

NP head;
NP tail;

int main() {
	int in,status,n,i,flag=0;
	char order[12];
	NP t;
	tail = make1node(-2,NULL,head);
	head = make1node(-1,tail,NULL);
	scanf("%d", &n);
	//printf("DEBUG1\n");
	for (i = 0; i < n; i++) {
		//printf("DEBUG2\n");
		scanf("%s", order);
		//printf("%d", i + 1);
		if (strcmp(order, "insert") == 0) {
			scanf("%d", &in);
			insert(in);
			/*if (flag == 0) {
				tail->prev = head->next;
				flag = 1;
			}*/
			//printf("Insert\n");
		}
		else if (strcmp(order, "delete") == 0) {
			scanf("%d", &in);
			del(in);
			//if (head->next == NULL && flag==1) flag = 0;
			//printf("Delete\n");
		}
		else if (strncmp(order, "deleteF",7) == 0) {
			t = head->next;
			head->next = t->next;
			t->next->prev = head;
			free(t);
			//printf("DleteFirst\n");
		}
		else if (strncmp(order, "deleteL",7) == 0) {
			/*t = head;
			while (t->next->next!=NULL) {
				t = t->next;
			}
			t->next = NULL;
			*/
			
			tail->prev=tail->prev->prev;
			tail->prev->next = tail;

			//free(tail->prev);

			//printf("DeleteLast\n");
		}
		//print();
	}
	//printf("DEBUG3\n");
	print();
	return 0;
}

NP make1node(int key, NP p1,NP p2) {
	NP n;
	n = (NP)malloc(sizeof(struct a));
	n->data = key;
	n->next = p1;
	n->prev = p2;
	return n;
}

NP find(int key) {
	NP n;
	for (n = head; n->next != NULL; n = n->next) {
		if (n->next->data == key) return n;
	}
	return NULL;
}

NP insert(int key) {
	NP newnode;
	newnode = make1node(key, head->next,head);

	head->next->prev = newnode;
	head->next = newnode;

	return newnode;
}

NP del(int key) {
	NP n,delnode;

	if ((n = find(key)) != NULL) {
		delnode = n->next;
		n->next = delnode->next;
		delnode->next->prev = n;
		free(delnode);
		return n;
	}
	else return NULL;
}

void print(void) {
	NP t;
	for (t = head->next; t->next != tail; t = t->next) {
		printf("%d ", t->data);
	}
	printf("%d\n", t->data);
}


Measured memory_bytes: 32996
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int Ceil(int a,int b){return ((a%b==0)?a/b:a/b+1);}

int main(){
	int n,a[110],sum=0,ans=INF;
	cin>>n;
	REP(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	for(int i=-100;i<=100;i++){
		sum=0;
		REP(j,n){
			sum+=pow(abs(i-a[j]),2);
		}
		ans=std::min(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
  int N; cin >> N;
  vector<int> S(N);
  for (int i = 0; i < N; i++) cin >> S[i];
  int M; cin >> M;
  vector<int> T(M);
  for (int i = 0; i < M; i++) cin >> T[i];

  int count = 0;
  for (int i = 0; i < M; i++) {
    int k = *lower_bound(S.begin(),S.end(),T[i]);
    if (k == T[i]) count++;
  }

  cout << count << endl;
}


Measured memory_bytes: 3260
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int l = Integer.parseInt(sc.next());
        int r = Integer.parseInt(sc.next());
        int d = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int result = 0;
        for (int i = l; i <= r; i++) {
            if (i % d == 0) {
                result++;
            }
        }

        // 出力
        System.out.println(result);
    }
}


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

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

    ll N; cin >> N;
    vector<int> A(N+1); rep(i,N+1) cin >> A[i];
    vector<int> B(N); rep(i,N) cin >> B[i];

    ll sum = 0;
    rep(i,N) {
        if (0 > A[i] - B[i]) {
            sum += A[i];
            B[i] -= A[i];
        } else {
            sum += B[i];
            continue;
        }

        if (0 > A[i + 1] - B[i]) {
            sum += A[i + 1];
            A[i + 1] = 0;
        } else {
            sum += B[i];
            A[i + 1] -= B[i];
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <array>
#include <algorithm>

using namespace std;

using ll = long long int;

const ll md = 1000000007;

int main(){
    
    ll N;
    string S[2];
    
    cin >> N;
    cin >> S[0] >> S[1];

    ll dp[52][3][3] = {0};
    
    if(S[0][0] == S[1][0]){
        dp[0][0][0] = 1;
        dp[0][1][1] = 1;
        dp[0][2][2] = 1;
    }else{
        dp[0][0][1] = 1;
        dp[0][1][0] = 1;
        dp[0][0][2] = 1;
        dp[0][2][0] = 1;
        dp[0][1][2] = 1;
        dp[0][2][1] = 1;
    }
    
    for(ll i = 1; i < N; ++i){
        if(S[0][i] == S[1][i]){
            for(ll j = 0; j < 3; ++j){
                for(ll k = 0; k < 3; ++k){
                    for(ll l = 0; l < 3; ++l){
                        if(j != k && j != l){
                            dp[i][j][j] += dp[i - 1][k][l];
                        }
                    }
                }
                dp[i][j][j] %= md;
            }
        }else if(S[0][i] == S[0][i - 1]){
            for(ll k = 0; k < 3; ++k){
                for(ll l = 0; l < 3; ++l){
                    dp[i][k][l] = dp[i - 1][k][l];
                }
            }
        }else{
            for(ll j = 0; j < 3; ++j){
                for(ll m = 0; m < 3; ++m){
                    if(j != m){
                        for(ll k = 0; k < 3; ++k){
                            for(ll l = 0; l < 3; ++l){
                                if(j != k && m != l){
                                    dp[i][j][m] += dp[i - 1][k][l];
                                }
                            }
                        }
                        dp[i][j][m] %= md;
                    }
                }
            }
        }
    }
    
    ll sum = 0;
    for(ll k = 0; k < 3; ++k){
        for(ll l = 0; l < 3; ++l){
            sum += dp[N - 1][k][l];
        }
    }
    cout << sum % md << endl;
    return 0;
}

Measured memory_bytes: 256