akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<math.h>
#include<map>
#include<set>
#include<queue>
#include<vector>

using namespace std;



int main() {
	int a, b;
	cin >> a >> b;
	float c = float(2) * b - a;
	cout << c;
}

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

using namespace std;
 
#define vi vector<vector<int> >
#define pb push_back
#define mp make_pair

const int Max = 1e5+5;
int dist[Max];
bool visited[Max];
vi adj(Max);
int indeg[Max]={};

void dfs(int u){
    assert(!visited[u]);
    visited[u]=true;
    for(int d=0;d<adj[u].size();d++){
        int b=adj[u][d];
        dist[b]=max(dist[b],dist[u]+1);
        --indeg[b];
        if(indeg[b]==0){
            dfs(b);
        }
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int s,d;
        cin>>s>>d;
        adj[s].pb(d);
        ++indeg[d];
    }
    memset(visited,false,sizeof(visited));
    for(int i=1;i<=n;i++){
        if(!visited[i] && indeg[i]==0){
            dfs(i);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,dist[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    cout<<fixed;
//    cout<<setprecision(10);

    string a,b;
    cin>>a;
    for (int i=0;i<a.size();i++)
        cout<<'x';
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int a=0;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if(500*i+100*j+50*k==X){
          a++;}
      }
    }
  }
  cout << a << endl;}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int a,b,amari,tmp;

  scanf("%d%d",&a,&b);

  if(a<b){
    tmp=a;
    a=b;
    b=tmp;
  }
  amari=a%b;
  while(amari!=0){
    a=b;
    b=amari;
    amari=a%b;
  }
  printf("%d\n",b);
  
  return 0;
}

  
  



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

int main(){
  ll A,B,C,cnt=0;
  cin >> A >> B >> C;
  if(A==1&&B==1&&C==1){
    cout << "0" << endl;
  }else if(A==B&&B==C&&C==A){
    cout << "-1" << endl;
  }else{
    while(!(A%2)&&!(B%2)&&!(C%2)){
      ll a=0,b=0,c=0;
      a += B/2 + C/2;
      b += A/2 + C/2;
      c += B/2 + A/2;
      A = a;
      B = b;
      C = c;
      ++cnt;
    }
    cout << cnt << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <stack>
#include <bitset>
#include <utility>
#include<iomanip>
// #include <numeric>
using namespace std;



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector<vector<ll>> vvint;
typedef vector<string> vstring;
typedef vector<vector<string>> vvstring;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<long double> vdouble;
typedef vector<vector<long double>> vvdouble;
typedef vector<vector<vector<long double>>> vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INT_MAX 2147483647
#define LLONG_MAX 9223372036854775807
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define DIVIDER 1000000007


//
// struct Node{
//   vint children;
//   ll index;
//   ll prop;
// };



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

// ll X,Y,Z,K;
// ll pmax = 30000000000;
// vint A,B,C;




// int binary_search(int key){
//  //isOKを満たす要素のうち最小のインデックスを返す。（要ソート）
//   int left = -1;
//   int right = N;
//
//   while(right - left > 1){
//     int mid = left + (right - left)/2;
//
//     if(isOK(mid, key)) right=mid;
//     else left=mid;
//   }
//
//   return right;
// }

// ll gcd(ll m, ll n){
//   if(m<n) swap(m,n);
//   if(n==0) return m;
//   return gcd(n, m%n);
// }

ll get_pow(ll x, ll y){
  ll ret=0;
  ll temp = y;
  while(true){
    if(x<=temp) break;
    ret++;
    temp *= 2;
  }
  return ret;
}



int main() {
  cout<<fixed<<setprecision(10);

  ll N,K;
  cin>>N>>K;

  long double ans = 0;

  ll n = get_pow(10,3);

  rep(i, N){
    ans += 1.0/N*pow(0.5, get_pow(K,i+1));
  }

  cout << ans << endl;
}

















//


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

int main() {
  int N;
  cin >> N;
  int64_t ans=1;
  for (int i=1; i<N+1; i++) {
    ans=ans*i;
    ans=ans%1000000007;
  }
  cout << ans << endl;
}

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

int gcd(long int x,long int y) {
  if(y == 0) {
    return x;
  }
  else {
    return gcd(y,x%y);
  }
}

int main() {
  long int x,y;
  cin >> x >> y;

  cout << gcd(x,y) << endl;
  return 0;
}

Measured memory_bytes: 1160
#!/usr/bin/env pytHon3
# -*- coding: utf-8 -*-


def main():
    N, T = map(int, input().split())
    t = list(map(int, input().split()))

    result = T
    for i in range(1, N):
        result += min(T, t[i] - t[i - 1])
    print(result)


if __name__ == "__main__":
    main()


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

int main() {
  int N, K, x, s = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x < (K - x)) {
      s += 2 * x;
    } else {
      s += 2 * (K - x);
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define rrep(i,m,n) for(int i = m; i >= n; i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;
ll N;
ll a[25][25];
ll dp[25][1LL<<22] = {};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i,0,N){
        rep(j,0,N){
            cin >> a[i][j];
        }
    }
    dp[0][0] = 1;
    rep(bit,0,(1LL<<N)){
        ll i = __builtin_popcount(bit);
        // if(__builtin_popcount(bit) != i) continue; //ペアリングが一致していない時
        rep(j,0,N){
            if(a[i][j] == 1 && (((bit << j) & 1) == 0)){
                dp[i+1][bit | (1 << j)] += dp[i][bit] % MOD;
                dp[i+1][bit | (1 << j)] %= MOD;
            }
        }
    }
    print(dp[N][(1LL<<N) - 1]);

}


Measured memory_bytes: 338176
A = [[1,3,5,7,8,10,12],[4,6,9,11],[2]]
x,y = map(int, input().split())
flg = 0
for a in A:
    if x in a and y in a:
        flg = 1

if flg == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
	int a,b,k,i,count=0,max;
	scanf("%d %d %d",&a,&b,&k);
	if(a>b){
		max=a;
	}else{
		max=b;
	}
	for(i=max;i>0;i--){
		if(a%i==0&&b%i==0){
			count+=1;
			if(k==count){
				printf("%d\n",i);
			}
		}
	}
}

Measured memory_bytes: 128
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
    }

    if (s == "AAA".to_string()) | (s == "BBB".to_string()) {
        println!("No");
    } else {
        println!("Yes")
    }
}


