akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b) {
	return a/gcd(a,b)*b;
}
inline ll qpow(ll a,ll b) {
	ll r=1,t=a;
	while(b) {
		if(b&1)r=(r*t)%mod;
		b>>=1;
		t=(t*t)%mod;
	}
	return r;
}
inline ll inv1(ll b) {
	return qpow(b,mod-2);
}
inline ll exgcd(ll a,ll b,ll &x,ll &y) {
	if(!b) {
		x=1;
		y=0;
		return a;
	}
	ll r=exgcd(b,a%b,y,x);
	y-=(a/b)*x;
	return r;
}
inline ll read() {
	ll x=0,f=1;
	char c=getchar();
	for(; !isdigit(c); c=getchar()) if(c=='-') f=-1;
	for(; isdigit(c); c=getchar()) x=x*10+c-'0';
	return x*f;
}
long long n, x,ans;
ll gcdgcd(ll x,ll n) {
	if(n%x==0)
		return n*2-x;
	ans=n/x*x*2+gcdgcd(n%x, x);
	return ans;
}

int main() {
	scanf("%lld%lld",&n,&x);
	cout<<gcdgcd(x, n-x)+n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int a,b,h;
  cin >> a >> b >> h;
  cout << (a+b)*h/2 << endl;

  return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N; cin >> N;
  vector<int> P(100010,0);
  rep(i,N) {
    int A; cin >> A;
    P[A]++;
  }
  ll sum = 0;
  rep(i,P.size()) {
    sum += i*P[i];
  }
  int Q; cin >> Q;
  vector<ll> S(Q);
  rep(i,Q) {
    ll B, C; cin >> B >> C;
    sum -= B*P[B];
    sum += C*P[B];
    P[C] += P[B];
    P[B] = 0;
    S[i] = sum;
  }
  for(auto s:S) cout << s << endl;
}


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

