akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <vector>
#include <cstring>
#include <bits/stdc++.h>
#include <deque>
#define Long long long int
#define For(i,a,b) for(Long i=a;i<=b;i++)
#define ForR(i,a,b) for(Long i=a;i>=b;i--)
#define e5 100009
#define maxD 10
#define mod 1000000007
#define vc 1000000000
using namespace std;

bool isAddToEnd[200100];
Long dem = 0;
deque<Long> mydeque;
vector<Long> color[200003];
Long permute[200005];
Long gt[200003];

Long cal(Long b, Long exp){
	if(exp == 1) return b%mod;
	Long c = cal(b,exp/2);
	if(exp % 2==0){		
		return (c*c) % mod ;
	}
	return ((c*c)%mod *b)%mod;
}
main(){
	Long N,X,Y;
	Long c,w;
	cin >> N >> X >> Y;
	For(i,1,N){
		scanf("%d%d",&c,&w);
		color[c].push_back(w);
	}
	Long index1 = c;
	Long index2 = c;	
	dem = 0;
	For(i,1,N){
//		cout <<"ff-";
		if(color[i].empty()){
//			cout << "1111";
			continue;
		}
		dem ++;
//		cout << "2222";
		sort(color[i].begin(),color[i].end());
//		cout << "sorted";
		if(color[i][0]<color[index1][0]){
//			cout << "-------";
			index1 = i;
		}
	}		
	if(dem == 1){
		permute[index1]=upper_bound(color[index1].begin(),color[index1].end(),X-color[index1][0])-color[index1].begin();
	}	else	{
		color[0].push_back(vc);		
		index2 = 0;
		For(i,1,N){				
			if(color[i].empty()){
				continue;
			}			
			if(color[i][0]<color[index2][0] && i!= index1){
				index2 = i;
			}
		}				
		For(i,1,N){
			if(color[i].empty()){
				permute[i] = 0;
				continue;
			}
			if(i == index1){
				permute[i]=upper_bound(color[i].begin(),color[i].end(),Y-color[index2][0])-color[i].begin();
			}	else	{
				permute[i]=upper_bound(color[i].begin(),color[i].end(),Y-color[index1][0])-color[i].begin()	;
			}
			Long temp = upper_bound(color[i].begin(),color[i].end(),X-color[i][0])-color[i].begin();
			if(temp > 1 && permute[i] >= 1){
				permute[i]=max(permute[i],temp);	
			}			
		}		
	}	
//	cout << "\nindex1 =" << index1 << " index2 = " << index2;
	Long result = 1;
	Long maxP = 0;
	For(i,1,N){
		maxP += permute[i];
//		cout << "\npermute " << i << " : " << permute[i];
	}
	gt[0]=1;
	For(i,1,maxP){
		gt[i] = gt[i-1]*i;
		gt[i] %= mod;
	}
	result = gt[maxP];
//	cout << "    ddd" << maxP << "  <" << result << "gt[maxP]" << gt[maxP];
	For(i,1,N){
		if(permute[i] == 0) {
			continue;
		}
		Long CAL=cal(gt[permute[i]],mod-2);
//		cout << "\n CAL : " << CAL << "permute : " << permute[i] << "gt :" << gt[permute[i]]; 
		
		result = (result * CAL) % mod;
	}
	cout << result;
}

Measured memory_bytes: 12544
n=int(raw_input())
cards=[[0 for j in range(13)]for i in range(4)]
for i in range(n):
        c=map(str,raw_input().split())
        if c[0]=="S":
                c[0]=0
        elif c[0]=="H":
                c[0]=1
        elif c[0]=="C":
                c[0]=2
        elif c[0]=="D":
                c[0]=3
        cards[int(c[0])][int(c[1])-1]=1
for i in range(4):
        for j in range(13):
                if cards[i][j] == 0:
                        if i == 0:
                                k=str("S")
                        elif i == 1:
                                k=str("H")
                        elif i == 2:
                                k=str("C")
                        elif i == 3:
                                k=str("D")
                        print k,j+1

Measured memory_bytes: 4264
#!/usr/bin/env python3
import sys


