akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
long long MOD = 1000000007;


template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


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

    if(S[S.length()-1] == 's')cout << S << "es" << endl;
    else cout << S << 's' << endl; 

}



Measured memory_bytes: 3624
N = int(input())
D = list(map(int,input().split()))
M = int(input())
T = list(map(int,input().split()))
flag = 1
DiD = {}
DiT = {}
for i in range(len(D)) :
    if D[i] not in DiD :
        DiD[D[i]] = 1
    else :
        DiD[D[i]] += 1
for i in range(len(T)) :
    if T[i] not in DiT :
        DiT[T[i]] = 1
    else :
        DiT[T[i]] += 1
        

for i in DiT :
    if (i not in DiD) or (DiT[i] > DiD[i]) :
        flag = 0
if flag == 1:
    print("YES")
else :
    print("NO")
    

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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REP1(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
const int MOD = (int)1e9 + 7;
const int INF = 1145141919;
using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;
using d_d = pair<double, double>;
using vint = vector<int>;
using vbool = vector<bool>;

int main() {
    int a, b;
    cin >> a >> b;
    int ans = a + b;
    ans = max(ans, a - b);
    ans = max(ans, a * b);
    cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <random>
#include <functional>
#include <ctime>
using std::cout;
using std::endl;
using std::cin;

class dice{
public:
	explicit dice(int in[6]){
		for(int i=0;i<6;i++){
			v[i]=in[i];
		}
	}
	void mov(const char c){
		int buf;
		switch(c){
			case 'N':{
				buf = v[0];
				v[0] = v[1];
				v[1] = v[5];
				v[5] = v[4];
				v[4] = buf;
				break;
			}
			case 'E':{
				buf = v[0];
				v[0] = v[3];
				v[3] = v[5];
				v[5] = v[2];
				v[2] = buf;
				break;
			}
			case 'W':{
				buf = v[0];
				v[0] = v[2];
				v[2] = v[5];
				v[5] = v[3];
				v[3] = buf;
				break;
			}
			case 'S':{
				buf = v[0];
				v[0] = v[4];
				v[4] = v[5];
				v[5] = v[1];
				v[1] = buf;
				break;
			}
		}
	}
	int top(){
		return v[0];
	}
	int operator[](size_t i){return v[i];}
private:
	int v[6];
};

int p_r(dice d,int up,int front){
	auto rgen = std::bind(std::uniform_int_distribution<>(0,3),std::mt19937(time(NULL)));
	char dir[]={'N','E','W','S'};
	while(up!=d[0]||front!=d[1]){
		d.mov(dir[rgen()]);
	}
	return d[2];
}

int main(){
	int in[6],n,p_u,p_f;
	for(int i=0;i<6;i++){
		cin >> in[i];
	}
	dice d(in);
	cin >> n;
	while(n--){
		cin >> p_u;
		cin >> p_f;
		cout << p_r(d,p_u,p_f) << endl;
	}
}

Measured memory_bytes: 1168
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

int main(){
	string s;
	while(cin>>s,s != "0"){
		int a = 0,b = 0;
		for(int i = 1; i < sz(s); i++){
			if(s[i]=='A') a++; else b++;
		}
		if(a>b) a++; else b++;
		printf("%d %d\n",a,b);
	}
	return 0;
}

Measured memory_bytes: 1188
#include<iostream>
using namespace std;
int main(){
    long long n, a, min, max, sum;
    cin >> n;
    cin >> a;
    min = a;
    max = a;
    sum = a;
    for(int i = 0; i < n-1; i++){
        cin >> a;
        sum += a;
        if(a < min){
            min = a;
        }
        if(a > max){
            max = a;
        }
    }
    cout << min << " " << max << " " << sum << endl;
    
    return 0;
    
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9+7;
//const ll mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int ninf = 0xc0c0c0c0; 
int main(){
	//freopen("in.txt","r",stdin);
	int n;
	int a[200005]={0};
	cin>>n;
	int t;
	for(int i=0;i<n-1;i++){
		cin>>t;
		a[t]++;
	}
	for(int i=1;i<=n;i++){
		cout<<a[i]<<endl;
	}
	return 0;
}

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

int main()
{
	int N,A,B;
	cin >> N >> A >> B;
	int ans = 0;
	for (int i = 1; i <= N; ++i)
	{
		int temp = i;
		int now = 0;
		while(temp > 0)
		{
			now += temp % 10;
			temp /= 10;
		}
		if (now >= A && now <= B)
		{
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <map>
#include <vector>
using namespace std;
long long N;
long long K;
long long nums[200000 + 5];
vector<long long> vec;
map<long long, long long> mp;
int main() {
    ios::sync_with_stdio(0);
    cin >> N >> K;
    for (long long i = 1; i <= N; ++i) {
        cin >> nums[i];
    }
    mp.clear();
    mp[1] = 1;
    long long cur = 1, j = 1, i;
    vec.push_back(1);
    while (1) {
        long long next = nums[cur];
        ++j;
        if (mp[next] != 0) {
            i = mp[next];
            break;
        }
        else {
            mp[next] = j;
            cur = next;
            vec.push_back(cur);
        }
    }
    long long t = j - i;
    if (K <= i - 1) {
        cout << vec[K] << endl;
    }
    else {
        long long temp = (K + 1) - (i - 1);
        long long ii = (temp - 1) % t + 1;
        cout << vec[i - 1 + ii - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 18576
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

int main() {
	int X, Y, Z;
	cin >> X >> Y >> Z;
	cout << Z << ' ' << X << ' ' << Y << endl;
}

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

int main() {
	int n;
	cin>>n;
	int mon[n+1];
	for(int i=0;i<n+1;i++){
	    cin>>mon[i];
	}
	int her[n];
	for(int i=0;i<n;i++){
	    cin>>her[i];
	}
	long long ans=0;
	int k;
	for(int i=0;i<n;i++){
	       k=min(her[i],mon[i]);
	       ans+=k;
	       her[i]-=k;
	       mon[i]-=k;
	       k=min(her[i],mon[i+1]);
	       ans+=k;
	       her[i]-=k;
	       mon[i+1]-=k;
	    
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	cout.tie(NULL);
  	long long int n , i , x , y , z;
    cin >> n;
    long long int a[n];
    for(i = 0 ; i < n ; i++){
        cin >> a[i];
    }
    x = 0;
    y = abs(a[1] - a[0]);
    for(i = 2 ; i < n ; i++){
        z = min(abs(a[i] - a[i - 2]) + x , abs(a[i] - a[i - 1]) + y);
        x = y;
        y = z;
    }
    cout << y ;
    return 0;
}

Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <tuple>
#include <climits>
#include <unordered_map>

using namespace std;

long long MOD = 998244353;
long long f[200001];
long long P(long long a, long long b) {
    long long ans = 1;
    while (b) {
        if (b & 1) ans = ans * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ans;
}
long long inv(long long a) {
    return P(a, MOD - 2);
}
long long C(long long n, long long m) {
    return f[n] * inv(f[m] * f[n-m] % MOD) % MOD;
}
int main() {
    long long N, M, K;
    cin>>N>>M>>K;
    f[0] = 1;
    for (int i=1; i<=N; i++) f[i] = f[i-1] * i % MOD;
    long long ans = 0;
    for (int i=0; i<=K; i++) {
        ans = (ans + M * P(M-1, N - i - 1) % MOD * C(N - 1, i) % MOD) % MOD;
    }
    cout<<ans<<endl;
}


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

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();

		if (A == 1) {
			A = 14;
		}
		if (B == 1) {
			B = 14;
		}

		if (A > B) {
			System.out.println("Alice");
		} else if (A < B) {
			System.out.println("Bob");
		} else {
			System.out.println("Draw");
		}
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}
}


Measured memory_bytes: 9808
#include<bits/stdc++.h>
using namespace std;
long long p[100001];
int main()
{
    long long ans=0,n,a,b;
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)
     cin>>p[i];
    for(int i=2;i<=n;i++)
     ans+=min((p[i]-p[i-1])*a,b);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
def comb(n,k):
    res = 1
    for i in range(1,k+1):
        res *= (n+1-i)
        res //= i
    return res


n,p = map(int, input().split())
a = list(map(int, input().split()))
a = [ai % 2 for ai in a]
odd, even = a.count(1), a.count(0)

ans = 0
for i in range(p,odd+1,2):
    ans += comb(odd, i) * pow(2, even)
print(ans)

Measured memory_bytes: 9140
#include <stdio.h> 
 
 
 int main(){ 
     char number[1001]; 
     int i, sum; 
     while(1){ 
         scanf("%s", number); 
         if(number[0]=='0')break; 
         sum=0; 
         for(i=0;number[i]!='\0';i++){ 
             sum+=number[i]-'0'; 
         } 
         printf("%d\n", sum); 
     } 
 
 
     return 0; 
 } 



Measured memory_bytes: 2100
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import GHC.ST
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
-- templete

subs = ["", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"]

split10000 n = sub n
  where
    sub 0 = []
    sub x = case divMod x 10000 of (q,r) -> r : sub q

f s 0 = ""
f s n = show n ++ s


main = map (concat . reverse . zipWith f subs . split10000 . apply2 (^)) . takeWhile (any (/=0)) . map (map readInteger . words) . lines <$> getContents >>= mapM_ putStrLn
    


Measured memory_bytes: 4336
#include<iostream>

using namespace std;

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

	int r[n]; cin >> r[0];
	int minv = r[0];
	int maxpro = -1000000001;
	for(int i=1;i<n;i++){
		cin >> r[i];
		maxpro = max(maxpro,r[i]-minv);
		minv = min(minv,r[i]);
	}

	cout << maxpro << endl;
	return 0;
}

Measured memory_bytes: 1940
a=[list(map(int,input().split()))for i in range(3)]
s,t,u=((a[0][0]-a[1][0])**2+(a[0][1]-a[1][1])**2)**0.5,((a[2][0]-a[1][0])**2+(a[2][1]-a[1][1])**2)**0.5,((a[0][0]-a[2][0])**2+(a[0][1]-a[2][1])**2)**0.5
p=(s+t+u)/2
q=(p*(p-s)*(p-t)*(p-u))**0.5
r=2*q/(s+t+u)
g=max(s,t,u)
print(g/(2+g/r))

Measured memory_bytes: 3188
import java.util.Scanner

object Main {
  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val b = sc.nextLine()
    val r = b match {
      case "A" => "T"
      case "T" => "A"
      case "C" => "G"
      case "G" => "C"
    }

    println(s"$r")
  }
}


Measured memory_bytes: 25796
S = list(input())
K = int(input())
N = len(S)

C0 = []
cnt = 1
for i in range(1,N):
    if S[i]==S[i-1]:
        cnt+=1
        if i==N-1:
            C0.append(cnt)
    else:
        C0.append(cnt)
        cnt = 1
out0 = 0
for m in C0:
    out0 += m//2

if S[0]!=S[-1]:
    out = out0*K
elif N==1:
    out = K//2
elif len(C0)==1:
    X = C0[0]*K
    out = X//2
else:
    X = (C0[0] + C0[-1])//2
    Y = C0[0]//2 + C0[-1]//2
    out = (out0-Y)*K
    out += X*(K-1)
    out += Y
print(out)

Measured memory_bytes: 38740
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){

  string s, t;
  cin >> s;
  cin >> t;
  int cnt = 0;
  if(s[0] == t[0]) ++cnt;

  if(s[1] == t[1]) ++cnt;

  if(s[2] == t[2]) ++cnt;

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
int n,x,s,a;
int main() {
//	freopen("1.txt","r",stdin);
	read(n); read(a);
	for (int i=1;i<=n;i++) {
		read(x); s+=x;
		if (s>a) { printf("%d\n",i); return 0; }
	}
	printf("%d\n",n+1);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm> 

using namespace std;

int main(void){
  int A[4];
  cin >> A[0] >> A[1] >> A[2] >> A[3];
  sort(A, A+4);

  if(A[0] == A[1] && A[2] == A[3]){
    cout << "yes\n";
  }else{
    cout << "no\n";
  }

  return 0;
}

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

bool dp[1005][1005][1005];

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

    int a,b;
    cin >> a >> b;
    int c = a+b;
    int d = a-b;
    int e = a*b;
    cout << max(max(c,d),e) << endl;
}


Measured memory_bytes: 256
A,B,C,D = map(int,input().split())

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

CD = C * D // gcd(C,D) 

tgC = max(B//C - (A-1)//C, 0)
tgD = max(B//D - (A-1)//D, 0)
tgCD = max(B//CD - (A-1)//CD, 0)

print((B-A+1)-(tgC+tgD-tgCD))

Measured memory_bytes: 3064
import re
import numpy as np

N, Q = [int(item) for item in re.split(r"\s", input())]
S = input()

l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = [int(item) for item in re.split(r"\s", input())]

# ACの場所を探す
p_list = [0] * (N + 1)
i = 0
while i < N - 1:
    if S[i:i + 2] == "AC":
        p_list[i + 1] = 1
        i += 2
    else:
        i += 1


cumsum = np.cumsum(p_list)

out_list = []
for q in range(Q):
    # qに答える
    l_i = l[q] - 1
    r_i = r[q] - 1

    if l_i >= 0:
        c_l = cumsum[l_i]
    else:
        c_l = 0
    c_r = cumsum[r_i]
    out_list.append(str(c_r - c_l))

print("\n".join(out_list))


Measured memory_bytes: 30460
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a =[0]+list(map(int, input().split()))
    b = list(accumulate(a))
    c = sum(a)
    res = 10000000000000000
    for i in range(1, n):
        s = b[i]
        t = c-s
        res = min(res, abs(s-t))
    print(res)


if __name__ == '__main__':
    main()

Measured memory_bytes: 27652
#include <iostream>
#include <cmath>
#include <functional>
#include <map>


constexpr int64_t const max = 1000000000 + 7;

std::int64_t fact(std::int64_t v) {
    std::int64_t result = 1;
    for (std::int64_t i = 1; i <= v; ++i) {
        result = result * i % max;
    }
    return result;
}

int main() {
    std::int64_t n, m;
    std::cin >> n >> m;

    if (std::abs(n - m) > 1) {
        std::cout << "0" << std::endl;
        return 0;
    }

    std::int64_t r = 1;
    if (n == m) r = 2;

    std::int64_t result = (fact(n) * fact(m) * r) % max;
    std::cout << result << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cctype>
#define il inline
#define vd void
#define rg register
#define rep(i,x,y) for(rg int i=x;i<=y;++i)
#define drp(i,x,y) for(rg int i=x;i>=y;--i)
using namespace std;
const int Len=2333333;
char buf[Len],*p1=buf,*p2=buf,duf[Len],*q1=duf;
il char gc(); il int rd(); il vd pc(char c); il vd rt(int x); il vd flush();
int n;
int main(){
	n=rd();
	rep(i,1,9) rep(j,1,9) if(i*j==n) return puts("Yes"),0;
	puts("No");
	return flush(),0;
}

il char gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,Len,stdin),p1==p2)?-1:*p1++;}
il int rd(){char c;
	while(!isdigit(c=gc())&&c!='-');
	int f=c=='-'?c=gc(),1:0,x=c^48;
	while(isdigit(c=gc())) x=((x+(x<<2))<<1)+(c^48);
	return f?-x:x;
}
il vd pc(char c){q1==duf+Len&&fwrite(q1=duf,1,Len,stdout),*q1++=c;}
il vd rt(int x){x<0?pc('-'),x=-x:0,pc((x>=10?rt(x/10),x%10:x)+48);}
il vd flush(){fwrite(duf,1,q1-duf,stdout);}

Measured memory_bytes: 2304
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

int N, K;
vector<int> can_use(10, true);

void input(void) {
	cin >> N >> K;
	for (int i = 0; i < K; ++i) {
		int di; cin >> di;
		can_use[di] = false;
	}
}

int res = (1 << 30);

void dfs(int now, int d) {
	if (now >= N) {
		res = min(now, res);
		return;
	}
	if (d >= 6) return;
	for (int i = 0; i < 10; ++i)
		if (can_use[i])
			dfs(now * 10 + i, d + 1);
}

void solve(void) {
	dfs(0, 0);
}

int main(void) {
	input(); solve();
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		long inf = 1000000007;
		Scanner in = new Scanner(System.in);
		int h = in.nextInt();
		int w = in.nextInt();
		int k = in.nextInt();
		if(w==1) {
			System.out.println(1);
		}else {
			int[] fib = new int[w];
			fib[0] = 1;
			fib[1] = 2;
			for(int i=2;i<w;i++) {
				fib[i] = fib[i-1] + fib[i-2];
			}
			int[][] puttern = new int[w][3];
			puttern[0][0] = 0;
			puttern[0][1] = fib[w-2];
			puttern[0][2] = w-3>=0?fib[w-3]:1;
			for(int i=1;i<w-1;i++) {
				puttern[i][0] = (i-2>=0?fib[i-2]:1) * (w-i-2>=0?fib[w-i-2]:1);
				puttern[i][1] = (i-1>=0?fib[i-1]:1) * (w-i-2>=0?fib[w-i-2]:1);
				puttern[i][2] = (i-1>=0?fib[i-1]:1) * (w-i-3>=0?fib[w-i-3]:1);
			}
			puttern[w-1][0] = w-3>=0?fib[w-3]:0;
			puttern[w-1][1] = fib[w-2];
			puttern[w-1][2] = 0;
			
			long[][] dp = new long[h+1][w];
			dp[0][0] = 1;
			for(int i=0;i<h;i++) {
				dp[i+1][0] = (dp[i][0]*puttern[0][1]%inf + dp[i][1]*puttern[0][2]%inf)%inf;
				for(int j=1;j<w-1;j++) {
					dp[i+1][j] = (dp[i][j-1]*puttern[j][0]%inf + dp[i][j]*puttern[j][1]%inf + dp[i][j+1]*puttern[j][2]%inf)%inf;
				}
				dp[i+1][w-1] = (dp[i][w-2]*puttern[w-1][0]%inf + dp[i][w-1]*puttern[w-1][1]%inf)%inf;
			}
			System.out.println(dp[h][k-1]);
		}
		
		
		
	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define ll long long
#define mod (ll)1000000007
using namespace std;
ll dp[102][5][2];
int n;
vector<int> a;

ll rec(int pos, int remk, int f){
    if(pos == n){
        if(remk == 0)
            return 1;
        return 0;
    }

    if(dp[pos][remk][f]!=-1)    return dp[pos][remk][f];

    ll ans = 0;

    int LMT;
    if(f == 0)
        LMT = a[pos];
    else
        LMT = 9;

    for(int d = 0; d <= LMT; d++){
        int nf = f;
        if(f == 0 && d < LMT) nf = 1;
        if(d && remk>0){
            ans = ans + rec(pos+1, remk-1, nf);
        }
        if(d == 0){
            ans = ans + rec(pos+1, remk, nf);
        }
    }

    dp[pos][remk][f] = ans;

    return ans;
}
void solve(string s, int k){
    n = s.size();

    for(int i = 0; i < n; i++){
        a.push_back(s[i]-'0');
    }
    ll ans = 0;
    for(int i = 0; i <= 9; i++){
        if(i <= a[0]){
            if(i)
                ans = ans + rec(1, k-1, (i!=a[0]));
            else
                ans = ans + rec(1, k, (i!=a[0]));
        }
    }

    cout<<ans<<"\n";
}
int main()
{
    string s;
    int k;
    memset(dp,-1,sizeof(dp));
    cin>>s>>k;
    solve(s, k);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
typedef long long ll;
typedef long double ld;

 
int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    ll ans = a[0];
    int cnt = 1;
    int idx = 1;
    while(1) {
        if (cnt == n-1) break;
        ans += a[idx];
        ++cnt;
        if (cnt&1) ++idx;
        //cout << cnt << " " << idx << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4672
#  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_2_A&lang=jp
#   Parallel/Orthogonal : python3
#  2018.12.15 yonezawa

#from collections import deque
import sys
input = sys.stdin.readline
#import cProfile
from math import cos,sin,radians,sqrt

def main():

    for i in range(int(input())):
        (x1,y1,x2,y2,x3,y3,x4,y4) = map(int,input().split())

        inner = (x2-x1) * (x4-x3) + (y2-y1) * (y4-y3)
        cross = (x2-x1) * (y4-y3) - (x4-x3) * (y2-y1)               
        if inner == 0:
            print("1")
        elif cross == 0:
            print ("2")
        else:
            print("0")

    
if __name__ == '__main__':
    main()
    #pr = cProfile.Profile()
    #pr.runcall(main)
    #pr.print_stats()


Measured memory_bytes: 5784
#include <iostream>
#include <vector>
using namespace std;
typedef unsigned long long LL;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	vector<LL> A(N);
	int i;
	int env=0;
	for (i=0;i<N;i++){
		cin>>A[i];
		if (A[i]%2==0){
			env++;
		}else{
			A[i]=0;
		}
	}
	if (env==0){
		cout<<0<<endl;
		return 0;
	}
	int ans=0;
	while (true){
		env=0;
		for (i=0;i<N;i++){
			if (A[i]==0){
				continue;
			}
			env=1;
			while (A[i]%2==0){
				A[i]/=2;
				ans++;
			}
			A[i]=0;
			break;
		}
		if (env==0){
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

const int x[] = {
	1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

int main() {
	int k;
	
	ios_base::sync_with_stdio(0), cin.tie(0), cin >> k, cout << x[k-1];
	
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};


vector<PI> V[30];
bool vis[1<<8][30];
int ti[30];

main(){
  int n,m,p,a,b;
  ios::sync_with_stdio(false);
  while(cin>>n>>m>>p>>a>>b,n){
    --a,--b;
    rep(i,n)cin>>ti[i];
    rep(i,m)V[i].clear();

    rep(i,p){
      int x,y,z;
      cin>>x>>y>>z;
      --x,--y;
      V[x].pb(mp(y,z));
      V[y].pb(mp(x,z));
    }

    priority_queue<pair<float,PI>,vector<pair<float,PI> > ,greater<pair<float,PI> > > Q;
    Q.push(mp(0,mp(a,0)));
    memset(vis,0,sizeof(vis));
    float ans=-1;

    while(!Q.empty()){
      int v=Q.top().S.F,cst=Q.top().S.S;
      float cc=Q.top().F;
      Q.pop();
      if(vis[cst][v])continue;
      vis[cst][v]=true;
      if(v==b){
        ans=cc;
        break;
      }

      rep(i,n){
        if(cst>>i&1)continue;
        rep(j,SZ(V[v])){
          int nv=V[v][j].first;
          int tc=V[v][j].second;
          int nst=cst|(1<<i);
          if(vis[nst][nv])continue;
          float nc=cc+1.0f*tc/ti[i];
          Q.push(mp(nc,mp(nv,nst)));
        }
      }
    }
    if(ans<0)puts("Impossible");
    else printf("%f\n",ans);
  }
}

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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll n;
  cin >> n;
  vll p(n);
  rep(i, n) cin >> p[i];

  vll a(n);
  rep(i, n) {
    a[p[i] - 1] = i;
  }

  ll l = 0;
  ll r = 1;

  ll mx = 0;

  while (r < n) {
    if (a[r - 1] < a[r]) {
      r++;
    } else {
      chmax(mx, r - l);
      l = r;
      r++;
    }
  }
  chmax(mx, r - l);

  cout << n - mx << endl;

  return 0;
}


Measured memory_bytes: 6352
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskG solver = new TaskG();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskG {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int l = in.nextInt();
            String s = in.nextString();
            String t = in.nextString();

            if (s.compareTo(t) > 0) {
                String tmp = s;
                s = t;
                t = tmp;
            }

            if (t.startsWith(s) && (s + t).compareTo(t + s) > 0) {
                if (check(out, l, t, s)) return;
                if (check(out, l, s, t)) return;
            } else {
                if (check(out, l, s, t)) return;
            }

            throw new RuntimeException();
        }

        private boolean check(PrintWriter out, int l, String s, String t) {
            int sLen = s.length();
            int tLen = t.length();
            for (int i = 0; i * tLen <= l; i++) {
                if ((l - i * tLen) % sLen == 0) {
                    StringBuilder sb = new StringBuilder();
                    for (int j = 0; j < (l - i * tLen) / sLen; j++) {
                        sb.append(s);
                    }
                    for (int j = 0; j < i; j++) {
                        sb.append(t);
                    }
                    out.println(sb.toString());
                    return true;
                }
            }
            return false;
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

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

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 30144
#include<stdio.h>
#define N 100

int main(){
    int n, i, j, ex, ans = 0, flag = 1, A[N];
    
    scanf("%d",&n);
    for(i=0 ; i<n ; i++){
        scanf("%d",&A[i]);
    }
    
    while(flag){
        flag = 0;
        for(j=n-1 ; j>0 ; j--){
            if(A[j] < A[j-1]){
                ex = A[j];
                A[j] = A[j-1];
                A[j-1] = ex;
                flag = 1;
                ans++;
            }
        }
    }
    for(i=0 ; i<n ;i++){
        if(i != 0)printf(" ");
        printf("%d",A[i]);
    }
    printf("\n%d\n",ans);
    return 0;
}



Measured memory_bytes: 2128
import java.io.*
import java.util.*
import kotlin.math.*

fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))

	var (n,x,m) = f.readLine().split(" ").map{it.toLong()}

	val values = mutableListOf<Long>()
	values.add(x)

	val hmap = HashMap<Long,Int>()
	hmap.put(x,0)
	var start = -1

	while(true){
		val add = (values[values.size-1]*values[values.size-1])%m
		//println(add)
		if(hmap.containsKey(add)){
			start = hmap.get(add)!!
			break
		}
		hmap.put(add,values.size)
		values.add(add)
	}

	if(n <= values.size){
		var answer = 0L
		for(k in 0 until n.toInt()){
			answer += values[k]
		}
		println(answer)
	} else {

		var answer = 0L
		for(k in 0 until start){
			answer += values[k]
		}

		//println(answer)

		var sum = 0L

		for(k in start until values.size){
			sum += values[k]
		}

		//println(sum)
		n-=start
		answer += sum*(n/(values.size-start))

		var remain : Long = 0L
		for(k in 0 until ((n%(values.size-start)))){
			remain += values[start+k.toInt()]
		}

		//println(remain)

		answer += remain
		println(answer)

	}
}


Measured memory_bytes: 46564
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
  read(x), read(y...);
}
const int N=2e5+10;
int n,p,L,S;
int head[N];
struct Edge {
  int to,last;
  Edge () {}
  Edge (int a,int b) :to(a),last(b) {}
}edge[N<<1];
void ADD(int a,int b) {
  edge[++p]=Edge(b,head[a]); head[a]=p;
  edge[++p]=Edge(a,head[b]); head[b]=p;
}
void DFS(int u,int f,int dis) {
  if(dis>L) L=dis,S=u;
  for(int i=head[u];i;i=edge[i].last) {
    int v=edge[i].to;
    if(v!=f) DFS(v,u,dis+1);
  }
}
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n);
  for(int i=1;i<n;++i) {
    int u,v; read(u,v);
    ADD(u,v);
  }
  DFS(1,0,1); DFS(S,0,1);
  int t=L%3;
  if(t==2) puts("Second");
  else puts("First"); 
  return 0;
}


Measured memory_bytes: 13568
class Integer
  def nCr(k, m = MOD)
    u = d = 1
    n = self
    (1..k).each{|i|
      u = u * n % m
      d = d * i % m
      n -= 1
    }
    u * d.pow(m - 2, m) % m
  end

  def nHr(r, m = MOD)
    (self + r - 1).nCr(r, m)
  end
end

MOD = 10**9+7
S = gets.to_i

max = S / 3
ans = 0
(1..max).each{|i|
  rest = S - i * 3
  i.nHr(rest)
  ans += i.nHr(rest)
}
p ans % MOD

Measured memory_bytes: 14376
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
//#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

int bit(int64_t num, int n) {
	return (num >> n) & 1;
}

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

	int N;
	int64_t K, A[100000];
	cin >> N >> K;
	REP(i, N)
		cin >> A[i];

	int64_t dp[41][2];
	for (int d = 40; d >= 0; d--) {
		REP(i, 2)
			dp[d][i] = -1e18;
	}
	dp[40][0] = 0;
	for (int i = 39; i >= 0; i--) {
		int64_t D = 1LL << i;
		int num1 = 0;
		REP(d, N) 
			if (bit(A[d], i))num1++;

		int num0 = N - num1;
		if (bit(K, i)) {
			dp[i][0] = max(dp[i][0], dp[i + 1][0] + D * num0);
			dp[i][1] = max(dp[i][1], dp[i + 1][0] + D * num1);
		}
		else
			dp[i][0] = max(dp[i][0], dp[i + 1][0] + D * num1);
		
		dp[i][1] = max(dp[i][1], dp[i + 1][1] + D * max(num0, num1));
		
	}
	int64_t ans = max(dp[0][0], dp[0][1]);
	cout << ans << endl;
	return 0;
}



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

int main(){
 	int a,b;
	cin >> a >> b;
	if(a == 2 || b == 2) {
		cout << "No" << endl;
		return 0;
	}
	if(a == 4 || a == 6 || a == 9 || a == 11){
		if(b == 4 || b == 6 || b == 9 || b == 11) {
	  		cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
		return 0;
	}	
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
while True:
   try:
      a,b,c,d,e,f = map(float, input().split())
      x = (c*e - b*f) / (a*e - b*d)
      y = (a*f - c*d) / (a*e - b*d)
      if x == -0:
         x = int(x)
      if y == -0:
         y = int(y)
      X = Decimal(x).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP)
      Y = Decimal(y).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP)
      print(f'{X:.3f} {Y:.3f}')
   except EOFError:
      break


Measured memory_bytes: 6408
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <complex>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i:a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	string s; getline(cin, s);
	bool flag = true;
	if (s == "1 0 0" || s == "0 1 0" || s == "0 0 0")flag = false;
	puts(flag ? "Open" : "Close");
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

void print(ll x){
    cout << x << ".00000000000000" << endl;
}

int main(){
    int N;
    cin >> N;
    ll x[N];
    rep(i, N) cin >> x[i];
    ll d[N-1];
    rep(i, N-1) d[i] = x[i+1]-x[i];
    int M; ll K;
    cin >> M >> K;
    int dp[60][N-1];
    rep(i, N-1) dp[0][i] = i;
    rep(i, M){
        int a;
        cin >> a;
        swap(dp[0][a-2], dp[0][a-1]);
    }
    rep2(i, 1, 59){
        rep(j, N-1) dp[i][j] = dp[i-1][dp[i-1][j]];
    }
    ll ans = x[0];
    print(ans);
    rep(i, N-1){
        int now = i;
        rep(j, 60){
            if(K&(1LL<<j)) now = dp[j][now];
        }
        print(ans += d[now]);
    }
}

Measured memory_bytes: 27776
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;
    static CF_Reader in;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        in = new CF_Reader();

        int a = in.intNext(), b = in.intNext();
        StringBuilder res = new StringBuilder();
        if (a > b) for (int i = 0; i < a; i++) res.append(b);
        else for(int i = 0; i < b; i++) res.append(a);
        out.println(res);

        out.close();
    }

    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long longNext() throws IOException {
            return Long.parseLong(next());
        }

        int intNext() throws IOException {
            return Integer.parseInt(next());
        }

        double doubleNext() throws IOException {
            return Double.parseDouble(next());
        }

        char charNext() throws IOException {
            return next().charAt(0);
        }

        public int[] nextIntArray(final int n) throws IOException {
            final int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = intNext();
            return a;
        }

        public long[] nextLongArray(final int n) throws IOException {
            final long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = longNext();
            return a;
        }

        String line() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 20308
#include<bits/stdc++.h>
using namespace std;
void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1,
    x=-x;
  }
  while(x){
    f[s++]=x%10,
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int D, N, arr[101];
int main(){
  int Lj4PdHRW, res;
  rd(N);
  for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
    rd(D);
    arr[D]=1;
  }
  {
    int KL2GvlyY, Q5VJL1cS;
    if(101==0){
      Q5VJL1cS = 0;
    }
    else{
      Q5VJL1cS = arr[0];
      for(KL2GvlyY=1;KL2GvlyY<101;KL2GvlyY++){
        Q5VJL1cS += arr[KL2GvlyY];
      }
    }
    res =Q5VJL1cS;
  }
  wt_L(res);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20171023-1 [beta]

// --- original code ---
// int N, D, arr[101];
// {
//   int res;
//   
//   rd(N);
//   rep(N){
//     rd(D);
//     arr[D]=1;
//   }
//   res = sum(arr(101));
//   wt(res);
// }


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

void dfs(int pos, int apos, int bpos, int cpos);

int N, A, B, C;
int banboo[10];
int al[10], bl[10], cl[10];
int res = INF;

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

    cin >> N >> A >> B >> C;
    for(int i = 0; i < N; ++i) {
        cin >> banboo[i];
    }

    dfs(0, 0, 0, 0);
    cout << res << endl;

    return 0;
}

void dfs(int pos, int apos, int bpos, int cpos) {
    if(pos == N) {
        if(apos == 0 || bpos == 0 || cpos == 0) return;
        int asum = 0, bsum = 0, csum = 0;
        for(int i = 0; i < apos; ++i) {
            asum += al[i];
        }
        for(int i = 0; i < bpos; ++i) {
            bsum += bl[i];
        }
        for(int i = 0; i < cpos; ++i) {
            csum += cl[i];
        }

        int cost = (apos + bpos + cpos - 3) * 10;
        res = min(res, cost + abs(asum - A) + abs(bsum - B) + abs(csum - C));

        return;
    }

    al[apos] = banboo[pos]; dfs(pos + 1, apos + 1, bpos, cpos);
    bl[bpos] = banboo[pos]; dfs(pos + 1, apos, bpos + 1, cpos);
    cl[cpos] = banboo[pos]; dfs(pos + 1, apos, bpos, cpos + 1);
    dfs(pos + 1, apos, bpos, cpos);

    return;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7




n,q=map(int,input().split())
G=[[] for i in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    a-=1;b-=1
    G[a].append(b)
    G[b].append(a)
data=[0]*n
for i in range(q):
    p,x=map(int,input().split())
    data[p-1]+=x
visited=[0]*n
visited[0]=1
stack=[0]

while stack:
    node=stack.pop()
    for v in G[node]:
        if not visited[v]:
            visited[v]=1
            data[v]+=data[node]
            stack.append(v)


print(*data)

Measured memory_bytes: 94720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define per(i,a,b) for(ll i=b-1;i>=a;i--)
const ll maxn=4e3+5;
ll cnt[3],a[maxn],ans,n;
string s;
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>n>>s;
    rep(i,0,n) a[i]=s[i]=='R'?0:s[i]=='G'?1:2;
    rep(i,0,n) {
        rep(j,i+1,n) if(a[i]!=a[j]) {
            ans+=cnt[3-a[i]-a[j]];
            if(0<=2*i-j && a[2*i-j]+a[i]+a[j]==3) ans--;
        }
        cnt[a[i]]++;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define se second
#define fi first
ll binsearch(ll x, vector<ll> v)
{
  ll l = 0, r = v.size() - 1, mid, ans = 0;
  while (l <= r)
  {
    mid = (l + r) / 2;
    if (v[mid] < x)
      l = mid + 1, ans = mid;
    else if (v[mid] > x)
      r = mid - 1;
    else
      return mid;
  }
  return ans;
}
int main()
{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ll  n;
  cin >> n;
  if (n % 1000 == 0)
  {
    cout << "0" << endl;
  }
  else
    cout << 1000 - n % 1000 << endl;


}

Measured memory_bytes: 3620