akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;

#define f(x) ((x)*(x) < 4 ? sqrt(4-(x)*(x)) : 0)


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

    int n;
    cin >> n;
    int a = n;
    int x=0;
    while(n){
        x += n %10;
        n/=10;
    }
    if(a % x==0) cout << "Yes" << endl;
    else cout << "No" << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest118-A
#  TODO https://atcoder.jp/contests/abc118/tasks/abc118_a

def solveProblem(Seme,Uke):
	amari = Uke % Seme
	if amari == 0:
		answer = Uke + Seme
	else:
		answer = Uke - Seme
	return answer


if __name__ == '__main__':
	A,B = map(int,input().strip().split(' '))
	solution = solveProblem(A,B)
	print("{}".format(solution))


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>
 
using namespace std;
 
int main()
{
	long long n;
	int m;
	while(cin>>n>>m,n){
		vector<int> c(m),x(n);
		for(int i=0;i<m;i++) cin>>c[i];
		for(long long i=0;i<n;i++) cin>>x[i];

		vector<vector<long long> > dp(n+1,vector<long long>(256,100000000LL));

		dp[0][128]=0;

		for(long i=0;i<n;i++){
			for(int j=0;j<256;j++){
				for(int k=0;k<m;k++){
					int tmp=j+c[k];
					tmp=min(tmp,255);
					tmp=max(tmp,0);
					dp[i+1][tmp]=min(dp[i+1][tmp],dp[i][j]+(tmp-x[i])*(tmp-x[i]));
				}
			}
		}

		long long res=dp[n][0];
		for(int i=1;i<256;i++) res=min(res,dp[n][i]);
		cout<<res<<endl;

	}

	return 0;
}

Measured memory_bytes: 42064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
#define re resize
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int N=1505,mod=998244353;
int n,jb,d[N],vis[N];
char ch[N][N];
bitset<N> E[N];
vector<int> A[N][N];
vector<char> e[N][N];
void GG(){
	puts("0"); exit(0); 
}
void dfs(int p){
	if(vis[p])return;
	jb+=d[p]; vis[p]=1; 
	For(i,1,n)if(E[p][i])dfs(i);
}
int main(){
	#ifdef Brollan
		freopen("1.in","r",stdin);
	#endif
	n=read();
	For(i,1,n-1){
		scanf("%s",ch[i]+1);
	}
	For(i,0,n){
		int x=0,y=i,dx=1,dy=y==n?-1:1;
		while(!A[x][y].size()||A[x][y].back()!=i){
			//if(y<=n)cout<<x<<" "<<y<<" "<<dx<<" "<<dy<<" "<<n<<endl;
			A[x][y].pb(i);
			x+=dx; y+=dy;
			if(y==n||y==0)dy*=-1;
			if(x==n||x==0)dx*=-1;
		}
	}
	For(i,1,n-1)For(j,1,n-1)if(A[i][j].size()>=2){
		/*for(auto k:A[i][j])wri(k); puts("fjh");
		assert(A[i][j].size()==2);*/
		int x=A[i][j][0],y=A[i][j][1];
		//cout<<i<<" "<<j<<" "<<x<<" "<<y<<endl;
		e[x][y].pb(ch[i][j]);
		e[y][x].pb(ch[i][j]);
	}
	int sum=0;
	For(i,0,n){
		For(j,i+1,n)if(e[i][j].size()){
			//cout<<i<<" "<<j<<" "<<e[i][j].size()<<endl;
			int f=0,g=0;
			for(auto k:e[i][j])if(k=='o')f=1; else if(k=='x')g=1;
			if(f&&g)GG();
			if(f){
				d[i]++; d[j]++;
			}else if(!g){
				E[i][j]=E[j][i]=1;
				sum++;
			}
		}
	}
	vector<int> zs[2];
	For(i,0,n)zs[i%2].pb(i);
	For(o,0,1){
		int nn=zs[o].size();
		if(nn%2){
			for(auto i:zs[o])if(!vis[i]){
				sum++; jb=0;
				dfs(i);
				if(jb%2)GG();
			}
			sum-=nn;
		}
	}
	ll ans=1;
	For(i,1,sum)ans=ans*2%mod;
	cout<<ans<<endl;
}
/*
5
oxox
xxxo
oxxx
xoxo
*/

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