Measured memory_bytes: 4352
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

mod = 10 ** 9 + 7
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]

ans = 0

def comb(n, r):
  if n >= r:
    return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod
  else:
    return 0
 
for i in range(2, N + 1):
  fac.append( ( fac[-1] * i ) % mod )
  inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) )
  finv.append( finv[-1] * inv[-1]  % mod )

if K == 1:
  print(0)
else:
  for i, x in enumerate(A):
    cnt = x * ( comb(i, K-1) - comb(N-1-i, K-1) ) % mod
    ans += cnt
    ans %= mod
  print(ans)

Measured memory_bytes: 104340
from collections import deque
s = deque(list(input()))
q = int(input())
cnt = 1
for _ in range(q):
    query = input()
    if len(query)==1:
        cnt = 1-cnt
    else:
        f = query[2]
        c = query[-1]
        if cnt:
            if f =='1':
                s.appendleft(c)
            else:
                s.append(c)
        else:
            if f=='1':
                s.append(c)
            else:
                s.appendleft(c)
print(''.join(s) if cnt else ''.join(s)[::-1])

Measured memory_bytes: 103460
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner in= new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();
	String s;

	if (a < b && b < c)
		s = "Yes";
	else
		s = "No";
        System.out.printf("%s%n", s);
    }   
}

Measured memory_bytes: 17312
unittest
{
	assert( [ "1", "100", "30" ].parse.expand.solve == "2100.000" );
	assert( [ "2", "60 50", "34 38" ].parse.expand.solve == "2632.000" );
	assert( [ "3", "12 14 2", "6 2 7" ].parse.expand.solve == "76.000" );
	assert( [ "1", "9", "10" ].parse.expand.solve == "20.250" );
	assert( [ "10", "64 55 27 35 76 119 7 18 49 100", "29 19 31 39 27 48 41 87 55 70" ].parse.expand.solve == "20291.000" );
}



import std.algorithm;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto ts = input.front.split.to!( long[] );
	input.popFront;
	auto vs = input.front.split.to!( long[] );
	return tuple( ts, vs );
}

auto solve( long[] ts, long[] vs )
{
	// 速度上限配列から時間基準の速度配列を作成
	auto ss = new double[ 100 * 200 * 2 + 2 ];
	auto tt = 1L;
	ss[ 0 ] = 0;
	foreach( t, v; lockstep( ts, vs ) )
	{
		auto t2 = t * 2;		// 奇数秒を2で割る場合があるので、時間を0.5秒区切りにして整数で扱えるようにする
		ss[ tt - 1 ] = min( ss[ tt - 1 ], v );
		ss[ tt .. tt + t2 ] = v;
		tt += t2;
	}
	ss.length = tt;
	ss[ 0 ] = 0;
	ss[ $ - 1 ] = 0;
	
	// 加速を計算
	for( auto i = 0L; i < ss.length.signed - 1; i++ )
	{
		if( ss[ i ] < ss[ i + 1 ] ) ss[ i + 1 ] = ss[ i ] + 0.5;		// 時間が0.5秒区切りなので1m/s^2の半分を加算
	}
	
	// 減速を計算
	for( auto i = ss.length.signed - 1; 0 < i; i-- )
	{
		if( ss[ i ] < ss[ i - 1 ] ) ss[ i - 1 ] = ss[ i ] + 0.5;
	}
	
	// 速度変更のタイミングを抽出
	double[] pts;
	double[] pvs;
	double[] pas;
	auto a = 2.0;
	foreach( i, s; ss[ 0L .. $ - 1 ] )
	{
		auto b = sgn( ss[ i + 1 ] - ss[ i ] );
		if( a == b ) continue;
		pts ~= i / 2.0;		// 時間を0.5秒区切りから1秒区切りに戻す
		pvs ~= ss[ i ];
		pas ~= b;
		a = b;
	}
	pts ~= ( ss.length.signed - 1 ) / 2;
	pvs ~= 0;
	pas ~= 0;
	
	// 合計距離を計算
	auto ans = 0.0;
	for( auto i = 0L; i < pts.length.signed - 1; i++ )
	{
		auto t = pts[ i + 1 ] - pts[ i ];
		ans += pvs[ i ] * t + 0.5 * pas[ i ] * ( t ^^ 2 );
	}
	return format( "%0.3f", ans );
}


Measured memory_bytes: 2556
#include <iostream>
#include <vector>
#include <deque>

#define K_MAX 100000
#define INF 1000000

using namespace std;

