akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;

ll inv[200001], invf[200001];

ll exp(ll a, ll b) {
    if (b == 0LL) return 1LL;
    if (b == 1LL) return a;
    ll ans = exp(a, b>>1);
    ans = (ans * ans) % MOD;
    if (b&1LL) ans = (ans * a) % MOD;
    return ans;
}

void work() {
    ll n, a, b; cin>>n>>a>>b;
    ll ans = (exp(2LL, n) - 1LL) % MOD;
    
    // a
    ll d1 = max(a, n-a), d2 = min(a, n - a);
    ll fact_n = 1LL;
    for (ll i = n; i > d1; --i) fact_n = (fact_n * i) % MOD;

    inv[1] = 1LL;
    invf[0] = invf[1] = 1LL;
    ll m = d2 + 1LL;
    for(ll i = 2LL; i < m; ++i) {
        inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;
        invf[i] = (inv[i] * invf[i-1LL]) % MOD;
    }
    ll na = (fact_n * invf[d2]) % MOD;
    ans = (ans - na + MOD) % MOD;
    //cout << na << endl;

    // if (b == n-a) {
    //     cout << ans << endl;
    //     return;
    // }

    // b
    d1 = max(b, n-b), d2 = min(b, n - b);
    fact_n = 1LL;
    for (ll i = n; i > d1; --i) fact_n = (fact_n * i) % MOD;

    inv[1] = 1LL;
    invf[0] = invf[1] = 1LL;
    m = d2 + 1LL;
    for(ll i = 2LL; i < m; ++i) {
        inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;
        invf[i] = (inv[i] * invf[i-1LL]) % MOD;
    }
    ll nb = (fact_n * invf[d2]) % MOD;
    ans = (ans - nb + MOD) % MOD;
    //cout << nb << endl;

    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    work();

    return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<cmath>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;


ll dp[110000][4];

int main(){
  int counth;
  string S;
  cin>>S;
  dp[0][0]=1;
  //cout<<S<<endl;
  for(int i=0;i<(int)S.size();i++){
    //cout<<i<<endl;
    for(int j=0;j<4;j++){
      //cout<<j<<endl;
      if(S[i]=='?'){
        //cout<<"?"<<endl;
        if(j<3) dp[i+1][j+1]+=dp[i][j];
        dp[i+1][j]+=dp[i][j]*3;
        //cout<<i+1<<" "<<j+1<<" "<<dp[i+1][j+1]<<endl;
        //cout<<i+1<<" "<<j<<" "<<dp[i+1][j]<<endl;
      }else if(j==S[i]-'A'){
        //cout<<"A"<<endl;
        dp[i+1][j+1]+=dp[i][j];
        dp[i+1][j]+=dp[i][j];
      }else{
        dp[i+1][j]+=dp[i][j];
        //cout<<"X"<<endl;
        //cout<<i+1<<" "<<j<<" "<<dp[i+1][j]<<endl;
      }
      dp[i+1][j+1]%=MOD;
      dp[i+1][j]%=MOD;
      //cout<<i<<" "<<j<<endl;
    }
  }
  cout<<dp[(int)S.size()][3]<<endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

const int maxN = 1e2 + 5, maxW = 1e5 + 5, INF = 1e9 + 5;;

long long int dp[maxW][maxN] = {0};
int v[maxN], wt[maxN];

long long int rc(int w, int in) {
    if(dp[w][in] != -INF) return dp[w][in];
    if(!w || !in) {
        return dp[w][in] = 0; // knapsack wt is 0 or no of items are 0, so max value is 0
    }
    return dp[w][in] = max(w - wt[in - 1] >= 0 ? (rc(w - wt[in - 1], in - 1) + v[in - 1]) : 0 , rc(w, in - 1));
}

int main()
{
    int n, w;
    cin >> n >> w;
    for(int i = 0; i < n; i++) cin >> wt[i] >> v[i];
    for(int i = 0; i <= w; i++) {
        for(int j = 0; j <= n; j++) dp[i][j] = -INF;
    }
    cout << rc(w, n) << endl;
    return 0;
}


Measured memory_bytes: 85540
import java.io.*;
import java.util.*;

public class Main {
	FastScanner in;
	PrintWriter out;

	void solve() {
		int n = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt() - 1;
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			if (a[a[i]] == i) {
				cnt++;
			}
		}
		out.println(cnt / 2);
	}

	void run() {
		try {
			in = new FastScanner(new File("object.in"));
			out = new PrintWriter(new File("object.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().runIO();
			}
		}, "1", 1 << 26).start();
	}
}

Measured memory_bytes: 22676
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

//population count
int popcount(int x) {
	int ret = 0;
	while (x) {
		x &= x - 1;
		ret++;
	}
	return ret;
}

signed main() {
	cout << fixed << setprecision(8);
	int N, M; cin >> N >> M;
	vector<double> L(N), a(N), b(N);
	rep(i, 0, N)cin >> L[i] >> a[i] >> b[i];

	double ans = 0;
	for (int mask = 0; mask < (1 << N); mask++) {
		if (popcount(mask) != M)continue;
		double tmp = 0;
		rep(i, 0, N) {
			if ((mask&(1 << i)) == 0)continue;
			rep(j, i + 1, N) {
				if ((mask&(1 << j)) == 0)continue;
				tmp += (L[i] - L[j])*(L[i] - L[j])
					+ (a[i] - a[j])*(a[i] - a[j])
					+ (b[i] - b[j])*(b[i] - b[j]);
			}
		}
		chmax(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3280
# For taking integer inputs.
import math
 
 
def inp():
    return(int(input()))
 
 
# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))
 
 
# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))
 
 
# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))
 
 
def valid(x, y): return True if x >= 0 and x < row and y >= 0 and y < col else False
 
 
fx = [+0, +0, +1, -1, -1, +1, -1, +1]
fy = [-1, +1, +0, +0, +1, +1, -1, -1]
row, col = invr()
mat = []
for _ in range(row):
    mat.append(instr())
 
for i in range(row):
    for j in range(col):
        if mat[i][j] == ".":
            count = 0
            for k in range(len(fx)):
                nx = i + fx[k]
                ny = j + fy[k]
                if valid(nx, ny):
                    if mat[nx][ny] == "#":
                        count += 1
            mat[i][j] = str(count)
 
for r in mat:
    for i in r:
        print(i, end="")
    print()

Measured memory_bytes: 3572
/*input
4
1 2 3 4
3
1 2
3 4
2 4
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
#define ll long long 
#define ld long double
#define pii pair<int,int>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e12;
const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1){
            res=(res*a)%MOD;
        }
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
const ll maxn=1e6+5;
const ll maxlg=__lg(maxn)+2;
ll cnt[maxn];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    ll ans=0;
    REP(i,n){
        int x;
        cin>>x;
        ans+=x;
        cnt[x]++;
    }
    int q;
    cin>>q;
    REP(i,q){
        ll b,c;
        cin>>b>>c;
        ans-=cnt[b]*b;
        ans+=cnt[b]*c;
        cnt[c]+=cnt[b];
        cnt[b]=0;
        cout<<ans<<'\n';
    }
}

Measured memory_bytes: 4436
#include<bits/stdc++.h>
using namespace std;
main(){
 long long n,t[1000]={},a[1000]={},j;
 cin>>n;
 for(int i=0;i<n;i++){
  cin>>t[i]>>a[i];
  if(i){
   j=max((a[i-1]-1)/a[i],(t[i-1]-1)/t[i])+1;
   a[i]*=j;t[i]*=j;
  }
 }
 cout<<a[n-1]+t[n-1]<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        long N = nl();
        for (long a = 1; a <= 3500; a++) {
            for (long b = 1; b <= 3500; b++) {
                if((4*a*b-N*b-N*a)<=0) continue;
                if(N*a*b % (4*a*b-N*b-N*a)==0){
                    long c = N*a*b / (4*a*b-N*b-N*a);
                    out.print(a);
                    out.print(" ");
                    out.print(b);
                    out.print(" ");
                    out.print(c);
                    out.println();
                    return;
                }
            }
        }
 
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);

    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 33264
#include <iostream>
#include <algorithm>
#include <cmath>
#include <list>
#include <queue>
#include <set>
#include <vector>

using namespace std;

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

typedef long long ll;
typedef pair<ll, ll> P;

vector<int> tree[200001];
int res[200001];

void dfs(int p, int x) {
  for (auto t : tree[p]) {
    if (x == t) continue;
    res[t] += res[p];
    dfs(t, p);
  }
}

int main() {
  int N, Q;
  cin >> N >> Q;
  REP(i,N-1) {
    int a,b;
    cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  REP(i,Q) {
    int p, x;
    cin >> p >> x;
    res[p] += x;
  }
  dfs(1, 0);

  FORE(i,1,N) cout << res[i] << ' ';
  cout << endl;
}

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

int main() {
  int M1, D1, M2, D2;
  cin >> M1 >> D1>>M2>>D2;

  if (D2 == 1){
    cout << 1 <<endl;
  }
  else{
    cout << 0 <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define inf 1000000000000000001
#define mod 1000000007
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
#define Set(N,p) N=((N)|((1LL)<<(p)))
#define Reset(N,p) N=((N)&(~((1LL)<<(p))))
#define Check(N,p) (!(((N)&((1LL)<<(p)))==(0)))
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define OUT(x) for(auto a:x) cout << a << " "; cout << endl;
#define OK cout << "@===================ok===================@" <<endl;
#define WTF cout <<"< "<<lo<<" | "<< hi <<" >" << endl;

using namespace std;

int main()
{
    int n;
    cin >> n;
    vll v(n);
    for(int i=0;i<n;i++) cin >> v[i];

	ll ans=0;

	auto ok=[&](ll len){
		ll need=1;
		ans=0;
		for(int i=0;i<n;i++){
			if(v[i]==need){
				need++;
			}
			else{
				ans++;
			}
			//if(need>len) break;
		}
		if(need>len) return 1;
		else return 0;
	};

	ll lo=1;
	ll hi=n-1;

	while(hi-lo>1){
		ll mid=(lo+hi)/2;
		if(ok(mid)){
			lo=mid;
		}
		else hi=mid-1;
	}

	ll need=1;
	ans=0;
	for(int i=0;i<n;i++){
		if(v[i]==need){
			need++;
		}
		else{
			ans++;
		}
	}
	if(need>lo){
		cout <<ans << endl;
		return 0;
	}
	cout << -1 << endl;


}


Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int r = scanner.nextInt();
        int D = scanner.nextInt();
        int x2000 = scanner.nextInt();

        List<Long> list = new ArrayList<>();
        long x = x2000 * r - D;
        list.add(x);
        for (int i=2002; i <= 2010; i++) {
            x = x * r - D;
            list.add(x);
        }

        list.forEach(System.out::println);
    }
}

Measured memory_bytes: 26832
using System;

class program
{

    public static void Main()
    {
        var str = Console.ReadLine().Split(' ');
        double a = double.Parse(str[0]);
        double b = double.Parse(str[1]);
        int C = int.Parse(str[2]);

        double c = Math.Sqrt(a * a + b * b - 2.0 * a * b * Math.Cos(Math.PI * C / 180));

        double s = (a + b + c) / 2.0;
        double S = Math.Sqrt(s * (s - a) * (s - b) * (s - c));

        double L = a + b + c;
        double h = 2.0 * S / a;

        Console.WriteLine("{0:f5}", S);
        Console.WriteLine("{0:f5}", L);
        Console.WriteLine("{0:f5}", h);
    }
}

Measured memory_bytes: 5748
package main

import (
	"fmt"
	"strconv"
)

func main() {
	buttonA, buttonB, err := readButtons()
	if err != nil {
		return
	}

	larger := 0
	smoller := 0
	if buttonA > buttonB {
		larger = buttonA
		smoller = buttonB
	} else {
		larger = buttonB
		smoller = buttonA
	}

	largerShouldBeClickedOnce := false
	if larger-1 > smoller {
		largerShouldBeClickedOnce = true
	}

	if largerShouldBeClickedOnce == true {
		fmt.Println(larger + (larger - 1))
	} else {
		fmt.Println(larger + smoller)
	}

	return
}

func readButtons() (int, int, error) {
	var buttonA = ""
	var buttonB = ""

	fmt.Scan(&buttonA)
	fmt.Scan(&buttonB)

	buttonANum, err := strconv.Atoi(buttonA)
	buttonBNum, err := strconv.Atoi(buttonB)

	if err != nil {
		return 0, 0, err
	}

	return buttonANum, buttonBNum, nil
}


Measured memory_bytes: 512
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
set<int> discovered;
int maximum=0;
int count;
void dfs(set<int> graph[],int s)
{  
    ::count+=1;
    discovered.insert(s);
    if (::count>maximum)
       maximum=::count;
    for(auto i=graph[s].begin();i!=graph[s].end();i++)
    {
        if (discovered.find(*i)==discovered.end())
           {dfs(graph,*i);}
    }
}
int main()
{   int n,m;
    cin>>n>>m;
    set<int> graph[n+1];
    int a,b,i;
    for(i=0;i<m;i++)
    {
        cin>>a>>b;
        graph[a].insert(b);
        graph[b].insert(a);
    }
    //cout<<"\n\n\n";
    for(int i=1;i<=n;i++)
    {   if (discovered.find(i)==discovered.end())
           { 
                //cout<<i<<"SEnding"<<endl;
                ::count=0;
               dfs(graph,i);
           }
    }
    cout<<maximum<<endl;
}

Measured memory_bytes: 53588
#include <bits/stdc++.h>
using namespace std;
long long int MOD = 998244353;

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

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

    vector<long long int> exponent(s+1);// formal power series
    exponent[0] = 1;
    for(int i=0; i<n; i++){// * (1 + (1 + x^a[i]))
        vector<long long int> next(s+1);
        for(int j=0; j<=s; j++){
            next[j] += 2 *exponent[j];
            if(j - a[i] >= 0) next[j] += exponent[j-a[i]];
            next[j] %= MOD;
        }
        exponent = next;
    }
    cout << exponent[s] << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int l; sc(l)
    vector<int> X(l);
    for (int i = 0; i < l; i++) sc(X[i])
    vector<int> Y = X;
    sort(X.begin(), X.end());
    int right = X[X.size()/2], left = X[X.size()/2-1];
    int mid = (left + right) / 2;
    for (int i = 0; i < l; i++){
        if (Y[i] > mid) cout << left << endl;
        else cout << right << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
s = list(str(input()))
n = len(s) - 1 #間の数

t = []
y = 0

t.append(int(s[n]) * (2 ** n ))

for i in range(n):
    y = 0
    for j in range(1,len(s)+1):
        if j == len(s) + 1 - i:
            continue
        elif j == len(s) - i:
            y = y + int(s[i]) * (10 ** (n - i)) * (2 ** i)
            t.append(y)
        else:
            y = y + int(s[i]) * (10 ** (j - 1)) * (2 ** (n - j))

print(sum(t))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
bool used[100][100];
int n,p[2][100][100],sx,sy;
bool dfs(int x,int y){
  if(sx==x&&sy==y)return 1;
  if(used[y][x])return 0;
  used[y][x]=1;
  return used[y][x]=dfs(p[0][y][x],p[1][y][x]);
}
int main(){
  while(cin>>n&&n){
    int c=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	cin>>p[0][i][j]>>p[1][i][j],used[i][j]=0;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)if(!used[i][j])sx=j,sy=i,c+=dfs(p[0][i][j],p[1][i][j]);
    cout<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 1248
fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map(String::toLong)
    val aList = readLine()!!.split(' ').map(String::toLong).sorted()
    val fList = readLine()!!.split(' ').map(String::toLong).sortedDescending()
    if (aList.sum() <= k) {
        println(0)
        return
    }

    fun checkCanReach(v: Long): Boolean {
        var sum = 0L
        for (i in 0 until n.toInt()) {
            val ma = v / fList[i]
            if (ma < aList[i]) sum += aList[i] - ma
            if (sum > k) return false
        }
        return true
    }
//二分探索
    var targetIndex = 1L shl 60
    for (i in 59 downTo 0) {
        val currentIndex = targetIndex - (1L shl i)
        if (checkCanReach(currentIndex)) {
            targetIndex -= 1L shl i
        }
    }
    println(targetIndex)
}

Measured memory_bytes: 114800
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
ll n,x,m;
int vis[N],id=1;
ll pre[N];
int main(){
	scanf("%lld%lld%lld",&n,&x,&m);
	ll ans=0;
	while(n--){
		vis[x]=id++;
		pre[x]=ans;
		ans+=x;
		x=x*x%m;
		if(vis[x]>0){
			int jie=(id-vis[x]);
			ans+=(ans-pre[x])*(n/jie);
			n%=jie; 
		}
	} 
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4900
# -*- coding: utf-8 -*-
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

s = list(input())
g = 0
p = 0
ans = 0
for i in range(len(s)):
    if s[i] == 'g' and p + 1 <= g:
        ans += 1
        p += 1
        #print('a')
    elif s[i] == 'g' and p <= g + 1:
        g += 1
        #print('b')
    elif s[i] == 'p' and p + 1 <= g:
        p += 1
        #print('d')
    elif s[i] == 'p' and p <= g + 1:
        ans -= 1
        g += 1
        #print('c')
print(ans)


Measured memory_bytes: 3956
using System;

class Program
{
    static void Main(string[] args)
    {
        var whxy = Console.ReadLine().Split();
        var w = double.Parse(whxy[0]);
        var h = double.Parse(whxy[1]);
        var x = double.Parse(whxy[2]);
        var y = double.Parse(whxy[3]);

        var ans1 = w * h / 2;
        var ans2 = (w / 2 == x && h / 2 == y) ? 1 : 0;

        Console.WriteLine($"{ans1} {ans2}");
    }
}


Measured memory_bytes: 13268
def fbit(k,n):
    t=[]
    kk=k
    for i in range(n):
        t.append(kk%2)
        kk=int(kk/2)
    return t        

n,m=map(int,input().split())
s=[]
for i in range(m):
    si=[]
    for j in range(n):
        si.append(0)
    s.append(si)
    
for j in range(m):
    str=input().split()
    k_m=int(str[0])
    for k in range(k_m):
        ii=int(str[k+1])-1
        s[j][ii]=1

str=input().split()
p=[]
for k in range(m):
    p.append(int(str[k]))

icnt=0
for k in range(2**n):
    icnt2=0
    bit=fbit(k,n)
    for im in range(m):
        icnt3=0
        for kn in range(n):
            icnt3=icnt3+bit[kn]*s[im][kn]
        if icnt3%2==p[im]:
            icnt2=icnt2+1
    if icnt2==m:
        icnt=icnt+1
print(icnt)       

Measured memory_bytes: 3064
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,D,A = MI()
    XH = LLIN(N)
    XH.sort()
    q = deque()
    ans = 0
    now = 0
    for x,h in XH:
        while q and x > q[0][0]:
            now -= q.popleft()[1]
        h-=now
        if h>0:
            ans += (h+A-1)//A
            q.append((x+2*D, ((h+A-1)//A)*A))
            now += ((h+A-1)//A)*A
    print(ans)
    



if __name__ == '__main__':
    main()

Measured memory_bytes: 102360
ans = input()
l = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

for i in range(25):
  if l[i] == ans:
    print(l[i+1])
  else:
    continue

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
	double a,b,c,d;
	cin>>a>>b>>c>>d;
	int x=ceil(a/d);
	int y=ceil(c/b);
	if(y>x)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3700
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <climits>
#include <stack>
#define FOR(i,p,k) for(int i = (p);i<(k);i++)
typedef long long int LL;
using namespace std;

int n;
int tab[100007];

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

	FOR(i,0,n) 
		scanf("%d",&tab[i]);
	FOR(i,0,n)
		tab[i]--;

	int ans = 0;
	FOR(i,0,n) {
		int j = tab[i];
		if(tab[j] == i)
			ans++;
	}

	cout<<ans/2<<"\n";
}

int main() {
  dane();
  return 0;
}

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

int main(){
    size_t H, W, N;
    cin >> H >> W >> N;
    size_t sr, sc;
    cin >> sr >> sc;
    string S, T;
    cin >> S >> T;

    size_t u = sr, d = sr, r = sc, l = sc;
    auto f = [&u, &d, &r, &l](char a){
        if(a == 'U')--u;
        if(a == 'D')++d;
        if(a == 'R')++r;
        if(a == 'L')--l;
    };
    for(unsigned long i = 0; i < N; ++i){
        f(S[i]);
        if(u == 0 || l == 0 || d > H || r > W)return 0 & puts("NO");
        swap(u, d);
        swap(r, l);
        f(T[i]);
        swap(u, d);
        swap(r, l);
        d = max(1UL, d);
        u = min(H, u);
        l = min(W, l);
        r = max(1UL, r);
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<
    pair<int, int>,
    null_type,
    less_equal<pair<int, int>>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define lb(v, z) lower_bound(all(v), z)
#define ub(v, z) upper_bound(all(v), z)
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rdp(i, a, b) for (int i = (a); i >= (b); i--)
#define rlt(i, a, b) for (int i = (a); i < (b); i++)
#define cns(z) cout << (z) << ' '
#define cnl(z) cout << (z) << '\n'
#define M1 1000000007
#define M2 998244353
#define MAXN 300005
#define INF (1ll << 60)
#define endl "\n"
#define garr(ip)       \
    for (auto &x : ip) \
        cin >> x;
#define parr(ip)          \
    for (auto &x : ip)    \
        cout << x << " "; \
    cout << endl;
#define nl cout << endl
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vp;

void solve(int testCaseNumber = 1)
{
    int ans = 0;
    rep(i, 1, 5)
    {
        int x;
        cin >> x;
        if (!x)
            ans = i;
    }
    cnl(ans);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};




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

  
int n;
cin>>n;
set<int>st;

for(int i=0;i<n;i++)
{
  int x; cin>>x; st.insert(x);
}

if(st.size()==n)cout<<"YES\n";
else cout<<"NO\n";






}

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


def solve(N: int, d: "List[int]"):
    a = set(d)
    print(len(a))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    d = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int h,w;
  cin>>h>>w;
  vs s(h);
  rep(i,h)cin>>s[i];

  int dist[50][50]={};

  rep(i,h)rep(j,w)dist[i][j]=INF;
  dist[0][0]=1;
  queue<pii>q;

  q.push(pii(0,0));

  int d[]={0,1,0,-1,0};

  while(q.size()){
    int x=q.front().first;
    int y=q.front().second;
    q.pop();
    rep(i,4){
      int nx=x+d[i];
      int ny=y+d[i+1];
      if(nx < 0 || nx >= h || ny < 0 || ny >= w || s[nx][ny]=='#')
	continue;
      if(dist[nx][ny]==INF){
	dist[nx][ny]=dist[x][y]+1;
	q.push(pii(nx,ny));
      } 
    }
  }


  int sum=0;
  rep(i,h)rep(j,w)if(s[i][j]=='.')sum++;

  int ans=dist[h-1][w-1];

  if(ans==INF)
    cout<<-1<<endl;
  else 
    cout << sum - ans << endl;

}


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  rep(i, 0, 7) {
    int a, b;
    cin >> a >> b;
    cout << (a - b) << endl;
  }
}



Measured memory_bytes: 3128
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		while(true) {
			int n=in.nextInt();
			if(n==0)break;
			
			int dp[][]=new int[n][n];
			for(int i=0;i<n;i++) {
				String str=in.next();
				for(int j=0;j<n;j++) {
					dp[i][j]=str.charAt(j)=='.'? 1 : 0;
				}
			}
			
			
			int max=0;
			for(int i=0;i<n;i++) {
				for(int j=0;j<n;j++) {
					if(dp[i][j]>0 && isEx(dp,i,j)) {
						dp[i][j]=Math.min(dp[i-1][j], Math.min(dp[i][j-1], dp[i-1][j-1]))+1;
					}
					max=Math.max(max, dp[i][j]);
				}
			}
			System.out.println(max);
		}
	}
	
	static boolean isEx(int A[][],int y,int x) {
		if(y-1>=0 && x-1>=0) {
			if(A[y-1][x]>0 && A[y][x-1]>0 && A[y-1][x-1]>0)return true;
		}
		return false;
	}

}



Measured memory_bytes: 69916
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>

typedef long long ll;

#define debug(x) cout << #x << "=" << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << " "
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)

using namespace std;

int main(){
    ll h, attackNum = 0,monsterNum = 1;
    cin >>h;
    while(h != 1){
        attackNum += monsterNum;
        monsterNum *= 2;
        h /= 2;
    }
    attackNum += monsterNum;

    cout << attackNum << endl;
}

Measured memory_bytes: 384
#include <cstdio>
typedef long long ll;
const ll p = 1000000007;

ll f[5000];
int main()
{
	int s;
	scanf("%d", &s);
	f[0] = 1;
	for (int i = 1; i <= s; i++)
	{
		f[i] = 0;
		for (int j = 0; i-j >= 3; j++)
		{
			f[i] += f[j];
			f[i] %= p;
		}
	}
	printf("%lld\n", f[s]);
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll solve() {
    ll N, a;
    cin >> N;
    bool win = false;
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        if ( a & 1 ) win = true;
    }
    return win;
}

int main() {
    string ans = solve() ? "first" : "second";
    cout << ans << "\n";
    return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  cout << fixed << setprecision(12);
  int a,b,c; cin>>a>>b>>c;
  if (c>b) swap(c,b);
  if (b>a) swap(b,a);
  if (c>b) swap(c,b);
  out(c+b);
  

  return 0;
}


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

#define println(msg) cout << msg << endl
#define sort_vec(vec) sort(vec.begin(), vec.end())
#define rsort_vec(vec) sort(vec.rbegin(), vec.rend()) // greater<int>()

int main() {
  // 入力
  int N;
  cin >> N;

  vector<int> a(3 * N);
  for (int i = 0; i < (3 * N); i++) {
    cin >> a.at(i);
  }
  
  // 計算
  sort_vec(a);

  vector<int> b;
  for (int i = 0; i < (2 * N); i++) {
    b.push_back(a.at(i + N));
  }
  
  long sum = 0L;
  for (int i = 0; i < (2 * N); i+=2) {
    sum += b.at(i);
  }  
  
  // 出力
  println(sum);
}


Measured memory_bytes: 5404
from math import comb
n, p = list(map(int, input().split()))
a = list(map(int, input().split()))

n0 = 0
n1 = 0

for i in range(n):
    if a[i] % 2 == 0:
        n0 += 1
    else:
        n1 += 1

x = 0
if p == 0:
    for i in range(0, n1+1, 2):
        x += comb(n1, i)
else:
    for i in range(1, n1+1, 2):
        x += comb(n1, i)

print(2**n0 * x)

Measured memory_bytes: 9160
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

typedef long long ll;
typedef pair<ll, ll> P;

//const int MAX = 700000;
//static const ll MOD = 1000000007;
//static const ll INF = 100000000;

int main() {
    ll X;

    // input
    cin >> X;

    // process
    ll num_item = X / 100;
    if (num_item >= 99) {
        cout << 1 << endl;
        return 0;
    }

    X -= num_item * 100;

    ll require_item = 0;
    for (require_item = 0; X > 0; require_item++) {
        if (X >= 5) {
            X -= 5;
            continue;
        } else if (X >= 4) {
            X -= 4;
            continue;
        } else if (X >= 3) {
            X -= 3;
            continue;
        } else if (X >= 2) {
            X -= 2;
            continue;
        } else if (X >= 1) {
            X -= 1;
            continue;
        }
    }

    if (require_item <= num_item) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

Int gcd(Int x, Int y) {
    return y == 0 ? x : gcd(y, x % y);
}

int main(void) {
    Int K;
    cin>>K;

    Int sum = 0;
    for(Int a = 1;a <= K;a++) {
        for(Int b = 1;b <= K;b++) {
            for(Int c = 1;c <= K;c++) {
                sum += gcd(a,gcd(b,c));
            }
        }
    }

    cout<<sum<<endl;


    return 0;
}




Measured memory_bytes: 3196
a=[]
for i in range(5):
    a.append(int(input()))
k = int(input())
d=[]
for i in range(5):
    for j in range(5):
        if a[i] - a[j] > k:
            print(":(")
            break
    else:
        continue
    break
else:
    print("Yay!")

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

int main(){
  int d;
  cin >> d;
  
  if(d==22){
    cout << "Christmas Eve Eve Eve" <<endl;
  }else if(d==23){
    cout << "Christmas Eve Eve" <<endl;
  }else if(d==24){
    cout << "Christmas Eve" <<endl;
  }else{
    cout << "Christmas" <<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#define next dskjgf

using namespace std;

const int mo=1e9+7; 

int n,m,to[1001],next[1001],first[21],e1=0;
int mi2[301],f[1<<15],g[1<<15],c[1<<15],d[1<<15];

void insert(int o,int p)
{
	to[e1]=p;next[e1]=first[o];first[o]=e1++;
}

int get(int o,int p)
{
	int yu=0;
	for(int i=first[p];i!=-1;i=next[i])
		if((1<<(to[i]-1))&o) yu++;
	return mi2[yu]-1;
}

int main()
{
	mi2[0]=1;
	for(int i=1;i<=300;i++) mi2[i]=1ll*mi2[i-1]*2%mo;
	memset(first,-1,sizeof(first));
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		insert(x,y);insert(y,x);
		for(int s=0;s<1<<n;s++)
		{
			if(((1<<(x-1))&s)||((1<<(y-1))&s)) d[s]++;
			if(((1<<(x-1))&s)&&((1<<(y-1))&s)) c[s]++;
		}
	}
	for(int i=0;i<1<<n;i++)
		if(i&1)
		{ 
			f[i]=mi2[c[i]];
			for(int j=i;j;j=(j-1)&i)
				f[i]=(f[i]-1ll*f[i^j]*mi2[c[j]]%mo+mo)%mo;
		}
	for(int i=0;i<1<<n;i++)
		if((i>>1)&1)
		{ 
			g[i]=mi2[c[i]];
			for(int j=i;j;j=(j-1)&i)
				g[i]=(g[i]-1ll*g[i^j]*mi2[c[j]]%mo+mo)%mo;
		}
	int ans=mi2[m];
	for(int i=0;i<1<<n;i++)
	{
		int s=((1<<n)-1)^i;
		for(int j=s;j;j=(j-1)&s)
			if((c[i]+c[j])==c[i|j])
				ans=(ans-1ll*f[i]*g[j]%mo*mi2[m-d[i|j]]%mo+mo)%mo;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 768
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

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

s = str(input())
x,y = II()

N = len(s)
yoko = []
tate = []
ziku = True
count = 0

for i in range(N):
    if s[i]=='F':
        count += 1
    else:
        if ziku:
            yoko.append(count)
            ziku = False
        else:
            tate.append(count)
            ziku = True
        count = 0

if count!=0:
    if ziku:
        yoko.append(count)
    else:
        tate.append(count)

yoko.append(0)
tate.append(0)

if s[0]=='F':
    fstart = True
else:
    fstart = False

sum1 = sum(yoko)
sum2 = sum(tate)

if abs(x)>sum1 or abs(y)>sum2:
    print('No')
    exit()

yoko_yes = [False]*(2*sum1+1)
yoko_yes[sum1] = True

for k,yk in enumerate(yoko):
    ok = []
    if k==0 and fstart:
        ok.append(sum1+yk)
    else:
        for i in range(2*sum1+1):
            if yoko_yes[i]:
                if 0<=i+yk<=2*sum1:
                    ok.append(i+yk)
                if 0<=i-yk<=2*sum1:
                    ok.append(i-yk)
    yoko_yes = [False]*(2*sum1+1)
    for o in ok:
        yoko_yes[o] = True

tate_yes = [False]*(2*sum2+1)
tate_yes[sum2] = True

for t in tate:
    ok = []
    for i in range(2*sum2+1):
        if tate_yes[i]:
            if 0<=i+t<=2*sum2:
                ok.append(i+t)
            if 0<=i-t<=2*sum2:
                ok.append(i-t)
    tate_yes = [False]*(2*sum2+1)
    for o in ok:
        tate_yes[o] = True

if yoko_yes[x+sum1] and tate_yes[y+sum2]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 50140
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
using namespace std;
#define MATH_PI 3.14159265358979323846
bool cmp(int iNum1, int iNum2){
	return iNum1 > iNum2;
}
int main(){
	ios::sync_with_stdio(false);
	int m, n;
	register int i, j, k;
	scanf("%d%d", &m, &n);
	if (m * 10000<n){
		cout << "-1 -1 -1\n";
		goto endapp;
	}
	if (m * 1000>n){
		cout << "-1 -1 -1\n";
		goto endapp;
	}
	if (n % 1000 != 0){
		cout << "-1 -1 -1\n";
		goto endapp;
	}
	for (i = 0; i <= m; ++i)
		for (j = 0; j <= m; ++j)
			for (k = 0; k <= m, i + j + k <= m; ++k){
				if (i + j + k == m && i * 1000 + j * 5000 + k * 10000 == n){
					cout << k << ' ' << j << ' ' << i << endl;
					goto endapp;
				}
			}
	cout << "-1 -1 -1\n";
endapp:
	//system("pause > nul");
	return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

int main(){
  int n;
  cin>>n;
  
  vector<ll> A(n);
  rep(i,n) cin>>A[i];
  
  ll ans=0;
  ll x=A[0];
  
  rep(i,n){
    if(A[i]<x) ans+=x-A[i];
    else if(A[i]>x) x=A[i];
  }
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 4784
/******
author :- Mahmoud Tarek.
*******/

#include<bits/stdc++.h>

using namespace std ;

#define rg register
#define dbg(v) cerr << #v << " " << v ;
typedef long long ll ;

int main() {

   int n, c ;
   cin >> n ;
   for(int i = 0 ; i < n ; i++){
    cin >> c ;
    if(c % 2 == 0)
    if(c % 3 && c % 5){
        cout << "DENIED" ;
        return 0 ;
    }
   }

   cout << "APPROVED" ;

}

/*
 Empty set of troubles.
*/


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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int a[N];
int main() {
	#   ifdef LOCAL_PROJECT
        freopen("in.txt", "r", stdin);
    #   endif
    int n;
    scanf("%d",&n);
    int sum =0;
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
            if(i&1)sum+=a[i];
            else sum-=a[i];
    }
    for(int i=1;i<=n;i++){
        printf("%d ",sum);
        //x 0 x
        sum=(a[i]-sum/2)*2;
    }
    return 0;
}

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

    cin >> M;
    vector<string> t(M);
    for (int i = 0; i < M; i++){
        cin >> t.at(i);
    }

    vector<int> sum(N);
    for (int i = 0; i < N; i++){
        for (int j = 0; j < N; j++){
            if(s.at(i) == s.at(j)){
                sum.at(i)++;
            }
        }

        for(int j = 0; j < M; j++){
            if(s.at(i) == t.at(j)){
                sum.at(i)--;
            }
        }
    }

    int max_sum = sum.at(0);
    for (int i = 0; i < N; i++){
        if(max_sum < sum.at(i)){
            max_sum = sum.at(i);
        }
    }
    if (max_sum < 0){
        cout << 0 << endl;
    } else cout << max_sum << endl;

}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef std::pair<int,int> pair2;
typedef std::pair<int,pair2> pair3;
const ll INF = 1LL<<60;

int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll ans=-INF;
ans=max(ans,a*c);
  ans=max(ans,a*d);
  ans=max(ans,b*c);
  ans=max(ans,b*d);
  cout<<ans<<endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("Yes\n")
#define NO printf("No\n")
#define all(c) (c).begin(),(c).end()
using namespace std;
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
#define N 1000005
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
int main()
{
  sync;
  lld a,b;
  cin>>a>>b;
  string s;
  cin>>s;
  if(sz(s) != (a+b+1)) return 0*NO;
  rep(i,0,sz(s)) {
    if(i == a) {
      if(s[i]=='-') continue;
      return 0*NO;
    }
    if(s[i]>='0' and s[i]<='9') continue;
    return 0*NO;
  }
  YES;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int A, B;
    cin >> A >> B;
    cout << ( (A * B) % 2 == 1 ? "Yes" : "No" ) << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from operator import mul
from functools import reduce
from collections import Counter

n = int(input())
s = input()

c = Counter(s)
if len(c) != 3:
    print(0)
    sys.exit()

ans = reduce(mul, c.values())

for i in range(n - 1):
    x, y, z = i, i + 1, i + 2
    while z <= n - 1:
        if s[x] != s[y] and s[x] != s[z] and s[y] != s[z]:
            ans -= 1
        y += 1
        z += 2

print(ans)

Measured memory_bytes: 9608
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    map<long, int> p;
    p[0]++;
    int n;
    cin >> n;
    long s = 0;
    long res = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        s += x;
        res += p[s];
        p[s]++;
    }
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 12800