akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) printf("Case #%d: ",i);
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;

#define MAX_V 100010
struct edge {
	int to;
	int cost;
};
using P = pair<int, int>;
int V;
vector<edge> G[MAX_V];
ll d[MAX_V];
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P> > que;
	fill(d, d + V, INF);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;

		for (int i = 0; i < G[v].size(); ++i) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int main(){
	cin >> V;
	rep(i, 0, V - 1) {
		int p1, p2, p3; cin >> p1 >> p2 >> p3;
		p1--; p2--; 
		G[p1].push_back({ p2,p3 });
		G[p2].push_back({ p1,p3 });
	}
	int q, k; cin >> q >> k;
	dijkstra(k - 1);
	rep(i, 0, q) {
		int q1, q2; cin >> q1 >> q2;
		q1--; q2--;
		printf("%lld\n", d[q1] + d[q2]);
	}
	return 0;
}

Measured memory_bytes: 8820
//https://atcoder.jp/contests/abc118/tasks
// S011:追いかけっこ
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define max(a, b) (((a) > (b)) ? (a) : (b))

int main()
{
    int a, b, ans;
    scanf("%d%d", &a, &b);

    // AがBの約数ならA+B
    if (b % a == 0) {
        ans = a + b;
    } else {
        ans = b - a;
    }
    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int[] d = new int[K];
		int[] A = new int[N];

		for(int i=0; i<K; i++) {
			d[i] = sc.nextInt();
			for(int j=0; j<d[i]; j++) {
				int s = sc.nextInt();
				A[s-1]++;
			}
		}
		sc.close();
		int k=0;
		for(int i=0; i<N; i++) {
			if(A[i]==0) {
				k++;
			}
		}
		System.out.println(k);
	}

}

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


double p[302][302][302],ev[302][302][302];
int cnt[4];
int32_t main(){
	int n;
	cin >> n;
	vector<int> A(n);
	
	for(auto &a:A){
		cin >> a;
		cnt[a]++;	
	}
	p[cnt[1]][cnt[2]][cnt[3]] = 1.0;
	for(int c =n;c>=0;c--)
		for(int b =n;b>=0;b--)
			for(int a=n;a>=0;a--){
				if(a==0 and b==0 and c==0) continue;
				if((a+b+c) > n) continue;
				double sum = a+b+c;
				double p_w = (n-sum)/n;
				double value = p_w / (1-p_w) +1;
				ev[a][b][c]+=value*p[a][b][c];
				//a-1
				if(a-1>=0){
					p[a-1][b][c] += (p[a][b][c]*(a/sum));
					ev[a-1][b][c] += (ev[a][b][c]*(a/sum));
				}
				// b-1 a+1
				if((b-1)>=0){
					p[a+1][b-1][c] += (p[a][b][c]*(b/sum));
					ev[a+1][b-1][c] += (ev[a][b][c]*(b/sum));
				}
				//c-1 b+1
				if((c-1)>=0){
					p[a][b+1][c-1] += (p[a][b][c]*(c/sum));
					ev[a][b+1][c-1] += (ev[a][b][c]*(c/sum));
				}
			}
	cout << fixed << setprecision(10)<< ev[0][0][0] << '\n';
}

