akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string.h>
#define MAX_LINE 8
using namespace std;
void searchString(string box);
int main() {
    int count = 0;
    char str[8];
    string box;
    while(cin >> str){
        box.append(str);
        count++;
        if(count%MAX_LINE == 0){
            searchString(box);
            box = "";
        }
    }
}
void searchString(string box){
    string A("1100000011");
    string B("1000000010000000100000001");
    string C("1111");
    string D("1000000110000001");
    string E("11000000011");
    string F("100000001100000001");
    string G("110000011");
    if (box.find(A) != string::npos) {
        cout << "A" << endl;
    }
    else if(box.find(B) != string::npos) {
        cout << "B" << endl;
    }
    else if(box.find(C) != string::npos) {
        cout << "C" << endl;
    }
    else if(box.find(D) != string::npos) {
        cout << "D" << endl;
    }
    else if(box.find(E) != string::npos) {
        cout << "E" << endl;
    }
    else if(box.find(F) != string::npos) {
        cout << "F" << endl;
    }
    else if(box.find(G) != string::npos) {
        cout << "G" << endl;
    }
}




Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int n,W;
    cin>>n>>W;
    int v[n],wt[n];
    for(int i=0;i<n;i++){
        cin>>wt[i]>>v[i];
    }
    long dp[n+1][W+1]={0};
    for(int i=0;i<=n;i++){
        for(int w=0;w<=W;w++){
            if(i==0||w==0)
                dp[i][w]=0;
            else if(wt[i-1]<=w){
                dp[i][w]=max(dp[i-1][w],dp[i-1][w-wt[i-1]]+v[i-1]);
            }
            else dp[i][w]=dp[i-1][w];
        }
    }
    cout<<dp[n][W];
}

Measured memory_bytes: 79104
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<28)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int dp[1024][256];
int dist[2][256][256];
int N,M,R;
int z[1024];

void wf(){
  rep(k,N) rep(i,N) rep(j,N){
    rep(l,2){
      if(i==j) dist[l][i][j] = 0;
      dist[l][i][j] = min(dist[l][i][j], dist[l][i][k] + dist[l][k][j]);
    }
  }
}

void solve(){
  wf();
  rep(i,1024) rep(j,256) dp[i][j] = INF;
  rep(i,N) dp[0][i] = dist[0][z[0]][i] + dist[1][i][z[0]];
  for(int i=1;i<R;i++){
    rep(j,N) rep(k,N){
      if(j==k) dp[i][j] = min(dp[i][j], dp[i-1][j] + dist[0][z[i-1]][z[i]]);
      else dp[i][k] = min(dp[i][k], dp[i-1][j] + dist[0][z[i-1]][j] + dist[1][j][k] + dist[0][k][z[i]]);
    }
  }
  int res = INF;
  rep(i, N) res = min(res, dp[R-1][i]);
  printf("%d\n", res);
}

int main(){
  while(scanf("%d%d",&N,&M) && N||M){
    rep(k,2) rep(i,256) rep(j,256) dist[k][i][j] = INF;
    rep(i,M){
      int x,y,t; char sl;
      scanf("%d%d%d %c", &x,&y,&t,&sl); x--; y--;
      if(dist[sl=='S'][x][y] > t) dist[sl=='S'][x][y] = t;
      if(dist[sl=='S'][y][x] > t) dist[sl=='S'][y][x] = t;
    }

    scanf("%d", &R);
    rep(i,R){ scanf("%d",z+i); z[i]--; }
    solve();
  }
  return 0;
}

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    bool ac[N+1] = {};
    int wa_cnt[N+1] = {};
    int ans = 0;
    rep(i, M){
        int p; cin >> p;
        string S; cin >> S;
        if(!ac[p]){
            if(S == "WA"){
                wa_cnt[p]++;
            }
            else{
                ac[p] = true;
                ans += wa_cnt[p];
            }
        }
    }
    int num_solve = 0;
    rep(i, N+1) num_solve += ac[i];
    cout << num_solve << " " << ans << endl;
    return 0;
}

Measured memory_bytes: 4084
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

ans = []
tmp = 0
for i in range(n):
    tmp += a[i]
    tmp1 = 0
    for j in range(i,n):
        tmp1 += b[j]
    ans.append(tmp+tmp1)

print(max(ans))


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

int main() {
  int N;
  int A[8], B[8];
  int NUM[8];
  double sum = 0;
  cin >> N;
  rep(i, N) {
    cin >> A[i] >> B[i];
  }
  rep(i, N) NUM[i] = i;
  do {
    rep(i, N-1) {
      sum += sqrt(pow(A[NUM[i+1]]-A[NUM[i]], 2)
                + pow(B[NUM[i+1]]-B[NUM[i]], 2));
    }
  } while(next_permutation(NUM, NUM+N));
  rep(i, N) sum /= (i+1);
  cout << fixed << setprecision(10) << sum << endl;
  return 0;
}


Measured memory_bytes: 3820
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;

const int N = 105;
int n, f[N][10], p[N][11], res = INT_MIN;