int main() {
  int K;
  vector<int> dist;
  deque<int> queue;
  int update;

  scanf("%d", &K);
  dist.resize(K);

  for(int i=0; i<K; i++) {
    dist[i] = INF;
  }
  dist[1] = 0;
  queue.push_front(1);

  while(!queue.empty()) {
    int i, j;
    i = queue.front();
    queue.pop_front();

    j = (i + 1) % K;
    if(dist[j] > dist[i] + 1){
      dist[j] = dist[i] + 1;
      queue.push_back(j);
    }

    j = (i * 10) % K;
    if(dist[j] > dist[i]) {
      dist[j] = dist[i];
      queue.push_front(j);
    }
  }

  printf("%d\n", dist[0] + 1);

  return 0;
}


Measured memory_bytes: 896
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int x = max(a, c);
	int y = min(b, d);

	int f = y - x;
	if (f < 0)
	{
		f = 0;
	}

	cout << f << endl;
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int k; cin >> k;
    int a, b; cin >> a >> b;

    for (int i = 1; i <= 1000; ++i) {
        int c = k * i;
        if (a <= c && c <= b) {
            puts("OK");
            return 0;
        }
    }

    puts("NG");
}

Measured memory_bytes: 3620
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int a, b; cin >> a >> b;
	vector<string> res;
	rep(i, 50)
	{
		string s = "";
		rep(j, 100)s += '.';
		res.push_back(s);
	}
	rep(i, 50)
	{
		string s = "";
		rep(j, 100)s += '#';
		res.push_back(s);
	}
	int x = 0;
	int y = 0;
	--a, --b;
	while (b > 0)
	{
		if (y >= 100)
		{
			x += 2;
			y = 0;
		}
		res[x][y] = '#';
		y += 2;
		--b;
	}
	x = 51;
	y = 0;
	while (a > 0)
	{
		if (y >= 100)
		{
			x += 2;
			y = 0;
		}
		res[x][y] = '.';
		y += 2;
		--a;
	}
	cout << 100 << " " << 100 << endl;
	rep(i, 100)cout << res[i] << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt(), y = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
		int p[] = new int[a];
		int q[] = new int[b];
		int r[] = new int[c];
		for (int i = 0; i < a; ++i)
			p[i] = sc.nextInt();
		Arrays.sort(p);
		for (int i = 0; i < b; ++i)
			q[i] = sc.nextInt();
		Arrays.sort(q);
		for (int i = 0; i < c; ++i)
			r[i] = sc.nextInt();
		Arrays.sort(r);
		sc.close();
		int pp = a - 1, pq = b - 1, pr = c - 1;
		long ans = 0;
		for (int i = 0; i < x + y; ++i) {
			int pd = (pp >= a - x ? p[pp] : 0);
			int qd = (pq >= b - y ? q[pq] : 0);
			int rd = (pr >= 0 ? r[pr] : 0);
			int max = Math.max(pd, qd);
			max = Math.max(max, rd);
			// System.out.println(pd + " " + qd + " " + rd + " " + max + " ??");
			ans += (long) max;
			if (pd == max)
				pp--;
			else if (qd == max)
				pq--;
			else if (rd == max)
				pr--;
			// System.out.println(pp + " " + pq + " " + pr + " " + max + " //");
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 95016
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;

const int MAXN = 200000 + 10;
const int MAXL = 100000 + 10;

struct DSU
{
    int fa[MAXN];

    int find(int x)
    {
        if(x == fa[x])
            return x;
        return fa[x] = find(fa[x]);
    }

    void merge(int x, int y)
    {
        fa[find(x)] = find(y);
    }
}d1, d2;

int tmp[MAXN], ans[MAXN], cnt[MAXN];

void init(DSU & d)
{
    for(int i = 0; i < MAXN; i++)
        d.fa[i] = i;
}

int N, K, L;
int main()
{
    init(d1);
    init(d2);
    int u, v;
    cin >> N >> K >> L ;

    for(int i = 1; i <= K; i++)
        cin >> u >> v, d1.merge(u, v);
    for(int i = 1; i <= L; i++)
        cin >> u >> v, d2.merge(u, v);

    for(int i = 1; i <= N; i++)
        d1.fa[i] = d1.find(i),
        d2.fa[i] = d2.find(i);
    for(int i = 1; i <= N; i++)
        tmp[i] = i;
    sort(tmp+1, tmp+N+1, [](int x, int y)-> bool {return d1.fa[x] < d1.fa[y];});


    for(int i = 1; i <= N; i++)
    {
        int j = i;
        while(j < N && d1.fa[tmp[j]] == d1.fa[tmp[j+1]])
            j++;

        for(int t = i; t <= j; t++)
            cnt[d2.fa[tmp[t]]]++;
        for(int t = i; t <= j; t++)
            ans[tmp[t]] = cnt[d2.fa[tmp[t]]];
        for(int t = i; t <= j; t++)
            cnt[d2.fa[tmp[t]]]--;
        i = j ;
    }

    for(int i = 1; i <= N; i++)
        cout << ans[i] << " " ;

    return 0;
}


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

int main() {
  int A, B, C, N;
  cin >> A >> B >> C >> N;
  if (N <= A) {
    cout << N << endl;
  } else if (N <= A+B) {
    cout << A << endl;
  } else {
    cout << A - (N - A - B) << endl;
  }
}

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

using namespace std;

long long solve(long long N)
{
	long long ans = N;
	for (long long x = 1; x * x <= N; ++x) {
		if (N % x == 0) {
			long long y = N / x;
			ans = min(ans, x - 1 + y - 1);
		}
	}
	return ans;
}

int main()
{
	long long N;
	cin >> N;
	cout << solve(N) << endl;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

int N,M;
vector<vector<int>> adj;

LL ans = 0;

void search(int now,int used){
	if(used==(1<<N)-1){
		//cout << "finish:" << now << endl;
		ans++;
	}
	for(int next : adj[now]){
		if(!((used>>(next-1))&1)){
			//cout << now <<"->" << next << endl;
			search(next,used + (1<<(next-1)));
		}
	}
}

void solve(){
	search(1,1);
}
 
int main(){
    cin >> N >> M;
    adj = vector<vector<int>>(N+1);
    for(int i=0;i<M;i++){
    	int a,b;cin >> a >> b;
    	adj[a].push_back(b);
    	adj[b].push_back(a);
    }
 
    solve();

    cout << ans << endl;
    return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k ;
    int i,j;
    j=0;
    i=-1;
    while(j==0){
        if ((int)pow(k,i)>n){
            break;
        }
        ++i;

    }
    cout << i << endl;
    

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

bool in_range(ll v, ll n) {
    if (v >= 0 && v < n) return true;
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    ll n, ans = 0;
    cin >> n;
    vector<ll> a(n), l(n), r(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a.at(i);
        if (in_range(i + a.at(i), n)) ++l.at(i + a.at(i));
        if (in_range(i - a.at(i), n)) ++r.at(i - a.at(i));
    }
    for (ll i = 0; i < n; ++i) ans += l.at(i) * r.at(i);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7956
#-*- coding:utf-8 -*-

#入力数値を分単位に変更
def convert_time(n):
    return (n/100)*60 + n%100

#コマーシャルの共通部分を返す
def kyotsu(cm1,cm2):
    result = []
    for i in range(len(cm2)/2):
        #cm2の各CMとかぶっている部分を取得
        for j in range(len(cm1)/2):
            stt = max(cm2[i*2],cm1[j*2])
            edt = min(cm2[i*2+1],cm1[j*2+1])
            if edt - stt > 0:
                result.append(stt)
                result.append(edt)

    return result

#コマーシャルを見ずにテレビを見られる最長時間を求める
while 1:
    cond = [int(r) for r in raw_input().split()]
    if cond[0]==cond[1]==cond[2]==0: #入力がすべて0なら終了
        break

    #開始時間、終了時間を算出
    start = convert_time(cond[1])
    end = convert_time(cond[2])

    cms = []
    #各チャンネルのコマーシャル時間を求める
    for i in range(cond[0]):
        n = int(raw_input()) #コマーシャル数
        input = [convert_time(int(r)) for r in raw_input().split()]
        j=0
        cmstmp = []
        while j < n:
            st = input[2*j]
            ed = input[2*j+1]
            if not i:
                cms.append(st)
                cms.append(ed)
            else:
                cmstmp.append(st)
                cmstmp.append(ed)
            j += 1
        if i > 0:
            cms = kyotsu(cms,cmstmp)


    #cmsを利用してコマーシャルを見なくてすむ最大時間を出力
    cms = [start] + cms + [end]
    print max([cms[i*2+1]-cms[i*2] for i in range(len(cms)/2)])

Measured memory_bytes: 4308
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lld long double
#define w(x) ll x;cin>>x;while(x--)
#define mod 1000000007
#define speed ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;

int main(){
    speed;
    int n;  cin>>n;
    int x=0;
    while(x<n){
        x+=1000;
    }
    cout<<x-n<<'\n';
    return 0;
}

Measured memory_bytes: 3652
//h16-1 オレンジの出荷
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#include <boost/multiprecision/cpp_int.hpp>
namespace boost_multiprecision = boost::multiprecision;
#define LL long long
#define CINT boost_multiprecision::cpp_int
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775807
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int N,M;
LL K;
vector<LL> A;

LL dp[20000];
LL dp2[20000][1001];

LL solve(int now){
    if(now == N) return 0;
    if(dp[now] != LL_MAX) return dp[now];

    LL re = LL_MAX;
    for(int i=1; i<M+1; i++){
        if(now+i > N) break;
        re = min(re, solve(now+i) + i * dp2[now][i] + K);
    }
    dp[now] = re;
    //cout << now << " " << re << endl;
    return re;
}

int main(){
    cin >> N >> M >> K;
    for(int i=0; i<N; i++){
        LL tmp;
        cin >> tmp;
        A.push_back(tmp);

        dp[i] = LL_MAX;
    }

    for(int i=0; i<N; i++){
        LL ma = LL_MIN+1;
        LL mi = LL_MAX-1;
        for(int j=1; j<M+1; j++){
            if(i+j > N) break;
            ma = max(ma, A[i+j-1]);
            mi = min(mi, A[i+j-1]);
            dp2[i][j] = ma - mi;
            //cout << i << " " << j << " " << ma << " " << mi;
        }
    }

    cout << solve(0) << endl;

    return 0;
}



Measured memory_bytes: 160176
def lcs(S, T):
    dp = [[0]*(len(T)+1) for _ in range(len(S)+1)]
    for i in range(1,len(S)+1):
        for j in range(1,len(T)+1):
            dp[i][j] = max(dp[i][j-1], dp[i-1][j], dp[i-1][j-1] + (S[i-1]==T[j-1]))

    res = []
    x,y = len(S),len(T)
    v = dp[x][y]
    while v > 0:
        if dp[x-1][y] == v:
            x -= 1
        elif dp[x][y-1] == v:
            y -= 1
        else:
            res.append(S[x-1])
            x -= 1
            y -= 1
        v = dp[x][y]
    return ''.join(reversed(res))

####################################################################################################################
import sys
input = sys.stdin.readline

S,T = input(),input()
print(lcs(S,T))

Measured memory_bytes: 144688
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
#include <algorithm>
#include <string>


using namespace std;
using ll = long long;
using ull = unsigned long long;


#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)

int main() {
	int ans = 0;
	int N, K;
	vector<int> x;
	cin >> N >> K;

	x.resize(N);
	rep(i, 0, N) {

		cin >> x.at(i);
	}


	rep(i, 0, N) {
		ans += 2 * min(K - x.at(i), x.at(i));
	}



	cout << ans << endl;
	

	return 0;
}



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

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

const long long MOD = 1000000007;

int main(){
  double r;
  cin >> r;
  cout << fixed << setprecision(6);
  cout << 2*r*3.141592 << endl;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

int main(){
    int n;
    scanf("%d", &n);
    lint a[n];
    lint x = 0;
    int d[n];
    rep(i, n){
        scanf("%lld", &a[i]);
        x ^= a[i];
        int j = 0;
        while(!((a[i]>>j)&1)) ++j;
        d[i] = j;
    }
    sort(d, d+n, greater<>());
    int ans = 0;
    rep(i, n){
        if((x>>d[i])&1){
            x ^= (1<<(d[i]+1)) - 1;
            ++ans;
        }
    }
    printf("%d\n", x ? -1 : ans);
}

Measured memory_bytes: 1408
a = list(input())
ans = 0
for i in range(1<<(len(a)-1)):
  s = a[0]
  for j in range(len(a)-1):
    if (i >> j) & 1:
      s += "+"
    s += a[j+1]
  ans += eval(s)

print(ans)
      
      
      
  

Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
ll n,k;
int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    ll ans=n%k;
    ans=min(ans,abs(ans-k));
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
//AOJ0338.cpp

#include <iostream>
using namespace std;

int gcd(int m,int n){
  if(n==0)
    return m;

    return gcd(n,m%n);
}

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

  int g = gcd(W,H);

  cout << W/g*H/g*C <<endl;

  return 0;
}

Measured memory_bytes: 3084
(a,b,h,m)=gets.split.map(&:to_i)

r0 =  (h/12.0 + m / 60.0 / 12 ) * 2 * Math::PI
r1 =  (m / 60.0) * 2 * Math::PI

x0 = Math.sin(r0)*a
y0 = Math.cos(r0)*a

x1 = Math.sin(r1)*b
y1 = Math.cos(r1)*b

print Math.sqrt((x0-x1)**2 + (y0-y1)**2)

Measured memory_bytes: 14816
#include <bits/stdc++.h>
using namespace std;
int pow2(int x){
  int ans = 1;
  for (int i = 0; i < x; i++){
    ans *= 2;
  }
  return ans;
}
int pow3(int x){
  int ans = 1;
  for (int i = 0; i < x; i++){
    ans *= 3;
  }
  return ans;
}
string ternary(int x, int L){
  string ans;
  for (int i = 0; i < L; i++){
    ans += x % 3 + '0';
    x /= 3;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
int main(){
  int N;
  cin >> N;
  string S = to_string(N);
  int L = S.size();
  int ans = 0;
  for (int i = 1; i < L; i++){
    ans += pow3(i) - pow2(i) * 3 + 3;
  }
  for (int i = 0; i < pow3(L); i++){
    string T = ternary(i, L);
    string tmp;
    int cnt7 = 0;
    int cnt5 = 0;
    int cnt3 = 0;
    for (int j = 0; j < L; j++){
      if (T[j] == '0'){
        tmp += '7';
        cnt7++;
      }
      if (T[j] == '1'){
        tmp += '5';
        cnt5++;
      }
      if (T[j] == '2'){
        tmp += '3';
        cnt3++;
      }
    }
    if (cnt7 > 0 && cnt5 > 0 && cnt3 > 0 && tmp <= S){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
l = list(input().split())
ll,lr = l[::2],l[1::2]
dl,dr = {},{}
for i in ll: dl[i] = dl.get(i,0)+1
for j in lr: dr[j] = dr.get(j,0)+1
ltl = sorted(dl.items(),key=lambda k:-k[1])
ltr = sorted(dr.items(),key=lambda k:-k[1])
if ltl[0][0] != ltr[0][0]:
  print(n-ltl[0][1]-ltr[0][1])
elif len(ltl)<2:
  print(n//2)
else:
  print(n-ltl[0][1]-max(ltl[1][1],ltr[1][1]))

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

int h, w, c = 0;
int l[2000][2000], r[2000][2000], u[2000][2000], d[2000][2000];
string s[2000];

int main()
{
	cin >> h >> w;

	for (int i = 0; i < h; i++)
		cin >> s[i];

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '.') {
				if (j == 0)
					l[i][j] = 1;
				else
					l[i][j] = l[i][j - 1] + 1;
			}
			else
				l[i][j] = 0;
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = w - 1; j >= 0; j--) {
			if (s[i][j] == '.') {
				if (j == w - 1)
					r[i][j] = 1;
				else
					r[i][j] = r[i][j + 1] + 1;
			}
			else
				r[i][j] = 0;
		}
	}

	for (int j = 0; j < w; j++) {
		for (int i = 0; i < h; i++) {
			if (s[i][j] == '.') {
				if (i == 0)
					u[i][j] = 1;
				else
					u[i][j] = u[i - 1][j] + 1;
			}
			else
				u[i][j] = 0;
		}
	}

	for (int j = 0; j < w; j++) {
		for (int i = h - 1; i >= 0; i--) {
			if (s[i][j] == '.') {
				if (i == h - 1)
					d[i][j] = 1;
				else
					d[i][j] = d[i + 1][j] + 1;
			}
			else
				d[i][j] = 0;
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '.')
				c = max(c, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
		}
	}

	cout << c << endl;

	return 0;
}

Measured memory_bytes: 66816
N,D,A=map(int,input().split())
D*=2 # 爆発の長さ
X=[None]*N
for i in range(N):
  X[i]=list(map(int,input().split()))

X=sorted(X,key=lambda x:x[0])
lastX=X[-1][0] # 最後のモンスターの場所
from collections import defaultdict
damage=defaultdict(int)
ans=0
for i in range(len(X)):
  x=X[i][0]
  if X[i][1]>0:
    dele=set()
    for d in damage.items():
      if d[0]<x:
        dele.add(d[0])
      else:
        X[i][1]-=d[1]
        if X[i][1]<=0:
          break
    for p in dele:
      del damage[p]
  if X[i][1]>0:
    turn=(X[i][1]+A-1)//A
    if x+D>lastX:
      damage[lastX]+=turn*A
    else:
      damage[x+D]=turn*A
    ans+=turn
print(ans)


Measured memory_bytes: 56784
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		int min = Integer.MAX_VALUE;
		for (int i = 2; i < s.length; i++) {
			int x = (s[i-2]-'0')*100+(s[i-1]-'0')*10+(s[i]-'0');
			min = Math.min(min,Math.abs(753-x));
		}
		System.out.println(min);
		sc.close();
	}
}

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

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

    int n;
    cin >> n;

    vector<int64_t> x(n), s(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> s[i + 1];
        s[i + 1] += s[i];
    }

    vector<int> l(n), r(n);
    int i1;
    int64_t m;

    i1 = -1;
    for (int i = 0; i < n; i++) {
        int64_t t = -(s[i] - x[i]);
        if (i1 < 0 || t > m) {
            m = t;
            i1 = i;
        }
        l[i] = i1;
    }
    i1 = -1;
    for (int i = n - 1; i >= 0; i--) {
        int64_t t = s[i + 1] - x[i];
        if (i1 < 0 || t > m) {
            m = t;
            i1 = i;
        }
        r[i] = i1;
    }

    int64_t ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, (s[r[i] + 1] - x[r[i]]) - (s[l[i]] - x[l[i]]));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
function main()
  
  (N,T) = map(x -> parse(Int,x), split(readline()))
  
  
  ans = 10000
  
  for i in 1:N
    
    (c,t) = map(x -> parse(Int,x), split(readline()))
    
    if t <= T
      ans = min(ans,c)
    end
    
  end
  
  if ans == 10000
    println("TLE")
  else
    println(ans)
  end
  
end

main()

Measured memory_bytes: 115956
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    StringBuffer buf = new StringBuffer();
    buf.append(str[0].substring(0,1));
    buf.append(str[1].substring(0,1));
    buf.append(str[2].substring(0,1));
    System.out.println(buf.toString().toUpperCase());
  }
}

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

int main() {
  int k;
  cin >> k;
  
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a[k - 1] << endl;


  
  return 0;
}

Measured memory_bytes: 256
k = int(input())
a, b = map(int, input().split())

x = 0

# rangeは最後を取らない
for i in range(b - a + 1):
    # print(i)
    # print(i, b-a)
    # print("a")
    if a % k == 0:
        x = 1
        break
    # print(x)
    a += 1

# print(x)
if(x == 1):
    print('OK')
else:
    print('NG')

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

const int MOD = 1000000007;

char a[1010][1010];
long dp[1010][1010];

template<class T> void add_mod(T &a, const T b){
	a += b;
	if(a >= MOD) a -= MOD;
}

int main(){
	int h, w;
	scanf("%d%d", &h, &w);
	for(int i=0; i < h; i++) scanf("%s", a[i]);
	dp[0][0] = 1;
	for(int i=0; i < h; i++) {
		for(int j=0; j < w; j++) {
			if(a[i][j] == '#') continue;
			if(i-1 >= 0) add_mod(dp[i][j], dp[i-1][j]);
			if(j-1 >= 0) add_mod(dp[i][j], dp[i][j-1]);
		}
	}
	printf("%ld\n", dp[h-1][w-1]);
}

Measured memory_bytes: 9216
#include <iostream>
using namespace std;
unsigned long long n,q,h,s,d;
unsigned long long khuye[120000000];
int main()
{
    cin>>q>>h>>s>>d;
    cin>>n;
    h=min(h,2*q);
    s=min(s,2*h);
    d=min(d,s*2);
    cout<<n/2*d+n%2*s;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(),x.end()

int main(){
  ll n;
  cin >> n;
  if(n<=9){
    cout << n << endl;
  }
  else if(n<100){
    cout << 9 << endl;
  }
  else if(n<=999){
    cout << n-90 << endl;
  }
  else if(n<10000){
    cout << 909 << endl;
  }
  else if(n<=99999){
    cout << n-9090 << endl;
  }
  else{
    cout << 90909 << endl;
  }
}

Measured memory_bytes: 256
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n, m, k = map(int, input().split())
    fgraph = [list() for i in range(n)]
    bgraph = [list() for i in range(n)]
    cgraph = [list() for i in range(n)]
    
    rks = [None] *n
    sys.setrecursionlimit(10**9)
    # r: どの連結成分に存在するかをメモするid
    def dfs(graph,s,r):
        if rks[s] is None:
            rks[s] = r
        for i in range(len(graph[s])):
            if rks[graph[s][i]-1] is not None:
                continue
            dfs(graph, graph[s][i]-1,r)

    for i in range(m):
        a,b = map(int, input().split())
        fgraph[a-1].append(b)
        fgraph[b-1].append(a)

    # print(fgraph)
    #print(bgraph)
    # 連結成分に対してid的なindexをつける
    c = -1
    for i in range(n):
        if rks[i] is None:
            c += 1
            dfs(fgraph, i, c)
    
    for i in range(k):
        c,d = map(int, input().split())
        if rks[c-1] == rks[d-1]:
            bgraph[d-1].append(c)
            bgraph[c-1].append(d)

    counter = Counter(rks)
    for i in range(n):
        # counter[rks[i]] 連結成分のサイズ
        # len(fgraph[i]) 友達の数
        # len(bgraph[i]) 連結成分内のブロックの数
        # 1 自分
        print(counter[rks[i]] - len(fgraph[i]) - len(bgraph[i]) - 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 66768
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	string s;
	int A, Z;
	
	cin >> s;

	rep(i, s.length()) {
		if (s[i] == 'A') {
			A = i;
			break;
		}
	}

	rrep(i, s.length()) {
		if (s[i] == 'Z') {
			Z = i;
			break;
		}
	}

	cout << Z - A + 1 << endl;

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long int
using namespace std;

ll fastExp(ll exp)
{
	ll result = 1;
	ll base = 2;
	while(exp > 0)
	{
		if(exp % 2 == 1)
			result = result * base;
		base = base * base;
		exp = exp / 2;
	}
	return result;
}

int main()
{
    ll n;
    cin >> n;

    ll count = 0;
    while(n > 0)
    {
    	n = n / 2;
    	count ++;
    }
    cout << fastExp(count) - 1 << endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

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

	int n;
	cin >> n;

	vector<int> g[n];
	vector<pii> es;

	rep(i, n-1){
		int a, b;
		cin >> a >> b;
		a--; b--;
		if(b < a) swap(a, b);
		g[a].push_back(b);
		g[b].push_back(a);
		es.push_back({a, b});
	}

	vector<bool> visited(n, false);
	queue<int> q;
	q.push(0);
	visited[0] = true;

	int cur = 1;
	vector<int> cs(n, 0);


	int K = 0;
	map<pii, int> col;

	while(!q.empty()){
		int p = q.front(); q.pop();
		if(K < g[p].size()) K = g[p].size();

		int cur = 1;
		for(int x: g[p]){
			if(visited[x]) continue;
			if(cur == cs[p]) cur++;
			cs[x] = col[(pii){p, x}] = col[(pii){x, p}] = cur;
			cur++;
			visited[x] = true;
			q.push(x);
		}
	}

	cout << K << endl;
	for(pii e : es) cout << col[e] << endl;
}


Measured memory_bytes: 19704
#include<bits/stdc++.h>
using namespace std;
int n,m,len,X,Y;
int U,L,R,D;
char s1[202020],s2[202020];
int main()
{
	scanf("%d%d%d%d%d",&n,&m,&len,&X,&Y);
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	for (int i=len;i>=1;--i)
	{
		if (s2[i]=='L') R=max(0,R-1);
		if (s2[i]=='R') L=max(0,L-1);
		if (s2[i]=='U') D=max(0,D-1);
		if (s2[i]=='D') U=max(0,U-1);

		if (s1[i]=='L') ++L;
		if (s1[i]=='R') ++R;
		if (s1[i]=='U') ++U;
		if (s1[i]=='D') ++D;

		if (U+D==n || L+R==m)
		{
			printf("NO\n");
			return 0;
		}
	}
	if (X<=U || X>=n-D+1) 
	{
		printf("NO\n");
		return 0;
	}
	if (Y<=L || Y>=m-R+1)
	{
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#define INF 100000000000
int main(){
    int N ;
    scanf("%d",&N);
    int i;
    int data[100010];
    for(i=0;i<N;i++){
        data[i] = 0;
    }
    
    for(int i=0;i<N;i++){
        scanf("%d",&data[i]);
    }   
    long long dP[100010];
    for(i=0;i<N;i++)dP[i]=INF;
    dP[0] = 0;
    dP[1] = abs(data[1]-data[0]);
    for(i=2;i<N;i++){
        if(dP[i-1]+abs(data[i-1]-data[i])>dP[i-2]+abs(data[i-2]-data[i])){
            dP[i] = dP[i-2]+abs(data[i-2]-data[i]);
        }else dP[i] = dP[i-1]+abs(data[i-1]-data[i]);
    }
    printf("%lld\n",dP[N-1]);
    
    return 0;
}



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

int calcDigitSum(int n) {
  int digitSum = 0;
  string s = to_string(n);
  for (char c: s) {
    digitSum += c - '0';
  }
  return digitSum;
}

int main() {
  int N;
  cin >> N;
  
  int a, b, tmp;
  int min = 108;
  for (a = 1; a < N; a++) {
    b = N - a;
    tmp = calcDigitSum(a) + calcDigitSum(b);
    if (tmp < min) {
      min = tmp;
    }
  }
  
  cout << min << endl;
}


Measured memory_bytes: 3648
# editorialコピペ
n = int(input())
e = [0] * (n+1)
for i in range(2, n+1):
    cur=i
    for j in range(2, n+1):
        while cur % j==0:
            e[j] += 1
            cur //= j

def num(m):
    return len(list(filter(lambda x:x>=m-1, e)))

print(num(75) + num(25) * (num(3) -1) + num(15) * (num(5)-1) + num(5) * (num(5)-1)* (num(3)-2)//2)

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

using namespace std;

int main(void){
  int n, k;
  cin >> n >> k;
  int ans = 0;
  
  vector<int> x(n);
  
  for(int i = 0;i < n;i++) cin >> x[i];
  
  for(int i = 0;i < n;i++){
    if(abs(k-x[i]) < abs(x[i])) ans += 2*abs(k-x[i]);
    else ans += 2*x[i];
  }
  
  cout << ans << endl;
}

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();
    List<Integer> arr = new ArrayList<>();
    for(int i = 0; i < n; i++) {
      arr.add(0, sc.nextInt());
    }
    for(int i = 0; i < n; i++) {
      if(i == n - 1) {
        System.out.println(arr.get(i));
      } else {
      System.out.print(arr.get(i) + " ");}
    }
  }
}



Measured memory_bytes: 26268
x = int(input())

def is_prime(x):
    if x == 1:
        return False
    
    for i in range(2,int(x**0.5)+1):
        if x % i == 0:
            return False
    return True

while True:
    if is_prime(x):
        print(x)
        break
    x += 1

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

#define select(_1, _2, x, ...) x

#define repn(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, ...) select(__VA_ARGS__, repr, repn)(i, __VA_ARGS__)

#define rrepn(i, n) for (int i = (n - 1); i >= 0; i--)
#define rrepr(i, a, b) for (int i = (b - 1); i >= (a); i--)
#define rrep(i, ...) select(__VA_ARGS__, rrepr, rrepn)(i, __VA_ARGS__)

#define umax(m, x) (m = max(m, x));
#define umin(m, x) (m = min(m, x));

#define rng(v) v.begin(), v.end()
#define rrng(v) v.rbegin(), v.rend()

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;

using ll = long long int;

using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;

using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;

const int INF = 1e9;
const ll LINF = 1e18;

inline void yn(bool f) { cout << (f ? "Yes" : "No") << endl; }


int main() {
    ll x;
    cin >> x;

    ll a = 100;
    ll cnt = 0;
    while (a < x) {
        a *= 1.01;
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan =  new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        ArrayList<Integer>[] list = new ArrayList[n];
        for(int i=0;i<n;i++){
            ArrayList<Integer> sublist =  new ArrayList<>();
            list[i] = sublist;
        }

        for(int i=0;i<m;i++){
            int u = scan.nextInt() - 1;
            int v = scan.nextInt() - 1;
						list[u].add(v);
						list[v].add(u);
        }

        Queue<Integer> queue = new ArrayDeque<>();

				queue.add(0);

				int[] visit =  new int[n];
				visit[0]=1;
				int[] bef =  new int[n];

        while(!queue.isEmpty()){
					int from = queue.poll();
						for (int i=0;i<list[from].size();i++){
							int lf = list[from].get(i);
							if ( visit[lf] == 0){
								bef[lf] = from;
								visit[lf] = 1;
								queue.add(lf);
							}
						}
				}
				
				System.out.println("Yes");
				for(int i=1;i<bef.length;i++){
					System.out.println(bef[i]+1);
				}

    }
}


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


int main() {
    int A,B;
    cin>>A>>B;
    for(int i=1;i<=1000;i++){
        if(floor(i*0.08)==A&&floor(i*0.1)==B){
            cout<<i<<endl;
            return 0;
    }
}
cout<<-1<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iomanip>
using namespace std;

int main(void)
{
    long long a;
    long double b;

    cin >> a >> b;
    cout.setf(ios::fixed);
    cout << setprecision(0) << floor(a * b) << endl;

    return 0;
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
int n;
char a[110],b[110];
int main(){
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	for(int i=1;i<=n;++i)
		cin>>b[i];
	for(int i=1;i<=n;++i)
		cout<<a[i]<<b[i];
	return 0;
}

Measured memory_bytes: 256
N=int(input())
S=list(map(int,input().split()))
S.sort()
p = [S.pop(-1)]
r = S

for i in range(N):
    nr = []
    for p_ in p[::-1]:
        while r:
            r_ = r.pop()
            if r_ < p_:
                p.append(r_)
                break
            nr.append(r_)
    p.sort()
    r+=nr[::-1]

print("Yes" if len(r)==0 else "No")


Measured memory_bytes: 33964
N = int(input())
for h in range(1, 3501):
    for w in range(1, 3501):
        b = 4*h*w - N*(h+w)
        if b == 0: continue
        a = N*h*w
        n = a//b
        r = a%b
        if r == 0 and n > 0:
            print(h, n, w)
            exit()

Measured memory_bytes: 68312
<?php

  fscanf(STDIN, "%d %d" ,$s,$c);

  $result = 0;


  if($c >= $s *2){
    $result = $s;
    $c -= $s*2;
    $c2scc = floor($c/4);
    $result += $c2scc;
  }else {
    $result += floor($c/2);
  }

  echo $result;


Measured memory_bytes: 3576
r, c = map(int, input().split())

array = []
for _ in range(r):
    x = list(map(int, input().split()))
    x.append(sum(x))
    array.append(x)

column = [list(ary) for ary in zip(*array)]
row = [sum(col) for col in column]
array.append(row)

for ary in array:
    print(' '.join(map(str, ary)))


Measured memory_bytes: 5812