Measured memory_bytes: 430336
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>A;//きゅー
int main(void)
{
	char S[100010];
	scanf("%s", S);
	int i = 0;
	while (S[i]!='\0') {
		if (i % 2 == 0) {
			if (S[i] == 'L') {
				printf("No");
				return 0;
			}
		}
		else {
			if (S[i] == 'R') {
				printf("No");
				return 0;
			}
		}
		i++;
	}
	printf("Yes");
	return 0;

}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int N,Y;
    cin>>N>>Y;
    Y/=1000;
    int x,y,z=-1;
    
    int l = max(0, (5*N-Y+3)/4);
    int r = min(min(N,Y),(10*N-Y)/9);
    
    for(int i=l;i<=r;i++){
        if(i%5==Y%5){
            z = i;
            break;
        }
    }
    if(z==-1)cout<<"-1 -1 -1"<<endl;
    else{
        x = (Y-z)/5 - N + z;
        y = N-z-x;
        
        cout<<x<<" "<<y<<" "<<z<<endl;
    }
}



Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n = II()
    d = LIR(n)
    i = 0
    for a, b in d:
        if a == b:
            i += 1
        else:
            i = 0
        if i == 3:
            print("Yes")
            return
    print("No")
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 76828
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
int n, m, x, y;ll z = 0, w, h, sum = 0, ans = 0;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int main(void) {
	cin >> n; vector<ll> a(n);
	rep(i, n) cin >> a[i];
	sort(a.rbegin(), a.rend());
	ll an[2], po = 0;
	an[0] = 0; an[1] = 0;
	rep(i, n - 1) {
		if (a[i] == a[i + 1]) {
			an[po] = a[i];
			po++; i++;
		}
		if (po > 1) break;
	}cout << an[0] * an[1] << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    // Here your code !
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(c>=a&&c<=b)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 128
N = int(input())
X = list(map(int, input().split()))
p = 0
s = sum(X)
for n in range(N):
  s -= X[n] 
  s = s % (10**9 + 7)
  p += s * X[n]
  p = p % (10**9 + 7)

print(p)

Measured memory_bytes: 31448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, s, t;
  in(n);
  vector<ll> a(n);
  rep(i, n)
    in(a[i]);
  sort(all(a));
  s = n - 1;
  while(true){
    if(a[s - 1] == a[s])
      break;
    s--;
    if(s == 0){
      out(0);
      memi;
      return 0;
    }
  }
  t = s - 2;
  while(true){
    if(a[t - 1] == a[t])
      break;
    t--;
    if(t == 0){
      out(0);
      memi;
      return 0;
    }
  }
  out(a[s] * a[t]);
  memi;
}

Measured memory_bytes: 1024
import itertools


X = int(input())

u = -1000
A = []
while u < 1000:
    A.append(u)
    u += 1
AA = list((itertools.product(A, repeat=2)))
for a,b in AA:
    if a**5-b**5 == X:
        print(a,b)
        break

Measured memory_bytes: 300964
N=int(input())
S=[]
cnt=Alist=Blist=0
key=False
for i in range(N):
    s=input()
    cnt+=s.count("AB")
    S=list(s)
    if S[0] == "B":
        Blist+=1
    if S[-1] == "A":
        Alist+=1
    if (S[0] == "B" and S[-1] != "A") or (S[0] != "B" and S[-1] == "A"):
        key = True

cnt += min(Alist,Blist)
if key or min(Alist,Blist)==0:
    print(cnt)
else:
    print(cnt-1)



Measured memory_bytes: 3064
n, k = map(int, input().split())

sum1 = 0
for i in range(n):
    cnt = 0
    s = i + 1
    if s >= k:
        sum1 += 1/n
    else:
        while True:
            s *= 2
            cnt += 1
            if s >= k:
                break
        sum1 += 1/n * 0.5**cnt
    
print(sum1)

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int n;
    cin >> n;
    pair <int,int> data[20];
    for(int i=0;i<n;i++) {
        cin >> data[i].second >> data[i].first;
        data[i].second *= -1;
    }
    sort(data,data + n);
    cout << -data[n-1].second << " " <<  data[n-1].first << endl;
}

