akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long LL;
const int MaxN = 1e5 + 5;
int n;
char s[MaxN];
int ans[MaxN];
bool flag;
void search(int x, int y){
	int p = 0;
	ans[++p] = x;
	ans[++p] = y;
	for(int i = 2; i <= n; i++){
		if(ans[i] == 1){
			if(s[i] == 'o')
				ans[i + 1] = ans[i - 1];
			else if(s[i] == 'x')
				ans[i + 1] = -ans[i - 1];
		}
		else if(ans[i] == -1){
			if(s[i] == 'o')
				ans[i + 1] = -ans[i - 1];
			else if(s[i] == 'x')
				ans[i + 1] = ans[i - 1];
		}
	}
	if(ans[1] == ans[1 + n]){
		if(ans[1] == 1){
			if(s[1] == 'o' && ans[2] == ans[n]) flag = true;
			else if(s[1] == 'x' && ans[2] != ans[n]) flag = true;
		}
		else if(ans[1] == -1){
			if(s[1] == 'o' && ans[2] != ans[n]) flag = true;
			else if(s[1] == 'x' && ans[2] == ans[n]) flag  = true;
		}
	}	
}
int main(){
	while(~scanf("%d", &n)){
		scanf("%s", s + 1);
		for(int i = -1; i <= 1; i++){
			for(int j = -1; j <= 1; j++){
				if(i == 0 || j == 0) continue;
				if(!flag) search(i, j);
			}
		}
		if(!flag) printf("-1\n");
		else{
			for(int i = 1; i <= n; i++)
				if(ans[i] == 1) printf("S");
				else if(ans[i] == -1) printf("W");
			printf("\n");
		}
	memset(ans, 0, sizeof(ans));
	memset(s, 0, sizeof(s));
	flag = false;
	}
	return 0;
}
				


Measured memory_bytes: 768
#include<stdio.h>
int main(){
	int flag,min,MAX,i,I,x,y,z,N,M,a[1000],weight;
	scanf("%d %d",&N,&M);
	for(i=0;i<N;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;;i++){
		x = N*i;
		if((x%M)==0) break;
	}
	y = x/M;
	min = a[0];
	MAX = a[0];
	I = 0;
	flag = 1;
	weight = 0;
	for(i=0;i<y;i++){
		for(;I<(M*flag);I++){
			z = I % N;
			if(min>a[z]) min = a[z];
			if(MAX<a[z]) MAX = a[z];
		}
		flag++;
		weight = weight + MAX - min;
		z = I % N;
		MAX = a[z];
		min = a[z];
	}
	printf("%d\n",weight);
	return 0;
}

Measured memory_bytes: 604
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

        int n=gi();
        int m=gi();
        int[] K=new int[n];
        boolean[][] A = new boolean[n][m];
        
        for (int i=0; i<n;i++) {
        	for (int j=0; j<m;j++) {
            	A[i][j]=false;
            	
            }
        }
        for (int i=0; i<n;i++) {
        	K[i]=gi();
        	for (int j=0; j<K[i];j++) {
            	int a=gi();
            	A[i][a-1]=true;
            	
            }
        }
        
        int s=0;
        for (int i=0; i<m;i++) {
        	boolean flg=true;
        	for (int j=0; j<n;j++) {
            	if(A[j][i]==false) {
            		flg=false;
            		break;
            	}
            	
            }
        	if(flg)s++;
        }
	    System.out.println(s);

//        if (s>L[n-2]) {
//        	System.out.println("Yes");
//        }else {
//        	System.out.println("No");
//        }
	}


	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 38608
let print_array a =
  Array.iteri (fun i s -> Printf.printf (if i = 0 then "%s" else " %s") s) a;
  print_newline ()

let swap i j a = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp

let bubble_sort a n cmp =
  let rec bubble j flag =
    if j <= 0 then doit flag
    else if cmp a.(j - 1) a.(j) <= 0 then bubble (j - 1) flag
    else (swap j (j - 1) a; bubble (j - 1) true)
  and doit flag =
    if not flag then ()
    else bubble (n - 1) false
  in
  doit true

let selection_sort a n cmp =
  let rec select j minj =
    if j >= n then minj
    else select (j + 1) (if cmp a.(j) a.(minj) < 0 then j else minj)
  in
  let rec doit i =
    if i >= n then ()
    else begin
      let minj = select i i in
      if minj <> i then swap i minj a;
      doit (i + 1)
    end
  in
  doit 0

let cmp_card x y =
  let num_of_char c = Char.code c - Char.code '0' in
  compare (num_of_char x.[1]) (num_of_char y.[1])

let cmp_card x y =
  let num_of_char c = Char.code c - Char.code '0' in
  compare (num_of_char x.[1]) (num_of_char y.[1])

let stable_p a b n =
  let rec doit i =
    if i >= n then true
    else if a.(i) <> b.(i) then false
    else doit (i + 1)
  in
  doit 0

let () =
  let n = read_int () in
  let a = Array.of_list (Str.split (Str.regexp " ") (read_line ())) in
  let b = Array.copy a in
  bubble_sort a n cmp_card;
  selection_sort b n cmp_card;
  print_array a;
  print_endline "Stable";
  print_array b;
  print_endline (if stable_p a b n then "Stable" else "Not stable")

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