int main(){
    string s; cin >> s;
    int front = (s[0]-'0')*10 + s[1]-'0';
    int back = (s[2]-'0')*10 + s[3]-'0';

    if((front == 0 && back == 0) || (front > 12 && back > 12) || (front > 12 && back == 0) || (front == 0 && back > 12)) cout << "NA";
    else if((front > 12 || front == 0) && back <= 12) cout << "YYMM";
    else if(front <= 12 && (back >12 || back == 0)) cout << "MMYY";
    else cout << "AMBIGUOUS";
    cout << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()

def g(t):
    l = []
    b = "x"
    c = 0
    for i, t_i in enumerate(t):
        if b != t_i:
            l.append(c)
            c = 0
        c += 1
        b = t_i
    l.append(c)
    return l[1:]

l = g(S)
len_l = len(l)
score = sum(l)-len_l

score += min(len_l//2, K)*2 - (len_l%2==0 and len_l//2 <= K)

print(score)

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

signed main(void)
{
	int n, m, x;
	cin >> n >> m >> x;
	int tab[n + 1];
	rep(i, n + 1) tab[i] = 0;
	rep(i, m) 
	{
		int a;
		cin >> a;
		tab[a]++;
	}
	for(int i = x; i < n; i++) tab[i + 1] += tab[i];
	for(int i = x; i > 0; i--) tab[i - 1] += tab[i];
	cout << min(tab[n], tab[0]) << endl;
	return 0;	
}


Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)

from = 0
to = (10**N) - 1

check = M.times.to_a.map do
  gets.split.map(&:to_i)
end


from.upto(to) do |i|
  s = i.to_s
  next if s.size != N
  c = check.all? do |v|
    s[v[0] - 1].to_i == v[1]
  end
  if c
    print i
    exit
  end
end

print(-1)


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <cmath>
 
using namespace std;
 
// typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<string> vs;
 
// container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for (typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
// repetition
#define FOR(i,m,n) for (ll (i) = ((ll) m); (i) < ((ll) n); ++(i))
#define RFOR(i,m,n) for (ll (i) = ((ll) (m)-1); (i) >= ((ll) n); --(i))
#define REP(i,n) FOR(i,0,n)
 
// i/o
#define TFOUT(b,t,f) cout << ((b)? (t) : (f)) << endl
 
//constant
const double    EPS     = 1e-10;
const double    PI      = acos(-1.0);
const int       INFTY   = (1<<21);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

int main() {
    int h, w, d; cin >> h >> w >> d;
    vector< pair<int,int> > a(h*w, MP(0, 0));
    vector<int> m;
    REP(i, h) {
        REP(j, w) {
            int e; cin >> e;
            e--;
            a[e].first = i;
            a[e].second = j;
        }
    }
    FOR(i, 0, d)
        m.push_back(0);
    FOR(i, d, h*w)
        m.push_back(m[i-d] + abs(a[i-d].first - a[i].first) + abs(a[i-d].second - a[i].second));
    int q; cin >> q;
    REP(i, q) {
        int l, r; cin >> l >> r;
        l--; r--;
        cout << (m[r] - m[l]) << endl;
    }

}

Measured memory_bytes: 2296
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    char c;
    cin>>c;
    if(c=='A')W('T');
    else if(c=='T')W('A');
    else if(c=='G')W('C');
    else if(c=='C')W('G');
    return 0;
}