Measured memory_bytes: 1164
# coding: utf-8
# Your code here!
import fractions
from functools import reduce
N=int(input())
A=list(map(int,input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
l=lcm_list(A)
ans=0

for i in range(N):
    ans+=(l//A[i])
print(ans%(10**9+7))

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

int main(){
 string S,T; cin>>S>>T;
 vector<UL> AM(T.size()+1); AM[0]=~0u;
 UL q = ~0u;
 rep(p,T.size()){
  while(q!=~0u){ if(T[p]==T[q]) break; else q=AM[q]; }
  AM[p+1] = ++q;
 }
 vector<UL> X(S.size());
 q = 0;
 rep(p,S.size()){
  while(q!=~0u){ if(S[p]==T[q]) break; else q=AM[q]; }
  X[p] = ++q;
  if(q==T.size()){ printf("%u\n",p-q+1); q=AM[q]; }
 }
 return 0;
}



Measured memory_bytes: 7932
#include <stdio.h>
#include <string.h>
int main(void){
	int H,W,N;
	scanf("%d",&H);
	scanf("%d",&W);
	scanf("%d",&N);
	if(W>=H&&N%W==0){
		printf("%d",N/W);
	}
	else if(W>=H&&N%W!=0){
		printf("%d",N/W+1);
	}
	else if(W<H&&N%H==0){
		printf("%d",N/H);
	}
	else{
		printf("%d",N/H+1);
	}
	return 0;
	}

	

Measured memory_bytes: 128
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))

h = {}
for i in range(N):
    b = h.get(a[i], 0)
    h[a[i]] = b + 1

if len(h.keys()) <= K:
    print(0)
else:
    ans = 0
    keys = sorted(h.keys(), key=lambda x: h[x])
    for i in range(len(keys) - K):
        ans += h[keys[i]]
    print(ans)

Measured memory_bytes: 32184
S = input()

MMYY_flag = False
YYMM_flag = False
if 1 <= int(S[:2]) <= 12:
    MMYY_flag = True
if 1 <= int(S[2:]) <= 12:
    YYMM_flag = True
if MMYY_flag and YYMM_flag:
    print('AMBIGUOUS')
elif MMYY_flag:
    print('MMYY')
elif YYMM_flag:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 2940
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define LL long long
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define pii pair < int , int >

int n;
int A,B;

int main(){

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

	int ans = 0;
	cin >> A >> B;
	int C = 1;
	while ( C < B ){
		ans++;
		C += A - 1;
	}
	cout << ans << endl;
	
	return 0;
}

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

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int main(){
    int n, c;
    scanf("%d %d", &n, &c);
    int d[c+1][c+1];
    rep(i, 1, c+1){
        rep(j, 1, c+1){
            scanf("%d", &d[i][j]);
        }
    }
    int t[3][c+1];
    rep(i, 0, 3){
        rep(j, 0, c+1){
            t[i][j] = 0;
        }
    }
    rep(i, 1, n+1){
        rep(j, 1, n+1){
            int p;
            scanf("%d", &p);
            t[(i+j)%3][p]++;
        }
    }
    int ans = INT_MAX;
    rep(i, 1, c+1){
        rep(j, 1, c+1){
            rep(k, 1, c+1){
                if(i==j || j==k || k==i){
                    continue;
                }
                int buf[3] = {i, j, k};
                int cnt = 0;
                rep(l, 0, 3){
                    rep(m, 1, c+1){
                        cnt += t[l][m] * d[m][buf[l]];
                    }
                }
                if(cnt < ans){
                    ans = cnt;
                }
            }
        }
    }
    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitsf(n) __builtin_popcount(n)
ll power(ll x, ll y); 

const ll MOD = 1000000007;
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    string s;
    cin >> s;
    int n = s.size() + 1;
    vector<int> l, r;
    l.pb(-1), r.pb(-1);
    rep(i, 0, n-1) if(s[i] == '<') l.pb(i); else r.pb(i);
    l.pb(n-1), r.pb(n-1);
    int arr[n];
    rep(i, 0, n){
        int a = abs(*(--LB(all(r), i)) - i) - 1;
        int b = abs(*(LB(all(l), i)) - i);
        arr[i] = max(a, b);
    }

    ll res = 0;
    rep(i, 0, n) res += arr[i];
    cout << res;
}
 
ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}


Measured memory_bytes: 4984
import java.io.*;
import java.util.*;
import java.lang.*;
import java.awt.*;
import java.awt.geom.*;
import java.math.*;
import java.text.*;
import java.math.BigInteger.*;
import java.util.Arrays; 

public class   Main
{
  BufferedReader in;
  StringTokenizer as;
  double nums[][][],nums2[];
  ArrayList < Integer > [] ar;
  int a;
  public static void main (String[] args)
  {
    new Main  ();
  }
  
  public double solve(int aa, int bb, int cc)
  {
    if(nums[aa][bb][cc] != 0)
      return nums[aa][bb][cc];
    else if (aa == 0 && bb == 0 && cc == 0)
      return 0;
    double ans = 0;
    if(cc != 0)
      ans += cc * 1.0 /a * (solve(aa,bb+1,cc-1)+1);
    if(bb != 0)
      ans += bb * 1.0/a * (solve(aa+1,bb-1,cc)+1);
    if(aa != 0)
      ans += aa * 1.0 /a * (solve(aa-1,bb,cc)+1);
    double temp = (a-aa-bb-cc) * 1.0 /a;
    ans += temp;
    ans = ans/(1-temp);
    nums[aa][bb][cc] = ans;
    return ans;
    
  }
  public int GCD(int a, int b) {
    if (b==0) return a;
    return GCD(b,a%b);
  }
  
  public Main  ()
  {
    try
    {
      
      in = new BufferedReader (new InputStreamReader (System.in));
       a = nextInt();
      nums = new double [a+1][a+1][a+1];
      int aa = 0;
      int bb = 0;
      int cc = 0;
      for(int x =0;x<a;x++)
      {
        int c = nextInt();
        if(c == 3)
          cc++;
        else if (c == 2)
          bb++;
        else
          aa++;
      }
      System.out.println(solve(aa,bb,cc));
    }
    
    catch(IOException e)
    {
      
    }
  }
  
  
  
  
  
  
  