int judge(char c){
    char right[12]={'y','h','n','u','j','m','i','k','o','l','p'};
    
    for(int i = 0 ; i < 11 ; i++){
        if(c == right[i]) return 1;
    }
    return 0;
}

int main(void){
    string str;
    
    while(1){
        int cnt = 0;
        cin >> str;
        if(str == "#") break;

        for(int i = 1 ; i < str.size() ; i++){
            if(judge(str[i-1]) != judge(str[i])) cnt++;
        }
        
        cout << cnt << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1184
import sys
input = sys.stdin.buffer.readline
H, N = map(int, input().split())

INF = 1 << 40
dp = [INF]*(H+1)
dp[H] = 0
for i in range(N):
    a, b = map(int, input().split())
    for j in range(H, -1, -1):
        x = max(0, j-a)
        dp[x] = min(dp[x], dp[j]+b)

print(dp[0])


Measured memory_bytes: 72112
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


const int N = (int) 2e5 + 100;
bool cb[N];
int cnt[N];

int main(int,  char **)
{
#ifdef LOCAL
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    int n, m;
    scanf("%d%d", &n, &m);
    
    cb[0] = true;
    for (int i = 0; i < n; i++)
        cnt[i] = 1;

    for (int i = 0; i < m; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        a--;
        b--;
        if (cb[a])
            cb[b] = true;
        cnt[a]--;
        cnt[b]++;
        if (cnt[a] == 0)
            cb[a] = false;
    }

    int ans = 0;
    for (int i = 0; i < n; i++)
        if (cb[i])
            ans++;

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

	return 0;
}




Measured memory_bytes: 768
//FIRST THINK THEN CODE.

  #include <bits/stdc++.h>


  using namespace std;

  typedef long long ll;

  #define rep(i,a,b) for(ll i=a;i<b;++i)
  #define rrep(i,a,b) for(ll i=a;i>b;--i)
  #define FOR(i,n)  for(ll i=0;i<n;i++)
  #define vi vector<int>
  #define vl vector<ll>
  #define ld long double
  #define vld vector<ld>
  #define vvi vector<vector<int>>
  #define vvl vector<vector<long long>>
  #define vvld vector<vector<ld>>
  #define pii pair<int,int>
  #define pll pair<long,long>
  #define vpii vector<pii>
  #define vpll vector<pll>
  #define ff first
  #define ss second
  #define pb push_back
  #define pf push_front
  #define mp make_pair
  #define lb lower_bound
  #define ub upper_bound
  #define bs binary_search
  #define d1(x) cout<<(x)<<endl
  #define d2(x,y) cout<<(x)<<" "<<(y)<<endl
  #define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
  #define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
  #define PI 3.1415926535897932384626433832795
  #define fix(f,n) fixed<<setprecision(n)<<f
  #define all(x) x.begin(),x.end()
  #define rev(p) reverse(p.begin(),p.end());
  #define endl "\n"
  #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  #define popcount(x) __builtin_popcountll(x)
  #define sz(x) ((ll)x.size())
  const ll M=1000000007;
  const ll MM=998244353;
  ll begtime = clock();
  #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
  //#define _Find_next 
  //#define _Find_first 



  ll newmod(ll a,ll b)
  {
  return ((a%b)+b)%b;
  }


  ll powM(ll a,ll b,ll m )
  { 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
  if(b&1)ans=ans*a%m;
  a=a*a%m;
  b>>=1;
  }

  return ans;
  }



  ll poww(ll a,ll b)
  { 

  ll ans=1;
  while(b)
  {
  if(b&1)ans=ans*a;
  a=a*a;
  b>>=1;
  }

  return ans;

  }

  template<typename T,typename F>
  void chmax( T &a,F b){
  if(b>a)a=b;
  }

  template<typename T,typename F>
  void chmin( T &a,F b){
  if(b<a)a=b;
  }

string tostring(ll x){
  stringstream sss;
  sss<<x;
  string ans=sss.str();
  return ans;
}


  const ll N=1e3+5;



  int main()
  { 

ll n;cin>>n;
ll m;cin>>m;


ll ans=min(n,m/2);

m-=2*ans;

if(m>0)ans+=m/4;

d1(ans);

  return 0;

  }

Measured memory_bytes: 3612
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define R register int
const ll N=333;
int n,k;
ll c[N][N],m,f[N][N],g[N][N];
#define add(a,b) (((a)+(b))%m)
#define mul(a,b) ((a)*(b)%m)
int main(){
    scanf("%d%d%lld",&n,&k,&m);++n;c[0][0]=1;
    for(int i=1;i<N;i++){
        c[i][0]=1;
        for(int j=1;j<=i;j++)c[i][j]=add(c[i-1][j-1],c[i-1][j]);
    }
    for(int i=k;~i;i--)f[1][i]=1,g[1][i]=g[1][i+1]+1;
    for(int i=2;i<=n;i++)for(int x=k;~x;x--){
        for(int j=1;j<i;j++)f[i][x]=add(f[i][x],mul(mul(g[j][x+1],f[i-j][x]),c[i-2][j-1]));
        g[i][x]=add(f[i][x],g[i][x+1]);
    }
    //for(int i=1;i<=n;i++)for(int j=1;j<=i&&j<=k;j++)f[i]=add(f[i],mul(mul(c[k][j],c[i-1][j-1]),f[i-j]));
    printf("%lld",f[n][0]);
    return 0;
}

Measured memory_bytes: 2688
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  string S;
  cin >> S;
  ll ans = 0;
  rep (i, S.size() /  2) {
    if (S[i] != S[S.size() - 1 - i]) ans++;
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}


Measured memory_bytes: 256
n = gets.to_i
as = gets.split
bs = []
if n.even?
  as.each_with_index do |a, i|
    if i.even?
      bs << a
    else
      bs.unshift(a)
    end
  end
else
  as.each_with_index do |a, i|
    if i.odd?
      bs << a
    else
      bs.unshift(a)
    end
  end
end

puts bs.join(" ")

Measured memory_bytes: 20064
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vi a(8);

int main(){
	cin>>n;
	int t=0;
	for(int i=0;i<n;i++){
		int A;
		cin>>A;
		A/=400;
		if(A>7) t++;
		else a[A]++;
	}
	int num=0;
	for(int i=0;i<8;i++) if(a[i]) num++;
	if(!num) cout<<1<<' '<<t<<endl;
	else cout<<num<<' '<<num+t<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
const int MAXN = 1e5+5;
int  pen[MAXN]{ };
bool yes[MAXN]{ };
int M, N, p;
char S;

int main() {
  scanf(" %d%d", &N, &M);
  int ac = 0;
  int wa = 0;
  for (int i = 0; i < M; ++i) {
    scanf("%d", &p);
    scanf(" %c%*s", &S);
    if (S == 'A') {
      if (!yes[p]) {
        wa += pen[p];
        yes[p] = true;
        ++ac;
      }
    } else {
      ++pen[p];
    }
  }
  printf("%d %d\n", ac, wa);
  return 0;
}

Measured memory_bytes: 768
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<map>
#include<set>
using namespace std;
long long N,W;
long long w[105],v[105];
long long f[210000];
int main()
{
	cin>>N>>W;
	for(int i=0;i<210000;i++) 
	    f[i]=2e18;
	f[0]=0;
	int now=0;
	for(int i=1;i<=N;i++)
	{
		cin>>w[i]>>v[i];	
		for(int j=now+v[i];j>=v[i];j--)
		    f[j]=min(f[j],f[j-v[i]]+w[i]);
		now+=v[i];
	}	    
	for(int i=now;i>=0;i--)
	    f[i]=min(f[i],f[i+1]);
	int ans=0;
	while(f[ans]<=W)
	    ans++;
	cout<<ans-1;
	return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int s;cin>>s;
    map<int, int> m;m[s]++;
    int index = 1;
    while(1){
        index++;
        int nw = (s%2==0)?s/2:3*s+1;
        if(m[nw]>0){co(index);return 0;}
        m[nw]++;
        s = nw;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;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 INF 2e9
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;


int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int n,k;
    cin >> n>> k;
    VV a(k+1,V(n+1));//VV a(k,V(n))だとセグフォになる
    map<int,int> mp;
    REP1(i,k){
        int d;
         cin >> d;
         REP1(j,d){
             cin >> a[i][j]; 
             mp[a[i][j]]++;
         }
    }
    int count = 0;
    REP1(i,n){
        if(mp[i]==0) count++;
    }
    cout << count << endl;


}
 

Measured memory_bytes: 3680
#a×bの数列
a, b = map(int, input().split())
fields=[]
for i in range(a):
  fields.append(list(input()))

#スニペット
#左上、上中、右上、左、（中を飛ばす）、右、左下、下中、右下
dx=[-1,0,1,-1,1,-1,0,1]
dy=[-1,-1,-1,0,0,1,1,1]

for i in range(a):
  for j in range(b):
    count = 0
    if fields[i][j]=="#":
      pass
    else:
      for k in range(8):
        if i+dx[k]>=0 and j+dy[k]>=0 and i+dx[k]<a and j+dy[k] < b :
          if fields[i+dx[k]][j+dy[k]]=="#":
            count+=1
      fields[i][j]=str(count)  
      
for i in range(a):
  print("".join(fields[i]))


Measured memory_bytes: 3188
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000002486618624LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, a[222222];

  long long S = 0, s = 0, dm = INF;

  std::cin >> N;

  for (int i = 0; i < N; i ++) {
    std::cin >> a[i];

    S += a[i];
  }

  for (int i = 0; i < N - 1; i ++) {
    s += a[i];

    dm = std::min(std::abs(S - s - s), dm);
  }

  std::cout << dm << std::endl;

  return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

// int MOD = 998244353;
int MOD = 1000000007;

//----------------------------------------------------------------
signed main(){

	ll s;
	cin >> s;

	// ll ok = 0;  //解が存在する値
    // ll ng = 100;//解が存在しない値 

    // 条件を満たす最小を求める
    ll ok = 2000000001;  //解が存在する値
    ll ng = -1;  //解が存在しない値 

    while(abs(ok-ng)>1){
        ll mid = (ok+ng)/2;
		ll X = mid/2;
		ll Y = mid-mid/2;
        if(X*Y >= s){
            ok = mid;
        }else{
            ng = mid;
        }
    }
	ll X = ok/2;
	ll Y = ok-ok/2;

	cout << "0 0 1 " << Y << " " << X << " " << X*Y-s << endl; 

	return 0;
}

//----------------------------------------------------------------

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://agc036.contest.atcoder.jp/tasks/agc036_a

Measured memory_bytes: 256
#include <iostream>


int D[100];
int F[100];
int V[100][100];

int cnt = 0;
int n;

void dfs(int r) {
    D[r] = ++cnt;
    for (int i = 0; i < n; i++) {
        if ((V[r][i] == 1) && (D[i] == 0)) {
            dfs(i);
        }
    }
    F[r] = ++cnt;
}

int main() {
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        int id, e_num;
        std::cin >> id >> e_num;
        for (int j = 0; j < e_num; j++) {
            int t;
            std::cin >> t;
            V[id - 1][t - 1] = 1;
        }
    }

    for (int i = 0; i < n; i++) {
        if (!D[i]) dfs(i);
    }

    for (int i = 0; i < n; i++) {
        std::cout << i + 1 << " " << D[i] << " " << F[i] << std::endl;
    }
}


Measured memory_bytes: 3156
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,n;
    long long int sum=0,div=0,result;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        sum+=i;
    }
    for(i=3;i<=n;i+=3)
    {
        div+=i;
    }
    for(i=5;i<=n;i+=5)
    {
        div+=i;
    }
    for(i=15;i<=n;i+=15)
    {
        sum+=i;
    }
    result=sum-div;
    printf("%lld",result);
    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
      int sum = 0;
    for (int j = i; j != 0; j /= 10) {
      sum += j % 10;
    }
    if (sum >= a && sum <= b) {
      ans += i;
    }
	}
	cout << ans << '\n';
	return 0;
}


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