def solve(x: "List[int]", y: "List[int]"):
    base = [x[1]-x[0], y[1]-y[0]]
    x3, y3 = [x[1]-base[1], y[1] + base[0]]
    x4, y4 = [x3-base[0], y3-base[1]]
    # x4 = x[0] + y[0]-y[1]
    # y4 = y[0] - x[0]-x[1]
    print(*[x3, y3, x4, y4])
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = [int()] * (2)  # type: "List[int]"
    y = [int()] * (2)  # type: "List[int]"
    for i in range(2):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(x, y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
    string s;
    cin >> s;
    int ans = 700;
    rep(i, s.size()){
        if(s[i] == 'o') ans += 100;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
def spaceinput():
    return list(map(int,input().split(" ")))


N=int(input())
a=spaceinput()

#a=sorted(a)

H=[0]*(10**5+1)
for sa in a:
    H[sa]+=1

maxsum=0
for i in range(1,len(H)-1):
    sum=H[i-1]+H[i]+H[i+1]
    if maxsum<sum:
        maxsum=sum

print(maxsum)


Measured memory_bytes: 13964
import bisect

N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0
# a <= b <= c

for b in range(1,N-1):
  for c in range(b+1,N):
    # search min(c) with a + b > c <=> a > c - b
    idx = bisect.bisect_left(L[:b],L[c]-L[b]+1)
    #print(L[b],L[c],idx)
    ans += max(b-idx,0) if idx >= 0 else 0 
    #print(idx, ans)
#print(L)
print(ans)

Measured memory_bytes: 51676
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
/*
         ########     ########   ########   #########   ##       #######   ##       #######
         #      #     #      #   #      #       #       # #      #     #   # #      #     #
         #      #     #      #   #      #       #       #  #     #     #   #  #     #     #
         ########     #      #   #      #       #       #   #    #     #   #   #    #     #
         ###          #      #   #      #       #       #    #   #######   #    #   #######
         #  #         #      #   #      #       #       #   #    #     #   #   #    #     #
         #   #        #      #   #      #       #       #  #     #     #   #  #     #     #
         #    #       #      #   #      #       #       # #      #     #   # #      #     #
         #     #      ########   ########       #       ##       #     #   ##       #     #     
*/

#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define debug(a)          \
    cerr << #a << ": ";   \
    for (auto i : a)      \
        cerr << i << " "; \
    cerr << '\n';
#define trace(a) cerr << #a << ": " << a << "\n"
#define print(ar, n)            \
    for (int u = 0; u < n; u++) \
    {                           \
        cout << ar[u] << " ";   \
    }                           \
    cout << endl;
#define int long long
#define M 1000000007
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
signed main()
{
    rootdada;

    int x;
    cin >> x;
    if (360 % x == 0)
        cout << 360 / x << endl;
    else
    {
        int l = __gcd((int)360, x);
        int y = x / l;
        cout << (y * 360) / x << endl;
    }
}

Measured memory_bytes: 3648
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;
#define int long long
const int N = (int) 0, mod = (int) 0;

int32_t main() {
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	for (int pos = 0; pos <= n - 1; ++pos) {
		int neg = n - 1 - pos;
		int stval = neg * -c + pos * c;
		int l = stval - (d - c) * neg;
		int r = stval + (d - c) * pos;
		if (l <= b - a && b - a <= r) {
			cout << "YES\n";
			return 0;
		}
	}
	cout << "NO\n";
}





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

int n, m, t[105], p, x;
long long sum;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> t[i];
		sum += t[i];
	}

	cin >> m;
	while (m--) {
		cin >> p >> x;
		cout << sum - (t[p] - x) << '\n';
	}
 
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,n;
    cin >> h >> w >> n;
    int sr,sc;
    cin >> sr >> sc;
    string s,t;
    cin >> s >> t;
    int l=0,r=w+1,u=0,d=h+1;
    int ml=0,mr=w+1,mu=0,md=h+1;
    for(int i=n-1;i>=0;--i){
        if(t[i]=='L'){
            r = min(w+1,r+1);
        }else if(t[i]=='R'){
            l = max(0,l-1);
        }else if(t[i]=='U'){
            d = min(h+1,d+1);
        }else if(t[i]=='D'){
            u = max(0,u-1);
        }
        ml = max(l,ml);
        mr = min(r,mr);
        mu = max(u,mu);
        md = min(d,md);
        if(s[i]=='L'){
            l = min(w+1,l+1);
        }else if(s[i]=='R'){
            r = max(0,r-1);
        }else if(s[i]=='U'){
            u = min(h+1,u+1);
        }else if(s[i]=='D'){
            d = max(0,d-1);
        }
        ml = max(l,ml);
        mr = min(r,mr);
        mu = max(u,mu);
        md = min(d,md);
        //cout << l << " " << r << " " << u << " " << d << endl;
    }
    //cout << ml << " " << mr << " " << mu << " " << md << endl;    
    if(ml>=w||mr<=1||mu>=h||md<=1){
        cout << "NO" << endl;
        return 0;
    }
    if(sc<=l||sc>=r||sr<=u||sr>=d){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 920
N,M = map(int,input().split())
vertex = [[0 for j in range(N+1)] for i in range(N+1)]
AB = [list(map(int,input().split())) for _ in range(M)]

for i in range(M):
    a,b = AB[i]
    vertex[a][b] = 1
    vertex[b][a] = 1

from itertools import permutations

ans = 0
for v in permutations([i+2 for i in range(N-1)], N-1):
    v = [1] + list(v)
    canmake = 1
    for j in range(N-1):
        if not vertex[v[j]][v[j+1]]:
            canmake = 0
            break
    if canmake:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <math.h>
using namespace std;

void findNumOfDigit(long n,int base){
	
		int dig = (int)(floor( log(n)/log(base))+1);
		
		printf("%d",dig);
	}

int main(){
	long n;int base;
	scanf("%ld %d",&n,&base);
	findNumOfDigit(n,base);
	return 0;
	}


Measured memory_bytes: 2324
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;
template<typename T>
struct Edge {
    int u, v;
    T cost;
    Edge(int u, int v, T c) : u(u), v(v), cost(c) {}
    bool operator< (const Edge &e) const {return cost < e.cost;}
};

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;
ll R[300005], C[300005];
map<P, bool> m;

int main(void) {
    int H, W, M;
    cin >> H >> W >> M;
    vector<P> p;
    rep(i, 0, M) {
        int r, c;
        cin >> r >> c;
        p.pb(mp(r, c));
        R[r]++; C[c]++;
        m[mp(r, c)] = true;
    }

    vector<pair<ll, int>> RR, CC;
    rep(i, 0, 300005) {
        RR.pb(mp(R[i], i));
        CC.pb(mp(C[i], i));
    }
    sort(rall(RR));
    sort(rall(CC));

    rep(i, 0, M) {
        P tmp = p[i];
        int r = tmp.first, c = tmp.second;
        ll sum1 = R[r]+CC[0].first;
        ll sum2 = C[c]+RR[0].first;
        if ( m[mp(r, CC[0].second)] ) sum1--;

        if ( m[mp(RR[0].second, c)] ) sum2--;
        ll sum = max(sum1, sum2);
        
        ans = max(ans, sum);

    }

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





Measured memory_bytes: 75976
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PI pair<int,int>
#define ff first
#define ss second
#define MOD 1000000007
int32_t main()
{
    boost;
    /*#ifndef ONLINE_JUDGE
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
    #endif // ONLINE_JUDGE
	*/
    int n,k;
    cin>>n>>k;
    int tmp,cnt=0;

    for(int i=0;i<n;i++)
    {
    	cin>>tmp;
    	if(tmp>=k)
    		cnt++;
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
#define fi first
#define se second
#define endl '\n'

const int N = 1e3+5;

char g[N][N];
int dist[N][N];

int ii[4] = {1, -1, 0, 0};
int jj[4] = {0, 0, -1, 1};

bool check(int i, int j, int h, int w){
    return ((i > 0) && (j > 0) && (i <= h) && (j <= w));
}

void Dijkstra(pii src, int h, int w){

    memset(dist, -1, sizeof dist);

    set<pair<int, pii> > qu;
    qu.insert({0, src});

    pair<int, pii> aux;
    int t, x, y, movx, movy;
    while(!qu.empty()){
        aux = *qu.begin();
        qu.erase(*qu.begin());

        t = aux.fi;
        x = aux.se.fi;
        y = aux.se.se;

        //cout <<"(" <<x <<", " <<y <<") " <<t <<endl;

        if(dist[x][y] == -1) dist[x][y] = t;
        else continue;

        for(int i = 0; i<4; i++){
            movx = x + ii[i];
            movy = y + jj[i];
            if(check(movx, movy, h, w) && dist[movx][movy] == -1 && g[movx][movy] == '.'){
                qu.insert({t+0, {movx, movy}});
            }
        }

        for(int i = x-2; i<=x+2; i++){
            for(int j = y-2; j<=y+2; j++){
                movx = i; movy = j;
                if(check(movx, movy, h, w) && dist[movx][movy] == -1 && g[movx][movy] == '.'){
                    qu.insert({t+1, {movx, movy}});
                }
            }
        }
    }

    return;
}

int main(){

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int h, w; cin >>h >>w;

    pii src, dest;
    cin >>src.fi >>src.se;
    cin >>dest.fi >>dest.se;

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

    Dijkstra(src, h, w);

    cout <<dist[dest.fi][dest.se] <<endl;

    return 0;
}


Measured memory_bytes: 9408
#include<stdio.h>
#include<string.h>
int main(){
    char s[200];scanf("%s",s);

    int cnt=0;
    for(int i=0;i<strlen(s)/2;i++){
        if(s[i]!=s[strlen(s)-i-1]){
            cnt++;
        }
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
                  
using namespace std;
          
typedef long long ll;
#define mp make_pair
#define pub push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define db long double

string s;
int x, y;
bool can[8008];

int main(){
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> s >> x >> y;
    vector<int> a, b;
    int was = 0;
    int f = 1;
    bool fr = 1;

    for (int i = 0; i < s.size(); i++){
    	if (s[i] == 'F') was++;
    	else {
			if (fr){
				x -= was;
			} else {
				if (f) a.pub(was); else b.pub(was);
			}
			fr = 0;
			f ^= 1;
			was = 0;
    	}
    }
	if (fr){
		x -= was;
	} else {
		if (f) a.pub(was); else b.pub(was);
	}	
    //cout << x << ' ' << y << endl;
    x = abs(x), y = abs(y);
    int sum1 = 0, sum2 = 0;
    for (int xx : a) sum1 += xx;
    for (int xx : b) sum2 += xx;
    //cout << sum1 << ' ' << sum2 << endl;
    sum1 -= x;
	sum2 -= y;
	if (sum1 < 0 || sum2 < 0 || sum1 % 2 == 1 || sum2 % 2 == 1) cout << "No", exit(0);
	sum1 /= 2, sum2 /= 2;

	for (int i = 0; i < 8008; i++) can[i] = 0;
	can[0] = 1;
	
	for (int x : a){
		for (int i = 8008 - 1; i >= 0; i--) if (i - x >= 0 && can[i - x]) can[i] = 1;
	}

	if (sum1 >= 8008 || !can[sum1]) cout << "No", exit(0);

	for (int i = 0; i < 8008; i++) can[i] = 0;
	can[0] = 1;
	
	for (int x : b){
		for (int i = 8008 - 1; i >= 0; i--) if (i - x >= 0 && can[i - x]) can[i] = 1;
	}

	if (sum2 >= 8008 || !can[sum2]) cout << "No", exit(0);
	cout << "Yes";
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int N,K,a,b,null;
    scanf("%d%d",&N,&K);
    null=N/2;
    for(int i=0;i<K;i++)
    {
        scanf("%d %d",&a,&b);
        if(a>null)a=N-a+1;
        if(b>null)b=N-b+1;
        if(a>b)a=b;
        a%=3;
        if(a==0)a+=3;
        printf("%d\n",a);
    }
    return 0;
}

Measured memory_bytes: 1188
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,f[100111];
int gf(int x){return x==f[x]?x:f[x]=gf(f[x]);}

set<int> st[100111];
map<int,int> cnt[100111];

int main()
{
	get1(n);
	for(int i=1;i<=n;i++)f[i]=i;
	queue<pii>q;
	for(int i=1,a,b,c,d;i<n;i++)
	{
		get2(a,b);get2(c,d);
		cnt[a][b]++;cnt[b][a]++;cnt[c][d]++;cnt[d][c]++;
		if(cnt[a][b]==2)q.push(mp(a,b));
		if(cnt[c][d]==2)q.push(mp(c,d));
		st[a].insert(b);st[b].insert(a);
		st[c].insert(d);st[d].insert(c);
	}
	int tot=0;
	while(--n)
	{
		while(!q.empty()&&gf(q.front().ff)==gf(q.front().ss))q.pop();
		if(q.empty())
		{
			puts("NO");
			return 0;
		}
		int a=q.front().ff,b=q.front().ss;q.pop();
		a=gf(a);b=gf(b);
		if((int)st[a].size()<(int)st[b].size())swap(a,b);
		st[a].erase(b);st[b].erase(a);cnt[a][b]=cnt[b][a]=0;
		f[gf(b)]=gf(a);
		for(auto&tc:st[b])
		{
			tot++;
			int c=gf(tc);
			st[a].insert(c);
			st[c].insert(a);
			cnt[a][c]+=cnt[b][c];
			cnt[c][a]+=cnt[c][b];
			cnt[b][c]=cnt[c][b]=0;
			if(cnt[a][c]==2)q.push(mp(a,c));
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 59008
// Problem : C - management
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

const int MOD = 1e9 + 7;
using Int = long long;


#define long long int;
int32_t main() {
	int N; cin >> N;
	vector<int> account (N); 
	for (int buff; cin >> buff;) ++account[buff-1];
	for (auto it: account) cout << it << "\n";
	cout << endl;
}

Measured memory_bytes: 4048
import numpy as np
from collections import Counter

n = int(input())
v = np.array([int(i) for i in input().split()])

v_even = v[::2]
v_odd = v[1::2]

even_count = Counter(v_even)
values_even, counts_even = zip(*even_count.most_common())
odd_count = Counter(v_odd)
values_odd, counts_odd = zip(*odd_count.most_common())

if(values_even[0]!=values_odd[0]): #最も頻度が高いものが偶数番目と機数番目で違う
    print(int(np.sum(counts_odd[1:]) + np.sum(counts_even[1:])))

else: #最も頻度が高いものが偶数番目と機数番目で同じ
    if(len(counts_odd)==1 and len(counts_even)==1):
        print(len(v_odd))
    else:
        if(counts_odd[1] >= counts_even[1]):
            print(int(counts_odd[0] + np.sum(counts_odd[2:]) + np.sum(counts_even[1:])))
        else:
            print(int(counts_even[0] + np.sum(counts_even[2:]) + np.sum(counts_odd[1:])))

Measured memory_bytes: 30292
#include<bits/stdc++.h>
 using namespace std;
#define INF 1000000000
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
int main(){
    int N;
    string S;
    cin>>N;
    cin>>S;
    int ans=0;
    int x=0;
    REP(i,N){
        if(S[i]=='I'){
           x++;
        }else{
           x--;
        }
        ans=max(ans,x);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    ll n,m; cin>>n>>m;
    vector<ll> a(n);
    vector<pair<ll,ll>> b(m);
    rep(i,n) cin>>a[i];
    rep(i,m) cin>>b[i].second>>b[i].first;
    sort(b.begin(), b.end(), greater<pair<ll,ll>>());
    ll cnt=0;
    rep(i,m){
        if(cnt>=n) break;
        rep(j,b[i].second){
            a.push_back(b[i].first);
            cnt++;
            if(cnt>=n) break;
        }
    }
    sort(a.begin(), a.end(), greater<ll>());
    ll res=0;
    rep(i,n) res+=a[i];
    cout<<res<<endl;
    return 0;
}

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

using namespace std;

int main()
{
    string str;
    cin>>str;

    sort(str.begin(),str.end());
    if(str[0]==str[1] && str[2]==str[3] && str[1]!=str[2]) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	string st; cin >> st;
	for (int i = 0; i < 4; ++i) {
		cout << st[i];
	}
	cout << " ";
	for (int i = 4; i < 12; ++i) {
		cout << st[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 764
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <queue>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <deque>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 123456;

int main() {
    int N, K;
    while (~scanf("%d %d", &N, &K)) {
          int tg = 0;
          for (int i = 1; i <= N; i++) {
              int tmp;
              scanf("%d", &tmp);
              if (tmp == 1) tg = i;
          }
          int ans = 1;
          int fl = 1, fr = K;
          while (fr < N) {
                ans++;
                fl = fr;
                fr += (K - 1);
          }
          printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(rng(x))
#define RSORT(x) sort(rrng(x))
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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

int main () {
  int x, y, z;
  int K;
  cin >> x >> y >> z;
  cin >> K;
  vll a(x), b(y), c(z);

  rep(i,x) cin >> a[i];
  rep(i,y) cin >> b[i];
  rep(i,z) cin >> c[i];

  RSORT(a);
  RSORT(b);
  RSORT(c);

  vll abc;
  rep(i,x) {
    rep(j,y) {
      if ((i+1)*(j+1)>K) break;
      rep(k,z) {
        if ((i+1)*(j+1)*(k+1)>K) break;
        abc.pb(a[i]+b[j]+c[k]);
      }
    }
  }
  RSORT(abc);

  rep(i,K) {
    printf("%lld\n", abc[i]);
  }
  
  return 0;
}

Measured memory_bytes: 1404
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <climits>

using namespace std;
#define ll long long
#define ve vector
#define umap unordered_map

int main() {
    int n; cin >> n;
    ve<int> a(n);
    for(int& i:a) cin>>i;
    int m=INT_MAX;
    sort(a.begin(),a.end());
    if(a[0]==a[n-1]) { 
        cout<<0<<endl;
        return 0;
    }
    for(int i=a[0];i<a[n-1];i++) {
        int c=0;
        for(int j:a) {
            c+=(j-i)*(j-i);
        }
        m=min(m,c);
    }
    cout<<m<<endl;
}

Measured memory_bytes: 256
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())
inline void Fail(){
	printf("0");
	exit(0);
}

const int maxn=1005;
const int mod=1e9+7;
int n,ans=1;
int cnt[maxn];

void get_prime(int x){
	for(int i=2;i*i<=x;i++){
		while(x%i==0){
			cnt[i]++;
			x/=i;
		}
	}
	if(x>1)cnt[x]++;
}

int main(){
	scanf("%d",&n);
	REP(i,n)get_prime(i);
	REP(i,n)ans=1LL*ans*(cnt[i]+1)%mod;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
ll K;
const int LG = 61;
const int maxN = 2 * (int)1e5 + 100;
// where, how many
pair < ll, int > up[LG][maxN];
int a[maxN];
int b[5 * maxN];
int nxt[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n >> K;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        b[i] = a[i];
    }
    for (int i = 1; i <= n; i++) {
        a[i + n] = a[i];
        a[i + 2 * n] = a[i];
        a[i + 3 * n] = a[i];
    }
    for (int i = 2 * n; i >= 1; i--) {
        if (i <= n) {
            up[0][i].second = nxt[a[i]] % n + 1;
            if (nxt[a[i]] < n) up[0][i].first = 0;
            else if (nxt[a[i]] < 2 * n) up[0][i].first = 1;
            else up[0][i].first = 2;
        }
        nxt[a[i]] = i;
    }
    for (int j = 0; j + 1 < LG; j++) {
        for (int i = 1; i <= n; i++) {
            up[j + 1][i].first = up[j][i].first + up[j][up[j][i].second].first;
            up[j + 1][i].second = up[j][up[j][i].second].second;
        }
    }
    ll cur_jumps = 0;
    int cur_val = 1;
    for (int k = LG - 1; k >= 0; k--) {
        if (cur_jumps + up[k][cur_val].first <= K - 1) {
            cur_jumps += up[k][cur_val].first;
            cur_val = up[k][cur_val].second;
        }
    }
    vector < bool > has(maxN, false);
    vector < int > now;
    for (int i = cur_val; i <= (K - 1 - cur_jumps) * n + n; i++) {
        if (!has[a[i]]) {
            now.push_back(a[i]);
            has[a[i]] = true;
        }
        else {
            while (has[a[i]]) {
                has[now.back()] = false;
                now.pop_back();
            }
        }
    }
    for (int v : now) cout << v << " ";
    return 0;
}

Measured memory_bytes: 196084
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

from numba import njit


def getInputs():
    D = int(readline())
    CS = np.array(read().split(), np.int32)
    C = CS[:26]
    S = CS[26:].reshape((-1, 26))
    return D, C, S


@njit('(i8, i4[:], i4[:, :], i4[:], )', cache=True)
def _compute_score1(D, C, S, out):
    score = 0
    last = np.zeros(26, np.int32)
    for d in range(len(out)):
        i = out[d]
        score += S[d, i]
        last[i] = d + 1
        score -= np.sum(C * (d + 1 - last))
    return last, score


def _update_score():
    pass

@njit('(i8, i4[:], i4[:, :], i4[:], i8, )', cache=True)
def _ramdom_update(D, C, S, out, score):
    d = np.random.randint(0, D)
    q = np.random.randint(0, 26)
    p = out[d]
    out[d] = q

    if p == q:
        return out, score

    last, new_score = _compute_score1(D, C, S, out)
    if score < new_score:
        score = new_score
    else:
        out[d] = p

    return out, score



def _random_swap():
    pass


def step1(D, C, S):
    out = []
    LAST = 0
    for d in range(D):
        max_score = -10000000
        best_i = 0
        
        for i in range(26):
            out.append(i)
            last, score = _compute_score1(D, C, S, np.array(out, np.int32))
            if max_score < score:
                max_score = score
                LAST = last
                best_i = i
            out.pop()

        out.append(best_i)

    return np.array(out), LAST, max_score


def step2(D, C, S, out, score):
    for i in range(10 ** 4):
        out = out.astype(np.int32)
        try:
            assert len(out) == D
        except:
            print(i)
            print(len(out))
            break
        out, score = _ramdom_update(D, C, S, out, score)
    return out, score


def output(out):
    out += 1
    print('\n'.join(out.astype(str).tolist()))


D, C, S = getInputs()
out, _, score = step1(D, C, S)
#print(score)
out, score = step2(D, C, S, out, score)
output(out)
#print(score)

Measured memory_bytes: 107668
#include <bits/stdc++.h>
#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++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int n;
  cin >> n;
  char c[n];
  REP(i, n) cin >> c[i];
  int left = 0, right = n - 1, cnt = 0;

  while(left < right) {
    if(c[left] != 'W') left++;
    if(c[right] != 'R') right--;
    if(c[left] == 'W' && c[right] == 'R') {
      left++;
      right--;
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3808
package main

import "fmt"

func main() {
	var x int
	fmt.Scan(&x)

	for i := x; ; i++ {
		if isPrime(i) {
			fmt.Println(i)
			return
		}
	}
}

func isPrime(n int) bool {
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

long long N;

// 753を含んでいるか
bool with753(long long n) {
	for(int i : {7, 5, 3}) {
		int t = n;
		while(true) {
			if(t % 10 == i) {
				break;
			}
			t /= 10;
			if(t == 0) {
				return false;
			}
		}
	}
	return true;
}

int solve(long long n) {
	if(n > N) {
		return 0;
	}

	int result = 0;
	if(with753(n)) {
		result++;
	}
	for(int i : {7, 5, 3}) {
		result += solve(n * 10 + i);
	}
	return result;
}

int main() {
	cin >> N;

	cout << solve(0) << endl;
}


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

int main() {
  int N, ans=0;
  cin >> N;
  vector<int> value_item(N);
  vector<int> cost_item(N);

  for (int i = 0; i < N; i++) cin >> value_item.at(i);
  for (int j = 0; j < N; j++) cin >> cost_item.at(j);
  
  for (int k = 0; k < N; k++) if (cost_item.at(k) < value_item.at(k)) ans = ans + value_item.at(k) - cost_item.at(k);

  cout << ans << endl;
}

Measured memory_bytes: 3656
import math
N = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

a, b, c= 0, 0, 0
d = []

for i in range(N):
    diff = abs(X[i] - Y[i])
    a += diff
    b += (diff)**2
    c += (diff)**3
    d.append(diff)

print('{0:8f}'.format(a))
print('{0:8f}'.format(math.sqrt(b)))
print('{0:8f}'.format(c**(1/3)))
print('{0:8f}'.format(max(d)))


Measured memory_bytes: 5700
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd
#define bod 100000007
/****************************/
string s,t;
int a,b;
string n;
int main()
{
	ios::sync_with_stdio(0);
	cin>>s>>t;
	cin>>a>>b;
	cin>>n;
	if(n==s)
	{
		a--;
	}
	else
	{
		b--;
	}
	cout<<a<<" "<<b;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b,c;
    cin>>a>>b>>c;

    if(a==b){
        cout<<c<<endl;
    }
    else if (a==c) {
        cout<<b<<endl;
    }
    else {
        cout<<a<<endl;
    }

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define f(i,l,r) for(int i=l;i<r;i++)
using namespace std;
ll dp[1001][1001];
ll h,w;
char g[1001][1001];
ll m=1000000007;
ll solve(ll i,ll j)
{
    if(dp[i][j]!=-1)    return dp[i][j];
    else
    {
        if(i==0||j==0){  return dp[i][j]=0; }
        if(i==1&&j==1)
        {
            //cout<<"REACHED\n";
            return dp[i][j]=1;
            
        }
        if(g[i][j-1]=='#')
        {
            if(g[i-1][j]=='#')
                return dp[i][j]=0;
            else
            {
                return dp[i][j]=solve(i-1,j);

            }
            
        }
        else if(g[i-1][j]=='#')
            return dp[i][j]=solve(i,j-1);
        else
        {
            return dp[i][j]=(solve(i-1,j)+solve(i,j-1))%m;
        }
    }
    
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for(int i=0;i<1001;i++) for(int j=0;j<1001;j++) dp[i][j]=-1;
    cin>>h>>w;
    for(int i=0;i<=h;i++)
    {
        for(int j=0;j<=w;j++)
        {
            if(!i||!j)  g[i][j]='#';
            else
            {
                cin>>g[i][j];
            }
            
        }
    }
    // for(int i=0;i<=h;i++)
    // {
    //     for(int j=0;j<=w;j++)
    //     {
    //         cout<<g[i][j];
    //     }
    //     cout<<"\n";
    // }
    
    //for(int j=0;j<=h;j++)    cout<<g[j]<<"\n";
    ll ans=solve(h,w);
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <string>
#include <utility>
#include <functional>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main(){
    int H,A;
    cin>>H>>A;
    cout<<(H+(A-1))/A;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 5 && b == 5 && c == 7 || 
        a == 5 && b == 7 && c == 5 ||
        a == 7 && b == 5 && c == 5) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    return 0;
}

Measured memory_bytes: 256
_,_,x,y=map(int,input().split())
xl=list(map(int,input().split()))
yl=list(map(int,input().split()))
f=0
for i in range(max(xl),min(yl)):
  if x<i<y:
    f=1
if f==1:
  print("No War")
else:
  print("War")

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

int main(){
	int a;cin>>a;
	int fi=a/100;
	int se=a%100;
	if(1<=fi&&fi<=12){
		if(1<=se&&se<=12)cout<<"AMBIGUOUS"<<endl;
		else cout<<"MMYY"<<endl;
	}else{
		if(1<=se&&se<=12)cout<<"YYMM"<<endl;
		else cout<<"NA"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;

long long int n, m, k, a, b, c, t;
vector<long long int> s;
long long int ans;
typedef pair<long long int, long long int> P;
vector<P> v;
vector<long long int> w;
int q[3010];

long long int func(long long int x, long long int y, long long int z){
	if(y == s[x+1]) return 0;
	long long int tmp = t - z;
	if(tmp < 0) return 0;
	tmp /= a;
	if(y - 1 + tmp >= s[x+1]) tmp = s[x+1] - y;
	return tmp;
}

int main(){
	scanf("%lld %lld %lld %lld %lld %lld %lld", &n, &m, &k, &a, &b, &c, &t);
	for(int i=0; i<m; ++i){
		long long int tmp;
		scanf("%lld", &tmp);
		s.push_back(tmp);
		if((tmp-1) * b <= t) ++ans;
	}
	s.push_back(n+1);

	for(int i=0; i<m; ++i){
		long long int tmp = func(i, s[i]+1, (s[i]-1)*b);
		ans += tmp;
		v.push_back(P(i, s[i]+tmp+1));
		++q[i];
	}
//	printf("%lld\n", ans);

//	for(int i=0; i<v.size(); ++i) printf("%lld %lld\n", v[i].first, v[i].second);

	for(int i=0; i<v.size(); ++i){
		if(q[v[i].first] > k) continue;
		long long int tmp = 0;
		if((s[v[i].first]-1)*b + (v[i].second-s[v[i].first])*c <= t) ++tmp;
		tmp += func(v[i].first, v[i].second+1, (s[v[i].first]-1)*b+(v[i].second-s[v[i].first])*c);
		w.push_back(tmp);
		if(tmp > 0){
			v.push_back(P(v[i].first, v[i].second+tmp));
			++q[v[i].first];
		}
	}

	sort(w.begin(), w.end(), greater<long long int>());

//	for(int i=0; i<w.size(); ++i) printf("w%lld\n", w[i]);

	for(int i=0; i<min(k-m, (long long int)w.size()); ++i){
		ans += w[i];
//		printf("%lld\n", ans);
	}

	printf("%lld\n", ans-1);
}

Measured memory_bytes: 100700
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int N;
vector<int> G[200005], revG[200005];
vector<int> topo;
bool used[200005];
int lpid, lpstart;
int grundy[200005];
int scc[200005];

void tpsort(int v)
{
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		if(used[G[v][i]]) continue;
		tpsort(G[v][i]);
	}
	topo.push_back(v);
}

void dfs(int v, int id)
{
	used[v] = true;
	scc[v] = id;
	for(int i = 0; i < revG[v].size(); i++){
		if(used[revG[v][i]]) continue;
		dfs(revG[v][i], id);
	}
}

int main(void)
{
	cin >> N;
	int p;
	for(int i = 1; i <= N; i++){
		cin >> p;
		G[p].push_back(i);
		revG[i].push_back(p);
	}
	
	for(int i = 1; i <= N; i++){
		if(!used[i]) tpsort(i);
	}
	reverse(topo.begin(), topo.end());
	
	for(int i = 1; i <= N; i++) used[i] = false;
	for(int i = 0; i < topo.size(); i++){
		if(!used[topo[i]]) dfs(topo[i], i);
	}
	
	set<int> s;
	lpid = -1;
	for(int i = 1; i <= N; i++){
		if(s.count(scc[i])){
			lpid = scc[i];
			lpstart = i;
			break;
		}
		s.insert(scc[i]);
	}
	reverse(topo.begin(), topo.end());
	
	int v, g;
	for(int i = 0; i < topo.size(); i++){
		s.clear();
		v = topo[i];
		for(int j = 0; j < G[v].size(); j++){
			if(grundy[G[v][j]] == -1 || scc[G[v][j]] == lpid){
				grundy[v] = -1;
				goto end;
			}
			s.insert(grundy[G[v][j]]);
		}
		g = 0;
		while(s.count(g)) g++;
		grundy[v] = g;
		end:;
	}
	
	for(int k = 0; k < 2; k++){
		v = lpstart;
		s.clear();
		for(int i = 0; i < G[v].size(); i++){
			s.insert(grundy[G[v][i]]);
		}
		g = 0;
		while(s.count(g)) g++;
		if(k == 1){
			g++;
			while(s.count(g)) g++;
		}
		grundy[v] = g;
		
		while(1){
			v = revG[v][0];
			if(v == lpstart) break;
			
			s.clear();
			for(int j = 0; j < G[v].size(); j++){
				s.insert(grundy[G[v][j]]);
			}
			g = 0;
			while(s.count(g)) g++;
			grundy[v] = g;
		}
		
		s.clear();
		for(int j = 0; j < G[v].size(); j++){
			s.insert(grundy[G[v][j]]);
		}
		g = 0;
		while(s.count(g)) g++;
		if(grundy[v] == g){
			cout << "POSSIBLE" << endl;
			return 0;
		}
		
		for(int i = 1; i <= N; i++){
			if(scc[i] == lpid) grundy[i] = -1;
		}
	}
	
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 31476
R,C,K=map(int,input().split())
point=[[0]*C for _ in range(R)]
for _ in range(K):
    r,c,v=map(int,input().split())
    point[r-1][c-1]=v

dp=[[[0]*C for _ in range(R)] for _ in range(4)]
dp[1][0][0]=point[0][0]
for i in range(R):
    for j in range(C-1):
        for k in range(4):
            dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j])
            if k!=0:
                dp[k][i][j+1]=max(dp[k][i][j+1],dp[k-1][i][j]+point[i][j+1])
    if i==R-1:
        break
    for j in range(C):
        mx=0
        for k in range(4):
            mx=max(dp[k][i][j],mx)
        dp[0][i+1][j]=mx
        dp[1][i+1][j]=mx+point[i+1][j]
ans=0
for i in range(4):
    ans=max(ans,dp[i][R-1][C-1])
print(ans)

Measured memory_bytes: 429312
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}


int main() {
    ll n;
    int k;
    cin >> n >> k;
    ll ans = 1;
    while (n >= k) {
        n /= k;
        ans++;
    }

    cout << (ans) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  long long n, k; cin >> n >> k;
  long long r = 0;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  for (int b = k+1; b <= n; b++) {
    int cnt = b - k;
    int loop = n / b;
    r += loop * cnt;
    r += max(n % b - (k - 1), 0ll);
  }
  cout << r << endl;
}

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

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

    if (n % 10 == 3) {
        cout << "bon" << endl;
    }
    else if (n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) {
        cout << "pon" << endl;
    }
    else {
        cout << "hon" << endl;
    }
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	int n,cnt=1,ans=0;
	cin>>n;
	vector<int>a(n);
	rep(i,n)cin>>a[i];
	sort(a.begin(),a.end());
	a.push_back(1000000007);
	rep(i,n){
	    if(a[i]<a[i+1]){
	        if(cnt>=a[i])ans+=(cnt-a[i]);
	        else ans+=cnt;
	        cnt=1;
	    }
	    else cnt++;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
suits = ['S','H','C','D']

table = [[False]*14 for i in range(4)]

n = int(input())

for loop in range(n):
  mark,num = input().split()

  num = int(num)

  if mark == 'S':
    table[0][num] = True
  elif mark == 'H':
    table[1][num] = True
  elif mark == 'C':
    table[2][num] = True
  else:
    table[3][num] = True

for i in range(4):
  for j in range(1,14):
    if table[i][j] == False:
      print(suits[i], j)


Measured memory_bytes: 5600
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<map>
#define PRE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
const int Mod = 1e9 + 7;
int dp[1 << 10], lst[105][11], ls[105][11];

int main()
{
	PRE;
	int n;
	cin >> n;
	for (int i = 1;i <= n;i++)
	{
		for (int j = 1;j <= 10;j++)cin >> lst[i][j];
	}
	for (int i = 1;i <= n;i++)
	{
		for (int j = 0;j <= 10;j++)cin >> ls[i][j];
	}
	ll ans = -1e9 - 5;
	for (int i = 1;i < 1 << 10;i++)
	{
		ll t = 0;
		for (int k = 1;k <= n;k++)
		{
			int g = 0;
			for (int j = 1;j <= 10;j++)
			{
				if (i & (1 << (j - 1)) && lst[k][j])g++;
			}
			t += ls[k][g];
		}
		ans = max(t, ans);
	}
	cout << ans;
}

Measured memory_bytes: 3156
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int n,x;
	int a[105],d[105];
	cin>>n>>x;
	cin>>a[0];
	for(int i=1;i<n;i++){
		cin>>a[i];
	}
	d[0]=0;
	for(int i=1;i<=n;i++){
		d[i]=a[i-1]+d[i-1];
	}
	int cnt=0;
	for(int i=0;i<=n;i++){
		if(d[i]<=x){
			cnt++;
		}
	}
	cout<<cnt;
	return 0;
} 

Measured memory_bytes: 256
x, k, d = map(int, input().split())
x = abs(x)
s = int(x/d)
ans = x%d

if k < s:
    print(x-d*k)
else:
    if ans < -ans+d:
        if (k-s)%2 == 0:
            print(ans)
        else:
            print(-ans+d)
    else:
        if (k-s)%2 == 0:
            print(ans)
        else:
            print(-ans+d)

Measured memory_bytes: 9196
#include <iostream>
using namespace std;
int main(void){
    int N;
    int K;
    int A=0;
    cin >> N >> K;
    for (int i=0; i<N; i++){
        int x;
        cin >> x;
        if (x * x <= (K - x) * (K - x)){
            A = A + 2*x;
        }
        else if (x * x > (K-x)*(K-x)){
            A = A + 2*(K-x);
        }
    }
    cout << A << endl;
}

Measured memory_bytes: 3644
import numpy as np


def main(N):
    f = [0]*(N+1)
    for x in range(100):
        for y in range(100):
            for z in range(100):
                if (x+y+2)**2+(x+z+2)**2+(z+y+2)**2 > 2*N:
                    break
                f[((x+y+2)**2+(x+z+2)**2+(z+y+2)**2)//2] += 1
    return f


N = int(input())
f = main(N)
for i in range(N):
    print(f[i+1])


Measured memory_bytes: 27124