  String next () throws IOException
  {
    while (as == null || !as.hasMoreTokens ())
    {
      as = new StringTokenizer (in.readLine ().trim ());
    }
    
    
    return as.nextToken ();
  }
  
  
  
  long nextLong () throws IOException
  {
    return Long.parseLong (next ());
  }
  
  
  int nextInt () throws IOException
  {
    return Integer.parseInt (next ());
  }
  
  
  double nextDouble () throws IOException
  {
    return Double.parseDouble (next ());
  }
  
  
  String nextLine () throws IOException
  {
    return in.readLine ().trim ();
  }
}

Measured memory_bytes: 305876
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;




int main(int argc, const char* argv[]){
    int N;
    cin >> N;
   
    int amari = N % 1000;
    if(amari == 0){
        cout << 0 << endl;
    } else{
        cout << 1000 - amari << endl;
    }
    
    return 0;
}





Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string dectobin(int a){
	string tmp="";
	while(a) { tmp+=(a%2)+'0'; a>>=1;}
	while(tmp.size()<5) tmp+='0';
	reverse(tmp.begin(),tmp.end());
	return tmp;
}
char strtoch(string str){
		if(str=="101") return ' ';
		else if(str=="110") return 'E';
		else if(str=="111") return 'P';
		else if(str=="0101") return 'C';
		else if(str=="0001") return 'D';
		else if(str=="0111") return 'I';
		else if(str=="0110") return 'K';
		else if(str=="1000") return 'R';
		else if(str=="00100") return 'L';
		else if(str=="00101") return 'O';
		else if(str=="00110") return 'S';
		else if(str=="00111") return 'T';
		else if(str=="01001") return 'F';
		else if(str=="000000") return '\'';
		else if(str=="000001") return '?';
		else if(str=="000010") return 'W';
		else if(str=="000011") return ',';
		else if(str=="010000") return 'H';
		else if(str=="010001") return '.';
		else if(str=="100101") return 'A';
		else if(str=="10010001") return '-';
		else if(str=="10011010") return 'B';
		else if(str=="10011011") return 'G';
		else if(str=="10011000") return 'J';
		else if(str=="10011001") return 'M';
		else if(str=="10011110") return 'N';
		else if(str=="10011111") return 'Q';
		else if(str=="10011100") return 'U';
		else if(str=="10011101") return 'V';
		else if(str=="10010010") return 'X';
		else if(str=="10010011") return 'Y';
		else if(str=="10010000") return 'Z';
		else return 'a';
}
int main() {
	string str;
	while(getline(cin,str)){
		string tmp="";
		for(int i=0;i<str.size();i++){
			char ch; ch=str[i];
			if(ch-'A'>=0 && ch-'Z'<=0) tmp+=dectobin(ch-'A');
			else if(ch==' ') tmp+="11010";
			else if(ch=='.') tmp+="11011";
			else if(ch==',') tmp+="11100";			
			else if(ch=='-') tmp+="11101";
			else if(ch=='\'') tmp+="11110";
			else if(ch=='?') tmp+="11111";
		}
		string ans="";
		for(int i=0;i<tmp.size();i++){
			for(int j=1;i+j-1<=tmp.size()-1;j++){
				char ch=strtoch(tmp.substr(i,j));
				if(ch!='a' ) {ans+=ch;i+=j-1;break;}
			}
		}
		cout << ans << '\n' ;
	}
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define REP(i, n) for (decltype(n) i = 0; i < (n); ++i)
using namespace std;
using int64 = long long;

void solve(long long N, long long M, long long Q, std::vector<long long> a,
           std::vector<long long> b, std::vector<long long> c,
           std::vector<long long> d) {
  int64 maxp = 0;
  vector<int64> seq(N, -1);
  function<void(int, int)> search = [&](int i, int val) {
    if (i == N) {
      int64 dsum = 0;
      for (int j = 0; j < Q; ++j) {
        int64 aj = a[j] - 1;
        int64 bj = b[j] - 1;
        if (seq[bj] - seq[aj] == c[j]) {
          dsum += d[j];
        }
      }
      if (maxp < dsum) {
        maxp = dsum;
      }
      return;
    }
    seq[i] = val;
    for (int j = val; j <= min<int>(10, M); ++j) {
      search(i + 1, j);
    }
  };
  search(0, 1);
  cout << maxp << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  long long Q;
  scanf("%lld", &Q);
  std::vector<long long> a(Q);
  std::vector<long long> b(Q);
  std::vector<long long> c(Q);
  std::vector<long long> d(Q);
  for (int i = 0; i < Q; i++) {
    scanf("%lld", &a[i]);
    scanf("%lld", &b[i]);
    scanf("%lld", &c[i]);
    scanf("%lld", &d[i]);
  }
  solve(N, M, Q, std::move(a), std::move(b), std::move(c), std::move(d));
}


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

int main() {
	int n;
	std::cin >> n;
	std::vector<int> vec;
	vec.push_back(0);
	for (int i = 0; i < n; ++i) {
		int temp;
		std::cin >> temp;
		vec.push_back(temp);
	}
	vec.push_back(0);
	int total_length = 0;
	std::vector<int> len_i;
	for (int i = 0; i < vec.size() - 1; ++i) {
		const int distance = std::abs(vec.at(i) - vec.at(i + 1));
		len_i.push_back(distance);
		total_length += distance;
	}
	std::vector<int> dif_i;
	for (int i = 0; i < vec.size() - 2; ++i) {
		const int sub_distance = len_i.at(i) + len_i.at(i + 1);
		const int add_distance = std::abs(vec.at(i) - vec.at(i + 2));
		dif_i.push_back(add_distance - sub_distance);
	}
	for (auto d : dif_i) {
		std::cout << total_length + d << std::endl;
	}
	return 0;
}

Measured memory_bytes: 2552
#include <stdio.h>  

int main(void) {    

int a,b,c,i;    

int count;    

scanf("%d %d %d\n", &a, &b, &c);    

for(i=a,count=0;i<=b;i++) {         

if(c%i==0)

count ++;    

}     

printf("%d\n", count);        

  return 0;

} 

Measured memory_bytes: 600
#include<stdio.h>
int main(){
  int a[6],i,j,temp;
  for(i=0;i<5;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<4;i++){
    for(j=4;j>i;j--){
      if(a[j]>a[j-1]){
	temp=a[j];
	a[j]=a[j-1];
	a[j-1]=temp;
      }
    }
  }
  for(i=0;i<4;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[4]);
  return 0;
}

Measured memory_bytes: 596
n = int(input())
a = list(map(int,input().split()))
even_list = []
for i in range(n):
    if a[i] % 2 == 0:
        even_list.append(a[i])

x = 0
for m in range(len(even_list)):
    if even_list[m] % 3 == 0 or even_list[m] % 5 == 0:
        x += 1

if  x == len(even_list):
    print('APPROVED')

else:
    print('DENIED')

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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
  int m, d;
  cin >> m >> d;
  int cnt = 0;
  for (int M = 1; M <= m; ++M) {
    for (int D = 1; D <= d; ++D) {
      int d1 = D % 10;
      int d2 = D / 10;
      if (d1 >= 2 && d2 >= 2 && d1 * d2 == M) {
        ++cnt;
      }
    }
  }
  cout << cnt << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;
bool a[100005], c[100005];
int n;
int getans(int k){
	int i;
	memset(c, 0, sizeof(c));
	for(i=2; i<=k; i++){
		c[i]=c[i]^c[i-1];
		if((a[i]^c[i])^(a[i-1]^c[i-1])){
			if(i+k-1>n)
				return false;
			c[i]=!c[i];
			c[i+k-1]=!c[i+k-1];
		}
	}
	return true;
}
int main(){
	int i, l, r, mid;
	char ch;
	
	n=0;
	ch=getchar();
	while(~ch and ch>>5){
		a[++n]=ch&1; 
		ch=getchar();
	}
	l=1;
	r=n;
	while(l<r){
		mid=(l+r+1)>>1;
		if(getans(mid))
			l=mid;
		else
			r=mid-1;
	}
	printf("%d", l);
	return 0;
} 


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

using namespace std;

int dp[100];

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

  int dp[100];
  memset(dp, 100, sizeof(dp));
  dp[0] = 0;
  for (int i = 0; i < 100; ++i) {
    for (int j = 1; j <= 5; ++j) {
      if (i + j < 100) {
        dp[i + j] = min(dp[i + j], dp[i] + 1);
      }
    }
  }
  int x;
  cin >> x;
  cout << (dp[x % 100] <= x / 100);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

signed main(){
  int N,a;cin>>N;
  vector<int> array(N);
  REP(i,0,N){
    cin>>a;
    if(i+1==a){
      array[i]=1;
    }
    else{
      array[i]=0;
    }
  }
  int ans=0;
  REP(i,0,N-1){
    if(array[i]==1){
      ans++;
      array[i+1]=0;
    }
  }
  ans+=array[N-1];
  print(ans);

}


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

int main() {
    ll n,ans=0;
    cin>>n;
    vector<ll> a(n),num(1000100),div(1000100);
    for(int i=0; i<n; i++) {
        cin>>a[i];
        num[a[i]]++;
    }
    for(int i=1; i<=1000000; i++) {
        for(int j=i; j<=1000000; j+=i) {
            div[j] += num[i];
        }
    }
    for(int i=0; i<n; i++) {
        if(div[a[i]] == 1) ans++;
    }
    cout<< ans <<"\n";
}

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

#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

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

	ll x1, s1, x2, s2, t;
	cin >> x1 >> s1 >> x2 >> s2 >> t;

	if (s1 <= s2) {
		cout << "NO\n";
	}
	else {
		ll d = s1 - s2;

		if (abs(x1 - x2) <= t * d)
			cout << "YES\n";
		else
			cout << "NO\n";
	}
	return 0;
}

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