int main() {
  int a, b, c, d, e; cin >> a >> b >> c >> d >> e;
  int ans = 0;
  if (a < 0) ans += -a * c + d;
  cout << ans + (b - max(0, a)) * e << endl;
  return 0;
}



Measured memory_bytes: 3088
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    if (n < 10) {
        cout << n << '\n';
    } else if (n < 100) {
        cout << 9 << '\n';
    } else if (n < 1000) {
        cout << 9 + (n - 99) << "\n";
    } else if (n < 10000) {
        cout << 9 + 900 << "\n";
    } else if (n < 100000) {
        cout << 9 + 900 + (n - 9999) << "\n";
    } else {
        cout << 9 + 900 + 90000 << "\n";
    }

    return 0;
}

Measured memory_bytes: 888
N=input()	#N=a+b

ans=float("inf")
for a in range(N+1):
	b=N-a
	cnt=0
	for i in range(8,-1,-1):
		t=6**i
		if a>=t:
			cnt+=(a/t)
			a=a%t

	for i in range(8,-1,-1):
		t=9**i
		if b>=t:
			cnt+=(b/t)
			b=b%t
	ans=min(ans,cnt)

print ans
		

Measured memory_bytes: 33256
#define _USE_MATH_DEFINES //M_PI, M_E
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string a,b;
	cin>>a>>b;
	a += b;
	int h = stoi(a);
	if(int(sqrt(h))*sqrt(h)==h)
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
var input= require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.split(" ")).map(Number);
var W=Arr[0];
var H=Arr[1];
var x=Arr[2];
var y=Arr[3];
var r=Arr[4];
var tasu=0;
if(x-r>=0)tasu++;
if(y-r>=0)tasu++;
if(x+r<=W)tasu++;
if(y+r<=H)tasu++;
var str=(tasu==4)?"Yes":"No";
console.log(str);

