akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mxn= 1e5+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    int d,t,s;
    cin>>d>>t>>s;
    if(s*t>=d){
        cout<<"Yes";
    }
    else cout<<"No";
}

Measured memory_bytes: 3592
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 3e5 + 200;
const long long MNN = 5e3 + 100;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n, b[MXN], ans;
bool dp[22];

int main () {
    ios;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> b[i];
    }
    int l = 1, r = 0;
    for( ; l <= n; l++){
        while(r + 1 <= n){
            bool ok = 1;
            for(int i = 0; i < 21; i++){
                if((1 << i) & b[r + 1] && dp[i] == 1){
                    ok = 0;
                    break;
                }
            }
            if(ok == 0) break;
            for(int i = 0; i < 21; i++){
                if((1 << i) & b[r + 1]){
                    dp[i] = 1;
                }
            }
            r++;
        }
        ans += (r - l + 1);
        for(int i = 0; i < 21; i++){
            if((b[l] >> i) & 1){
                dp[i] = 0;
            }
        }
    }
    cout << ans;
    return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    int A, B; cin >> A >> B;
    A--, B--;
    int h = 100, w = 100;
    vector<string> maze(h, string(w, '.'));
    rep(i, h/2) maze[i] = string(w, '#');

    bool flag = false;
    for (int i = 0; i < h / 2; i += 2) {
        for (int j = 0; j < w; j += 2) {
            if (A == 0) {
                break;
                flag = true;
            }
            maze[i][j] = '.';
            A--;
        }
        if (flag) break;
    }
    flag = false;
    for (int i = h / 2 + 1; i < h; i += 2) {
        for (int j = 0; j < w; j += 2) {
            if (B == 0) {
                break;
                flag = true;
            }
            maze[i][j] = '#';
            B--;
        }
        if (flag) break;
    }
    cout << h << ' ' << w << endl;
    rep(i, h) {
        cout << maze[i] << endl;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>

int main(){
	int N;
	std::vector<long long int> A,B;
	std::vector<long long int> sub;
	long long int res=0;
	
	std::cin >> N;
	for(int i=0;i<N;i++){
		long long int A_, B_;
		std::cin >> A_ >> B_;
		A.emplace_back(A_);
		B.emplace_back(B_);
		sub.emplace_back(A_+B_);
	}
    
    std::vector<size_t> indices(sub.size());
    std::iota(indices.begin(), indices.end(), 0);

    std::sort(indices.begin(), indices.end(), [&sub](size_t i1, size_t i2) {
        return sub[i1] > sub[i2];
    });
    
    int idx = 0;
	bool pos = true;
    
    long long int res_t=0;
    long long int res_a=0;
    
    while(idx != N){
    	if(pos) res_t += A[indices[idx]];
    	else res_a += B[indices[idx]];
    	idx++;
    	
    	pos = !pos;
    }
	
	std::cout << res_t-res_a << std::endl;
	
	return 0;
}

Measured memory_bytes: 3680
#include<stdio.h>
#define rep(i,N) for(int i=0;i<(int)N;i++)
const int MAX=1e6;
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline int GCD(int a,int b){return !b?a:GCD(b,a%b);}
const int Primes[168]=
{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,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,
 227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,
 367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,
 509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,
 661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,
 829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997};
const char common[]="not coprime",disjoint[]="pairwise coprime",several[]="setwise coprime";
char esc[1000000];
static inline int Divise(int x)
{
  if(!x){return 0;}
  rep(i,168)
  {
    if(Primes[i]*Primes[i]>x)break;
    if(x%Primes[i])continue;
    if(esc[Primes[i]-1])return 0;
    esc[Primes[i]-1]=1;
    while(x%Primes[i]==0&&x)x/=Primes[i];
  }
  if(x>1){if(esc[x-1])return 0;esc[x-1]=1;}
  return 1;
}
int main(void)
{
  int N=IN(),A=0,flag=0,g=0;
  rep(i,N){A=IN();g=GCD(g,A);if(i&&g!=1){flag=1;}if(!Divise(A)){flag=1;}}
  if(g>1)return puts(common),0;else{if(flag)return puts(several),0;else return puts(disjoint),0;}
}

Measured memory_bytes: 2448
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define r(i,n) for(int i=0; i<n; i++)
typedef long long ll;
using namespace std;

int main(void){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans=0;
  ans+=min(a,b);
  ans+=min(c,d);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from itertools import accumulate
n = int(input())
lis = []
al=[]
bl=[]
for i in range(n):
    a,b=map(int, input().split())
    c=b-a%b
    al.append(a)
    bl.append(b)
ans=0
for i in range(n-1, -1, -1):
    if bl[i]==1:
        continue
    if (al[i]+ans)%bl[i]!=0:
        c=bl[i]-((al[i]+ans)%bl[i])
        ans+=c

print(ans)


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

int main() {
  int count;
  string a;
  cin >> a;
  
  if(a[0]==a[1] && a[1] ==a[2])
    cout << "Yes" << endl;
  else if(a[1]==a[2] && a[2] == a[3])
    cout << "Yes" << endl;
  else
    cout <<"No" << endl; 
/*
  if (A*B %2 == 0) {
    cout << "Odd" << endl;
  }else{
    cout << "Even" << endl;
  }
  */
  
  
  // ここにプログラムを追記
}


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

using namespace std;

int func(int n,int s,int mimnum){
    int  cnt=0;
    if(n==1 and s >= mimnum and s <= 9) return 1;
    for(int i=mimnum;i<min(11-n,s);i++){
        cnt += func(n-1,s-i,i+1);
    }
    return cnt;
}
int main(int argc, void *argv[]){
    int n,s;
    while(true){
        cin>>n>>s;
        if(n==0 and s==0) break;
        cout<<func(n,s,0)<<endl;;
    }
}

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

using namespace std;

int main() {
	long long x;
	cin >> x;

	long long y = 100;

	int ans = 0;
	while(y < x) {
		y += y / 100;
		++ans;
	}

	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#include <deque>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(),a.end())
#define ll long long

using namespace std;


#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

const ll inf =1000000007;
typedef pair<ll,ll> Pair;

#define ALL(x) (x).begin(), (x).end()
#define inputv(v,n) rep(i,n){\
ll x;\
cin>>x;\
v.push_back(x);\
}
typedef vector<ll> vl;


const ll INF=99999999999999;
const ll MOD=1000000007;

using Edge = pair<ll,ll>;  //　1つ目は結んでいるノード、2つ目はその辺の重みを指す
using Graph = vector<vector<Edge> >;  //隣接リスト

const ll maxR=100007;

bool visit[maxR];
ll kita[maxR];

void dijkstra(const Graph &G, vl &dist, ll s){  // sを始点とする最短経路
    priority_queue<Pair, vector<Pair>, greater<Pair> > que; //secondが頂点、firstがその頂点への暫定最小コストを表す
    dist[s] = 0;  //sへの距離は0

    que.emplace(0, s);

    while(!que.empty()){
        Pair p = que.top(); //キューから辺を取り出す
        que.pop(); //取り出した辺は破棄
        ll v = p.second;
        visit[v]=true;
        if(dist[v] < p.first) continue; //辺の行き先の距離が辺のコスト未満なら、そのまま
        for(auto e : G[v]){  //頂点vから出る各辺について
            if(dist[e.first] > dist[v] + e.second){  //辺Eを通るとコストが改善される場合
                dist[e.first] = dist[v] + e.second;  //更新
                kita[e.first]=v;
                que.emplace(Pair(dist[e.first], e.first));  //キューにその頂点を格納
            }
        }
    }
}

int main() {
    ll n,m;
    cin >> n>>m;
    Graph g(n);
    vl dist(n,INF);
    rep(i,n) visit[i]=false;

    visit[0]=true;

    rep(i,m){
        ll a,b,c;
        cin >> a >> b ;
        g[a-1].push_back(Edge(b-1,1));
        g[b-1].push_back(Edge(a-1,1));
    }

    dijkstra(g,dist,0);

    bool can=true;

    rep(i,n){
        if(!visit[i]) can = false;
    }

    if(can){
        kaku("Yes");
        rep(i,n-1){
            kaku(kita[i+1]+1);
        }
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}





Measured memory_bytes: 19652
#include <bits/stdc++.h>
                        
#define int long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

using namespace std;

int dp[105][100005];
int n, W, w[105], v[105];
int32_t main()
{
    IOS //FRE
    
    cin >> n >> W;
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
    }
    int x = 100000000000000;
    // memset(dp, x, sizeof(dp));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 100005; j++)
            dp[i][j] = x;
    }
    for(int i = 0; i < n; i++)
        dp[i][0] = 0;
    dp[0][v[0]] = w[0];
    for(int i = 1; i < n; i++){
        for(int j = 0; j < 100005; j++){
            if(j - v[i] >= 0){
                dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
            }
            else dp[i][j] = dp[i - 1][j];
        }
    }
    int ans = 0;
    for(int i = 100004; i >= 1; i--){
        if(dp[n - 1][i] <= W){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    // cout << dp[n - 1][ans];
    // for(int i = 0; i < n; i++){
    //     for(int j = 0; j <= 14; j++)
    //         cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    return 0;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    ll n;
    cin >> n;
    ll ans = 1e18;
    REP(i, 1, sqrt(n)+10) {
        if(n%i != 0) continue;
        ll j = n / i;
        chmin(ans, i+j-2);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

vector<string> vals;
long long N;
string NS;
int N_size;

void rec(const string& val)
{
    if (N_size < val.size()) return;
    if (!val.empty()) vals.push_back(val);
    rec(val+'7');
    rec(val+'5');
    rec(val+'3');
}

bool is_ans(const string& val)
{
    if (val.size() < 3) return false;
    bool flag_7 = false, flag_5 = false, flag_3 = false;
    for (auto c : val) {
        if (c == '7') flag_7 = true;
        if (c == '5') flag_5 = true;
        if (c == '3') flag_3 = true;
    }
    if (!flag_7 or !flag_5 or !flag_3) return false;
    return stoll(val) <= N;
}

int main()
{
    cin >> NS;
    N = stoll(NS);
    N_size = NS.size();

    rec("");

    long long ans = 0;
    for (const auto& val : vals) {
        if (is_ans(val)) ++ans;
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){

	ll N, M; cin >> N >> M;

	ll ans = 0;
	if((M/2)<N){
		ans += M/2;
	}else{
		ans += N;
		M -= N*2;
		ans += M / 4;
	}

	cout << ans << endl;


	


	return 0;

}


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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] a = new int[10];
		int[] b = new int[10];
		for(int i = 0 ; i < a.length ; i++){
			a[i] = sc.nextInt();
		}
		for(int i = 0 ; i < a.length ; i++){
			b[i] = sc.nextInt();
		}
		Arrays.sort(a);
		Arrays.sort(b);
		System.out.println((a[a.length-1]+a[a.length-2]+a[a.length-3]) +" "+ (b[b.length-1]+b[b.length-2]+b[b.length-3]));
		sc.close();
	}

}

Measured memory_bytes: 17184
#include<bits/stdc++.h>
#define int long long
using namespace std;
 

bool comp1(pair<pair<int,int>,int>a,pair<pair<int,int>,int>b)
{
    return a.first.first<b.first.first;
}
bool comp2(pair<pair<int,int>,int>a,pair<pair<int,int>,int>b)
{
    return a.first.second<b.first.second;
}

int parent[100005];
int sz[100005];
int find_parent(int ver)
{
    if(ver==parent[ver])
        return ver;
    return parent[ver]=find_parent(parent[ver]);
}

bool merge(int a,int b)
{
    a=find_parent(a);
    b=find_parent(b);
    if(a!=b)
    {
        if(sz[a]<sz[b])
            swap(a,b);
        sz[a]+=sz[b];
        parent[b]=a;
        return true;
    }
    return false;
}

signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif    

    int n;
    cin>>n;
    vector<pair<pair<int,int> ,int> >pp;
    int x,y;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y;
        pp.push_back({{x,y},i});
    }
    sort(pp.begin(),pp.end(),comp1);
    vector<pair<int,pair<int,int> > >lol;
    for(int i=0;i<n-1;i++)
    {
        lol.push_back({abs(pp[i].first.first-pp[i+1].first.first),{pp[i].second,pp[i+1].second}});
    }
    sort(pp.begin(),pp.end(),comp2);
    for(int i=0;i<n-1;i++)
    {
        lol.push_back({abs(pp[i].first.second-pp[i+1].first.second),{pp[i].second,pp[i+1].second}});
    }
    for(int i=1;i<=n;i++)
    {
        parent[i]=i;
        sz[i]=1;
    }
    int ans=0;
    sort(lol.begin(),lol.end());
    for(auto i:lol)
    {
        if(merge(i.second.first,i.second.second))
            ans+=i.first;
    }
    cout<<ans;

}

Measured memory_bytes: 12044
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INF = 1145141919, MOD = 1e9 + 7;
const int64_t LINF = 8931145141919364364, LMOD = 998244353;
// const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
// const int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

int main() {
    int n,k; cin>>n>>k;
    if(k==1){
        cout<<0<<endl;
        return 0;
    }
    int maxi=n-k+1;
    int mini=1;
    cout<<maxi-mini<<endl;
    return 0;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define for_each(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = __INT_MAX__;               // 2^31 - 1
const long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    int a, b;
    cin >> a >> b;
    int ans = -1;
    rep(i, 1500) {
        if (floor(i * 0.08) == a && floor(i * 0.1) == b) {
            ans = i;
            break;
        }
    }
    out(ans);
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
#define ll long long
struct apple
{
    ll col,d;
}a[1000100];
bool mycmp(apple x,apple y)
{
    return x.d>y.d;
}
int main()
{
    ll x,y,A,B,C,d,tot=0;
    scanf("%lld%lld%lld%lld%lld",&x,&y,&A,&B,&C);
    for(ll i=1;i<=A;i++) {tot++;scanf("%d",&a[tot].d);a[tot].col=1;}
    for(ll i=1;i<=B;i++) {tot++;scanf("%d",&a[tot].d);a[tot].col=2;}
    for(ll i=1;i<=C;i++) {tot++;scanf("%d",&a[tot].d);a[tot].col=0;}
    sort(a+1,a+tot+1,mycmp);
    ll sum=0,tmp=0;
    for(ll i=1;i<=tot;i++)
    {
        if(a[i].col==1 && x)
        {
            x--;
            sum+=a[i].d;
        }
        if(a[i].col==2 && y)
        {
            y--;
            sum+=a[i].d;
        }
        if(a[i].col==0)
        {
            tmp++;
            sum+=a[i].d;
        }
        if(x+y==tmp) break;
    }
    printf("%lld\n",sum);
}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    int n,k,P[200001];
    cin>>n>>k;
    rep(i,n) cin>>P[i];
    int a=1,b=0,x=0,ans=0;
    rep(i,n-1){
        if(P[i]<P[i+1]) a++;
        else a=1;
        if(a>=k) b++;
        if(a>k) x++;
    }
    set<int> A,B;
    int z;
    rep(i,k) A.insert(P[i]),B.insert(-P[i]);
    for(int i=k;i<n;i++){
        z=0;
        int c=P[i-k],d=P[i];
        if(*A.begin()!=c) z=1;
        A.erase(c);
        A.insert(d);
        B.erase(-c);
        B.insert(-d);
        if(*B.begin()!=-d) z=1;
        if(z) continue;
        ans++;
    }
    cout<<(n-k+1)-(ans+b-x)+(b>0);
}

Measured memory_bytes: 19840
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#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 N, T, A; cin >> N >> T >> A;
  int ans = 0;
  double dif = 99999999.9;
  rep(i,N) {
    int h; cin >> h;
    if (abs(A - (T - h * 0.006)) < dif) {
      dif = abs(A - (T - h * 0.006));
      ans = i+1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5+5;
int c[26][N];char s[N];
inline int lowbit(int x){return x&(-x);}
void add(int i,int x,int num){
    while(x<=N){
        c[i][x]+=num;
        x+=lowbit(x);
    }
}
int sum(int i,int x){
    int ans=0;
    while(x){
        ans+=c[i][x];
        x-=lowbit(x);
    }
    return ans;
}
int main(){
	int n,m,op,x,y;char y1[2];
	scanf("%d%s",&n,s+1);
	for(int i=1;s[i];i++)add(s[i]-'a',i,1);
	scanf("%d",&m);
	for(int i=0;i<m;i++){
		scanf("%d",&op);
		if(op==1){
			scanf("%d%s",&x,y1);
			add(s[x]-'a',x,-1);
			s[x]=*y1;add(s[x]-'a',x,1);
		} 
		else{
			int ans=0;
			scanf("%d%d",&x,&y);
			for(int i=0;i<26;i++)if(sum(i,y)-sum(i,x-1))ans++;
			printf("%d\n",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 51584
import sys,collections
input = sys.stdin.readline

N = int(input())
A = list(map(int,input().split()))
Ac = collections.Counter(A)

def num_combi2(n):
    combi = n*(n-1)//2
    return combi

def sub_combi2(n):
    c_before = n*(n-1)//2
    c_after =(n-1)*(n-2)//2
    return c_after - c_before

all_combi = 0
for val in Ac.values():
    all_combi += num_combi2(val)

for i in range(N):
    print(all_combi + sub_combi2(Ac[A[i]]))


Measured memory_bytes: 109748
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
	boost;
	int n;
	cin>>n;
	while(n--){
		int x;
		cin>>x;
		if(x%2==0){
			//dg(x);
			if(x%3!=0 && x%5!=0){
				cout<<"DENIED";
				return 0;
			}
		}
	}
	cout<<"APPROVED";
	return 0;
}

Measured memory_bytes: 256
import numpy as np
A = np.zeros((3,3), dtype = "int")
A[0,0], A[0,1], A[0,2] = map(int,input().split())
A[1,0], A[1,1], A[1,2] = map(int,input().split())
A[2,0], A[2,1], A[2,2] = map(int,input().split())
N= int(input())
b = [int(input()) for i in range(N)]
for i in range(3):
	for j in range(3):
		for k in range(N):
			if A[i,j] == b[k]:
				A[i,j] = 0
if (A[0,0] == 0 and A[0,1] == 0 and A[0,2] ==0) or (A[1,0] == 0 and A[1,1] == 0 and A[1,2] == 0) or (A[2,0] ==0 and A[2,1] ==0 and A[2,2] == 0) or (A[0,0] == 0 and A[1,1] == 0 and A[2,2] == 0) or (A[2,0] == 0 and A[1,1] == 0 and A[0,2] == 0) or (A[0,0] == 0 and A[1,0] == 0 and A[2,0] == 0) or (A[0,1] == 0 and A[1,1] == 0 and A[2,1] == 0) or (A[0,2] == 0 and A[1,2] == 0 and A[2,2] == 0):
	print("Yes")
else:
	print("No")

Measured memory_bytes: 12528
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int dr[2] = { 1, 0 };
int dc[2] = { 0, 1 };

int revDr[2] = { -1, 0 };
int revDc[2] = { 0, -1 };

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll h, w;
  cin >> h >> w;
  vector<string> maze(h);
  rep(r, h) {
    cin >> maze[r];
  }

  vector<vector<ll>> dp(h, vector<ll>(w, INF));
  if (maze[h-1][w-1] == '#') {
    dp[h-1][w-1] = 1;
  } else {
    dp[h-1][w-1] = 0;
  }
  // We calculate rsult by dp. dp[i][j] .. min black for reach to (h-1,w-1).
  for (int r = h-1; r >= 0; --r) {
    for (int c = w-1; c >= 0; --c) {
      if (r < h-1) { // try bottom
        ll cand = dp[r+1][c];
        if (maze[r][c] == '#' && maze[r+1][c] != '#') {
          cand += 1;
        }
        dp[r][c] = min(dp[r][c], cand);
      }
      if (c < w-1) { // try right
        ll cand = dp[r][c+1];
        if (maze[r][c] == '#' && maze[r][c+1] != '#') {
          cand += 1;
        }
        dp[r][c] = min(dp[r][c], cand);
      }
      // cout << "(r,c):" << r<<","<<c<<endl;
      // cout << "dp[r][c]:" << dp[r][c] <<endl;
    }
  }

  cout << dp[0][0] << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int main(void){
    
    int n;
    cin >> n;
    
    vector<pair<int,int>> vpii;
    
    for(int i = 0; i < n; i++){
        int l,r;
        cin >> l >> r;
        
        vpii.push_back({l,r});
        
    }
    
    vpii.push_back({1000000,1000000});
    
    sort(vpii.begin(),vpii.end());
    
    int answer = 0;
    
    for(int i = 0; i < vpii.size()-1; i++){
        if(vpii[i].second >= vpii[i+1].first){
            answer += vpii[i+1].first - vpii[i].first + 1;
        }else{
            answer += vpii[i].second - vpii[i].first + 1;
        }
    }
    
    cout << answer << endl;
    
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>
#include<chrono>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

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

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

ll mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
    ll gcd(ll a, ll b) {
        return (a == 0 ? b : gcd(b % a, a));
    }
    ll gcdex(ll a, ll b, ll& x, ll& y) {
        if (a == 0) {
            x = 0; y = 1;
            return b;
        }
        ll x1, y1;
        ll d = gcdex(b % a, a, x1, y1);
        x = y1 - (b / a) * x1;
        y = x1;
        return d;
    }

    ll inv_eu(ll a, ll m) {
        ll x, y;
        ll g = gcdex(a, m, x, y);
        if (g != 1)
            assert(0);
        else {
            x = (x % m + m) % m;
            return x;
        }
    }
}

ll const maxn = 1e6 + 6;

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n; cin >> n;
    vector<ll>a(n);
    for (ll i = 0; i < n; i++) {
        ll x, y; cin >> x >> y;
        a[i] = x - y;
    }

    for (ll i = 0; i + 2 < n; i++) {
        if (a[i] == a[i + 1] and a[i + 1] == a[i + 2] and a[i] == 0) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
   
    return 0;
}

/*

*/

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
/*long maxValue(int n, int w, vector<int>& weight, vector<int>& value, int i) {
	if (w <= 0 or i == n) return 0;
	cout << w << endl;
	if (w-weight[i] < 0) return maxValue (n, w, weight, value, i+1);
	return (long) max ((long) value[i] + maxValue (n, w-weight[i], weight, value, i+1), 
				maxValue (n, w, weight, value, i+1));
}*/
int main() {
    long n; 
    cin >> n;
    long W;
    cin >> W;
    vector<long> weight(n), value(n);
    for (long i = 0; i < n; ++i)
    	cin >> weight[i] >> value[i];
    /*long sum = maxValue(n, W, weight, value, 0);
    cout << sum;*/
    long i, w; 
    long K[n + 1][W + 1];
    for (i = 0; i <= n; i++) { 
        for (w = 0; w <= W; w++) { 
            if (i == 0 || w == 0) 
                K[i][w] = 0; 
            else if (weight[i - 1] <= w) 
                K[i][w] = max( 
                    value[i - 1] + K[i - 1][w - weight[i - 1]], 
                    K[i - 1][w]); 
            else
                K[i][w] = K[i - 1][w]; 
        }
    } 
    cout << K[n][W];
}

Measured memory_bytes: 79104
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(1)
	n = sys.stdin.readline().rstrip()
	cnt = 0
	for si in n:
		cnt += int(si)
	if cnt % 9 == 0:
		print("Yes")
	else:
		print("No")
	


main()

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

int main(){

    ll n,k;
    cin >> n >> k;

    vector<ll> a(200001,0);

    rep(i,n){
        ll t;
        cin >> t;
        a[t]++;
    }

    sort(a.begin(),a.end());
    auto en=a.end();
    rep(i,k) en--;
    ll ans=0;
    for(auto it=a.begin();it!=en;it++){
        ans+= *it;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
import sys
input = sys.stdin.readline
q = int(input())
fact = [1]*(10**5+7)
fa_sum = [0]*(10**5+7)
fact[0] = 0
fact[1] = 0

for i in range(2,10**5+7):
  if fact[i]:
    for j in range(i*2,10**5+7,i):
      fact[j] = 0
  if fact[i] and fact[(i+1)//2]:
    fa_sum[i] = fa_sum[i-1] + 1
  else:
    fa_sum[i] = fa_sum[i-1]

for k in range(q):
  l,r = map(int,input().split())
  print(fa_sum[r]-fa_sum[l-1])

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

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

/*********** Constants ***********/
const auto INF = static_cast<ll>(1ll << 60);
const auto MOD = static_cast<ll>(1e9 + 7);
const auto NIL = -1;

/************* Utils *************/
struct Node {
    ll parent, left, right;
};

vector<Node> Tree;
vector<ll> Depth;
vector<ll> Height;

void setDepth(ll u, ll p) {
    Depth[u] = p;
    if (Tree[u].right != NIL) {
        setDepth(Tree[u].right, p + 1);
    }
    if (Tree[u].left != NIL) {
        setDepth(Tree[u].left, p + 1);
    }
}

ll setHeight(ll u) {
    ll h1 = 0, h2 = 0;
    if (Tree[u].left != NIL) {
        h1 = setHeight(Tree[u].left) + 1;
    }
    if (Tree[u].right != NIL) {
        h2 = setHeight(Tree[u].right) + 1;
    }
    return Height[u] = max(h1, h2);
}

/*********** Variables ***********/
ll N, ROOT;

/*********** Functions ***********/
bool init() {
    cin >> N;
    Tree.resize(N, Node{NIL, NIL, NIL});
    Depth.resize(N, 0);
    Height.resize(N, 0);
    for (ll i = 0; i < N; i++) {
        ll id, left, right;
        cin >> id >> left >> right;
        Tree[id].left = left;
        Tree[id].right = right;
        Tree[left].parent = Tree[right].parent = id;
    }
    return true;
}

void solve() {
    for (ll i = 0; i < N; i++) {
        if (Tree[i].parent == NIL) {
            ROOT = i;
            break;
        }

    }
    setDepth(ROOT, 0);
    setHeight(ROOT);
}

void output() {
    for (ll id = 0; id < N; id++) {
        cout << "node " << id << ": ";
        cout << "parent = " << Tree[id].parent << ", ";
        cout << "sibling = ";
        if (Tree[id].parent == NIL) {
            cout << -1 << ", ";
        }
        else if (Tree[Tree[id].parent].right == id) {
            cout << Tree[Tree[id].parent].left << ", ";
        }
        else {
            cout << Tree[Tree[id].parent].right << ", ";
        }
        cout << "degree = ";
        ll deg = 0;
        if (Tree[id].left != NIL) {
            deg++;
        }
        if (Tree[id].right != NIL) {
            deg++;
        }
        cout << deg << ", ";
        cout << "depth = " << Depth[id] << ", ";
        cout << "height = " << Height[id] << ", ";
        if (Tree[id].parent == NIL) {
            cout << "root" << endl;
        }
        else if (Tree[id].left == NIL && Tree[id].right == NIL) {
            cout << "leaf" << endl;
        }
        else {
            cout << "internal node" << endl;
        }
    }
}

int main() {
    init();
    solve();
    output();
    return 0;
}


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

/*
  ll n , m ;
  cin >> n >> m ;
  ll a , b , c ;
  cin >> a >> b >> c ;
  vector<ll> A(n) ;
  cout << "Yes" << endl ;
  cout << "No"  << endl ;
*/

int main(){
  ll n ;
  cin >> n  ;
  vector<ll> A(n) ;
  rep(i,n) cin >> A.at(i) ;
  ll kabu = 0 ;
  ll money = 1000 ;
  rep(i,n-1){
    if( A[i] < A[i+1] ){
      ll k = i ;
      //cout << i << ' ' << k << endl;
      while( A[k] < A[k+1] && k+1 <= n - 1 ){
		k++ ;
      }
      //cout << i << ' ' << k << endl;
      kabu = ( money / A[i] ) ;
      money =  money - A[i] * kabu ;
      money += A[k] * kabu ;
      i = k ;
      kabu = 0 ;
      //cout << k << ' '<< kabu << ' ' << money << endl;
    }
  }
  cout << money << endl ; 
}


Measured memory_bytes: 3604
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << "debug: " << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << "debug: " << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	int x; cin >> x;
	x ^= 1;
	cout << x << "\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;
// ついでに有理数型
using rat = boost::rational<bint>;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()

void solve(long long N, std::vector<long long> A, long long Q, std::vector<long long> B, std::vector<long long> C){
  map<ll,ll>x;
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    x[A[i]]++;
    ans += A[i];
  }
  for (int i = 0; i < Q; i++) {
    ans = ans + (C[i] - B[i])*x[B[i]] ;
    cout << ans << endl;
    x[C[i]]+=x[B[i]];
    x[B[i]]=0;
  }
}

int main(){
    long long N;
				scanf("%lld",&N);
				std::vector<long long> A(N);
				for(int i = 0 ; i < N ; i++){
								scanf("%lld",&A[i]);
				}
				long long Q;
				scanf("%lld",&Q);
				std::vector<long long> B(Q);
				std::vector<long long> C(Q);
				for(int i = 0 ; i < Q ; i++){
								scanf("%lld",&B[i]);
								scanf("%lld",&C[i]);
				}
    solve(N, std::move(A), Q, std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 11784
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    loop {
        let x:String = read();

        let mut sum = 0;
        for i in x.chars() {
            sum += i.to_digit(10).unwrap();
        }
        if sum == 0 {
            break;
        }
        println!("{}", sum);
    }
}


Measured memory_bytes: 5020
#include<bits/stdc++.h>
using namespace std;
int main(){
    char a;
    cin>>a;
    if(a=='A')cout<<'T'<<'\n';
    if(a=='T')cout<<'A'<<'\n';
    if(a=='C')cout<<'G'<<'\n';
    if(a=='G')cout<<'C'<<'\n';
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

#define MAX 1000000

void makelist(int *list, int x) {
  for (int i = x; i < MAX; i++) {
    list[i] = min(list[i], list[i-x]+1);
  }
}

int main() {
  int list1[MAX], list2[MAX], a, n;
  for (int i = 1; i < MAX; i++) {
    list1[i] = list2[i] = INF;
  }
  for (int i = 1; ; i++) {
    a = i*(i+1)*(i+2)/6;
    if (a >= MAX) break;
    makelist(list1, a);
    if (a & 1) makelist(list2, a);
  }
  while (cin >> n, n) {
    cout << list1[n] << " " << list2[n] << el;
  }
}

Measured memory_bytes: 8972
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

const ll MOD = 1e+9 + 7;
ll combi[2020][2020];
vector<int> g[2020];
int parent[2020];
int memo[2020][2020];
int cnt[2020];
int cnt2[2020];
int sum[2020];
int n, c, s, t;

void dfs(int node) {
  ll c = 1;
  sum[node] = 1;
  FORIT(it, g[node]) {
    dfs(*it);
    sum[node] += sum[*it];
  }
  ll rest = sum[node] - 1;
  FORIT(it, g[node]) {
    c = c * cnt[*it] % MOD * combi[rest][sum[*it]] % MOD;
    rest -= sum[*it];
  }
  cnt[node] = c;
}

ll Cnt(int node, int left, int child) {
  int rest = n - left;
  if (cnt2[node] == -1) {
    ll ret = 1;
    int r = sum[node] - 1;
    if (node != child) { r -= sum[child]; }
    FORIT(it, g[node]) {
      if (*it == child) { continue; }
      ret = ret * cnt[*it] % MOD * combi[r][sum[*it]] % MOD;
      r -= sum[*it];
    }
    cnt2[node] = ret;
  }
  rest--;
  int r = sum[node] - 1;
  if (node != child) {
    rest -= sum[child];
    r -= sum[child];
  }
  if (rest < 0) { return 0; }
  return cnt2[node] * combi[rest][r] % MOD;
}

ll calc(int node, int left, int child) {
  if (left < 0) { return 0; }
  if (memo[node][left] != -1) { return memo[node][left]; }
  ll ret = Cnt(node, left, child);
  if (node != 0) {
    ret = (ret * calc(parent[node], left - 1, node)) % MOD;
  }
  if (node != child) {
    ret = (ret + calc(node, left - 1, child)) % MOD;
  }
  return memo[node][left] = ret;
}

int main() {
  MEMSET(combi, 0);
  combi[0][0] = 1;
  REP(i, 2010) REP(j, 2010) {
    combi[i + 1][j] = (combi[i + 1][j] + combi[i][j]) % MOD;
    combi[i + 1][j + 1] = (combi[i + 1][j + 1] + combi[i][j]) % MOD;
  }
  while (scanf("%d %d %d %d", &n, &c, &s, &t) > 0) {
    n++;
    t = n - t;
    MEMSET(parent, 0);
    MEMSET(memo, -1);
    MEMSET(cnt, -1);
    MEMSET(cnt2, -1);
    MEMSET(sum, 0);
    REP(i, 2020) { g[i].clear(); }
    REP(i, c) {
      int from, to;
      scanf("%d %d", &to, &from);
      g[from].push_back(to);
      parent[to] = from;
    }
    FOR(i, 1, n) {
      if (parent[i] == 0) { g[0].push_back(i); }
    }
    dfs(0);
    ll ans = 0;
    if (sum[0] == n) {
      ans = calc(s, t, s);
    }
    printf("%lld\n", ans);
  }
}

Measured memory_bytes: 0
from itertools import *
def g(a,x,b):return a+b if x=='+'else a-b if x=='-'else a*b
def f(s):
 for a,b,c,d in permutations(s):
  for x,y,z in product('+-*',repeat=3):
   if g(g(a,x,b),y,g(c,z,d))==10:return f"(({a} {x} {b}) {y} ({c} {z} {d}))"
   if g(g(a,x,g(b,y,c)),z,d)==10:return f"(({a} {x} ({b} {y} {c})) {z} {d})"
 else:return 0
for e in iter(input,'0 0 0 0'):print(f(list(map(int,e.split()))))


Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
vector<int> all(N);
for (int i = 0; i < N; i++) {
  cin >> all.at(i);
}

int max=0;
for (int i = 0; i < N; i++) {
  if(max<all.at(i)){
    max = all.at(i);
  }
}

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

    sum += all.at(i);

}

if(sum-max*2>0){
    cout <<   "Yes" << endl;
}
else{
    cout <<   "No" << endl;
}
}


Measured memory_bytes: 256
# ABC106 C - To Infinity
s = input()
k = int(input())

idx = 0
last = 0
a11_one = True

for i in range(len(s)):
    if s[i:i+1] == '1':
        idx = i
    else:
        last = s[i:i+1]
        a11_one = False
        break
if k==1:
    print(s[0:1])
    exit()
if a11_one:
    print('1')
else:
    print('1' if k-1 <= idx else last)


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

int main() {
	int n;cin>>n;
	vector<int> a(n);
	vector<int> c(100001,0);
	for(int i=0;i<n;i++){
		cin>>a[i];
		c[a[i]]++;
	}
	int trash=0;
	for(int i=0;i<100001;i++){
		if(c[i]){
			trash+=c[i]-1;
		}
	}
	trash+=trash%2;
	cout<<n-trash<<endl;


	return 0;
}


Measured memory_bytes: 1024
while 1:
    try:
        line = raw_input()
    except EOFError:
        break
    i = 0
    ret = ''
    while i < len(line):
        if line[i] == '@':
            ret += line[i + 2] * int(line[i + 1])
            i += 3
        else:
            ret += line[i]
            i += 1
    print ret

Measured memory_bytes: 4212
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	alice := 0
	bob := 0
	for i := 0; i < n; i++ {
		if i%2 == 0 {
			alice += a[i]
		} else {
			bob += a[i]
		}
	}
	fmt.Println(alice - bob)
}


Measured memory_bytes: 512
#include <iostream>
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pii pair<ll, ll>
#define pll pair<ll , ll>
#define mpi make_pair
#define F first
#define S second
#define pb push_back
#define N 200005
#define INF 1000000000000000

int arr[200005];
int main()
{   
    fastio
    int n;
    cin>>n;

    for(int i = 0 ; i<n;i++)
    {
        cin>>arr[i];
    }

    int dp[n];
    for(int i = 0 ; i<n;i++)dp[i] = INT_MAX;

    dp[0] = 0;

    for(int i = 1 ; i<n;i++)
    {   
        // cout<<dp[i]<<" ";
        if(i-1 >=0)dp[i] = min(dp[i] , abs(arr[i]-arr[i-1]) + dp[i-1]);
        if(i-2 >=0)dp[i] = min(dp[i] , abs(arr[i]-arr[i-2]) + dp[i-2]);
        // cout<<dp[i]<<" ";
    }

    cout<<dp[n-1]<<endl;
    
    return 0;
} 

Measured memory_bytes: 1024