void init() {
//#if __GLIBCXX__ == 20160609
#ifdef FIRE_MIND
    freopen("a.in", "r", stdin);
    ///freopen("a.out", "w", stdout);
#else
    ///freopen(TASKNAME".in", "r", stdin);
    ///freopen(TASKNAME".out", "w", stdout);
#endif
}

typedef long long ll;
typedef long double ld;

const double EPS = 1e-9;
const int INF = (int)1e9 + 41;
const int N = (int)1e6 + 34;

int n, x;
ll a[N];
ll l, r, l1, r1;

int main() {
    init();
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &x);
        a[i] = x;
    }

    l = 2;
    r = 2;

    for (int i = n - 1; i >= 0; i--) {
        ll y = r - r % a[i];
        ll x = (l % a[i] ? l + a[i] - l % a[i] : l);
        y = y / a[i];
        x = x / a[i];
        if (x > y) {
            cout << "-1";
            return 0;
        }

        l = x * a[i];
        r = (y + 1) * a[i] - 1;
        //cout << l << " " << r << "\n";
    }

    cout << l << " " << r << "\n";

    return 0;
}


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

using namespace std;

int main()
{
    int D,N,ans=1;
    cin>>D>>N;
    for(int i=1;i<=D;i++)
        {
            ans*=100;
        }
    if(N<100) cout<<ans*N<<endl;
    else cout<<ans*101<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define inf 1000000007;
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;
}