void solve() {
    cin >> n;
	for(int i=0; i<n; i++)
		for(int j=0; j<10; j++)
			cin >> f[i][j];
	for(int i=0; i<n; i++)
		for(int j=0; j<=10; j++)
			cin >> p[i][j];
	for(int i=1; i< 1<<10; i++) {
		int a=0;
		for (int j=0; j<n; j++) {
			int b=0;
			for (int k=0; k<10; k++)
				b += bool(i & 1<<k) && f[j][k];
			a += p[j][b];
		}
		res = max(res, a);
	}
	cout<<res<<endl;
}
 
int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
x, k, d = gets.split.map(&:to_i)
dist = 0
if x.abs >= k * d
  dist = x.abs - k * d
else
  t = (x.abs / d.to_f).ceil # 座標が0以下到達する移動回数
  if (k - t).even?
    dist = x.abs - t * d
  else
    dist = x.abs - (t-1) * d
  end
end

puts dist.abs

Measured memory_bytes: 14304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
//ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////
int inf=(int)1E7;
#define MAX_V 1000000//調節！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
//辺を表す構造体{行き先、容量、逆辺}
struct edge{int to,cap,rev;};
vector<edge> G[MAX_V];
bool used[MAX_V];//dfsですでに調べたかのフラグ
//fromからtoへの流量capの辺をグラフに追加
void add_edge(int from,int to,int cap){
    G[from].push_back((edge){to,cap,static_cast<int>(G[to].size())});
    G[to].push_back((edge){from,0,static_cast<int>(G[from].size()-1)});
}
//増加パスをdfsで探す
int dfs(int v,int t,int f){
    if(v==t)return f;
    used[v]=true;
    for(int i=0;i<G[v].size();i++){
        edge &e=G[v][i];
        if(!used[e.to]&&e.cap>0){
            int d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
int max_flow(int s,int t){
    int flow=0;
    while(1){
        memset(used,0,sizeof(used));
        int f=dfs(s,t,inf);
        if(f==0)return flow;
        flow+=f;
    }
}
/////////////////////////////////////////////
int main(){
    int v,e;cin>>v>>e;
    while(e--){
        ll a,b,c;cin>>a>>b>>c;
        add_edge(a,b,c);
    }
    cout<<max_flow(0,v-1)<<endl;
    
    return 0;
}


Measured memory_bytes: 27608
#include<bits/stdc++.h>
using namespace std;
int a[55],b[55],c[55],d[55],n,m,i,j,num,s,mins=0x7fffffff;
int main(){
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
	for(i=1;i<=m;i++) scanf("%d%d",&c[i],&d[i]);
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			s=abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(s<mins) mins=s,num=j;
		}
		printf("%d\n",num);
		mins=0x7fffffff;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		
		
        
        int [] b = new int[N];
		int[][] d = new int[N][N];
		int[][] e = new int[N][N];
		for(int i = 0; i < N; i++){
            b[i] = sc.nextInt();
          
            for(int j = 0; j < b[i]; j++){
                d[i][j] = sc.nextInt();
                d[i][j] --;
             
                e[i][j] = sc.nextInt();
              
            }
        }
        int [] c = new int[N];
        int f = 0;
        int g = 0;
        boolean h = false;
		for(int i = 0; i < (int)Math.pow(2, N ); i++){
              int l = 1;
			for(int j = 0; j < N; j++){
                c[j] = (i / l) % 2;
              l = l * 2;
            }
            h = true;
            for(int j = 0; j < N && h; j++){
                for(int k = 0; k < b[j] && h; k++){
                    if(c[j] == 1 && e[j][k] != c[d[j][k]] ){
                        h = false;
                      
                    }
                }
            }
            if(h){
              
                for(int j = 0; j < N; j++){
                    f += c[j];
                }
                if(f > g){
                    g = f;
                  
                }
                f = 0;
            }
            
		}
      
		System.out.println(g);
		
		
	}
}


Measured memory_bytes: 37720
import java.util.Scanner;
public class Main{
    public static void main(String[]args){
        Scanner scan = new Scanner(System.in);
        int[][] arr = new int[3][3];
        int tmp,n;
        boolean flag;
        flag=false;
        for(int r=0;r<3;r++){
            for(int c=0;c<3;c++){
                arr[r][c]=scan.nextInt();
            }
        }
        n=scan.nextInt();
        for(int i=0;i<n;i++){
            tmp=scan.nextInt();
            for(int r=0;r<3;r++){
                for(int c=0;c<3;c++){
                    if(arr[r][c]==tmp) arr[r][c]=-1;
                }
            }
        }
        for(int r=0;r<3;r++){
            if(arr[r][0]==arr[r][1]&&arr[r][1]==arr[r][2]&&arr[r][2]==-1){
                flag=true;
            }
            if(arr[0][r]==arr[1][r]&&arr[1][r]==arr[2][r]&&arr[2][r]==-1){
                flag=true;
            }
        }
        if(arr[0][0]==arr[1][1]&&arr[1][1]==arr[2][2]&&arr[2][2]==-1){
            flag=true;
        }
        if(arr[2][0]==arr[1][1]&&arr[1][1]==arr[0][2]&&arr[0][2]==-1){
            flag=true;
        }
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 22996
#include <cstdio>
const int N = 10 + 10;
const int M = 50 + 10;
int a[M], b[M], c[M], d[M], n, m, q, f[N], sum, ans;
void dfs(int i, int pre)
{
	if (i > n)
	{
		sum = 0;
		for (int j = 1; j <= q; j++)
			if (f[b[j]] - f[a[j]] == c[j]) sum += d[j];
		if (ans < sum) ans = sum;
		return ;
	}
	for (int j = pre; j <= m; j++)
	{
		f[i] = j;
		dfs(i + 1, j);
	}
	return ;
}
int main()
{
	scanf("%d%d%d", &n, &m, &q);
	for (int i = 1; i <= q; i++)
		scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
	dfs(1, 1);
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 3124
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        long X = scanLong();
        long ans = 100;
        long count = 0;
        while (X > ans) {
            count++;
            ans = (long)(ans + ans * 0.01);
        }
        out.print(count);
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

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

#define endl '\n'

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  
  int a, b;
  cin >> a >> b;
  
  int x = a * b;
  int y = (2 * a) + (2 * b);
  
  cout << x << ' ' << y << endl;
  
  return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>

using namespace std;

int main() {
    string str;
    int a;scanf("%d", &a);
    int b = a / 100;
    a %= 100;
    if (a > 0 && a < 13 && b > 0 && b < 13) {
        printf("AMBIGUOUS\n");
    } else if (a > 0 && a < 13) {
        printf("YYMM\n");
    } else if (b > 0 && b < 13) {
        printf("MMYY\n");
    } else {
        printf("NA\n");
    }
    return 0;
}

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

using namespace std;

int main() {
    int D, G;

    cin >> D >> G;
    vector<vector<int>> a(D, vector<int>(2));

    for (int i = 0; i < D; i++) {
        cin >> a[i][0] >> a[i][1];
    }

    int ans = 1000000;
    for (int bit = 0; bit < (1<<D); bit++) {
        int score = 0;
        int ct = 0;

        for (int i = 0; i < D; i++) {
            if ((bit & (1<<i)) != 0) {
                score += a[i][0] * (100 * (i + 1)) + a[i][1];
                ct += a[i][0];
            }
        }

        if (G > score) {
            for (int i = D-1; i >= 0; i--) {
                if (!(bit & (1<<i))) {
                    for (int j = 0; j < a[i][0]; j++) {
                        if (score >= G)
                            break;
                        score += 100 * (i + 1);
                        ct++;
                    }
                }
            }
        }

        if (score >= G)
            ans = min(ans, ct);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int64_t> v = {2, 1};
  if(N == 0){
    cout << 2 << endl;
  }
  if(N == 1){
    cout << 1 << endl;
  }
    else{
      for(int i = 0; i < N-1; i++){
		int64_t a = v.at(i) + v.at(i + 1);
        v.push_back(a);
      }
      cout << (int64_t)v.at(N);
    }
}

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

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

int main(){
	int w;
	while( cin >> w, w!=-1 ){
		int v = 1150;
		if( w > 30 ){ v+=160*(w-30); w=30; }
		if( w > 20 ){ v+=140*(w-20); w=20; }
		if( w > 10 ){ v+=125*(w-10); }
		cout << (4280-v) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
<?php
// Your code here!
fscanf(STDIN, "%d%d", $n, $k);
$a = array_map("intval", explode(" ", trim(fgets(STDIN))));
$c = 1;
$sum = 0;
foreach($a as $b){
    $sum+=$b;
    if($sum>$k)break;
    $c++;
}
echo $c;

Measured memory_bytes: 4604
#ifndef ___CLASS_MODINT
#define ___CLASS_MODINT

#include <cstdint>

template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::uint64_t n_) : n(n_ % mod) {};
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	std::uint32_t get() const { return n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint binpow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
	modint inv() { return (*this).binpow(mod - 2); }
};

#endif // ___CLASS_MODINT

#include <vector>
#include <iostream>
using namespace std;
using modulo = modint<1000000007>;
int N, M, K; bool vis[2009][2009]; modulo dp[2009][2009];
modulo solve(int a, int b) {
	if (a + b == K) return modulo(1);
	if (vis[a][b]) return dp[a][b];
	modulo ans = 1;
	for (int i = 0; i <= K - 1; ++i) {
		int na = a - i, nb = b - (K - i - 1);
		if (na >= 1 && nb >= 1) ans += solve(na, nb);
	}
	vis[a][b] = true;
	dp[a][b] = ans;
	return ans;
}
int main() {
	cin >> N >> M >> K;
	modulo ans = solve(N, M);
	cout << ans.get() << endl;
	return 0;
}

Measured memory_bytes: 20224
// https://beta.atcoder.jp/contests/abc103/tasks/abc103_b

#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
	string S;
	string T;

	cin >> S;
	cin >> T;

	bool flag = false;
	if (S==T){
		flag = true;
	}
	for(int i = 0;i<S.size();i++){
		string temp = S.back() + S.substr(0,S.size()-1);
		// cout << temp << endl;
		if(temp == T){
			flag = true;
			break;
		}
		S = temp;
	}

	if (flag==true){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
int main(void){
    int Thp,Tat,Ahp,Aat;

    scanf("%d%d%d%d",&Thp,&Tat,&Ahp,&Aat);
    while((Thp>0)&&(Ahp>0)){
        Ahp=Ahp-Tat;
        if(Ahp>0)
            Thp-=Aat;
    }
    if(Ahp<=0)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 1624
#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++)

int main(){
    long long N;
    cin >> N;
    long long i = 1;
    long long tmp;
    while(i*i <= N){
        if(N%i == 0) tmp = i;
        i++;
    }
    cout << tmp + N/tmp -2;
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;
public class Main{
    static ArrayList<Integer>[] list;
    static int[] parent;
    static int[] c;
    
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader(); 
        int N, Q; {int[] a = r.ii(); N = a[0]; Q = a[1];}
        c = new int[N+1];        
        parent = new int[N+1];
        list = new ArrayList[N+1];
        for(int i = 1; i <= N; i++)
            list[i] = new ArrayList<>();
            
        for(int i = 0; i < N-1; i++){
            int[] tmp = r.ii();
            int a = tmp[0];
            int b = tmp[1];
            list[a].add(b);
            list[b].add(a);
        }
        
        for(int i = 0; i < Q; i++){
            int[] tmp = r.ii();
            int p = tmp[0];
            int x = tmp[1];
            c[p] += x;
        }
        
        deleteRoot(1);

        StringBuilder sb = new StringBuilder();
        solve(1);
        for(int i = 1; i <= N; i++)
            sb.append(c[i]).append(" ");
        println(sb);
    }
    static void deleteRoot(int root){
        ArrayList<Integer> al = list[root];
        for(int i : al){            
            parent[i] = root;
            list[i].remove(new Integer(root));      
            deleteRoot(i);
        }
    }
    static void solve(int root){
        for(int i : list[root])
            c[i] += c[parent[i]];
        for(int i : list[root])
            solve(i);        
    }
    static void print(Object o){
        System.out.print(o.toString());
    }
    static void println(Object o){
        System.out.println(o.toString());
    }
    static int Int(String s){
        return Integer.parseInt(s);
    }
    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return s().split(" ");
        }
        int i() throws IOException{
            return Int(s());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Integer.parseInt(ss[j]);
            return ii;
        }
        long l() throws IOException{
            return Long(s());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 154748
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a * b > c * d)
    cout << a * b << endl;
  else
    cout << c * d << endl;
}


Measured memory_bytes: 256
from fractions import gcd
from functools import reduce
def l(a,b):return a*b//gcd(a,b)
def L(N):return reduce(l,N)
n,m=map(int,input().split())
A=list(map(lambda x:int(x)//2,input().split()))
a=A[0]
c=0
while(a%2==0):
  a//=2
  c+=1
if any([(a%(2**c)==0 and a//(2**c))%2==0 for a in A]):
  print(0)
  exit()
a=L(A)
print((m+a)//(2*a))


Measured memory_bytes: 90080
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    vector<int> commonDivisor;
    for(int i = 1; i <= min(a, b); i++){
        if(a % i == 0 && b % i == 0){
            commonDivisor.push_back(i);
            //cout << i << endl;
        }
    }
    
    int ans = commonDivisor[commonDivisor.size() - 1 - (c - 1)];
    cout << ans << endl;
    return 0;
}

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

#define debug(...) fprintf(stderr, __VA_ARGS__)

#ifndef AT_HOME
#define getchar() IO::myGetchar()
#define putchar(x) IO::myPutchar(x)
#endif

namespace IO {
	static const int IN_BUF = 1 << 23, OUT_BUF = 1 << 23;

	inline char myGetchar() {
		static char buf[IN_BUF], *ps = buf, *pt = buf;
		if (ps == pt) {
			ps = buf, pt = buf + fread(buf, 1, IN_BUF, stdin);
		}
		return ps == pt ? EOF : *ps++;
	}

	template<typename T>
	inline bool read(T &x) {
		bool op = 0;
		char ch = getchar();
		x = 0;
		for (; !isdigit(ch) && ch != EOF; ch = getchar()) {
			op ^= (ch == '-');
		}
		if (ch == EOF) {
			return false;
		}
		for (; isdigit(ch); ch = getchar()) {
			x = x * 10 + (ch ^ '0');
		}
		if (op) {
			x = -x;
		}
		return true;
	}

	inline int readStr(char *s) {
		int n = 0;
		char ch = getchar();
		for (; isspace(ch) && ch != EOF; ch = getchar())
			;
		for (; !isspace(ch) && ch != EOF; ch = getchar()) {
			s[n++] = ch;
		}
		s[n] = '\0';
		return n;
	}

	inline void myPutchar(char x) {
		static char pbuf[OUT_BUF], *pp = pbuf;
		struct _flusher {
			~_flusher() {
				fwrite(pbuf, 1, pp - pbuf, stdout);
			}
		};
		static _flusher outputFlusher;
		if (pp == pbuf + OUT_BUF) {
			fwrite(pbuf, 1, OUT_BUF, stdout);
			pp = pbuf;
		}
		*pp++ = x;
	}

	template<typename T>
	inline void print_(T x) {
		if (x == 0) {
			putchar('0');
			return;
		}
		static int num[40];
		if (x < 0) {
			putchar('-');
			x = -x;
		}
		for (*num = 0; x; x /= 10) {
			num[++*num] = x % 10;
		}
		while (*num){
			putchar(num[*num] ^ '0');
			--*num;
		}
	}

	template<typename T>
	inline void print(T x, char ch = '\n') {
		print_(x);
		putchar(ch);
	}

	inline void printStr_(const char *s, int n = -1) {
		if (n == -1) {
			n = strlen(s);
		}
		for (int i = 0; i < n; ++i) {
			putchar(s[i]);
		}
	}

	inline void printStr(const char *s, int n = -1, char ch = '\n') {
		printStr_(s, n);
		putchar(ch);
	}
}
using namespace IO;

const int N = 500005, P = 1000000007;

int n, a[N], f[N];
int sum[N];
std::vector<int> p[1 << 20];

int solve(int x) {
	if (a[n] && a[n] != x) {
		return 0;
	}
	if (x == 0) {
		int ans = 1;
		for (int i = 1; i < (int)p[x].size(); ++i) {
			ans = 2ll * ans % P;
		}
		return ans;
	}
	int s = 0, si = 0;
	for (int i = 0; i < (int)p[x].size(); ++i) {
		f[i] = (1ll * s * sum[p[x][i]] + P - si + 1) % P;
		s = (s + f[i]) % P;
		si = (si + 1ll * f[i] * sum[p[x][i]]) % P;
	}
	return a[n] ? f[(int)p[x].size() - 1] : s;
}

int main() {
	read(n);
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
		a[i] ^= a[i - 1];
		sum[i] = sum[i - 1] + (a[i] == 0);
		p[a[i]].push_back(i);
	}
	int ans = 0;
	for (int i = 0; i < (1 << 20); ++i) {
		ans = (ans + solve(i)) % P;
	}
	print(ans);
}


Measured memory_bytes: 44312
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cstdlib>

using namespace std;

class c_fx
{
private:
    int n;
    long t[200000];
    
public:
    void f_fx();

};

void c_fx::f_fx()
{
    long i, j;
    long max_sa;
    long min_x;
    
    cin >> n;
    for ( i = 0; i < n; ++i ){
        cin >> t[i];
    }
    
    max_sa = t[1]-t[0];
    min_x = t[0];
    
    for ( j = 1; j < n; ++j ){
        if (max_sa < t[j]-min_x)max_sa = t[j]-min_x;
        if (min_x > t[j])min_x = t[j];
    }            
        
    cout << max_sa << endl;
    
}

int main(){
    c_fx fx01;
    
    fx01.f_fx();
    
    return 0;
}

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

int main(){
    string ss;
    int num[128];
    num['M'] = 1000;
    num['D'] = 500;
    num['C'] = 100;
    num['L'] = 50;
    num['X'] = 10;
    num['V'] = 5;
    num['I'] = 1;
    while( cin >> ss ){
        int answer = 0;
        string::iterator it = ss.begin();
        while( it != ss.end() ){
            if( it+1 == ss.end() || num[ *it ] >= num[ *(it+1) ] ){
                answer += num[ *it ];
            }else{
                answer += num[ *(it+1) ] - num[ *it ];
                it++;
            }
            it++;
        }
        cout << answer << endl;
    }
    return 0;
}

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

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() { // 日本語文字列のテスト
    int w = readint;
    int n = readint;

    auto xs = new int[w + 1];
    for (int i = 0; i < xs.length; i++)
        xs[i] = i;

    for (int i = 0; i < n; i++) {
        auto ab = readln.chomp.split(",").to!(int[]);
        int a = ab[0], b = ab[1];
        swap(xs[a], xs[b]);
    }

    foreach (x; xs[1 .. $])
        writeln(x);
}

Measured memory_bytes: 2464
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{
    static int[] preorder;
    static int[] inorder;
    static int[] postorder;
    public static void main(String[] Args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        preorder = new int[n];
        inorder = new int[n];
        postorder = new int[n];
        StringTokenizer st;
        st = new StringTokenizer(br.readLine(), " ");
        for(int i = 0; i<n; i++)
            preorder[i] = Integer.parseInt(st.nextToken());
        st = new StringTokenizer(br.readLine(), " ");
        for(int i = 0; i<n; i++)
            inorder[i] = Integer.parseInt(st.nextToken());
        rec(0, 0, 0, n);
        final StringBuilder sb = new StringBuilder();
        sb.append(postorder[0]);
        for(int i = 1; i<n; i++){
            sb.append(' ').append(postorder[i]);
        }
        System.out.println(sb);
    }
    static void rec(int pre, int in, int post, int n){
        if(n<=0) return;
        final int p = preorder[pre];
        postorder[post+n-1] = p;
        int i;
        for(i = in; inorder[i]!=p; i++);
        final int rlen = n-(i-in)-1;
        rec(pre+1, in, post, i-in);
        rec(pre+1+i-in, i+1, post+i-in, rlen);
    }

}

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

string f(string s) {
  string t;
  int n = s.size();
  t.push_back(s[0]);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'a' || s[i] == 'i' || s[i] == 'u' || s[i] == 'e' ||
        s[i] == 'o') {
      if (i + 1 < n)
        t.push_back(s[i + 1]);
    }
  }
  return t;
}

int main() {
  int n;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    vector<string> v(n), w(n);
    for (int i = 0; i < n; i++)
      cin >> v[i];
    for (int i = 0; i < n; i++)
      w[i] = f(v[i]);
    for (int k = 1; k <= 50; k++) {
      vector<string> s(n);
      for (int i = 0; i < n; i++)
        s[i] = w[i].substr(0, k);
      sort(s.begin(), s.end());
      bool ok = true;
      for (int j = 1; j < n; j++)
        if (s[j] == s[j - 1])
          ok = false;
      if (ok) {
        cout << k << endl;
        break;
      } else if (k == 50) {
        cout << -1 << endl;
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 3140
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

lint powmod(lint a,lint b){
  return b?powmod(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;
}

lint fac[510000],finv[510000],inv[510000];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<510000;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;
  }
}
lint COM(lint n,lint k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
lint facdiv(lint n,lint k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return (fac[n]*finv[k])%MOD;
}

int main(void){
    lint N;
    cin >> N;
    lint X[N],Y[N];
    rep(i,N) cin >> X[i] >> Y[i];
    lint d1[N],d2[N];
    rep(i,N) d1[i]=X[i]-Y[i],d2[i]=X[i]+Y[i];
    sort(d1,d1+N);
    sort(d2,d2+N);
    lint ans=0;
    ans=d1[N-1]-d1[0];
    ans=max(ans,d2[N-1]-d2[0]);
    cout << ans << endl;
}

Measured memory_bytes: 9892
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<int, int> P;
double dp[301][301][301];
int N;
double solve(int one, int two, int three) {
	if (one == 0 && two == 0 && three == 0) return 0;
	if (dp[one][two][three] != -1) return dp[one][two][three];
	double s = 1, x = 1, p;
	if (one > 0) {
		p = 1.0*one / N;
		x -= p;
		s += p * solve(one - 1, two, three);
	}
	if (two > 0) {
		p = 1.0*two / N;
		x -= p;
		s += p * solve(one + 1, two - 1, three);
	}
	if (three > 0) {
		p = 1.0*three / N;
		x -= p;
		s += p * solve(one, two + 1, three - 1);
	}
	return dp[one][two][three] = s / (1 - x);
}
int main() {
	cin >> N;
	int one = 0, two = 0, three = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (a == 1) one++;
		else if (a == 2) two++;
		else three++;
	}
	fill((double*)dp, (double*)(dp + 301), -1);
	printf("%.15lf\n", solve(one, two, three));
}


Measured memory_bytes: 213376
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int W = input.nextInt();
        int H = input.nextInt();
        int x = input.nextInt();
        int y = input.nextInt();
        int r = input.nextInt();
        if((((x - r) >= 0) && ((y - r) >= 0)) && (((x + r) <= W) && ((y + r) <= H))) System.out.println("Yes");
        else System.out.println("No");
    }
}



Measured memory_bytes: 26384
import math
N, K = map(int,input().split())
V = list(map(int,input().split()))
V_rev = list(reversed(V))
ans = 0
tmp = -1 * float("inf")
L = 0
R = 0

for A in range(min(N+1,K+1)):
  for B in range(min(N+1,K+1) - A):
    if A == 0 and B == 0:continue
    tmp = -1 * float("inf")
    if A == 0:
      tmp = sum(V_rev[:B])
    elif B == 0:
      tmp = sum(V[:A])
    else:
      tmp = sum(V[:A])+sum(V_rev[:B])
    if A == 0:
      push_list = V_rev[:B]
    elif B == 0:
      push_list = V[:A]
    else:
      push_list = V[:A] + V_rev[:B]
    push_list = sorted(push_list)
    #print(tmp,push_list,A,B)
    for i in range(min(len(push_list),K-(A+B))):
      if push_list[i] < 0:
        tmp += abs(push_list[i])
        #print("tmp",tmp)
    ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };
        

        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            var input = cin.SplitReadL();
            long N = input[0];
            long P = input[1];
            long L = P;

            long ans = 1;
            for(long i = 2; i <= Sqrt(P); i++)
            {
                long cnt = 0;
                while (L % i == 0)
                {
                    cnt++;
                    L /= i;
                }

                if (cnt >= N)
                {
                    ans *= (long)Pow(i, cnt / N);
                }
            }
            if (N == 1)
            {
                ans *= L;
            }
            

            Console.WriteLine(ans);

            //Console.Out.Flush();
        }
        
        
    }
    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
        static public long Modulo(long value, long mod)
        {
            long r = value % mod;

            if (r * mod < 0)
            {
                r += mod;
            }
            return r;
        }
    }

    

}


Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {
	static long max =Long.MIN_VALUE;
	static long[] C;
	static int[] P;

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

		C = new long[N + 1];
		P = new int[N + 1];

		for (int i = 1; i < N + 1; i++) {
			P[i] = sc.nextInt();
		}

		for (int i = 1; i < N + 1; i++) {
			C[i] = sc.nextLong();
		}

		//任意のマスから動く
		for (int i = 1; i <= N; i++) {
			//サイクルの累積和おきば
			long[] arr = new long[N + 1];
			long sum = 0;
			int start = i;
			int now =i;
			int con = 0;
			long round =K;
			//1サイクル分シュミレート
			while (true) {
				//遷移
				now = P[now];
				//累積
				sum += C[now];
				arr[con] = sum;
				//更新
				con++;
				round--;
				//終了条件
				if (round == 0) {
					for (int j = 0; j < con; j++) {
						max = Math.max(max, arr[j]);
					}
					break;
				}
				//一周
				if (now == start) {
					long cycle = sum;
					if (cycle <= 0) {
						for (int j = 0; j < con; j++) {
							max = Math.max(max, arr[j]);
						}
						break;
					}else {
						//終了時のround数-2まで累積和を更新
						if (round > con * 2) {
							long add = round / con - 2;
							long left = round % con;
							//addの分累積和を更新
							for (int j = 0; j < con; j++) {
								arr[j] = arr[j] + cycle * add;
							}
							//2周＋left回シュミ
							sum = arr[con - 1];
							for (int j = 0; j < con * 2 + left; j++) {
								int ind = j % con;
								//やる
								//遷移
								now = P[now];
								//累積
								sum += C[now];
								arr[ind] = sum;
								//更新
								max = Math.max(max, arr[ind]);
							}
						}else {
							sum = arr[con - 1];
							for (int j = 0; j < round; j++) {
								int ind = j % con;
								//やる
								//遷移
								now = P[now];
								//累積
								sum += C[now];
								arr[ind] = sum;
								//更新
								max = Math.max(max, arr[ind]);
							}
						}

						break;
					}
				}
			}
		}

		System.out.println(max);

	}
}

Measured memory_bytes: 57236
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  vector<int> C1(3) ;
  vector<int> C2(3) ;
  vector<int> C3(3) ;
  rep(i,3) cin >> C1[i] ;
  rep(i,3) cin >> C2[i] ;
  rep(i,3) cin >> C3[i] ;
  rep(i,101){
    if( C1[0]==0 ||C1[1]==0 ||C1[2]==0 ) break ;
    rep(j,3){
      if( C1[j] > 0 ) C1[j]-- ;
    }
    //if( C1[0]==0 ||C1[1]==0 ||C1[2]==0 ) break ;後ろだとだめ
  }
  rep(i,101){
    if( C2[0]== 0 ||C2[1]== 0 ||C2[2]==0 ) break ;
    rep(j,3){
      if( C2[j] > 0 ) C2[j]-- ;
    }
    
  }
   rep(i,101){
     if( C3[0]==0 ||C3[1]==0 ||C3[2]==0 ) break ;
    rep(j,3){
      if( C3[j] > 0 ) C3[j]-- ;
    }
  }
  //rep(i,3) cout << C1[i] << ' ' ;
 //cout << endl;
  //rep(i,3) cout << C2[i] << ' ' ;
  //cout << endl;
  //rep(i,3) cout << C3[i] << ' ' ;
  if(C1[0] == C2[0] && C3[0] == C2[0] && C1[1] == C2[1] && C1[1] == C3[1] && C1[2] == C2[2] && C1[2] == C3[2]){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())

ans = 0
tmp = ""
for i in range(N):
    if tmp == 1 and S[i] == "B":
        tmp += 1
    elif tmp == 2 and S[i] == "C":
        ans += 1
        tmp = ""
    elif S[i] == "A":
        tmp = 1
    else:
        tmp = 0
print(ans)


Measured memory_bytes: 3060
import random

class Dice():
    def __init__(self, numbers):
        self.numbers = numbers
        S = [1, 5, 2, 3, 0, 4]
        N = [4, 0, 2, 3, 5, 1]
        W = [3, 1, 0, 5, 4, 2]
        E = [2, 1, 5, 0, 4, 3]
        self.tumble = {0: S, 1: N, 2: W, 3: E}
        
    def rol(self, command):
        prev = self.numbers.copy()
        for i, t in enumerate(self.tumble[command]):
            self.numbers[t] = prev[i]

d1 = list(map(int, input().split()))
d2 = list(map(int, input().split()))

max_len= 24
dice_table = []
dice = Dice(d1)


for _ in range(1000):
    dice.rol(random.randint(0, 3))
    numbers = dice.numbers.copy()
    if numbers not in dice_table:
        dice_table.append(numbers)
        
if d2 in dice_table:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 8192
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define trav(x,a) for (const auto& x: a)
#define sz(x) (int)(x).size()
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int _i = 0; _i < (n); _i++) ni(a[_i])
#define nal(a, n) for (int _i = 0; _i < (n); _i++) nl(a[_i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define st first
#define nd second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int mod = 1e9 + 7;
const ll inf = 1e14 + 7;
const int N = 1e6 + 5;
const double eps = 1e-9;
int a[N], vis[N], b[N], nb[N];

int main() {
  int n, x; scanf("%d %d", &n, &x);
  ll ans = inf, sm = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), b[i] = a[i], sm += b[i];
  ans = min(ans, sm);
  for (int i = 1; i < n; i++) {
    nb[1] = min(b[n], a[1]);
    for (int j = 2; j <= n; j++)
      nb[j] = min(b[j-1], a[j]);
    swap(b, nb);
    sm = 0;
    for (int j = 1; j <= n; j++)
      sm += b[j];
    ans = min(ans, sm + i * 1ll * x);
  }
  printf("%lld\n", ans);
  return 0;
}


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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}




