akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
const int M = 1000000007;

long long gcd(long long a, long long b) {
    while (b > 0) { long long t = a % b; a = b; b = t; }
    return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> p(n);
    vector<int> rev(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        --p[i];
        rev[p[i]] = i;
    }
    vector<vector<long long>> k(n, vector<long long>(20, 0));
    vector<vector<long long>> sum(n, vector<long long>(20, 0));
    for (int i = 0; i < n; ++i) {
        int now = i;
        while (1) {
            ++k[i][0];
            sum[i][0] += now + 1;
            now = p[now];
            if (now == i) break;
        }
    }
    for (int i = 0; i < 18; ++i) {
        for (int j = 0; j < n; ++j) {
            k[j][i + 1] = lcm(k[j][i], k[min(n - 1, j + (1 << i))][i]);
            sum[j][i + 1] = (sum[j][i] * (k[j][i + 1] / k[j][i] % M) % M + sum[min(n - 1, j + (1 << i))][i] * (k[j][i + 1] / k[min(n - 1, j + (1 << i))][i] % M) % M) % M;
        }
    }
    for (int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        int d = r - l + 1;
        long long lc = 1, ans = 0;
        int now = l - 1;
        for (int j = 0; j < 20; ++j) {
            if ((d >> j) & 1) {
                long long nlc = lcm(lc, k[now][j]);
                ans = (ans * (nlc / lc % M) % M + sum[now][j] * (nlc / k[now][j] % M) % M) % M;
                now += 1 << j;
                lc = nlc;
            }
        }
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 42740
#include<set>
#include<queue>
#include<cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

const int dx[]={1,1,0,-1,-1,-1,0,1},dy[]={0,-1,-1,-1,0,1,1,1};

struct data{
	int S;
	int x,y;
	bool operator<(const data &D)const{
		if(S!=D.S) return S<D.S;
		if(x!=D.x) return x<D.x;
		return y<D.y;
	}
};

int n;

data next_state(int S,int x,int y){
	S|=1<<y*n+x;
	int T=0;
	rep(i,n) rep(j,n) {
		int cnt=0;
		rep(k,8){
			int yy=i+dy[k],xx=j+dx[k];
			if(0<=yy && yy<n && 0<=xx && xx<n && S&(1<<yy*n+xx)) cnt++;
		}
		if(S&(1<<i*n+j)){
			if(cnt==2 || cnt==3) T|=1<<i*n+j;
		}
		else{
			if(cnt==3) T|=1<<i*n+j;
		}
	}
	T&=~(1<<y*n+x);
	return (data){T,x,y};
}

int main(){
	for(;scanf("%d",&n),n;){
		data ini={};
		rep(i,n){
			char s[6]; scanf("%s",s);
			rep(j,n){
				if(s[j]=='#') ini.S|=1<<(i*n+j);
				if(s[j]=='@') ini.x=j, ini.y=i;
			}
		}

		int ans=-1;
		set<data> Vis;
		queue< pair<int,data> > Q; Q.push(make_pair(0,ini));
		while(!Q.empty()){
			int t=Q.front().first;
			data D=Q.front().second; Q.pop();

			if(t>11) break;

			if(Vis.count(D)>0) continue;
			Vis.insert(D);

			if(D.S==0){ ans=t; break; }

			rep(k,8){
				int yy=D.y+dy[k],xx=D.x+dx[k];
				if(0<=yy && yy<n && 0<=xx && xx<n && (D.S&(1<<yy*n+xx))==0){
					Q.push(make_pair(t+1,next_state(D.S,xx,yy)));
				}
			}
		}

		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <stdio.h>

#define MAX 1000000

using namespace std;

int main()
{
	char p[MAX]={1,1};
	int n,ans;

	for(int i=2;i*i<=MAX;i++){
		if(p[i]==0){
			for(int j=i*2;j<MAX;j+=i) p[j]=1;
		}
	}

	while(cin>>n){
		ans=0;
		for(int i=2;i<=n;i++){
			 if(p[i]==0) ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

string s;
int ans = 100;

signed main() {
	cin >> s;
	int n = (int)s.size();
	bool bl2 = true;
	for (int i = 1; i < n; i++)if (s[0] != s[i])bl2 = false;
	if (bl2) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < 26; i++) {
		char c = 'a' + i;
		string t1 = s, t2 = "";
		for (int j = 1;; j++) {
			for (int k = 0; k < n - j; k++) {
				if (t1[k] == c || t1[k + 1] == c)t2 += c;
				else t2 += t1[k];
			}
			t1 = t2;
			t2 = "";
			bool bl = true;
			for (int k = 1; k < n - j; k++)if (t1[0] != t1[k])bl = false;
			if (bl) {
				ans = min(ans, j);
				break;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
dp = [[0]*3 for _ in range(N+1)]

for i in range(N):
    a, b, c = map(int, input().split())
    dp[i+1][0] = max(dp[i][1], dp[i][2])+a
    dp[i+1][1] = max(dp[i][0], dp[i][2])+b
    dp[i+1][2] = max(dp[i][0], dp[i][1])+c

print(max(dp[N]))

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

int main() {
	int n;
	cin>>n;
	int ki=0;
	int gu=0;
	for(int i=1;i<=n;i+=2) {
		ki++;
	}
	for(int i=2;i<=n;i+=2) {
		gu++;
	}
	cout<<ki*gu<<endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

num = [0] * n
flag = 1
if m == 0:
    if n == 1:
        print(0)
        exit()
num[0] = 1
for i in range(m):
    s, c = map(int, input().split())
    if num[s - 1] == 0 or (s - 1 == 0 and num[0] == 1):
        num[s - 1] = c
    else:
        if num[s - 1] != c:
            flag = 0
    
if flag == 0 or (n != 1 and num[0] == 0):
    print(-1)
else:
    for i in range(n):
        print(num[i], end="")

Measured memory_bytes: 3064
N = int(input())
S = input()
 
left_black=0
right_white=S.count(".")
ans=left_black+right_white
 
for i in S:
    if i==".":
        right_white-=1
        ans=min(ans,left_black+right_white)
    else:
        left_black+=1
        ans=min(ans,left_black+right_white)
print(ans)

Measured memory_bytes: 3500
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn = 100010;
const int inf = 0x0fffffff;
const long long mod = 1000000007;
long long x[maxn], y[maxn], sx[maxn], sy[maxn];

int main()
{
	long long ans, sumx, sumy;
	int n, m, j, i;
	cin >> n >> m;
	for (int i = 0; i < n; i ++)
	{
		cin >> x[i];
	}
	for (int i = 0; i < m; i ++)
	{
		cin >> y[i];
	}
	sumx = sumy = 0;
	sx[0] = x[0];
	for (i = 1; i < n; i ++)
	{
		sumx = (sumx + (i * x[i] - sx[i - 1])) % mod;
		sx[i] += sx[i - 1] + x[i];
	}

	sy[0] =y[0];
	for (j = 1; j < m; j ++)
	{
		sumy = (sumy + (j * y[j] - sy[j - 1])) % mod;
		sy[j] += sy[j - 1] + y[j];
	}
	ans = (sumx * sumy) % mod;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  if(s == "ABC") cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}

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

namespace ITP1_1_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int s = 0, m = 0, h = 0;

            int a = int.Parse(Console.ReadLine());

            if (a >= 60)
            {
                m = a / 60;
                s = a % 60;
            }
            else
            {
                s = a;
            }

            if(m >= 60)
            {
                h = m / 60;
                m = m % 60;
            }

            Console.WriteLine("{0}:{1}:{2}", h, m, s);

        }
    }
}



Measured memory_bytes: 17992
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;


signed main(){
    int n;
    while(cin >> n, n){
        int d[10][6] = {0};
        rep(i, 0, n){
            rep(j, 0, 5){
                cin >> d[i][j];
            }
        }
        
        int ans = 0;
        bool f = true;
        while(f){
            f = false;
            rep(i, 0, n){
                rep(j, 0, 5){
                    int cnt = 1;
                    int now = d[i][j];
                    if(d[i][j] <= 0) continue;
                    rep(k, j + 1, 6){
                        if(d[i][j] == d[i][k]) cnt++;
                        else break;
                    }
                    if(cnt < 3) continue;
                    rep(k, j, j + cnt){
                        d[i][k] = -1;
                    }
                    // rep(k, 0, 6){
                    //     cout << d[i][k] << ' ';
                    // }
                    // cout << endl;
                    // cout << d[i][j] << ' ' << cnt << endl;
                    ans += now * cnt;
                    f = true;
                    j += cnt - 1;
                }
            }
            repb(i, n - 1, 0){
                rep(j, 0, 5){
                    if(d[i][j] != -1) continue;
                    if(i == 0) continue;
                    repb(k, i - 1, 0){
                        if(d[k][j] != -1){
                            swap(d[k][j], d[i][j]);
                            break;
                        }
                    }
                }
            }
            // rep(i, 0, n){
            //     rep(j, 0, 6) cout << d[i][j] << ' ';
            //     cout << endl;
            // }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
MOD = 10**9+7

k = int(input())
s = input()
MAX = k + len(s)

factorial = [0] * (MAX + 1)
factorial[0] = 1
for i in range(1, MAX + 1):
    factorial[i] = factorial[i-1] * i % MOD


ifactorial = [0] * (MAX + 1)
ifactorial[MAX] = pow(factorial[MAX], MOD - 2, MOD)
for i in range(MAX, 0, -1):
    ifactorial[i - 1] = ifactorial[i] * i % MOD

pow25 = [1] * (k + 1)
pow26 = [1] * (k + 1)
for i in range(k):
    pow25[i + 1] = pow25[i] * 25
    pow25[i + 1] %= MOD
    pow26[i + 1] = pow26[i] * 26
    pow26[i + 1] %= MOD


def combination(n, k):
    ret = factorial[n] * ifactorial[k] * ifactorial[n - k]
    return ret % MOD


ans = 0
for i in range(k + 1):
    tmp = combination(i + len(s) - 1, len(s) - 1)
    tmp *= pow25[i]
    tmp %= MOD
    # tmp *= pow(25, i, MOD)
    tmp *= pow26[k - i]
    # tmp *= pow(26, k - i, MOD)
    tmp %= MOD
    ans += tmp
    ans %= MOD
print(ans)


Measured memory_bytes: 132920
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using bint = boost::multiprecision::cpp_int;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
#define rrepSE(i,s,e) for (int i = (s); i > (e); i--)
#define ssort(v) sort(v.begin(), v.end())
#define gsort(v) sort(v.rbegin(), v.rend())
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
const int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
const int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;

int main()
{
    string s;
    cin >> s;
    if (s.back() == 's') {
        cout << s << "es" << "\n";
    }
    else {
        cout << s << "s" << "\n";
    }
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
    x += y;
    if( x >= m )
        x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
    x -= y;
    if( x < 0 )
        x += m;
}

ll gcd( ll x, ll y )
{
    while( y )
    {
        x %= y;
        swap(x,y);
    }
    return x;
}

int main() 
{
    fastio();

    int k;
    cin>>k;

    ll ans = 0;
    for(int a=1;a<=k;a++)
    {
        for(int b=1;b<=k;b++)
        {
            for(int c=1;c<=k;c++)
            {
                ll g = gcd(a,b);
                g = gcd(g,c);
                ans += g;
            }
        }
    }
    cout<<ans,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3652
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
alias Classes = Tuple!(long, "number", long, "person");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto n = lread();
    auto a = aryread();
    auto school = new Classes[](n);
    foreach(i, e; a)
    {
        school[i] = Classes(e, i + 1);
    }
    school.sort();
    foreach(i, e; school)
    {
        e.person.write(" ");
    }
    writeln();
}


Measured memory_bytes: 7752
h0, m0, h1, m1, k = map(int, input().split())

p0 = h0 * 60 + m0
p1 = h1 * 60 + m1

q = p1 - k
#print(p0,p1)
#print((p1 - p0) // k * k)

print(max(q - p0,0))

Measured memory_bytes: 9164
# coding: utf-8
# Your code here!

while True:
    N = int(input())
    if N == 0:
        break
    
    line = []
    for l in range(N):
        line.append(input())
    P,Q,R,C = [int(i) for i in input().split()]
    
    flag = False
    for l in range(N):
        s,p,q,r = [int(i) for i in line[l].split()]
        if p <= P and q <= Q and r <= R and 4*p+9*q+4*r <= C:
            print(s)
            flag = True
    if flag == False:
        print("NA")



Measured memory_bytes: 5768
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	tree := make([][]int, n)
	as := make([]int, n-1)
	bs := make([]int, n-1)
	for i := 0; i < n; i++ {
		t := make([]int, 0)
		tree[i] = t
	}
	for i := 0; i < n-1; i++ {
		a, _ := strconv.Atoi(stringLineScan())
		b, _ := strconv.Atoi(stringLineScan())
		a--
		b--
		tree[a] = append(tree[a], b)
		as[i] = a
		bs[i] = b
	}
	color := make(map[string]int)
	c := make([]int, n)
	c, color = dfs(0, tree, c, color)
	m := 0
	for _, i := range c {
		if m < i {
			m = i
		}
	}
	fmt.Println(m)
	for i := 0; i < n-1; i++ {
		fmt.Println(color[fmt.Sprint(as[i], bs[i])])
	}
}
func dfs(init int, tree [][]int, c []int, color map[string]int) ([]int, map[string]int) {
	e := 1
	for i := 0; i < len(tree[init]); i++ {
		idx := tree[init][i]
		if c[init] == e {
			e++
		}
		color[fmt.Sprint(init, idx)] = e
		c[idx] = e
		e++
		c, color = dfs(idx, tree, c, color)
	}
	return c, color
}


Measured memory_bytes: 38400
def sieve(n):
    """
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]
    """
    from math import sqrt
    M = 10**6
    p = [1]*(M+1)
    p[0] = p[1] = 0
    P = []
    for x in range(2, int(sqrt(M))+1):
        if p[x]:
            P.append(x)
            for y in range(x*x, M+1, x):
                p[y] = 0
    return P

def isPrime(n,p):
    cnt = 0
    while n%p==0:
        n //= p
        cnt += 1
    return cnt,n

N = int(input())
P = sieve(N)
ans = 0
d = dict()
for n in range(1,N):
    flg = 1
    m = n
    d[m] = 0
    fac = 1
    for p in P:
        if n!=m and n in d:
            d[m] = d[n]*fac
            flg = 0
            break
        elif n%p == 0:
            l,n = isPrime(n,p)
            fac *= l+1
            d[m//n] = fac
        if p > n:
            break

    if flg:
        if n > 1:
            fac += 1
        d[m] = fac
    ans += d[m]
print(ans)

Measured memory_bytes: 188836
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	int x=0;
	cin>>a>>b>>c>>d;
	for(int i=0;i<=100;i++)
	{
		if( a<i && b>=i && c<i && d>=i)
		{
			x++;
		}
	}
	cout<<x;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    
    int flag = 0;
    
    if (a > b){
      if (a > c && c > b){
        flag++;
      }
    }else{
      if (b > c && c > a){
        flag++;
      }
    }
    
    if (flag != 0)
      System.out.println("Yes");
    else
      System.out.println("No");
  }
      
}

Measured memory_bytes: 22868
from itertools import permutations

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

li = []
for i in range(1, N+1):
  li.append(i)

a, b, cnt = 0, 0, 1
for p in permutations(li, N):
  if list(p) == P:
    a = cnt
  if list(p) == Q:
    b = cnt
  cnt += 1
  
print(abs(a-b))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn =2e3+5;
int a[maxn];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	int cnt=0;
	for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]!=i)
        {
            cnt++;
        }
    }
    if(cnt>2)
    {
        cout<<"NO"<<'\n';
    }
    else
        cout<<"YES"<<'\n';



}


Measured memory_bytes: 256
/*
[ ( ^ _ ^ ) ]
*/

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;

    long max(long...x) {long rs = x[0]; for(long y: x) rs = Math.max(rs, y); return rs;}
    long min(long...x) {long rs = x[0]; for(long y: x) rs = Math.min(rs, y); return rs;}
    
    int[] s;
    int n, d;
    HashMap<Long, Long> mp;

    long go(int i, int t, int f) {
        t = t % d;
        if(i>=n) {
            if(t%d==0) return 1;
            else return 0;
        }
        long k = 100000000 * i + 100 * t + f;
        if(mp.containsKey(k)) return mp.get(k);
        long rs = 0;
        if(f==1) {
            for(int j=0; j<s[i]; j++) {
                rs += go(i+1, t+j, 0);
                rs %= MOD;
            }
            rs += go(i+1, t+s[i], 1);
            rs %= MOD;
        } else {
            for(int j=0; j<10; j++) {
                rs += go(i+1, t+j, 0);
                rs %= MOD;
            }
        }
        mp.put(k, rs);
        return rs;

    }

    void solve(InputReader in, PrintWriter out) throws IOException {
        String k = in.next();
        d = in.nextInt();
        n = k.length();
        
        s = new int[n];
        for(int i=0; i<n; i++) {
            s[i] = k.charAt(i)-'0';
        }
        mp = new HashMap<Long, Long>();
        long rs = go(0, 0, 1);
        rs = (rs - 1 + MOD) % MOD;
        out.println(rs);
    }
    

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 265212
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

template <typename T>
T powi(T a, ll n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= a; 
        a *= a;
        n >>= 1;
    }
    return ret;
}

template <ll mod>
class ModInt {
private:
    ll num;
public:
    ModInt() {};
    ModInt(ll n) { num = n % mod; }
    ModInt inv() const { return powi(*this, mod-2); }
    explicit operator ll() const { return num; }

    ModInt& operator+=(const ModInt& a) {
        num += a.num; 
        if (num >= mod) num -= mod; 
        return *this;
    }
    ModInt& operator-=(const ModInt& a) {
        if (num < a.num) num += mod;
        num -= a.num;
        return *this;
    }
    ModInt& operator*=(const ModInt& a) {
        num = num * a.num % mod;
        return *this;
    }
    ModInt& operator/=(const ModInt& a) { return *this *= a.inv(); }
    friend ModInt operator+(const ModInt& a, const ModInt& b) { return ModInt(a) += b; }
    friend ModInt operator-(const ModInt& a, const ModInt& b) { return ModInt(a) -= b; }
    friend ModInt operator*(const ModInt& a, const ModInt& b) { return ModInt(a) *= b; }
    friend ModInt operator/(const ModInt& a, const ModInt& b) { return ModInt(a) /= b; }

    friend ostream& operator<<(ostream& os, const ModInt& a) { return os << a.num; }
    friend istream& operator>>(istream& is, ModInt& a) {
        ll tmp;
        is >> tmp;
        a.num = tmp % mod;
        return is;
    }
};
using mint = ModInt<1000000007>;

mint dp[100010];

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> b(n+1, false);
    for (int i = 0; i < m; ++i) {
        int a;
        cin >> a;
        b[a] = true;
    }

    dp[0] = 1;
    for (int i = 0; i <= n-1; ++i) {
        if (!b[i+1]) dp[i+1] += dp[i];
        if (!b[i+2]) dp[i+2] += dp[i];
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x)//unsigned
{
	x = 0;
	char c;
	while (!isdigit(c = getchar()));
	while (isdigit(c))
	{
		x = (x << 1) + (x << 3) + (c ^ 48);
		c = getchar();
	}
}
int main()
{
	ios::sync_with_stdio(0);
	int a, b;
	string s, t, u;
	cin >> s >> t >> a >> b >> u;
	if (u == s) --a;
	else if (u == t) --b;
	cout << a << " " << b << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  long long N;
  cin >> N;
  vector<long long> A(N);
  for(long long i=0; i<N; i++){
    cin >> A[i];
  }
  
  long long t;
  long long sum = 0;
  for(long long i=1;i<N;i++){
    t=A[i-1]-A[i];
    if(t>0){
      A[i] += t;
      sum += t;
    }
  }
  
  cout << sum << endl;
  
  return 0;
}

Measured memory_bytes: 4772
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String[] aH = new String[H];
		for(int m=0; m<H; m++) {
			aH[m] = sc.next();
		}

		for(int i=0; i<aH[0].length()+2; i++) {
			System.out.print("#");
		}System.out.print("\n");

		for(int j=0; j<H; j++) {
			System.out.print("#");
			System.out.print(aH[j]);
			System.out.print("#");
			System.out.print("\n");
		}

		for(int k=0; k<aH[0].length()+2; k++) {
			System.out.print("#");
		}

	}

}


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

int main(){
  int n;
  cin >> n;
  int a, b;
  cin >> a >> b;
  vector<int> c(3,0);
  rep(i,n) {
    int p;
    cin >> p;
    if(p <= a) c[0]++;
    else if(a+1 <= p && p <= b) c[1]++;
    else c[2]++;
  }
  cout << min(c[0],min(c[1],c[2])) << endl;
  return 0;
}

Measured memory_bytes: 256
data = {
    'AC': 0,
    'WA': 0,
    'TLE': 0,
    'RE': 0,
}

n = int(input())
for i in range(n):
    s = input()
    data[s] += 1

print('AC x ' + str(data['AC']))
print('WA x ' + str(data['WA']))
print('TLE x ' + str(data['TLE']))
print('RE x ' + str(data['RE']))

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

ll ans;
int n;
string s;

void dfs(int i, string t)
{
    if (i == n)
    {
        if (t.back() != '+')
            return;
        // cout << t << endl;
        ll tmp = 0;
        rep(j, t.size())
        {
            if (t[j] == '+')
            {
                ans += tmp;
                tmp = 0;
            }
            else
            {
                tmp *= 10;
                tmp += t[j] - '0';
            }
        }
        return;
    }
    dfs(i + 1, t + s[i]);
    dfs(i + 1, t + s[i] + "+");
}

void solve()
{
    cin >> s;
    n = s.size();
    dfs(0, "");
    cout << ans << endl;
}

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

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;
int a[3010],b[3010];
int dp[3010][3010];
int dp1[200010];
signed main(){
   int n,T;
   cin>>n>>T;
   vector<pair<int,int>>v(n);
   REP(i,n) {
       cin>>v[i].first>>v[i].second;
      // v[i].second = -v[i].second;
   }
   sort(ALL(v));
   for (int i = 0; i < n; i++)
   {
       a[i] = v[i].first;
       b[i] = v[i].second;
   }
  // dp[0][a[0]]=b[0];
   show(v);
     for (int i = 0; i < n; ++i) {
    for (int w = 0; w < T; ++w) {
      if (w >= a[i]) dp[i+1][w] = max(dp[i][w-a[i]] + b[i], dp[i][w]);
      else dp[i+1][w] = dp[i][w];
    }
  }
  // cout<<dp[n-1][T-1]<<endl;
  int ans2=0;
  for (int i = 0; i < n; i++)
  {
      for (int j = i; j < n; j++)
      {
              ans2=max(ans2,dp[i][T-1]+b[j]);          
      }
      

  }
  cout<<ans2<<endl;
  

   int ans=0;
   for (int i = 0; i < n; i++)
   {
       for (int j = T-1; j >= 0; j--)
       {
           ans = max(ans,dp1[j]+b[i]);
           chmax(dp1[j+a[i]],dp1[j]+b[i]);
       }
   }
  // cout<<ans<<endl;

   
    return 0;
}

Measured memory_bytes: 71040
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;

void main(){
  auto ip = readln.split.to!(int[]);
  if(ip[0] * ip[1] % 2 == 0){
    writeln("Even");
  } else {
    writeln("Odd");
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <string>
#include <tuple>
#include <vector>
#include <set>
#include <map>
#include <iterator>
#include <random>
#include <cmath>

using namespace std;
using lint = long long int;

lint calc(lint n) {
	lint val = 1;
	for (lint i = n; i >= 2; i-=2) {
		val *= i;
	}

	lint count = 0;
	while (true) {
		if (val == 0)
			break;
		if (val % 10 == 0) {
			count++;
			val /= 10;
		}
		else
			break;
	}
	return count;
}

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

	int mod = n % 2;

	if (mod == 1) {
		cout << 0;
		return 0;
	}

	

	lint count5 = 0;
	for (lint i = 5; i < n; i *= 5) {
		count5 += (n / i) / 2;
	}


	//for (n = 1; ; n++) {
	//	cout << n << endl;
	//	int mod = n % 2;

	//	lint count5 = 0;
	//	for (lint i = 5; i <= n; i *= 5) {
	//		count5 += (n / i) / 2;
	//	}	

	//	if (calc(n) != count5) {
	//		int hoge = 0;
	//		hoge++;
	//	}
	//}

	cout << count5;

	return 0;

}


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

int main(){
    int a,b;
    cin >> a >>b;
    if(b % a == 0) cout << a + b << endl;
    else cout << b - a << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int len;
  int m,i,temp,j;
  int count;
  while(true){
    char str1[200];
    cin >> str1;
    if(str1[0] == '-'){
      return 0;
    }else{
      len = strlen(str1);
      cin >> m;
      count = 0;
      for(i = 0;i < m;++i){
        cin >> temp;
        count += temp;
      }
      count %= len;
      char temp1[count];
      for(i = 0;i < count;++i){
        temp1[i] = str1[i];
      }
      for(i = 0;i < len-count;++i){
        str1[i] = str1[i+count];
      }
      j = 0;
      for(i = i;i < len;++i){
        str1[i] = temp1[j];
        ++j;
      }
      for(i = 0;i < len;++i){
        cout << str1[i];
      }
      cout << "\n";
    }
  }
}


Measured memory_bytes: 3092
#include<stdio.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
static inline long IN(void)
{
  long x=0;int f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(long x){if(x<0)putchar('-'),x=-x;if(x>=10)OUT(x/10);putchar(x%10+48);}
static inline void Radix32(int A[],const int sz)
{
  int temp[200001];const int bit=0b1000;
  rep(k,0b100)
  {
    int u[0x100]={},v[0x100]={};
    rep(i,sz)u[A[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)u[i+1]+=u[i];
    rep(i,sz){temp[--u[A[sz-1-i]>>bit*k&((1<<bit)-1)]]=A[sz-1-i];}k++;
    rep(i,sz)v[temp[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)v[i+1]+=v[i];
    rep(i,sz)A[--v[temp[sz-1-i]>>bit*k&((1<<bit)-1)]]=temp[sz-1-i];
  }
}
int main(void)
{
  int N=IN(),x,p=0,m=0,z=0,minus=0,A[200000];
  long K=IN(),count=0,l=-2e18,r=-l,mid;
  while(N--){x=IN();if(x>0)A[m+p++]=x;else if(x<0)A[p+m++]=x;else z++;}
  Radix32(A,m+p);
  rep(i,m)A[p+i]*=-1;
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;
  if(K<=1l*m*p)r=1l;else l=-1l;
  while(l<=r)
  {
    mid=(l+r)/2;count=0;
    if(mid>=0)
    {
      int plus=p-1,minus=m-1;count+=1l*z*(p+m)+1l*z*(z-1)/2+1l*p*m;
      rep(i,plus){while(1l*A[i]*A[plus]>mid){plus--;}if(i>=plus){break;}count+=1l*plus-i;}
      rep(i,minus){while(1l*A[m+p-1-i]*A[m+p-1-minus]>mid){minus--;}if(i>=minus){break;}count+=1l*minus-i;}
    }
    else{mid*=-1l;minus=1;int low=0;rep(i,m){while(1l*A[low]*A[p+i]<mid&&low<p){low++;}count+=1l*p-low;}}
    if(count>=K){if(minus)r=-mid-1l;else r=mid-1l;}else{if(minus)l=-mid+1l;else l=mid+1l;}
  }
  return OUT(l),0;
}

Measured memory_bytes: 2952
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	ll a,b;
	cin>>a>>b;
	for(ll i = 1 ; i <= b ; i++){
		if( (a * i ) % b == 0){
			cout<<(a*i)<<endl;
			break;
		}
	}
}

Measured memory_bytes: 3596
#include <stdio.h>
 
int main(){
    int j,s_length = 0;
    char s[101],p[101];
    scanf("%s",s);
    scanf("%s",p);
 
    for(int i = 0; s[i] != '\0';i++) s_length++;
 
    for(int left = 0;s[left] != '\0';left++){
        for(j = 0;p[j] != '\0' && p[j] == s[(left+j)%s_length];j++);
        if(p[j] == '\0'){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int h[n+1];
    h[0]=0;
    for(int i=1;i<n+1;i++) cin>>h[i];
    int dp[n+1];
    dp[0]=0;
    dp[1]=0;dp[2]=abs(h[2]-h[1]);
    for(int i=3;i<n+1;i++)
    {
    	int p=abs(h[i]-h[i-1]);
    	int q=abs(h[i]-h[i-2]);
    	// if(p<q) dp[i]=dp[i-1]+p;
    	// else dp[i]=dp[i-2]+q;
    	dp[i]=min(p+dp[i-1],q+dp[i-2]);
    	
    }
    cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 1024
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=='?':
        break
    elif op=='+':
        print(a+b)
    elif op=='-':
        print(a-b)
    elif op=='*':
        print(a*b)
    elif op=='/':
        print(int(a/b))


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

int main(){
  int n,m;
  cin>>n;
  vector<string>s(n);
  rep(i,n)cin>>s[i];
  
  cin>>m;
  vector<string>t(m);
  rep(i,m)cin>>t[i];
  int ans=0;
  
  rep(i,n){
    int score=0;
    rep(j,n)if(s[i]==s[j])score++;
    rep(j,m)if(s[i]==t[j])score--;
    ans=max(ans,score);
  }
  cout<<ans<<endl;
  return 0;
}

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

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

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


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

long long lcm(long long a, long long b) {
  return a / gcd(a, b) * b;
}
//a x + b y = gcd(a, b)
long long extgcd(long long a, long long b, long long &x, long long &y) {
  long long g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}

long long InvMod(long long a, long long mod) {
  long long x, y;
  if (extgcd(a, mod, x, y) == 1) { return (x + mod) % mod; }
  return 0;
}


ll Mul(ll base, ll power, ll mod) {
  ll ret = 0;
  while (power > 0) {
    if (power & 1) { ret = (ret + base) % mod; }
    base = (base + base) % mod;
    power >>= 1;
  }
  assert(0 <= ret && ret < mod);
  return ret;
}
// need extgcd
ll ChineseRemainderTherom(const vector<ll> &anss, const vector<ll> &mods) {
  assert(anss.size() == mods.size());
  ll all = 1;
  for (int i = 0; i < (int)mods.size(); i++) {
    all *= mods[i];
  }
  ll ret = 0;
  for (int i = 0; i < (int)anss.size(); i++) {
    ll x, y;
    extgcd(mods[i], all / mods[i], x, y); 
    y = (y + all) % all;
    ret = (ret + Mul(Mul((anss[i] + all) % all, y, all), (all / mods[i]), all)) % all;
    //assert(ret >= 0); 
  }
  return ret;
}


int psize;
int prime[2];

int op[100010];
int y[100010];

int main() {
  int n;
  prime[psize++] = 797987;
  prime[psize++] = 798121;
  while (scanf("%d", &n) > 0) {
    REP(i, n) {
      scanf("%d %d", &op[i], &y[i]);
    }
    ll all = 1;
    vector<ll> ans;
    vector<ll> mod;
    REP(iter, psize) {
      all *= prime[iter];
      mod.push_back(prime[iter]);
      ll MOD = prime[iter];
      ll v = 0;
      REP(i, n) {
        if (op[i] == 1) {
          v = ((v + y[i]) % MOD + MOD) % MOD;
        } else if (op[i] == 2) {
          v = ((v - y[i]) % MOD + MOD) % MOD;
        } else if (op[i] == 3) {
          v = ((v * y[i]) % MOD + MOD) % MOD;
        } else if (op[i] == 4) {
          if (y[i] < 0) {
            v = (v * InvMod(-y[i], MOD)) % MOD;
            v = ((v * -1) % MOD + MOD) % MOD;
          } else {
            v = (v * InvMod(y[i], MOD)) % MOD;
          }
        }
      }
      ans.push_back(v);
    }
    ll v = ChineseRemainderTherom(ans, mod);
    if (v > (1LL << 31)) {
      v -= all;
    }
    printf("%lld\n", v);
  }
}

Measured memory_bytes: 1664
#include<stdio.h>
int main()
{
	long long a, b, c,k,r=0;
	char o;
	scanf("%lld %lld %lld %lld", &a, &b, &c,&k);
	scanf("%c", &o);
	if (k < a)
	{
		printf("%lld\n",k);
	}
	else if (k >= a && k <= a + b)
	{
		r = a;printf("%lld\n", a);
	}
	else if (k>a+b&&k<=a+b+c)
	{
		r =a- (k - (a + b));
         printf("%lld\n", r);
	}
	else if (k > a + b + c)
	{
		r = a - c;
		printf("%lld",r);
	}
	return 0;
}

Measured memory_bytes: 2128
/*
 * 日本でよく使われる紙幣は、10000 円札、5000 円札、1000 円札です。以下、「お札」とはこれらのみを指します。
 * 
 * 青橋くんが言うには、彼が祖父から受け取ったお年玉袋にはお札が N 枚入っていて、合計で Y 円だったそうですが、嘘かもしれません。
 * このような状況がありうるか判定し、ありうる場合はお年玉袋の中身の候補を一つ見つけてください。なお、彼の祖父は十分裕福であり、お年玉袋は十分大きかったものとします。
 */

import java.util.*;
	public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            //入力
            int n = Integer.parseInt(sc.next());
            int y = Integer.parseInt(sc.next());
            // 10000円札5000円札1000円札の枚数の配列num
            int[] num = new int[3];
            
            // 最も枚数が少ないように初期化
            num[0] = y/10000;
            num[1] = (y%10000)/5000;
            num[2] = (y%5000)/1000;
            
            // すべてのパターンの両替を考え、枚数の和がnであったらその組み合わせを出力してreturn
            for(int i=0; i<=num[0]; i++){
            	for(int j=0; j<=num[1] + 2*i; j++){
            		if(num[0]-i + num[1]+2*i-j + num[2]+5*j == n){
            			System.out.println(num[0]-i + " " + (num[1]+2*i-j) + " " + (num[2]+5*j));
                    	sc.close();
                    	return;
            		}
            	}
            }
            
            // 枚数の和がnになる組み合わせがなかったときは以下を出力
            System.out.println("-1 -1 -1");
            sc.close();
        }
    }
	

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
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; }

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

int main() {
    ll A, B;
    cin >> A >> B;
    cout << A*B/gcd(A, B) << endl;
    return 0;
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	int health,n;
	cin>>health>>n;
	int pow[n],cost[n];
	for(int i=0;i<n;i++)
		cin>>pow[i]>>cost[i];
	int dp[health+1];
	for(int i=0;i<=health;i++)
		dp[i]=INT_MAX;
	dp[0]=0;
	for(int i=1;i<=health;i++){
		for(int j=0;j<n;j++){
			//if(i==7)
			//cout<<dp[i]<<' '<<cost[j]<<' '<<j<<endl;
			if(i-pow[j]<=0)
				dp[i]=min(dp[i],cost[j]);
			else{
				dp[i]=min(dp[i],dp[i-pow[j]]+cost[j]);
			}
			//if(i==7)
				//cout<<dp[i]<<' '<<i<<' '<<pow[j]<<endl;
		}
	}
//	for(int i=0;i<=177;i++)
//		cout<<dp[i]<<' ';
	cout<<dp[health]<<endl;
	return 0;
}

Measured memory_bytes: 3688
#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
int a,b,c;
int s;
map<pair<pair<int,int> , int > ,bool>vis; 
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	vis[make_pair(make_pair(a,b),c)]=true;
	while(!(a&1) && !(b&1) && !(c&1))
	{
		s++;
		int ca=(b>>1)+(c>>1),cb=(a>>1)+(c>>1),cc=(a>>1)+(b>>1);
		a=ca;b=cb;c=cc;
		if(vis[make_pair(make_pair(a,b),c)])
		{
			printf("-1");
			return 0;
		}
		vis[make_pair(make_pair(a,b),c)]=true;
	}
	printf("%d",s);
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

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

  if(b == 1){
    std::cout << "0\n";
    return 0;
  }

  int tap_cnt = 0;
  int port_cnt = 0;

  while(port_cnt < b){
    tap_cnt++;
    port_cnt = (tap_cnt * (a-1) + 1);
  }

  printf("%d\n", tap_cnt);
 
  return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
0 0 3 4
1
2 5

output:
3.1200000000 4.1600000000
"""

import sys
from collections import namedtuple


def dot(a, b):
    return a.real * b.real + a.imag * b.imag


def project(s, p):
    base_vector = s.target - s.source
    prj_ratio = dot(p - s.source, base_vector) / pow(abs(base_vector), 2)
    return s.source + base_vector * prj_ratio


def solve(_prj_points):
    for point in _prj_points:
        xp, yp = map(int, point)
        p = xp + yp * 1j
        prj = project(prj_segment, p)
        print('{real:.10f} {imag:.10f}'.format(real=prj.real, imag=prj.imag))

    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()

    line = tuple(map(int, _input[0].split()))
    q_num = int(_input[1])
    prj_points = map(lambda x: x.split(), _input[2:])

    p1, p2 = (x + y * 1j for x, y in zip(line[::2], line[1::2]))
    Segment = namedtuple('Segment', ('source', 'target'))
    prj_segment = Segment(p1, p2)

    solve(prj_points)

Measured memory_bytes: 8248