int main() {
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i += 2) {
        int total = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) total++;
        }
        if (total == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
import Control.Monad.State
main = do
  [n,a,b] <-map read.words<$>getLine
  s <- getLine 
  let res = evalState (ans (a,b) s) (0,0)
  (mapM putStrLn) res

type St = (Int,Int)

solve :: St -> Char -> State St String
solve (a,b) 'a' =
  state (\(jpn,wld) ->
  if jpn+wld < a+b
    then ("Yes",(jpn+1,wld))
    else ("No",(jpn,wld)))
solve (a,b) 'b' =
  state (\(jpn,wld) ->
  if jpn+wld < a+b && wld < b
    then ("Yes",(jpn,wld+1))
    else ("No",(jpn,wld)))
solve _ 'c' =
  state (\s -> ("No",s))


ans :: St -> [Char] -> State St [String]
ans s [] = return []
ans s (fc:sc) = 
  solve s fc >>= (\x -> ans s sc >>= (\y -> return (x:y)))


Measured memory_bytes: 7676
//SILENT KILLER
#include<bits/stdc++.h>
//typedef long long ll;
using namespace std;
int main()
{string s, ss;
    cin >> s >> ss;
    bool ans = 1;

    for(int i = 0; i < s.size(); ++i) {
        if(s[i] != ss[i])
            ans=0;


    }if(ans)
    cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;



}













Measured memory_bytes: 3620
import Foundation

func f(A: Int, B: Int, H: Int, M: Int) -> Double {
    // A: cm
    // B: cm
    // H: 時
    // M: 分
    let h: Double = ((Double(H) + (Double(M)/60)) / 12 * 360).truncatingRemainder(dividingBy: 360) * Double.pi / 180
    let m: Double = (( Double(H)*60 + Double(M)) / 60 * 360).truncatingRemainder(dividingBy: 360) * Double.pi / 180
    let c: Double = sqrt( ((pow(Decimal(A), 2) + pow(Decimal(B), 2)) as NSDecimalNumber).doubleValue - Double(2*A*B) * cos(  abs(h - m) ) )
    return c
}

let input = readLine()!.components(separatedBy: " ").map{ Int($0)! }
print( f(A: input[0], B: input[1], H: input[2], M: input[3]) )

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

N=int(input())
A=tuple(map(int,input().split()))
B=tuple(map(int,input().split()))
sum = [0]*N

for i in range(N):
    sum[A[i]-1] += 1
    sum[B[i]-1] += 1

if max(sum) > N:
    print('No')
    exit()

print('Yes')
for i in range(N):
    hit = False
    for j in range(N):
        a = A[j]
        b = B[(j + i) % N]
        if a == b:
            hit = True
            break
    if not hit:
        ans = []
        for j in range(N):
            ans.append(str(B[(j+i) % N]))
        print(" ".join(ans))
        exit()

Measured memory_bytes: 124080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int dp[200010][2];
int a[200010];
int main(){
	int n;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(i+a[i]<=n) {
		dp[i+a[i]][1]++;
	  }
	  if(i-a[i]>=1){
		ans+=dp[i-a[i]][1];
	  }
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 5936
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector as V

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    getLine
    as <- getIntList
    print $ foldl1 gcd as

Measured memory_bytes: 2940
import sys
import bisect
sys.setrecursionlimit(10**9)
INF = 2**30
N = int(input())
A = list(map(int, input().split()))
E = []
for i in range(N):
    E.append([])
for i in range(N-1):
    u, v = list(map(int, input().split()))
    u -= 1
    v -= 1
    E[u].append(v)
    E[v].append(u)

ans = [0] * N
dp = [INF] * N

def dfs(now, par, len):
    ok = bisect.bisect_left(dp, A[now])
    memo = dp[ok]
    dp[ok] = A[now]

    ok1 = bisect.bisect_left(dp, INF)
    ans[now] = ok1

    for to in E[now]:
        if to == par:
            continue
        dfs(to, now, len+1)
    dp[ok] = memo

dfs(0, -1, 0)

for i in range(N):
    print(ans[i])


Measured memory_bytes: 381636
#include<iostream>

using namespace std;
int main() {
	//int a, b;
	//std::cin >> a >> b;
	//if (a > 9 || b > 9) {
	//cout << -1 << endl;
	//	return 0;
	//}
	//cout << a * b << endl;
	//return 0;

	int a;
	cin >> a;
	for (int i = 1; i <= 9; ++i) {
		for (int j = 1; j <= 9; ++j) {
			if (i * j == a) {
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 888
import java.io.*;
import java.util.*;
public class Main{
	static int X,Y;
	static int[][] field;
	static boolean[][] done;
	static final int[] dx = {1,0,-1,0};
	static final int[] dy = {0,1,0,-1};
	static int ans;
	
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String input[] = br.readLine().split(" +");
			Y = new Integer(input[0]);
			X = new Integer(input[1]);
			if(X==0 & Y==0) break;
			
			field = new int[X][Y];
			done = new boolean[X][Y];
			for(int y = 0; y < Y; y++){
				String str = br.readLine();
				for(int x = 0; x < X; x++){
					done[x][y] = false;
					String a = str.substring(x, x+1);
					if(a.equals("#")){
						field[x][y] = 0;
					}else if(a.equals("@")){
						field[x][y] = 1;
					}else if(a.equals("*")){
						field[x][y] = 2;
					}
				}
			}
			ans = 0;
			for(int y = 0; y < Y; y++){
				for(int x = 0; x < X; x++){
					if(!done[x][y]){
						ans++;
//						dfs(x,y,field[x][y]);
						bfs(x,y,field[x][y]);
					}					
				}
			}
			System.out.println(ans);
		}
	}
	
	private static void bfs(int x, int y, int type) {
		LinkedList<xy> ll = new LinkedList<xy>();
		ll.add(new xy(x,y));
		while(!ll.isEmpty()){
			xy p = ll.poll();
			for(int i = 0; i < 4; i++){
				if(p.x+dx[i]<0 | p.x+dx[i]>=X) continue;
				if(p.y+dy[i]<0 | p.y+dy[i]>=Y) continue;
				if(done[p.x+dx[i]][p.y+dy[i]]) continue;
				if(field[p.x+dx[i]][p.y+dy[i]] != type) continue;
				done[p.x+dx[i]][p.y+dy[i]] = true;
				ll.add(new xy(p.x+dx[i], p.y+dy[i]));
			}
		}
	}

//	ＤＰＳならいつもRuntime Errorなのに、BFSに変えるとすぐACしましたのはなぜでしょう
//	private static void dfs(int x, int y, int type) {
//		done[x][y] = true;
//		for(int i = 0; i < 4; i++){
//			if(x+dx[i]<0 | x+dx[i]>=X) continue;
//			if(y+dy[i]<0 | y+dy[i]>=Y) continue;
//			if(done[x+dx[i]][y+dy[i]]) continue;
//			if(field[x+dx[i]][y+dy[i]] != type) continue;
//			dfs(x+dx[i], y+dy[i], type);
//		}
//	}
}

class xy{
	int x,y;
	xy(int x, int y){
		this.x = x;
		this.y = y;
	}
}

Measured memory_bytes: 29744
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main{ // 

	public static void main(String args[]) {
		ConsoleScanner cin = new ConsoleScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	static long now() {
		return System.currentTimeMillis();
	}

	static void trace(Object... objects) {
		assert null != System.out.format("trace:%s\n", Arrays.deepToString(objects));
	}

	private static void solve(ConsoleScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;

		String s = cin.next();

		long start = now();

		String ans = solve(s);
		cout.println(ans);

		trace("elapsed", now() - start);
	}

	private static String solve(String s) {
		int[] w = new int['z' - 'a' + 1];
		for (char c : s.toCharArray())
			w[c - 'a'] += 1;
		for (char c = 'a'; c <= 'z'; c++)
			if (w[c - 'a'] == 0)
				return String.valueOf(c);
		return "None";
	}

	static class ConsoleScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

		String next() {
			try {
				while (!st.hasMoreElements())
					st = new StringTokenizer(br.readLine());
				return st.nextToken();
			} catch (IOException e) {
				throw new AssertionError(e);
			}
		}

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

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

}


Measured memory_bytes: 23124
implicit none
integer n,k,i,len
character(10) s

read(5,*) n
read(5,*) s
read(5,*) k

len=len_trim(s)

do i=1,len

if(s(i:i) .ne. s(k:k)) then
s(i:i)="*"
endif
enddo

write(6,*) s

end

Measured memory_bytes: 256
import std.algorithm;
import std.range;
import std.stdio;
import std.math;
import std.array;
import std.string;
import std.conv;

/// 数列の読み込み
auto readNums() {
	return readln().chomp.split.map!(to!int);
}

void main() {
	bool[char] dict;
	foreach(c; 'a' .. cast(char)('z' + 1)) {
		dict[c] = false;
	}
	foreach(c; readln()) {
		dict[c] = true;
	}
	writefln("%s", sort(dict.byPair.filter!("!a[1]").array).map!(a => to!string(a[0])).chain(only("None")).takeOne.front);
}


Measured memory_bytes: 508
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;

class Node {
	private ArrayList<Node> from = new ArrayList<Node>();
	private ArrayList<Node> to = new ArrayList<Node>();
	
	public void addDestination(Node e){
		if( !to.contains(e) ) {
			to.add(e);
		}
	}
	
	public void addSource(Node e){
		if( !from.contains(e) ){
			from.add(e);
		}
	}
	
	public ArrayList<Node> getTo(){
		return to;
	}
	
	public int getFromSize(){
		return from.size();
	}
	
}

class Main
{
	ArrayList<Node> nodes = new ArrayList<Node>();
	ArrayList<Node> visited = new ArrayList<Node>();
	ArrayList<Integer> answer = new ArrayList<Integer>();
	
	private void input(){
		Scanner sc = new Scanner(System.in);
		
		int m = sc.nextInt();
		int n = sc.nextInt();
		
		
		for(int i = 0; i < m; ++i){
			nodes.add(new Node());
		}
		
		for(int i = 0; i < n; ++i){
			int from, to;
			
			from = sc.nextInt() - 1;
			to = sc.nextInt() - 1;
			
			nodes.get(from).addDestination(nodes.get(to));
			nodes.get(to).addSource(nodes.get(from));
		}
		
	}

	private void output()
	{
		for(int i : answer ) {
			System.out.println( i );
		}
	}
	
	private void solve() {
		for(Node start : nodes) {
			if( start.getFromSize() == 0 ) {
				dfs( start );
			}
		}
		
		Collections.reverse( answer );
	}

	public static void main(String [] args)
	{
		Main solver = new Main();
		solver.input();
		solver.solve();
		solver.output();
	}
	
	private void dfs(Node x) {
		if( visited.contains(x) ) return ;
		visited.add(x);
		for(Node to : x.getTo()){
			dfs( to );
		}
		answer.add(1+nodes.indexOf(x));
	}
}

Measured memory_bytes: 19224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define div 1e9+7
using ll = long long;
using P = pair<int,int>;
ll fact(int n){
	return n==0?1:n*fact(n-1);
}
int main(){
	ll n;
	cin>>n;
	int x[n],y[n];
	rep(i,n)cin>>x[i]>>y[i];
	int a[n]={};
	rep(i,n)a[i]=i;
	double sum=0;
	do{
		rep(i,n-1){
			sum+=sqrt((x[a[i]]-x[a[i+1]])*(x[a[i]]-x[a[i+1]])+(y[a[i]]-y[a[i+1]])*(y[a[i]]-y[a[i+1]]));
		}
	}while(next_permutation(a,a+n));
	sum/=fact(n);
	cout<<setprecision(20)<<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define rrep(i,n) for (int i = (n - 1);i >= 0;i--)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

const ll INF = 1LL << 60;

vi dp(100010,INF);
vi h(100100,0);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    rep(i,n) cin >> h[i];
    dp[0] = 0;
    rep(i,n){
        for(int j = 1;j <= k;j++){
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;


int main(){
  string s;
  cin >> s;
  ll number=s.size();

char borw='A',color;
ll count=-1;
for(ll i=0;i<number;i++){
  color=s.at(i);
  if(color!=borw){
    borw=s.at(i);
    count++;
  }
}

cout << count << endl;

}


Measured memory_bytes: 3728
n,m=map(int,input().split())
a=list(map(int,input().split()))
a=[a[i]-1 for i in range(n)]

imos=[0 for i in range(m+1)]
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    val=(g-s)%m
    if val>1:
        s=(s+2)%m
        if s>g:
            imos[s]+=-1
            imos[m]+=1
            imos[0]+=-1
            imos[g+1]+=1
        else:
            imos[s]+=-1
            imos[g+1]+=1
        imos[(g+1)%m]+=val-1
        imos[(g+1)%m+1]+=-(val-1)

for i in range(1,m+1):
    imos[i]+=imos[i-1]

for i in range(1,m+1):
    imos[i]+=imos[i-1]

ans=-1
val=0
for i in range(m):
    if val>=imos[i]:
        ans=i
        val=imos[i]

val=0
for i in range(0,n-1):
    s,g=a[i],a[i+1]
    if (g-s)%m>1:
        if g>=s:
            if g>=ans>s:
                val+=1+(g-ans)%m
            else:
                val+=(g-s)%m
        else:
            if ans>s or g>=ans:
                val+=1+(g-ans)%m
            else:
                val+=(g-s)%m
    else:
        val+=(g-s)%m


print(val)


Measured memory_bytes: 57452
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
int v[3];
int f[3];
int n;
int main()
{
	cin >> n;
	cin >> v[0] >> v[1] >> v[2];
	f[0] = v[0],f[1] = v[1],f[2] = v[2];
	for(int i = 2; i <= n; i++)
	{
		cin >> v[0] >> v[1] >> v[2];
		int f0 = f[0],f1 = f[1],f2 = f[2];
		f[0] = max(f1,f2) + v[0];
		f[1] = max(f0,f2) + v[1];
		f[2] = max(f0,f1) + v[2];
	}
	int res = max(f[0],max(f[1],f[2]));
	cout << res << endl;
} 


Measured memory_bytes: 256
n=int(input())
arr=[list(map(int,input().split())) for i in range(n)]
arm=[list(map(int,input().split()))for j in range(n)]
ans=-9999999999
for item in range(1,1024):
    fund=0
    for i in range(n):
        cou=0
        for x in range(10):
            if(item>>x)%2==1 and arr[i][x]==1:
                cou+=1
        fund+=arm[i][cou]
    ans=max(ans,fund)
print(ans)

Measured memory_bytes: 3188
min_val = 10 ** 9
N = int(input())
A = list(map(int, input().split()))
minus_conut = 0
sum_val = 0
for num in A:
    if num < 0:
        minus_conut += 1
    abs_val = abs(num)
    min_val = min(min_val, abs_val)
    sum_val += abs_val

if minus_conut % 2 == 0:
    print(sum_val)
else:
    print(sum_val - 2 * min_val)

Measured memory_bytes: 14284
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(void){
    double height;
    double min = 1000000;
    double max = 0;
    
    while(cin >> height){
        if(height > max) max = height;
        if(height < min) min = height;
    }

    cout << max - min << endl;
}


Measured memory_bytes: 3264
import java.util.*;

public class Main {

    static List<Integer> list;
    static int n;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int p=0, q=0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            p += x * Math.pow(10, n-i-1);
        }
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            q += x * Math.pow(10, n-i-1);
        }
        boolean[] used = new boolean[n+1];
        list = new ArrayList<>();
        dfs(0, 0, used);
        Integer[] a = list.toArray(new Integer[list.size()]);
        Arrays.sort(a);
        int pi=0, qi=0;
        for (int i = 0; i < a.length; i++) {
            if(a[i] == p) pi = i;
            if(a[i] == q) qi = i;
        }
        System.out.println(Math.abs(pi-qi));
        sc.close();

    }
    private static void dfs(int x, int d, boolean[] used) {
        if(d == n){
            list.add(x);
            return;
        }
        for (int i = 1; i <= n; i++) {
            if(used[i])continue;
            used[i] = true;
            dfs(x + i * (int)Math.pow(10, d), d+1, used);
            used[i] = false;
        }
    }

}


Measured memory_bytes: 27232
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    string str;
    cin >> N >> str;

    vector<int> is_left(2 * N);
    int stock = 0;

    bool valid = true;

    for (int i = 0; i < 2 * N; i++) {
        if (stock % 2 == 0 && str[i] == 'B') {
            is_left[i]= true;
            stock++;
            if (stock > N) valid = false;
        } else if (stock % 2 == 0 && str[i] == 'W') {
            is_left[i] = false;
            stock--;
            if (stock < 0) valid = false;
        } else if (stock % 2 == 1 && str[i] == 'B') {
            is_left[i] = false;
            stock--;
            if (stock < 0) valid = false;
        } else {
            is_left[i] = true;
            stock++;
            if (stock > N) valid = false;
        }
    }

    int l_num = 0;
    int r_num = 0;
    for (int i = 0; i < 2 * N; i++) {
        if (is_left[i]) l_num++;
        else r_num++;
    }
    if (l_num != r_num) valid = false;

    if (!valid) {
        cout << 0 << endl;
        return 0;
    }

    int ret = 1;
    int right_num = 0;
    for (int i = 2 * N - 1; i >= 0; i--) {
        if (is_left[i]) {
            ret *= right_num;
            ret %= MOD;
            right_num--;
        } else {
            right_num++;
        }
    }

    for (int i = 1; i <= N; i++) {
        ret *= i;
        ret %= MOD;
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 2180
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
using namespace std;

//ダイクストラ法のテンプレ.graphはコスト付きの隣接リスト(node,costの順にpairに格納).
vector<int> dijkstra(vector<vector<pair<int,int>>> graph, int start){
	int inf = 2001001000;
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> que;
	vector<int> dist(graph.size(),inf);
	dist[start] = 0;
	que.push(pair<int,int>(0,start));
	while(!que.empty()){
		pair<int,int> now = que.top();
		que.pop();
		int c = now.first, from = now.second;
		// if (dist[from] < c) continue;
		for (int i = 0; i < graph[from].size(); i++){
			int to = graph[from][i].first, cost = graph[from][i].second;
			if (dist[to] > dist[from] + cost){
				dist[to] = dist[from] + cost;
				que.push(pair<int,int>(dist[to],to));
			}
		}
	}
	return dist;
}

int main(){
	int v,e,r; cin >> v >> e >> r;
	vector<vector<pair<int,int>>> graph(v,vector<pair<int,int>>());
	for (int i = 0; i < e;i++){
		int a,b,c; cin >> a >> b >> c;
		graph[a].push_back(pair<int,int>(b,c));
	}
	vector<int> ans = dijkstra(graph,r);
	for (int i=0;i<ans.size();i++){
		if (ans[i] == 2001001000) cout << "INF" << endl;
		else cout << ans[i] << endl;
	}

	return 0;
}




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

namespace ABC066A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, s;

            string[] word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            // a, b, cの最大値を求める
            int m = a;
            if (b > m) m = b;
            if (c > m) m = c;

            // 最大値を除く金額の和
            s = a + b + c - m;

            Console.WriteLine(s);

            //Console.ReadKey();
        }
    }
}

Measured memory_bytes: 27180
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>
#include <map>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////

int main() {

	string S, T;
	cin >> S >> T;

	bool ans = true;
	if (S.size() != T.size() - 1)ans = false;

	rep(i, S.size()) {
		if (S[i] != T[i])ans = false;
	}


	YesNo(ans);
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
class Asf{public static long n;
          public static long score=0;
  public static void DFS(string str)
  {
    if(long.Parse(str)>n){return;}
    bool ok=true;bool []s=new bool [3];
    for(int i=1;i<str.Length;i++){if(str[i]!='3'&&str[i]!='5'&&str[i]!='7'){ok=false; break;}
                                 if(str[i]=='3'){s[0]=true;}if(str[i]=='7'){s[2]=true;}
                                  if(str[i]=='5'){s[1]=true;}
                                 }
	if(ok&&s[0]&&s[1]&&s[2]){score++;}
    for(int i=0;i<3;i++){
  DFS(str+(3+2*i).ToString());
  
    }
  return ;
  }
static void Main(){
n=long.Parse(Console.ReadLine());
DFS("0");
  Console.WriteLine(score);
}
}

Measured memory_bytes: 15184
#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>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  ll money = 1000;
  rep(i, n - 1) {
    ll stocks = 0;
    if (a[i] < a[i + 1]) stocks = money / a[i];
    money += (a[i + 1] - a[i]) * stocks;
  }
  cout << money << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define N 200050
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
using namespace std;
int k, n,ar[N],ans;
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>k>>n;
    for(int i=0;i<n;i++)
        cin>>ar[i];
    for(int i=0;i<n;i++){
        int j = i+1;
        if(j==n){
            int tmp = k - ar[i] + ar[0];
            ans = max(ans,tmp);
        }
        else ans = max(ans, ar[j]-ar[i]);
    }
    cout<<k-ans;
    
        return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n;
  cin>>n;
  int a[100000];
  rep(i,n) cin>>a[i];
  sort(a,a+n);
  int now=0;
  int cnt=1;
  int ans=0;
  now=a[0];
  repi(i,1,n){
    if(now==a[i]) cnt++;
    else{
      if(now>cnt) ans+=cnt;
      else if(now<cnt) ans+=(cnt-now);
      now=a[i];
      cnt=1;
    }
  }
  if(now>cnt) ans+=cnt;
  else if(now<cnt) ans+=(cnt-now);
  cout<<ans<<endl;
      

  return 0;
}



Measured memory_bytes: 640
a=str(input())
f=int(a[0:2])
r=int(a[2:4])
if f>=1 and f<=12:
    f1=True
else:
    f1=False

if r>=1 and r<=12:
    r1=True
else:
    r1=False

if f1==True and r1==True:
    print('AMBIGUOUS')
if f1==True and r1==False:
    print('MMYY')
if f1==False and r1==True:
    print('YYMM')
if f1==False and r1==False:
    print('NA')

Measured memory_bytes: 3064
# Beginner 50 C
N, x = map(int, input().split())
A = list(map(int, input().split()))
sum_s = sum(A)

for i in range(N-1):
    s = A[i] + A[i+1] - x
    if s > 0:
        A[i+1] = x - A[i]
        if A[i+1] >= 0:
            pass
        else:
            A[i] = A[i] + A[i+1]
            A[i+1] = 0
    else:
        pass

sum_e = sum(A)
print(sum_s - sum_e)


Measured memory_bytes: 14132
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


void solve(){
    ll n,m,x;
    cin>>n>>m>>x;
    ll a[110];
    bool b[110]={};
    rep(i,m){
        cin>>a[i];
        b[a[i]]=true;
    }
    ll sum=0;
    rep(i,x+1){
        if(b[i]) sum++;
    }
    cout<<min(sum,m-sum)<<endl;


}



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    solve();

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  int N,M; cin>>N>>M;
  int r[N+1][2]; INIT2(r,N+1,2,0);
  int p; string s;
  REP(i,M){
    cin >> p >> s;
    if(s=="AC"){
      if(r[p][0]==0){
        r[p][0]++;
      }
    }else{
      if(r[p][0]==0){
        r[p][1]++;
      }
    }
  }
  int rt = 0;
  int rw = 0;
  for(int i=1;i<=N;i++){
    rt += r[i][0];
    if(r[i][0]>0){
      rw += r[i][1];
    }
  }
  printf("%d %d\n",rt,rw);
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

int frq[57];
int main(){
	Lancer();
	ll n, m, a, b;
	cin >> n >> m;
	while (m--){
		cin >> a >> b;
		frq[a]++; frq[b]++;
	}
	for (int i = 1; i <= n; i++)
		cout << frq[i] << endl;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3676
from math import *
while True:
    try:
        x1,y1,x2,y2,xp,yp= map(float, input().split(','))
    except:
        break
    ang, x, y= (atan2(yp-y1, xp-x1)-atan2(y2-y1, x2-x1)) * -2.0, xp-x1, yp-y1
    print("{0:.6f} {1:.6f}".format(x*cos(ang)-y*sin(ang)+x1,y*cos(ang)+x*sin(ang)+y1))

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

  int a;
  string S;
  int main() {
    cin >> S;
    if (S[0] == '1') a++;
    if (S[1] == '1') a++;
    if (S[2] == '1') a++;
  
 
 cout << a << endl; 

}



Measured memory_bytes: 256
#include<iostream>
    using namespace std;
     
    int cnt_digit(long a){
    	int digit=0;
    	while(a/=10){
    		digit++;
    	}
    	digit++;
    	return digit;
    }
    int main(){
    	long n;
    	int digit;
    	cin >> n;
    	digit = cnt_digit(n);
    	for(long i=2;i*i<=n;i++){
    		if(n%i!=0)continue;
    		int a = n/i;
    		int b = max(cnt_digit(i),cnt_digit(a));
    		digit = min(digit,b);
    	}
    	cout << digit;
    	return 0;
    }

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

#define int long long

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second

using vint = vector<int>;
using pint = pair<int, int>;
using vpint = vector<pint>;

template <typename A, typename B>
inline void chmin(A& a, B b) {
    if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A& a, B b) {
    if (a < b) a = b;
}

template <class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>& p) {
    ost << "{" << p.first << "," << p.second << "}";
    return ost;
}

template <class T>
ostream& operator<<(ostream& ost, const vector<T>& v) {
    ost << "{";
    for (int i = 0; i < v.size(); i++) {
        if (i) ost << ",";
        ost << v[i];
    }
    ost << "}";
    return ost;
}

inline int topbit(unsigned long long x) {
    return x ? 63 - __builtin_clzll(x) : -1;
}

inline int popcount(unsigned long long x) {
    return __builtin_popcountll(x);
}

inline int parity(unsigned long long x) {
    return __builtin_parity(x);
}
const int INF = 1001001001;
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, -1, 0, 1};

signed main() {
    int H, W;
    cin >> H >> W;

    int sy, sx, gy, gx;
    cin >> sy >> sx >> gy >> gx;
    sy--;
    sx--;
    gy--;
    gx--;

    vector<string> fld(H);
    rep(i, H) cin >> fld[i];

    vector<vint> dist(H, vint(W, INF));
    dist[sy][sx] = 0;
    deque<tuple<int, int, int> > que;
    que.eb(sy, sx, 0);
    while (que.size()) {
        int y, x, c;
        tie(y, x, c) = que.front();
        que.pop_front();
        if (dist[y][x] < c) continue;
        rep(d, 4) {
            int ny = y + dy[d];
            int nx = x + dx[d];
            if (ny < 0 || ny >= H || nx < 0 || nx >= W || fld[ny][nx] == '#') continue;
            int nc = c;
            if (dist[ny][nx] <= nc) continue;
            dist[ny][nx] = nc;
            que.emplace_front(ny, nx, nc);
        }

        for (int dy = -2; dy <= 2; dy++) {
            for (int dx = -2; dx <= 2; dx++) {
                int ny = y + dy;
                int nx = x + dx;
                if (ny < 0 || ny >= H || nx < 0 || nx >= W || fld[ny][nx] == '#') continue;
                int nc = c + 1;
                if (dist[ny][nx] <= nc) continue;
                dist[ny][nx] = nc;
                que.emplace_back(ny, nx, nc);
            }
        }
    }

    if (dist[gy][gx] == INF)
        cout << -1 << endl;
    else
        cout << dist[gy][gx] << endl;
    return 0;
}

Measured memory_bytes: 13524
#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;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
	COMinit();
	int S;
	cin >> S;
	ll ans = 0;
	for (int i = 1; i <= S/3; ++i)
	{
		ll temp = S - 3 * i;
		ans = (ans + COM(temp+i-1,temp)) % MOD;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define mk make_pair

typedef long long LL;
typedef pair<int,int> Interval;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){
    os << v.first <<" "<<v.second<<endl;
    return os;
}

const int maxn = 1e5+5;
vector<LL> res;
vector<LL> A;
vector<LL> B;

LL sum[maxn];
LL need = 0;
int N;

int main()
{
    cin >> N;
    _for(i,0,N){
        LL a;cin >> a;
        A.pb(a);
    }
    int smaller = 0;

    _for(i,0,N){
        LL b; cin >> b;
        if(A[i] - b > 0) res.pb(A[i]-b);
        else if(A[i] - b < 0){
            need += b - A[i];
            smaller++;
        }
    }
    sort(ALL(res),greater<LL>());
    _rep(i,1,res.size()){
        sum[i] = sum[i-1];
        sum[i] += res[i-1];
    }
    int ans = -1;

    //cout << need << endl;

    _rep(i,0,res.size()){
        if(need <= sum[i]){
            ans = smaller + i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


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

vector<pair<Int, Int>> primeFactors(Int n) {
    vector<pair<Int, Int>> result;
    Int factor = 0;
    Int factorCount = 0;
    Int q = n;
    if (n >= 2) {
        for (Int i = 2; i * i <= n;) {
            if (q % i == 0) {
                if (i != factor) {
                    factor = i;
                    factorCount = 1;
                } else {
                    factorCount++;
                }
                q /= i;
            } else {
                if (factor > 0) {
                    result.push_back(make_pair(factor, factorCount));
                    factor = 0;
                }
                i++;
            }
        }
    }
    if (q > 1) {
        result.push_back(make_pair(q, 1));
    }

    return result;
}

int main() {
    Int n, p;
    cin >> n >> p;
    auto factors = primeFactors(p);
    Int ans = 1;
    for (auto &factor : factors) {
        rep(i, factor.second / n) ans *= factor.first;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x <<": "<<x<<"\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
//using template <class T>vec = vector<T>;
template <class T> using Vec = std::vector<T>;
template <class T = int> T in(){T x; cin>>x;return(x);}
template <class T > void print(T& x){cout<<x<<"\n";}
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N=in(),D=in();
  cout <<ceil(N*1.0/(2*D+1))<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                long n = sc.nextLong();
                long a = sc.nextLong();
                long b = sc.nextLong();
                sc.close();
                long c = n / (a + b);
                long s = c * a;
                long d = n % (a + b);
        if(d > a){
                s = s + a;
        }else{
                s = s + d;
        }
        System.out.println(s);
        }
}
//鶏になれ

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

using namespace std;
const int MAX=3000;
int slen,tlen,dp[MAX+2][MAX+2];
string s,t;
vector<char> v;

int solve(int sp,int tp){
if(sp==slen ||tp==tlen) return 0;
if(dp[sp][tp]!=-1) return dp[sp][tp];
int ans = INT_MIN;
ans=max(ans,solve(sp,tp+1));
ans=max(ans,solve(sp+1,tp));
if(s[sp]==t[tp]) ans=max(ans,solve(sp+1,tp+1)+1);
return dp[sp][tp]=ans;
}

int main()
{
    cin>>s>>t;
    slen=s.length();
    tlen=t.length();
    memset(dp,-1,sizeof dp);
    solve(0,0);
    int x=0,y=0;
    while(x!=slen&&y!=tlen){
        int ans=INT_MIN,hold=0;
        if(solve(x,y+1)>ans){
            hold = 1;
            ans=solve(x,y+1);
        }
        if(solve(x+1,y)>ans){
            hold = 2;
            ans=solve(x+1,y);
        }
        if(s[x]==t[y] && solve(x+1,y+1)+1>ans){
            hold = 3;
        }
        if(hold==1) y++;
        if(hold==2) x++;
        if(hold==3){
            v.push_back(s[x]);
            x++;
            y++;
        }
    }
    for(int i=0;i<v.size();i++) cout<<v[i];
    return 0;
}


Measured memory_bytes: 35840
#include <stdio.h>

int main(void){

	int n = 0 ;			//?????????????´???°???????´???????
	int i = 0 ;			//for????????????????????????????????°

	scanf("%d" ,&n);
	int num[n];			//n??????????´??????????int????????????

	/*??°??????????????????*/
	for(i = 0 ; i < n ; i++){
		scanf("%d", &num[i]);
	}

	/*???????????????*/
	for(i = n-1 ; i > -1 ; i--){
		printf("%d",num[i]);

		if(i){				//num[0]????????????????????????????????????
			printf(" ");
		}

	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
   string s,t;
   cin>>s>>t;
   int ans=100000;
   for(int i=0;i<=s.size()-t.size();i++){
       string a=s.substr(i,t.size());
       int cnt=0;
       for(int i=0;i<t.size();i++){
         if(a[i]!=t[i])
         cnt++;
       }
     ans=min(ans,cnt);
   }
   cout<<ans<<endl;

    return 0;
}

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

int main(){
  string s; cin >> s;
  rep(i, 8){
    int c = s[0]-'0';
    string ans;
    ans.push_back(s[0]);
    rep(j,3){
      if((i>>j)&1){
        ans.push_back('+');
        ans.push_back(s[j+1]);
        c += s[j+1]-'0';
      }else{
        ans.push_back('-');
        ans.push_back(s[j+1]);
        c -= s[j+1]-'0';
      }
    }
    if(c==7){
      cout << ans << "=7" << endl;
      return 0;
    }
  }
  return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long A, long long P){
    cout << ((A*3+P)/2) << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long P;
    scanf("%lld",&P);
    solve(A, P);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define PI acos(-1)

using namespace std;

struct Mato
{
	int x;
	int y;

	Mato (int x = 0,int y = 0) : x(x), y(y) {}
	bool operator < (const Mato& a) const {
		return x == a.x ? y < a.y : x < a.x;
	}
	
};

int main()
{
	int n,m;
	while(cin >> n && n)
	{
		vector<Mato> temp;
		int dp[1000];
		memset(dp,0,sizeof(dp));

		rep(i,n)
		{
			int h,r;
			cin >> h >> r;
			temp.push_back(Mato(h,r));
		}

		cin >> m;

		rep(i,m)
		{
			int h,r;
			cin >> h >> r;
			temp.push_back(Mato(h,r));
		}

		sort(temp.begin(),temp.end());
		
		int ans = 0;

		rep(i,temp.size())
		{
			dp[i] = 1;

			rep(j,i)
			{
				if(temp[j].x < temp[i].x && temp[j].y < temp[i].y)
				{
					dp[i] = max(dp[i],dp[j]+1);
				}
			}
			ans = max(ans,dp[i]);
		}

		cout <<ans << endl;

	}
	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  int n; cin >> n;
  int d[n]; rep(i,n) cin >> d[i];
  
  int ans = 0;
  rep(i,n)rep(j,n){
    if(i==j) continue;
    ans += d[i]*d[j];
  }
  
  cout << ans/2 << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            Set<String> prize = new HashSet<>();
            for (int i = 0; i < n; i++) {
                prize.add(in.next());
            }

            // 出力
            out.println(prize.size());

        }

    }
}



Measured memory_bytes: 77112
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



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

  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ans = 0;
  sort(a.begin(), a.end());
  rep(i, n) {
    if (x - a[i] < 0) break;
    ans++;
    x -= a[i];
  }
  if (ans == n && x > 0) ans--;
  cout << ans << '\n';




  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1000000007;
const int N = 3003;

// dp[i][j] := p[i]まで決定p[i]にはj番目に小さい値
ll dp[N][N];

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

    dp[0][0] = 1;
    for(int i=1; i<n; ++i){
        if(s[i-1] == '<'){
            ll t = 0;
            rep(j,i+1){
                dp[i][j] = t;
                (t += dp[i-1][j]) %= mod;
            }
        }
        else{
            ll t = 0;
            for(int j=i; j>=0; --j){
                dp[i][j] = t;
                if(j>0) (t += dp[i-1][j-1]) %= mod;
            }
        }
    }

    ll ans = 0;
    rep(i,N) (ans += dp[n-1][i]) %= mod;
    cout << ans << endl;
    return 0;
}


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

class Program
{
    static void Main(string[] args)
    {

        string a = Console.ReadLine();

        if (a == "ABC")
        {
            Console.WriteLine("ARC");
        }
        else
        {
            Console.WriteLine("ABC");
        }


    }
}

Measured memory_bytes: 25780