long long sum(long long l , long long r){
  return (l+r)*(r-l+1)/2 ; 
}

int main(){
  int n , k ; cin >> n >> k ;
  mint ans ; 
  
  for(int i = k ; i <= n+1 ; i++){
    long long l = sum(0,i-1), r = sum(n-i+1,n) ;
    ans += r-l+1 ; 
  }
  cout << ans << endl ; 
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main() {
int N;
long long int A[114514]; 
cin >> N; 
for (int i = 0; i < N; ++i){
cin >> A[i]; 
}
sort(A, A+N, greater<int>()); 
long long int H = 0, W = 0; 
for (int i = 0; i < N-1; ++i){
if(A[i] == A[i+1]){
H = A[i]; 
A[i] = 0, A[i+1] = -1; 
break; 
}
}
for (int i = 0; i < N-1; ++i){
if(A[i] == A[i+1]){
W = A[i]; 
break; 
}
}
long long int S = H * W; 
cout << S << endl; 
}

Measured memory_bytes: 1024
def yakusu(n):
	l=int(n**0.5)
	ans=[]
	for i in range(1,l+1):
		if n%i==0:
			ans.append(i)
			ans.append(n//i)
	ans=list(set(ans))
	ans.sort()
	return ans

def gcd(a,b):
	if min(a,b)==0:
		return max(a,b)
	else:
		return gcd(min(a,b),max(a,b)%min(a,b))

def resolve():
	A,B,K=map(int,input().split())
	g=gcd(A,B)
	print(yakusu(g)[-K])
resolve()

Measured memory_bytes: 38640
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    vector<char> en = {'A','T','G','C'};
    char c;
    cin>>c;
    rep(i,4){
        if(c == en[i]) cout<<en[i^1]<<endl;
    }
}

Measured memory_bytes: 256
N = int(input())
remarks = []
for i in range(N):
    w = []
    for j in range(int(input())):
        w.append(list(map(int, input().split())))
    remarks.append(w)
     
def power2(n):
    if n == 1:
        return [[1], [0]]
    res = []
    for l in power2(n-1):
        res.append([1] + l)
        res.append([0] + l)
    return res
 
ans = 0
patterns = power2(N)

for p in patterns:
    flag = True
    for i, remark in enumerate(remarks):      
        if p[i] == 0: #不親切者の発言を無視
            continue
        else:
            for w in remark:
                if p[w[0]-1] != w[1]: #発言の矛盾を判定:
                    flag = False 
                    break
                # print(w)
    if flag: #すべての発言で矛盾がなかった場合
        ans = max(ans, p.count(1))
 
print(ans)

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

typedef long long ll;

ll a[100005];
ll b[100005];

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n+1;i++){
		cin>>a[i];
	}
	ll sum=0;
	for(int i=1;i<=n;i++){
		cin>>b[i];
		if(a[i]<=b[i]){
			sum+=a[i];
			b[i]-=a[i];
			if(a[i+1]<b[i]){
				sum+=a[i+1];
				a[i+1]=0;
			}
			else {
				a[i+1]-=b[i];
				sum+=b[i];
			}
		}
		else {
			sum+=b[i];
		}
	}
	cout<<sum<<endl;
	return 0;
}

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

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

    string S;

    cin>>S;
    string ans;
    if(S=="ABC"){
        ans = "ARC";
    }else{
        ans = "ABC";
    }

    cout<<ans<<"\n";


	
	return 0;
}

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
	private double t, y;

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			double v = scan.nextDouble();
			
			t = v / 9.8;
			y = 4.9 * t * t;
			
			int N = 1;
			while (true) {
				if (5 * N - 5 >= y) break;
				N++;
			}
			//debug();
			System.out.println(N);
		}
	}
	
	private void debug() {
		System.out.println(t + " " + y);
	}
}

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


#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =1001001001;
const ll BIG = 1000000007;
const double PI = 3.141592653589793;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int sum_vote=0;
    rep(i,n) sum_vote+=a[i];
    bool can_choose = false;
    int num = 0;
    rep(i,n){
        if(a[i]*4*m>=sum_vote) num++;
    }
    if(num>=m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636