Measured memory_bytes: 256
/**
 *      ABC 72 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-04 22:20:24
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int X, t; cin >> X >> t;
    X >= t ? cout << X - t : cout << 0;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll a,b,c;

    //input
    cin>>a>>b>>c;

    //calculation answer
    ll answer=0;
    if(a%2&&b%2&&c%2) answer=min(min(a*b,b*c),c*a);
    cout<<answer<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
f = [list(map(int,input().split())) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
ans = -10**10
for i in range(1,2**10):
    a = 0
    for j in range(n):
        a += p[j][sum(i>>k&1 and f[j][k] for k in range(10))]
    ans = max(ans,a)
print(ans)


Measured memory_bytes: 3064
fun main(args: Array<String>) {

    val (n, m, x, y) = readLine()!!.split(" ").map { it.toInt() }

    val xlist = readLine()!!.split(" ").map { it.toInt() }
    val ylist = readLine()!!.split(" ").map { it.toInt() }

    var isWar = false

    for (i in (x + 1..y)) {

        if (xlist.all { it < i } && ylist.all { it >= i }) {
            isWar = false
            break
        }
        isWar = true
    }

    if (isWar) {
        println("War")
    } else {
        println("No War")
    }
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100 + 47;
int A[MAX];
int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	FOR(i,0,n) cin >> A[i];
	sort(A, A + n);
	reverse(A, A + n);
	int ans = 0;
	FOR(i, 0,n)
	{
		if (i % 2 == 0)
		{
			ans += A[i];
			continue;
		}

		ans -= A[i];
	}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;

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

int main(){
    ll N;
    cin >> N;
    int head;
    int keta = 1;
    ll num = N;
    bool is_nine = true;
    while(1){
        if(num / 10 == 0){
            head = num;
            break;
        }else{
            if(num % 10 != 9) is_nine = false;
            num /= 10;
            keta++;
        }
    }
    int ans;
    if(is_nine){
        ans = head + 9 * (keta - 1);
    }else{
        ans = head + 9 * (keta - 1) - 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;

class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int[] cities_andX = new int[N+1];
    for(int i=0;i<N+1;i++){
      cities_andX[i] = scan.nextInt();
    }
    scan.close();
    
    Arrays.sort(cities_andX);
    
    int[] distances = new int[N];
    for(int i=0;i<N;i++){
      distances[i] = Math.abs(cities_andX[i]-cities_andX[i+1]);
    }
    
    int result = Arrays.stream(distances).distinct().sorted().reduce((a,b)->{
      int tmp;
      while((tmp=b%a)!=0){b=a;a=tmp;}
      return a;
    }).getAsInt();
    System.out.println(result);
      
  }//main
}//Main

Measured memory_bytes: 53836
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
inline LL read()
{
	LL x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*f;
}
inline int s(LL x)
{
	int tmp=0;
	while(x){
		tmp+=x%10;
		x/=10;
	}
	return tmp;
}
inline bool cmp(const LL &a,const LL &b)
{
	LL t1=a*s(b);LL t2=b*s(a);
	if(t1!=t2)	return t1<t2;
	return a<b;
}
LL k,tmp,a[1500008],tmp2,num,maxi;
int main()
{
	k=read();
	for(int i=1;i<=9999;++i){
		a[++num]=i;
		tmp2=1;
		for(int j=1;j<=11;++j){
			tmp2*=10;
			tmp=i*tmp2+tmp2-1;
			a[++num]=tmp;
			
		}
	}
	sort(a+1,a+num+1,cmp);
	unique(a+1,a+num+1);
	tmp=1;
	while(k){
		while(a[tmp]<maxi)	++tmp;
		maxi=a[tmp];
		printf("%lld\n",a[tmp]);
		++tmp;
		--k;
	}
	return 0;
}

Measured memory_bytes: 1152
w, h, n = gets.split.map(&:to_i)
x1 = y1 = 0
x2 = w
y2 = h
n.times{|i|
    x, y, a = gets.split.map(&:to_i)
    case a
        when 1
        x1 = [x1, x].max
        when 2
        x2 = [x2, x].min
        when 3
        y1 = [y1, y].max
        when 4
        y2 = [y2, y].min
    end
    }
p [x2 - x1, 0].max * [y2 - y1, 0].max

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

#define int long long

struct UnionFind{
  int n;
  vector<int> r,p;
  UnionFind(){}
  UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  int find(int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};

signed main() {
  int N, M;
  cin >> N >> M;

  vector<int> p(N);
  for ( int i = 0; i < N; i++ ) cin >> p[i], p[i]--;
  
  UnionFind uf(N);
  for ( int i = 0; i < M; i++ ) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    uf.unite(x, y);
  }

  int ans = 0;
  for ( int i = 0; i < N; i++ ) {
    ans += (uf.same(i, p[i]));
  }

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


Measured memory_bytes: 2560
import java.util.*;

class Main {

    static public long[] solve(int N, int[] A) {
        int[] d = new int[N+1];
        for (int n : A) d[n]++;
        
        long sum = 0;
        for (long v : d) {
            sum += v*(v-1)/2;
        }

        long[] res = new long[N];
        int i = 0;
        for (int n : A) {
            res[i++] = (d[n]==1) ? sum : (sum-d[n]+1);
        }
        return res;
    }

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

        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        sc.close();

        for (long n : solve(N, A))
            System.out.println(n);
    }
}

Measured memory_bytes: 94816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });


void solve(long long N, std::vector<long double> x, std::vector<std::string> u){
	double res = 0;
	REP(i, N) {
		if (u[i]=="JPY") res += x[i];
		else res += x[i]*380000.0;
	}
	PRINTD(res, 15);
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long double> x(N);
    std::vector<std::string> u(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%Lf",&x[i]);
        std::cin >> u[i];
    }
    solve(N, std::move(x), std::move(u));
    return 0;
}


Measured memory_bytes: 256
#include"iostream"
using namespace std;
int main()
{
	int n,k,l=1;
	cin>>n>>k;
	for(int i=0;i!=n;++i){
		int a=l+k,b=l*2;
		l=min(a,b);
	}
	cout<<l;
	return 0;
}

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


// ABC126A - Changing a Character
// https://atcoder.jp/contests/abc126/tasks/abc126_a
void ABC126A() {
	int N, K;
	cin >> N >> K;
	K--; //インデックスに使うので

	string S;
	cin >> S;

	if (S[K] == 'A') {
		S[K] = 'a';
	}
	else if (S[K] == 'B') {
		S[K] = 'b';
	}
	else {
		S[K] = 'c';
	}

	cout << S << endl;

}

int main() {
	ABC126A();

	return 0;
}

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

using namespace std;

int main() {
	int n;
	int ans = 0;
	cin >> n;
	for (int i = 1; i <= 9; i++) {
		if (n % i == 0&&n/i<10) {
			ans = 1;
		}
	}
	if (ans == 1) {
		cout << "Yes" << endl;
	}
	else if (ans == 0) {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

a = na()
for i in range(5):
    if a[i] == 0:
        print(i+1)


Measured memory_bytes: 61656
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")



#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <memory>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <string>
#include <unordered_map>
#include <iomanip>
#include <ctime>
#include <sstream>  
#include <deque>
#include <unordered_set>
#include <stack>
#include <functional>
#include <memory.h>
#include <bitset>
#include <numeric>

using namespace std;

//#define int long long

signed main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector <int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    int bot = 0;
    int top = 1000 * 1000 * 1000;
    while (top > bot + 1) {
        int mid = (bot + top) / 2;
        vector <pair <int, int> > cur;
        cur.push_back(make_pair(0, v[0]));
        int maxx = mid - 1;
        for (int i = 1; i < n; ++i) {
            if (v[i] <= v[i - 1]) {
                int nado_del = v[i - 1] - v[i];
                while (nado_del) {
                    if (cur.back().second <= nado_del) {
                        nado_del -= cur.back().second;
                        cur.pop_back();
                    }
                    else {
                        cur.back().second -= nado_del;
                        nado_del = 0;
                    }
                }
                int skip = 0;
                int good = 0;
                for (int j = (int)cur.size() - 1; j >= 0; --j) {
                    auto gg = cur[j];
                    if (gg.first != maxx) {
                        cur.resize(j);
                        if (gg.second != 1) {
                            cur.push_back(make_pair(gg.first, gg.second - 1));
                        }
                        cur.push_back(make_pair(gg.first + 1, 1));
                        if (skip != 0) {
                            cur.push_back(make_pair(0, skip));
                        }
                        good = 1;
                        break;
                    }
                    skip += gg.second;
                }
                if (!good) {
                    goto ff;
                }
            }
            else {
                if (cur.back().first == 0) {
                    cur.back().second += v[i] - v[i - 1];
                }
                else {
                    cur.push_back(make_pair(0, v[i] - v[i - 1]));
                }
            }
        }
        top = mid;
        continue;
    ff:
        bot = mid;
    }
    
    cout << top << endl;
}

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

int main()
{
  int n, a[100];
  cin >> n;
  for (int i=0; i<n; i++) cin >> a[i];
  for (int i=n-1; i>=0; i--)
    printf("%d%c", a[i], i==0?'\n':' ');
  return 0;
}



Measured memory_bytes: 3196
# Date [ 2020-08-22 21:02:22 ]
# Problem [ b.py ]
# Author Koki_tkg

import sys;      from decimal import Decimal
import math;     from itertools import combinations, product
import bisect;   from collections import Counter, deque, defaultdict

# sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b)

def Main():
    n = read_str()
    n = n.split()
    total = 0
    for i in n:
        total += int(i)
    
    if total % 9 == 0:
        print('Yes')
    else:
        print('No')


if __name__ ==  '__main__':
    Main()

Measured memory_bytes: 10092
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
long long combination(long n, long r, long long mod) {
  // nCrを返す　O(r)
  if (n < r) swap(n, r);
  long long bunbo = 1;
  long cnt = r;
  while (0 < cnt) {
    bunbo *= cnt;
    bunbo % mod;
    cnt--;
  }
  if (bunbo == 0) return 1;
  long long bunsi = 1;
  cnt = 0;
  while (cnt < r) {
    bunsi *= (n - cnt);
    bunbo %= mod;
    cnt++;
  }
  return bunsi / bunbo % mod;
}
int main() {
  int n;
  cin >> n;
  vector<long> a(n);
  REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  ll _n = a[n - 1];
  ll _r = a[0];
  ll avg = _n / 2, avg2 = (_n + 1) / 2, nowbib = (ll)INF*10;
  REP(i, n - 1) {
    if (abs(avg  - a[i]) < nowbib || abs(avg2 - a[i]) < nowbib) {
      _r = a[i];
      nowbib = abs(avg - _n + a[i]);
    }
  }
  cout << _n << " " << _r << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <map>
#include <algorithm>

#define REP(i, a, b) for (int i=a; i <b; i++)

using namespace std;

typedef long long ll;
typedef vector< int > vi;

int main() {
    int n;
    scanf("%d", &n);

    int ans = 0;
    REP(i, 0, 3) {
        if ((n % 2) == 1) {
            ans++;
        }
        n = n >> 1;
    }

    printf("%d\n", ans);
    return 0;
}


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

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;

const ll DIV = (ll)1e9+7;
// const ll MAXN = (ll)1e5+10;


int main(void) {
   ll N,T;
   cin>>N>>T;
   ll ans = INF;
   rep(i,0,N) {
      ll c,t;
      cin>>c>>t;
      if (t<=T) chmin(ans,c);
   }
   if (ans>INF/2) cout<<"TLE"<<endl;
   else cout<<ans<<endl;


   return 0;
}



Measured memory_bytes: 256
#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(){

	int n,m;
	cin >> n >> m;

	if(n <= 9 && m <= 9)cout << n*m << endl;
	else cout << -1 << endl;



	

	return 0;
}

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

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// 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://abc144.contest.atcoder.jp/tasks/abc144_b

Measured memory_bytes: 256
def f(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

n , k = map(int,input().split())

a = f(n, k)
print(len(a))

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
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 long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    char a;
    cin>>a;
    if('A'<=a&&a<='Z'){
        cout<<"A"<<endl;
    }
    else{
        cout<<"a"<<endl;
    }
}

Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <list>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

int dfs(int node, const vector<vector<int>>& graph, vector<int>& dp) {
  int& ans = dp[node];
  if (ans != -1) return ans;

  ans = 0;
  for (int neighbor : graph[node]) {
    ans = max(ans, dfs(neighbor, graph, dp) + 1);
  }
  return ans;
}

int main() {
  cin.sync_with_stdio(false);
  cin.tie(nullptr);

  int n, m;
  cin >> n >> m;

  vector<vector<int>> adj(n);
  while (m--) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
  }

  int best = 0;
  vector<int> dp(n, -1);
  for (int i = 0; i < n; i++) {
    best = max(best, dfs(i, adj, dp));
  }
  cout << best << endl;

  return 0;
}


Measured memory_bytes: 8192
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n, m, q = MI()
train = [LI() for _ in range(m)]
query = [LI() for _ in range(q)]
table = [[0 for _ in range(n)] for _ in range(n)]
ruisekiwa = [[0 for _ in range(n)] for _ in range(n)]
# O(nm)
# for p, q in query:
#     cnt = 0
#     for left, right in train:
#         if p <= left and right <= q:
#             cnt += 1
#     print(cnt)
for left, right in train:
    table[left-1][right-1] += 1

# pprint(table, width=40)

for i in range(n):
    for j in range(n):
        ruisekiwa[i][j] = table[i][j]
        if i > 0:
            ruisekiwa[i][j] += ruisekiwa[i-1][j]
        if j > 0:
            ruisekiwa[i][j] += ruisekiwa[i][j-1]
        if i > 0 and j > 0:
            ruisekiwa[i][j] -= ruisekiwa[i-1][j-1]

# pprint(ruisekiwa, width=40)
for p, q in query:
    ans = ruisekiwa[q-1][q-1]
    if p-1 > 0:
        ans -= ruisekiwa[p-2][q-1]
        ans -= ruisekiwa[q-1][p-2]
        ans += ruisekiwa[p-2][p-2]
    print(ans)


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

using namespace std;

int k, a, b;

void solve(){
    bool ret = false;
    for(int i = a; i <= b; i++){
        if(i % k == 0){
            ret =true;
        }
    }
    if(ret) puts("OK");
    else puts("NG");

}



int main(){

    cin >> k >> a >> b;

    solve();

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=2005;
const int MOD=998244353;

int n, k;
int fact[N], invfact[N];

int pow(int a, int b, int m)
{
	int ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}

int modinv(int k)
{
	return pow(k, MOD-2, MOD);
}

void precompute()
{
	fact[0]=fact[1]=1;
	for(int i=2;i<N;i++)
	{
		fact[i]=fact[i-1]*i;
		fact[i]%=MOD;
	}
	invfact[N-1]=modinv(fact[N-1]);
	for(int i=N-2;i>=0;i--)
	{
		invfact[i]=invfact[i+1]*(i+1);
		invfact[i]%=MOD;
	}
}

int nCr(int x, int y)
{
	if(y>x)
		return 0;
	int num=fact[x];
	num*=invfact[y];
	num%=MOD;
	num*=invfact[x-y];
	num%=MOD;
	return num;
}

int cache[N][N];

int increasing(int x, int len)
{
	if(x<=0)
		return 0;
	if(len==0)
		return 1;
	int &ans=cache[x][len];
	if(ans!=-1)
		return ans;
	ans=increasing(x-1, len);
	ans+=increasing(x, len-1);
	ans%=MOD;
	return ans;
}

int32_t main()
{
	IOS;
	memset(cache, -1, sizeof(cache));
	precompute();
	cin>>k>>n;
	for(int x=2;x<=k+1;x++)
	{
		int ans=0;
		for(int j=0;j<(x+1)/2;j++)
		{
			int distinct=nCr((x-1)/2, j);
			distinct*=pow(2LL, j, MOD);
			distinct%=MOD;
			int extra=n-j;
			if(extra<0)
				break;
			distinct*=increasing(j+k-x+1, extra);
			distinct%=MOD;
			ans+=distinct;
			ans%=MOD;
		}
		if(x%2==0)
		{
			n--;
			for(int j=0;j<(x+1)/2;j++)
			{
				int distinct=nCr((x-1)/2, j);
				distinct*=pow(2LL, j, MOD);
				distinct%=MOD;
				int extra=n-j;
				if(extra<0)
					break;
				distinct*=increasing(j+k-x+1, extra);
				distinct%=MOD;
				ans+=distinct;
				ans%=MOD;
			}
			n++;
		}
		cout<<ans<<endl;
	}
	for(int x=k;x>=2;x--)
	{
		int ans=0;
		for(int j=0;j<(x+1)/2;j++)
		{
			int distinct=nCr((x-1)/2, j);
			distinct*=pow(2LL, j, MOD);
			distinct%=MOD;
			int extra=n-j;
			if(extra<0)
				break;
			distinct*=increasing(j+k-x+1, extra);
			distinct%=MOD;
			ans+=distinct;
			ans%=MOD;
		}
		if(x%2==0)
		{
			n--;
			for(int j=0;j<(x+1)/2;j++)
			{
				int distinct=nCr((x-1)/2, j);
				distinct*=pow(2LL, j, MOD);
				distinct%=MOD;
				int extra=n-j;
				if(extra<0)
					break;
				distinct*=increasing(j+k-x+1, extra);
				distinct%=MOD;
				ans+=distinct;
				ans%=MOD;
			}
			n++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 31872
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	s := []byte(readString())
	t := []byte(readString())
	dp := make([][]*list, len(s))
	for i := range dp {
		dp[i] = make([]*list, len(t))
	}

	for i := range dp {
		for j := range dp[i] {
			if 0 < i {
				dp[i][j] = dp[i-1][j]
			}
			if 0 < j {
				dp[i][j] = max(dp[i][j], dp[i][j-1])
			}
			if s[i] == t[j] {
				var p *list
				if 0 < i && 0 < j {
					p = dp[i-1][j-1]
				}
				p = p.Append(s[i])
				dp[i][j] = max(dp[i][j], p)
			}
		}
	}

	ans := dp[len(s)-1][len(t)-1]
	println(ans.String())
}

type list struct {
	head   *node
	length int
}
type node struct {
	c    byte
	next *node
}

func (l *list) Append(c byte) *list {
	if l == nil {
		return &list{
			head: &node{
				c: c,
			},
		}
	}
	return &list{
		head:   l.head.Append(c),
		length: l.length + 1,
	}
}

func (l *list) String() string {
	if l == nil {
		return ""
	}
	res := make([]byte, 0, l.length)
	for p := l.head; p != nil; p = p.next {
		res = append(res, p.c)
	}

	for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
		res[i], res[j] = res[j], res[i]
	}
	return string(res)
}

func (n *list) Len() int {
	return n.length
}

func (n *node) Append(c byte) *node {
	res := new(node)
	res.c = c
	res.next = n
	return res
}

func max(a, b *list) *list {
	if a == nil {
		return b
	}
	if b == nil {
		return a
	}
	if a.Len() < b.Len() {
		return b
	}
	return a
}

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


Measured memory_bytes: 147912
#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 k, n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int maxDistance = -1;
  int maxIndex = -1;
  rep(i, n) {
    if (i != n - 1) {
      maxDistance = max(maxDistance, a[i + 1] - a[i]);
    } else {
      maxDistance = max(maxDistance, a[0] + (k - a[i]));
    }
    maxIndex = i;
  }
  ll res = k - maxDistance;
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 1024
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int, n)
    for i:=0;i<n;i++{
        fmt.Scan(&a[i])
    }
    ans := 0
    for{
        flg := false
        for i:=0;i<n;i++{
            if a[i]%2==0{
                a[i]/=2
            } else {
                flg = true
                break
            }
        }
        if flg{
            break
        }
        ans++
    }
    fmt.Println(ans)
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func sortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}

func reverseString(s string) string{
    t := []rune(s)
    for i,j := 0, len(s)-1 ; i < j ; i, j = i+1, j-1 {
        t[i], t[j] = t[j], t[i]
    }
    return string(t)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
#define Fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int main() {
    Fast
    
    int n; cin>>n;
    int arr[n], dp[n]; for(int &i:arr) cin>>i;
    for(int i:dp) i=INT_MAX;

    if(n==1) {cout<<0; return 0;}
    if(n==2) {cout<<abs(arr[0]-arr[1]); return 0;}
    dp[0]=0, dp[1]=abs(arr[0]-arr[1]);
    for(int i=2; i<n; i++) {
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
    }

    cout<<dp[n-1];

}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int A, B, C, K; cin >> A >> B >> C >> K;
    if (K <= A) cout << K << nl;
    else if (K <= A + B) cout << A << nl;
    else cout << A - (K - A - B) << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

using namespace std;

const int maxN = 100000;
const int mod = 998244353;

int N;
int D[maxN];
int c[maxN];

template <class T>
inline int pow_mod(int b, T e) {
	int ans = 1;
	for (; e > 0; e >>= 1) {
		if (e & 1)
			ans = (long long)ans * b % mod;
		b = (long long)b * b % mod;
	}
	return ans;
}

inline int answer() {
	if (D[0] != 0)
		return 0;

	for (int i = 0; i < N; i++) {
		if (D[i] >= N)
			return 0;
		c[D[i]]++;
	}

	if (c[0] > 1)
		return 0;

	int ans = 1;
	for (int d = 1; d < N; d++)
		ans = (long long)ans * pow_mod(c[d - 1], c[d]) % mod;

	return ans;
}

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

	cin >> N;
	for (int i = 0; i < N; i++)
		cin >> D[i];

	cout << answer() << '\n';

	return 0;
}


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

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

const int N = 1e5 + 5;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string s, t;
	int k;
	cin >> k >> s;
	if(s.size() > k) {
		for (int i = 0; i < k; i++)
			t.push_back(s[i]);
		t += "...";
	}
	else
		t = s;
	cout << t << "\n";
}


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

int main(){
    int k;
    string str, dot;
    cin >> k >> str;
    if(str.size() > k){
        dot = "...";
        str = str.substr(0,k);
    }
    cout << str << dot;
    return 0;
}

Measured memory_bytes: 3596
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int h, w; cin >> h >> w;
  vector<string> s(h); REP(i, h) cin >> s[i];
  int ans = 0;
  REP(sy, h) REP(sx, w) {
    if (s[sy][sx] == '#') continue;
    vector<vector<int> > dist(h, vector<int>(w, INF));
    dist[sy][sx] = 0;
    queue<pair<int, int> > que;
    que.emplace(sy, sx);
    int mx = 0;
    while (!que.empty()) {
      int i, j; tie(i, j) = que.front(); que.pop();
      REP(k, 4) {
        int y = i + dy[k], x = j + dx[k];
        if (0 <= y && y < h && 0 <= x && x < w && s[y][x] == '.' && dist[y][x] == INF) {
          dist[y][x] = dist[i][j] + 1;
          que.emplace(y, x);
          chmax(mx, dist[y][x]);
        }
      }
    }
    chmax(ans, mx);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
while True:
    n, m = map(int, input().split())
    if n == 0:
        break
    risks = [(p, d) for d, p in (map(int, input().split()) for _ in range(n))]
    risks.sort()
    remain = 0
    while risks:
        p, d = risks.pop()
        if d >= m:
            remain = p * (d - m)
            break
        m -= d
    print(remain + sum(p * d for p, d in risks))

Measured memory_bytes: 8776
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    int n;
    cin>>n;
    vector<double> v(n,0);
    for(int i = 0;i < n; i++){
        cin>>v[i];
    }
    /*
    for(int i = 0;i < n; i++){
        cout<<v[i]<<endl;
    }
    */
    //double sum=v[0];
    sort(v.begin(),v.end());
    double sum=v[0];
    for(int i = 1;i < n; i++){
        //cout<<sum<<endl;
        //cout<<v[i]<<" "<<i<<endl;
        sum=(sum+v[i])/2;
    }
    cout<<sum<<endl;
    //cout<<v[2]<<endl;
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    double a[52];
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    double ans = a[0];
    for(int i = 1; i < n; i++) ans = (ans + a[i]) * 1.0 / 2;
    printf("%.15f\n", ans);
}

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

int main(void){
    int N,K,l[50],sum = 0;
    cin >> N >> K;
    for(int i = 0;i < N;i++)cin >> l[i];
    sort(l,l+N,greater<int>());
    for(int i = 0;i < K;i++)sum += l[i];
    cout << sum << endl;
}

Measured memory_bytes: 256