Measured memory_bytes: 7384
#include <bits/stdc++.h>
using namespace std;
using s32 = int32_t;
using u32 = uint32_t;
using u64 = uint64_t;

int main() {
	string S;
	cin >> S;
	
	deque<char> sv;
	for(u32 i=0; i<S.size(); i++) sv.push_back(S[i]);
	
	u32 Q;
	cin >> Q;
	
	bool r = false;
	
	for(u32 q=0; q<Q; q++) {
		u32 T;
		cin >> T;
		
		if(T == 1) {
			r = !r;
		} else {
			u32 F;
			cin >> F;
			
			char C;
			cin >> C;
			
			if(r && (F == 1) || !r && (F == 2)) {
				sv.push_back(C);
			} else {
				sv.push_front(C);
			}				
		}
	}
	
	while(!sv.empty()) {
		if(r) {
			cout << sv.back();
			sv.pop_back();
		} else {
			cout << sv.front();
			sv.pop_front();
		}
	}
	
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using pll = pair<ll,ll>;
using Graph = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i,l,r) for(ll i = (l); i <= (ll)(r); i++)
#define rep3(i,l,r) for(ll i = (l); i >= (ll)(r); i--)
#define dup(x,y) (((x)+(y)-1)/(y)) // x/yの除算の切り上げ
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; }
const int inf = 1001001001;
const ll INF = 1LL << 60;
const ll mod = 1000000007; //1000000007
const ld pi = acos(-1);
 
//xor演算
//a^b=b^a
//a^(b^c)=(a^b)^c
//a^a=0
//a+b=a^b + 2(a&b)
//(4a)^(4a+1)^(4a+2)^(4a+3)=0

const ll A = 1000005;
 
int main(){
 
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n;
    cin >> n;
    vector<ll> a(n), c(A);
    rep(i,n){
        cin >> a[i];
        c[a[i]]++;
    }
    bool parwise = true;
    for(ll i = 2; i < A; i++){
        ll cnt = 0;
        for(ll j = i; j < A; j += i){
            cnt += c[j];
        }
        if(cnt > 1) parwise = false;
    }
    if(parwise){
        cout << "pairwise coprime" << endl;
        return 0;
    }
    ll g = 0;
    rep(i,n) g = gcd(g,a[i]);
    if(g == 1){
        cout << "setwise coprime" << endl;
        return 0;
    }
    cout << "not coprime" << endl;
}