signed main() {
	int n, ta = 0;
	string a, b, c;
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++) {
		if (a[i] != b[i] && a[i] != c[i] && b[i] != c[i])ta += 2;
		else if (a[i] == b[i] && b[i] == c[i]) {
			ta += 0;
		}
		else ta += 1;
	}
	cout << ta << endl;
	getchar(); getchar();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll; 
using namespace std; 
int main() { 
  cin.tie(0); 
  ios::sync_with_stdio(false); 
  double a,b,c; 
  cin>>a>>b; 	
  c=(1/a)+(1/b);
  cout<<fixed<<setprecision(10)<<1/c<<endl;
  return 0;
}

Measured memory_bytes: 3788
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	int a,b,c;
	public void solve() {
		a = nextInt();
		b = nextInt();
		c = nextInt();

		if(c >= a && c <= b){
			out.println("Yes");
		}else{
			out.println("No");
		}
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

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

Measured memory_bytes: 21204
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;


int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int n;
	scanf("%d", &n);
	char c = 'C' + n / 1000;
	printf("AB%c\n", c);

}

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

typedef long long ll;

int main() {
    ll N;
    ll ans;
    ll i;
    cin >> N;

    for (i = sqrt(N); i >= 1; i--) {
        if (N % i == 0) {
            ans = N / i;  
            break;
        }
    }

    int cnt = 0;
    while (ans > 0) {
        cnt++;
        ans /= 10;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=4005;
int A,B,n;
int sta[MAXN],tp;
char ch[15],ans[MAXN];
int main()
{
	A=read();B=read();
	if(A<=B)return puts("Impossible"),0;
	n=A+B;
	for(int i=1;i<=n;i++)
	{
		if(!tp)sta[++tp]=i;
		else
		{
			printf("? %d %d\n",sta[tp]-1,i-1);fflush(stdout);
			scanf("%s",ch+1);
			if(ch[1]=='Y')sta[++tp]=i;
			else --tp;
		}
	}assert(tp);
	int id=sta[tp];
	for(int i=1;i<=n;i++)
	{
		printf("? %d %d\n",id-1,i-1);fflush(stdout);
		scanf("%s",ch+1);
		if(ch[1]=='Y')ans[i]='1';
		else ans[i]='0';
	}
	printf("! ");
	for(int i=1;i<=n;i++)putchar(ans[i]);puts("");
	return 0;
}



Measured memory_bytes: 724
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

struct S
{
	int number,result;
	bool operator>(const S& other) const {
		return result == other.result ? number < other.number : result > other.result;
	}
};

int main()
{
	int m;
	while(cin >> m, m){
		cin.ignore();
		S s[41];
		for(int i = 0; i < m; ++i){
			int number;
			vector<int> v1,v2;
			string str;
			
			getline(cin,str);
			stringstream ss(str);
			ss >> number;
			int temp;
			while(ss >> temp){
				v1.push_back(temp);
			}			
			v2 = v1;
			
			int n = 1, point = 0, knock;
			int twice = 0;
			bool f = false;
			int prev = -1;
			for(int j = 0; j < v1.size(); ++j){
				if(prev == -1){
					if(v1[j] == 10){
						if(!(n >= 10)){
							v2[j + 1] += v1[j + 1];
							v2[j + 2] += v1[j + 2];
						}
						n++;
						prev = -1;
						continue;
					}
					prev = v1[j];
				} else {
					if(v1[j] + prev ==10){
						if(!(n >= 10))v2[j + 1] += v1[j + 1];
					}
					prev = -1;
					n += 1;
				}
			}
			point = accumulate(v2.begin(),v2.end(),0);
			s[i].number = number; s[i].result = point;
		}
		sort(s,s + m, greater<S>());
		for(int i = 0; i < m; ++i){
			cout << s[i].number << ' ' << s[i].result << endl;
		}
	}
}

Measured memory_bytes: 1252
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>


using namespace std;
typedef long long ll;

#define mod 100000
#define INF 100000000 //10^8
#define LLINF 4000000000000000000
#define SIZE 100000

int n;
int P[SIZE]={0};
vector<int> D;

bool check(int k){
    int dp[SIZE*2]={0};
    
    for(int i=0;i<n;i++){
        if(P[i]>0){
            if(P[i]>=k)
                dp[i]=0;
            else
                dp[i]=INF;
        }else
            dp[i]=1;
    }
    
    //[l,r)
    int l = 0,r=n,sum=0;
    
    while(l+1<r){
        
        sort(&dp[l],&dp[l]+3);
        
        sum=dp[l]+dp[l+1];
        
        if(sum>=INF)
            dp[r] = INF;
        else
            dp[r] = sum;
        
        l+=3;
        r++;
    }
    
    int b = (int)(D.end()-lower_bound(D.begin(), D.end(),k));
    
    if(dp[l] <= b){
        return true;
    }
    
    return false;
}

int main(){
    int m,p,d;
    
    scanf("%d%d",&n,&m);
    
    for(int i=0;i<m;i++){
        scanf("%d%d",&d,&p);
        P[p-1]=d;
    }
    
    for(int i=0;i<n-m;i++){
        scanf("%d",&d);
        D.push_back(d);
    }
    
    sort(D.begin(), D.end());
    
    //[l,r]
    int l=1,r=1000000000,mid;
    
    while(l<r){
        mid = (l+r+1)/2;
        
        if(check(mid)){
            l = mid;
        }else{
            r = mid-1;
        }
    }
    
    printf("%d\n",l);
    
    return 0;
}

Measured memory_bytes: 2716
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<min(a,b)+min(c,d)<<endl;

    return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<long long> vll;

#define pb push_back
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define sz(s) (ll) s.size()
#define deb(i) cout << "Aqui " << (ld) i << "\n";



int main(){
		
	int h,w,k;
	cin >> h >> w >> k;
	char grid[h][w];
	
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cin >> grid[i][j];
		}
	}
	ll ans = 0ll;
	for(int x=0; x<(1<<h); x++){
		for(int y=0; y<(1<<w); y++){
			
			char copy[h][w];
			
			for(int i=0; i<h; i++){
				for(int j=0; j<w; j++){
					copy[i][j] = grid[i][j];
				}
			}
			
			for(int i=0; i<h; i++){
				for(int j=0; j<w; j++){
					if((x & (1<<i)) || (y & (1<<j)))
						copy[i][j] = 'r';
				}
			}
			int cnt = 0;
			for(int i=0; i<h; i++){
				for(int j=0; j<w; j++){
					if(copy[i][j]=='#')
						cnt++;
				}
			}
			if(cnt==k){
				ans++;
			}
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3680
table = [1, 1, 2, 6, 24, 120, 720, 5040]

def factorial(n):
    return table[n]

def calc_order(A, N):
    l = [i + 1 for i in range(N)]
    order = 1
    for i in range(N):
        a = A[i]
        len_l = N - i
        index = l.index(a)
        # print(a, index, factorial(len_l - 1), order)
        order += index * factorial(len_l - 1)
        del l[index]
    return order

def main():
    N = int(input())
    P = list(map(int, input().split()))
    Q = list(map(int, input().split()))
    ord_p = calc_order(P, N)
    ord_q = calc_order(Q, N)
    ans = abs(ord_p - ord_q)
    # print(ord_p, ord_q)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9204
function Main(input) {
  const args = input.trim().split("\n");
  let n = parseInt(args[0]);
  let a = args[1].split(" ").map((x) => Number(x));

  let sum = 0;
  for (let i = 0; i < n; i++) {
    sum += a[i];
  }
  console.log(Math.min(...a) + " " + Math.max(...a) + " " + sum);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {

	char a[3], b[3];
	int ok=0, i, j;

	for (i = 0; i < 3; i++)cin >> a[i];
	for (i = 0; i < 3; i++)cin >> b[i];

	for (i = 0; i < 3; i++) {
		if (a[i] == b[2 - i])ok++;
	}

	ok == 3 ? cout << "YES" : cout << "NO";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s; cin >> s;
  int ans = MOD;

  rep(i, si(s) - 2) chmin(ans, abs(stoi(s.substr(i, 3)) - 753));

  cout << ans << endl;

  return (0);
}


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

int main()
{
  double v, t, y;
  int n;
  while (cin >> v){
    t = v / 9.8;
    y = 4.9 * t * t;
    for (n = 1; y > 5 * (n - 1); n++){
    }
    cout << n << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
char a[5];
bool check(){
	for(int i=0;i<3;i++)if(a[i]==a[i+1])return 0;
	return 1;
}
int main() {
	scanf("%s",a);
	puts(check()?"Good":"Bad");
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
 
public class Main {
	public static void main(String[] args) throws IOException {
		MScanner sc = new MScanner(System.in);
		//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw=new PrintWriter(System.out);
		int a=sc.nextInt();int b=sc.nextInt();int t=sc.nextInt();
		int ans=0;
		int k=1;
		while(k*a<=t) {
			k++;ans+=b;
		}
		pw.println(ans);
		
		pw.close();
		pw.flush();
 
	}

    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 21204
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu) FUNC(printe) FUNC(printe0);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll cand1 = x % d, cand2 = x % d - d;
    ll times = (x - cand1) / d;
    if(times >= k){
        cout << x - d * k << '\n';
    }else{
        cand2 = abs(cand2);
        cout << (k - times & 1 ? cand2 : cand1) << '\n';
   }
}


Measured memory_bytes: 3160
import collections
s = input()
t = input()
s_cnt = collections.Counter(s)
t_cnt = collections.Counter(t)
a = s_cnt.most_common()
b = t_cnt.most_common()
ans = True
for i in range(len(a)):
    if a[i][1] != b[i][1]:
        ans = False
        break

print('Yes' if ans else 'No')

Measured memory_bytes: 4016
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int c[12][12],t[12][12],l;
char s[80010];

int main(){
	while(cin>>s&&((l=strlen(s))>1||s[0]!='0')){
		memset(c,0,sizeof(c));
		int e=0,o=0,a=0;
		rep(i,l){
			int x=s[i]-'0';
			rep(j,11)copy(c[j],c[j]+11,t[j]);
			rep(j,11)rep(k,11){
				if(i%2)c[j][(k+x)%11]=t[j][k];
				else c[(j+x)%11][k]=t[j][k];
			}
			if(x){
				if(i%2)c[0][x]++;
				else c[x][0]++;
			}
			rep(j,11)a+=c[j][j];
		}
		cout<<a<<endl;
	}
}

Measured memory_bytes: 936