Measured memory_bytes: 18756
/*
██╗  ██╗ █████╗ ██████╗ ███████╗███████╗███╗   ███╗        ██╗  ██╗██╗  ██╗ █████╗ ██╗     ███████╗██████╗
██║ ██╔╝██╔══██╗██╔══██╗██╔════╝██╔════╝████╗ ████║        ██║ ██╔╝██║  ██║██╔══██╗██║     ██╔════╝██╔══██╗
█████╔╝ ███████║██████╔╝█████╗  █████╗  ██╔████╔██║        █████╔╝ ███████║███████║██║     █████╗  ██║  ██║
██╔═██╗ ██╔══██║██╔══██╗██╔══╝  ██╔══╝  ██║╚██╔╝██║        ██╔═██╗ ██╔══██║██╔══██║██║     ██╔══╝  ██║  ██║
██║  ██╗██║  ██║██║  ██║███████╗███████╗██║ ╚═╝ ██║███████╗██║  ██╗██║  ██║██║  ██║███████╗███████╗██████╔╝
╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═════╝
				Believe in yourself ,( try and try and then try ), You can do it  
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define clr(arr, x) memset(arr, x, sizeof arr)
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define OO 0x3f3f3f3f3f3f3f3fLL
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
void K_K(){ 
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
	K_K();
	int n, m;
	cin >> n >> m;
	vector<int>arr(n);
	for (auto &it : arr)
		cin >> it;
	vector<vector<int>>gr(n + 1);
	while (m--){
		int u, v;
		cin >> u >> v;
		gr[u].push_back(v);
		gr[v].push_back(u);
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++){
		bool ok = 1;
		for (int j = 0; j < sz(gr[i]); j++){
			if (arr[gr[i][j] - 1] >= arr[i - 1]){
				ok = 0;
				break;
			}
		}
		if (ok)
			cnt++;
	}
	cout << cnt;
}

Measured memory_bytes: 8748
def main():
    a, b, n = list(map(int, input().split()))
    
    limit = 0
    if n >= b-1:
        limit = b-1
    else:
        limit = n
    
    floor_sub = int(limit * a / b) - int(limit / b) * a
    print(floor_sub)

if __name__ == '__main__':
    main()

Measured memory_bytes: 8988
#include<iostream>
#include<cmath>
using namespace std;
int n,w,z,a[2010],b,c,s;
int main()
{
	cin>>n>>z>>w;
	for(int i=1;i<=n;i++) cin>>a[i];
	if(n==1) cout<<abs(a[1]-w)<<endl;
	else cout<<max(abs(a[n]-w),abs(a[n-1]-a[n]));
	return 0;
	}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void pre(){}
long long int n,x,y;
long long int dist(long long int a,long long int b){
    return min(abs(b-a),abs(a-x)+1+abs(b-y));
}
void solve(){
    cin>>n>>x>>y;x--;y--;
    long long int ans[n-1];
    for(long long int i=0;i<n-1;i++) ans[i]=0;
    for(long long int i=0;i<n;i++){
        for(long long int j=i+1;j<n;j++){
            //cout<<i+1<<" "<<j+1<<" "<<dist(i,j)<<"\n";
            ans[dist(i,j)-1]++;
        }
    }
    for(auto i:ans){
        cout<<i<<"\n";    
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
       	solve();
    }   
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(){
    int n;cin >> n;
    vii abc(n,vi(3));
    rep(i,n)rep(j,3)cin >> abc[i][j];

    vii dp(100100,vi(3));

    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<3;k++){
                if(j==k)continue;
                chmax(dp[i+1][k],dp[i][j]+abc[i][k]);
            }
        }
    }

    int ans = 0;
    for(int i=0;i<3;i++){
        chmax(ans,dp[n][i]);
    }
    cout << ans << endl;
    return 0;
}

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

bool func( string s ){
  reverse(s.begin(),s.end());
  string t = s;
  reverse(s.begin(),s.end());
  for(int i=0;i<s.size();i++){
    if( s.at(i) != t.at(i) ){
      return false;
    }
  }
  return true;
}

int main(){
  string s;
  cin >> s;
  int sz = s.size();
  string t = s.substr(0,(sz-1)/2);
  string u = s.substr((sz+3)/2-1);
  if( func(s) && func(t) && func(u) ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import math
import itertools
cnt = 0
n,k = map(int,input().split())
t = []
for i in range(1,n+1):
    t.append(i)
#print(t)
for i in range(k):
    n = int(input())
    a = list(map(int,input().split()))
    for i in range(len(a)):
        if a[i] in t:
            t.remove(a[i])
        
print(len(t))

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
 
int time(int h, int m, int s) {
  return s+m*60+h*60*60;
}
 
vector<int> watch(int s) {
  vector<int> a(3);
  a[2]=s%60;
  s/=60;
  a[1]=s%60;
  s/=60;
  a[0]=s;
  return a;
}
 
int main() {
  int n;
  while(cin >> n && n) {
    vector<int> w[n],a(3);
    for(int i=0; i<n; i++) {
      for(int j=0; j<3; j++) cin >> a[j];
      sort(a.begin(),a.end());
      do {
	vector<int> b=a;
	for(int j=0; j<60; j++) {
	  for(int k=0; k<3; k++) {
	    b[k]++;
	    b[k]%=60;
	  }
	  if(b[0]%5==b[1]/12) w[i].push_back(time(b[0]/5,b[1],b[2]));
	}
      } while(next_permutation(a.begin(),a.end()));
      sort(w[i].begin(),w[i].end());
    }
    int x1=(1<<28),t,z=12*60*60;
    for(int i=0; i<n; i++) {
      for(int j=0; j<w[i].size(); j++) {
	int x2=0;
	for(int k=0; k<n; k++) {
	  int x3=(1<<28);
	  for(int l=0; l<w[k].size(); l++) {
	    int x=w[i][j],y=w[k][l];
	    if(x>y) {
	      y+=z;
	      
	    }
	    x3=min(x3,y-x);
	  }
	  x2=max(x2,x3);
	}
	if(x1>x2) {
	  x1=x2;
	  t=w[i][j];
	} else if(x1==x2) t=min(t,w[i][j]);
      }
    }
    vector<int> x=watch(t),y=watch(t+x1);
    printf("%02d:%02d:%02d %02d:%02d:%02d\n",x[0],x[1],x[2],y[0],y[1],y[2]);
  }
  return 0;
}


Measured memory_bytes: 1224
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();
		sc.close();

		if (N % K == 0) {
			System.out.print(0);
		} else {
			System.out.print(1);
		}
	}
}

Measured memory_bytes: 21716
def doubleork(n, k):

    ans = 1

    for i in range(n):
        if ans * 2 < ans + k:
            ans *= 2
        else:
            ans += k

    return ans


def main():
    n = int(input())
    k = int(input())
    print(doubleork(n , k))


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod1=1e9+7,mod2=998244353,H=1e6+7;
bool isstart[500005];
bool used[500005];
ll ans[500005]={0};
ll pow(ll x,ll y,ll mod){
  if(y==0) return 1;
  ll res=pow(x,y/2,mod);
  res*=res;
  res%=mod;
  if(y%2==1) res*=x;
  return res%mod;
}
ll solve(vector<bool> vec){
  ll n=vec.size();
  for(int i=0;i<n;i++) vec.push_back(vec[i]);
  ll res=0,cnt=0;
  for(int i=0;i<n*2;i++){
    if(vec[i]) cnt++;
    else{
      res=max(res,cnt);
      cnt=0;
    }
  }
  return max(res,cnt);
}
int main(){
  string s,t;
  cin>>s>>t;
  ll sl=s.length();
  string ns=s;
  ll thash1=0,thash2=0;
  for(int i=0;i<t.length();i++){
    thash1+=(int)(t[i]);
    thash1*=H;
    thash1%=mod1;

    thash2+=(int)(t[i]);
    thash2*=H;
    thash2%=mod2;
  }
  while(ns.length()<=t.length()) ns+=s;
  ns+=s;
  ll shash1=0,shash2=0;
  for(int i=0;i<t.length();i++){
    shash1+=(int)(ns[i]);
    shash1*=H;
    shash1%=mod1;

    shash2+=(int)(ns[i]);
    shash2*=H;
    shash2%=mod2;
  }
  isstart[0]=(shash1==thash1&&shash2==thash2);
  ll mhash1=pow(H,t.length(),mod1),mhash2=pow(H,t.length(),mod2);
  for(int i=1;i<sl;i++){
    shash1-=(mhash1*(int)ns[i-1])%mod1;
    shash1+=mod1;
    shash1+=(int)(ns[i+t.length()-1]);
    shash1%=mod1;
    shash1*=H;
    shash1%=mod1;

    shash2-=(mhash2*(int)ns[i-1])%mod2;
    shash2+=mod2;
    shash2+=(int)(ns[i+t.length()-1]);
    shash2%=mod2;
    shash2*=H;
    shash2%=mod2;

    isstart[i]=(shash1==thash1&&shash2==thash2);
  }

  for(int i=0;i<sl;i++){
    used[i]=false;
  }
  ll ans=0;
  for(int i=0;i<sl;i++){
    if(!used[i]){
      used[i]=true;
      ll pos=i;
      vector<bool> cycle;
      cycle.push_back(isstart[i]);
      pos+=t.length();
      pos%=sl;
      while(!used[pos]){
        cycle.push_back(isstart[pos]);
        used[pos]=true;
        pos+=t.length();
        pos%=sl;
      }
      ll kans=solve(cycle);
      if(kans>=cycle.size()){
        cout<<"-1"<<endl;
        return 0;
      }
      ans=max(ans,kans);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 5812
import java.util.Scanner;

public class Main{
    public static void main(String argv[]){
	Scanner scan = new Scanner(System.in);

	int a = scan.nextInt();
	int b = scan.nextInt();
	int c = scan.nextInt();
	int i,count=0;
	for( i = b ; i >= a ;i-- )
	    {
		if( c % i == 0 )
		    count++;
	    }
	System.out.println(count);
    }
}
	

Measured memory_bytes: 26336
import os, sys, re, math

N,X = list(map(int,input().split(' ')))

memo_length = [0 for i in range(51)]
memo_patties = [0 for i in range(51)]
memo_length[0] = 1
memo_patties[0] = 1

for i in range(1,51):
    memo_length[i] = memo_length[i-1] * 2 + 3
    memo_patties[i] = memo_patties[i-1] * 2 + 1

def doit(level,x):
    if x == 0:
        return 0
    if x >= memo_length[level]:
        return memo_patties[level]

    tmp = memo_length[level-1]
    ret = 0

    if x >= 1:
        ret += doit(level-1, x-1)
    if x >= tmp + 2:
        ret += 1
        ret += doit(level-1, x-tmp-2)

    return ret

print(doit(N,X))


Measured memory_bytes: 3188
/*
	JAI JAGANNATH!
*/
//@Author : zanj0

#include<bits/stdc++.h>
using namespace std;

typedef long long int lli;

#define ff              first
#define ss              second
#define pb              push_back
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            lli x; cin>>x; while(x--)

void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
void solve() {
	vector <lli> v1(2);
	vector <lli> v2(2);
	for (lli i = 0; i < 2; i++) {
		cin >> v1[i];
	}
	for (lli i = 0; i < 2; i++) {
		cin >> v2[i];
	}
	lli ret = -inf;
	for (lli i = 0; i < 2; i++) {
		for (lli j  = 0; j < 2; j++) {
			ret = max(ret, v1[i] * v2[j]);
		}
	}
	cout << ret << endl;
}
int main()
{
	zanj0();
	solve();
	return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define For(i, j, k) for(int i = j; i <= (int)k; ++ i)
#define Forr(i, j, k) for(int i = j; i >= (int)k; -- i)
#define INF 0x3f3f3f3f
using namespace std;

string s;

int main(){
	cin >> s;
	For(i, 0, s.length() - 1 - 8)
		putchar(s[i]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

char s[105];
ll n,K,ans;

int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	read(K);
	int pre=1;
	while(pre<n&&s[pre]==s[pre+1]) pre++;
	int suf=n;
	while(suf>1&&s[suf]==s[suf-1]) suf--;
	if(pre==n){
		cout<<n*K/2<<endl;
		return 0;
	}
	ans+=pre/2+(n+1-suf)/2;
	if(s[1]==s[n]){
		ans+=(pre+n+1-suf)/2*(K-1);
	}
	else{
		ans+=(pre/2+(n+1-suf)/2)*(K-1);
	}
	rep(i,pre+1,suf-1){
		int c=1;
		while(i+1<=suf-1&&s[i]==s[i+1]){
			c++,i++;
		}
		ans+=c/2*K;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3772
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College

'''
from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')

file = 1

def solve():
    



    # for _ in range(ii()):

    a=ii()
    print(a+a*a+a*a*a)        
        








  
















if __name__ =="__main__":

    if(file):

        if path.exists('input1.txt'):
            sys.stdin=open('input1.txt', 'r')
            sys.stdout=open('output1.txt','w')
        else:
            input=sys.stdin.readline
    solve()

Measured memory_bytes: 69724
#include <iostream>

using namespace std;

int main()
{
    int k,a,b;
    cin >> k;
    cin >> a >> b;
    for(int i = a; i <= b; i++)
    {
        if( i % k == 0 )
        {
            cout << "OK" <<endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define ll long long
#define inf 0x3f3f3f3f
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
int a[maxn];
int n;
int check(ll k)
{
	for(int i=1;i<=n;i++)
		k-=k%a[i];
	return (k==2);
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	if(a[n]>2){
		puts("-1"); return 0;
	}
	ll now=2;
	for(int i=n-1;i;i--)
		now=((now-1)/a[i]+1)*a[i];
	if(!check(now)){
		puts("-1"); return 0;
	}
	ll l=now,r=1e15;
	while(l<r){
		ll mid=(l+r+1)>>1;
		if(check(mid))l=mid;
		else r=mid-1;
	}
	writesp(now); writeln(l);
	return 0;
}

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

int main() {
  int A, B, K, count = 0;
  cin >> A >> B >> K;
  for (int i = A; i > 0; i--) {
    if (A % i == 0 && B % i == 0) count++;
    if (count == K) {
      cout << i << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
board = [[False]*1000001]*1000001
while True:
    m = int(input())
    if m == 0: break
    star = tuple(tuple(map(int, input().split())) for i in range(m))
    sx, sy = star[0]
    
    n = int(input())
    starlist = [tuple(map(int, input().split())) for i in range(n)]
    for i in range(n):
        board[starlist[i][0]][starlist[i][1]] = True
    for i in range(n):
        flag = True
        for j in range(len(star)-1):
            dx = starlist[i][0] + star[j+1][0] - sx
            dy = starlist[i][1] + star[j+1][1] - sy
            if dx < 0 or 1000000 < dx or dy < 0 or 1000000 < dy or board[dx][dy] == False:
                flag = False
                break

        if flag == True:
            print("{} {}".format(starlist[i][0] - sx, starlist[i][1] -sy))
            break
    

Measured memory_bytes: 22432
#include<bits/stdc++.h>
using namespace std;
const int N=205;
char s[N];
int flag[N],a[N];
int main(){
	scanf("%s",s+1);
	if (strlen(s+1)==26){
		int Flag=0;
		for (int i=1;i<=26;i++){
			a[i]=s[i]-'a';
			Flag|=!(a[i]+i==26);
		}
		if (!Flag){
			puts("-1");
			return 0;
		}
		int Max=a[26];
		for (int i=25;i;i--){
			if (Max>a[i]){
				for (int j=1;j<i;j++)putchar(s[j]),flag[s[j]]=1;
				flag[s[i]]=1;
				for (int j=s[i];j;j++)
					if (!flag[j]){
						putchar(j);
						return 0;
					}
			}
			Max=a[i];
		}
	}
	for (int i=1;s[i];i++)flag[s[i]]=1,putchar(s[i]);
	for (int i='a';i;i++)
		if (!flag[i]){
			putchar(i);
			return 0;
		}
}

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

public class Main {
    static int[][] memo;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int K = scanner.nextInt();
        memo = new int[K + 1][K + 1];

        int sum = 0;
        for (int i = 1 ; i <= K ; i++) {
            for (int j = 1 ; j <= K ; j++) {
                for (int k = 1 ; k <= K ; k++) {
                    int[] target = {i, j, k};
                    Arrays.sort(target);
//                    System.out.printf("%d %d %d%n", target[0], target[1], target[2]);
                    sum += gcd(target[2], gcd(target[1], target[0]));
                }
            }
        }
        System.out.println(sum);
    }

    public static int gcd(int a, int b) {
//        System.out.printf("%7d %7d%n", a, b);
        if (memo[a][b] > 0) return memo[a][b];
        if (b == 0) return a;
        return gcd(b, a % b);
    }
}


Measured memory_bytes: 53460
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(i=0; i<n; i++)
#define out(x) cout<<(x)<<"\n"

int main(){
  char c;
  cin>>c;
  if(c=='a' || c=='i' || c=='e' || c=='o' || c=='u'){
    out("vowel");
  }
  else{
    out("consonant");
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
#define met(a,b) memset(a,b,sizeof a)
typedef long long ll;
using namespace std;
const int N = 2e5+10;
const int M = 24005;
const int MOD = 1e9+7;
int h,w,a,b;
ll f[N];
ll finv[N];

ll c(ll n,ll m) {
    ll ret=f[n];
    ret=(ret*finv[n-m])%MOD;
    ret=(ret*finv[m])%MOD;
    return ret;
}

ll calc(ll i,ll j) {
    return c(i+j-2,i-1);
}

ll qp(ll x,ll n) {
    ll ret=1;
    while (n) {
        if (n&1) ret=(ret*x)%MOD;
        n=n>>1;
        x=(x*x)%MOD;
    }
    return ret;
}

int main() {
    scanf("%d%d%d%d",&h,&w,&a,&b);
    memset(f,0,sizeof(f));
    memset(finv,0,sizeof(finv));
    f[0]=finv[0]=1;
    for (int i=1; i<=200000; i++) {
        f[i]=(f[i-1]*i)%MOD;
        finv[i]=qp(f[i],MOD-2);
    }
    ll ans=0;
    for (int i=1; i<=w-b; i++) {
        ans=(ans+(calc(a,i)*calc(h-a,w-i+1))%MOD)%MOD;
        ans=(ans+MOD)%MOD;
    }
    printf("%lld\n",ans);
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  string s;
  cin >> s;
  s.pop_back();
  bool iseven = false;
  while (iseven == false) {
    string a = "", b = "";
    if (s.length() % 2 != 0) {
      s.pop_back();
      continue;
    }
    for (int i = 0; i < s.length(); ++i) {
      if (i < s.length() / 2)
        a += s[i];
      else
        b += s[i];
    }
    if (a == b) {
      iseven = true;
    } else {
      s.pop_back();
    }
  }
  cout << s.size();
  return 0;
}



Measured memory_bytes: 3608
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int[] a = sc.nextIntArray(3);
        int ans = Integer.MAX_VALUE;
        for(int i = 0; i <= 2; i++){
            for(int j = 0; j <= 2; j++){
                for(int k = 0; k <= 2; k++){
                    if(i == j || j == k || k == i) continue;
                    ans = Math.min(ans,Math.abs(a[j]-a[i]) + Math.abs(a[k]-a[j]));
                }
            }
        }
        pw.println(ans);
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

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

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


Measured memory_bytes: 25464
#include <stdio.h>
#include <string.h>

char dict[30600000];

long encode(const char *key){
  int n=strlen(key),i;
  long sum=0;
  long keta=1;
  for(i=0;i<n;i++){
    if (key[i]=='A')      sum = sum + keta * 1;
    else if (key[i]=='C') sum = sum + keta * 2;
    else if (key[i]=='G') sum = sum + keta * 3;
    else if (key[i]=='T') sum = sum + keta * 4;
    keta=keta*5;
  }
  return (sum);
}

void insert(const char *key2) {
  long key=encode(key2);
  dict[key/8]=(dict[key/8]|(1<<(key%8)));
}

int find_h(const char *key2) {
  long key=encode(key2);
  return (dict[key/8] & 1<<(key%8));
}

int main(void) {
  long n,i;
  scanf("%ld\n",&n);
  for(i=0;i<n;i++){
    char cmd[8], str[14]; scanf("%s %s\n",cmd, str);
    if(cmd[0]=='i') {
      insert(str);
    }
    else {
      if(find_h(str)) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

Measured memory_bytes: 1432
char s[];main(){double*q=s,b;for(;~scanf("%s",s);getchar()&2&&printf("%f\n",*q))sscanf(s,"%lf",q+1)-1?b=*q--,*q=*s&1?*s-47?*q+=*s-45?b:-b:*q/b:*q*b:*++q;}

Measured memory_bytes: 0