akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define ll long long

using namespace std;

multiset < pair <ll, ll> > st;

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,m,x;
    cin >> n >> m;
    for(ll i = 1; i <= n; i++)
    {
        cin >> x;
        st.insert({x - x / 2, x});
    }
    for(ll i = 0; i < m; i++)
    {
        pair <ll, ll> p = *st.rbegin();
        st.erase(st.find(p));
        p.second = p.second / 2;
        p.first = p.second - p.second / 2;
        st.insert(p);
    }
    ll res = 0;
    for(auto &i : st)
    {
        res += i.second;
    }
    cout << res;
}


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

int main(){
  int N, M, sum;
  cin >> N >> M;
  sum = 0;
  vector<int> vec(N);
  for(int i = 0; i < N; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int cnt = 0;
  
  
  for(int i = 0; i < M; i++) {
    if(vec.at(i) < (double)sum/(4*M)) {
      cout << "No";
      break;
    }
    cnt++;
    if(cnt == M) {
      cout << "Yes";
    }
  }
}



Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine().toInt
  val a = StdIn.readLine().split(" ").map(_.toInt)
  val r = if(n == 1) 0 else a.sorted.sliding(2).foldLeft(0)((acc, ai) => acc + ai(1) - ai(0))
  println(r)

}


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

int main(){
  string s,base="abc"; cin>>s;
  int ca=0,cb=0,cc=0;
  for(int i=0;i<s.size();i++){
    if(s[i]==base[0]) ca++;
    else if(s[i]==base[1]) cb++;
    else cc++;
  }
  int x=s.size()/3;
  ca-=x; cb-=x; cc-=x;
  if(ca>=0 && ca<2 && cb>=0 && cb<2 && cc>=0 && cc<2){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 512
n,l=map(int,input().split())
a=[int(j)for j in input().split()]
for i in range(1,n):
    if a[i-1]+a[i]>=l:
        print("Possible")
        for j in range(i+1,n)[::-1]:
            print(j)
        for j in range(1,i+1):
            print(j)
        exit()
print("Impossible")

Measured memory_bytes: 14060
n = int(input().rstrip())
values = list(map(int,input().rstrip().split()))

m = 500000000 #max divide
for i in range(len(values)):
	nowV = values[i]
	nm = 0
	for j in range(500000000):
		if nowV % 2 == 0:
			nm += 1
			nowV = nowV / 2
		else:
			break 
	m = min(m,nm)
print(m)
			
		
	

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b) swap(a,b);
    if(b>c) swap(b,c);
    if(a>b) swap(a,b);
    cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}


Measured memory_bytes: 3068
import bisect,collections,copy,heapq,itertools,math,string
from collections import defaultdict as D
from functools import reduce
import numpy as np
import sys
import os
from operator import mul

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353    

N = I()

# 規則性を見つける
# X mod P <= X-1
ans = N*(N-1)//2

print(ans)

Measured memory_bytes: 27184
#include <bits/stdc++.h>
#define bug1(x) cout<<#x<<" = "<<x<<endl
#define bug2(x,y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<endl
#define bug3(x,y,z) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<endl
#define bug4(x,y,z,m) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<" "<<#z<<" = "<<z<<" "<<#m<<" = "<<m<<endl

using namespace std;

template<class T> 
ostream& operator<<(ostream &os, vector<T> input) {
    os << "[ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "]";
}

template<class T> 
ostream& operator<<(ostream &os, set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_set<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class T> 
ostream& operator<<(ostream &os, unordered_multiset<T> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << elem << " ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

template<class L, class R> 
ostream& operator<<(ostream &os, unordered_map<L,R> input) {
    os << "{ ";
    for(auto elem : input) { 
		os << "(" << elem.first << "," << elem.second << ") ";
	}
	return os << "}";
}

#define ll long long
const int MAXN = 1000005;
const ll INF = 1e18;
const int MOD = 998244353;
const int N = 500005;

long long sum[4*N] , lazy[4*N];
ll ones[N], pot10[N];

ll mul(ll a, ll b) {
	return a * b % MOD;
}

void push(int b,int e,int node){
	if(lazy[node] == -1) {
		return;
	}
	sum[node] = mul(lazy[node], ones[e-b+1]); 
    if(b != e){
        int le = 2*node + 1 , ri = le + 1;
        lazy[le] = lazy[node];
        lazy[ri] = lazy[node];
    }
    lazy[node] = -1;
}

void update(int b,int e,int node,int i,int j,int dig){
    push(b,e,node);
    if( b > j || e < i) return;

    if( i <= b && e<= j){
        lazy[node] = dig;
        push(b,e,node);
    }else{
        int mid = (b+e)>>1 , le = 2*node + 1 , ri = le +1;
        update(b,mid,le,i,j,dig);
        update(mid+1,e,ri,i,j,dig);
        sum[node] = mul(sum[le], pot10[e-mid]) + sum[ri];
		sum[node] %= MOD;
    }
}

class TaskE {
private:

public:
	void solveOne(int it){
		int n, q;
		cin >> n >> q;
		pot10[0] = 1;
		ones[0] = 0;
		for(int i = 1; i <= n; i++) {
			pot10[i] = mul(pot10[i-1], 10);
			ones[i] = (mul(ones[i-1], 10) + 1) % MOD;			
		}

		for(int i = 0; i < n; i++) {
			update(0, n-1, 0, i, i, 1);
		}
		for(int i = 0; i < q; i++) {
			int x, y, dig;
			cin >> x >> y >> dig;
			x--; y--;
			update(0, n-1, 0, x, y, dig);
			cout << sum[0] << endl;
		}
	}

	void solve(){
		int tc = 1;
		for(int it = 1; it <= tc; it++){
			solveOne(it);
		}
	}
};


int main(){
	ios_base::sync_with_stdio(false);
	TaskE solver;
	solver.solve();
	return 0;
}


Measured memory_bytes: 14988
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pll pair<ll,ll>
#define pint pll
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n;
  cin >> n;
  ll a[n],b[n];
  ll sum=0;
  rep(i,n)cin >> a[i];
  rep(i,n)cin >> b[i];
  ll s=0,t=0;
  rep(i,n){
    sum+=b[i]-a[i];
    if(a[i]>b[i])s+=a[i]-b[i];
    else t+=(b[i]-a[i])/2;
  }
  if(t>=s){
    cout << "Yes" << endl;
  }else cout << "No" << endl;
//  cout << s << ' ' << t << endl;
return 0;}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
using namespace std;
const int maxn=1e4+5;

map <string,int> mp;
map <string,int> ::iterator pt;
int n,m;
string blue;
string red;

int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>blue;
		mp[blue]++;
	}
	cin>>m;
	for(int i=0;i<m;i++)
	{
		cin>>red;
		if(mp.count(red)) mp[red]--;
	}
	int maxnum=0;
	for(pt=mp.begin();pt!=mp.end();pt++)
	{
		if(pt->second>maxnum) maxnum=pt->second;
	}
	cout<<maxnum<<endl;
} 

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

rc = S.count("R")
gc = S.count("G")

tc = int(rc*gc*(N-rc-gc))

aa = 0
for i in range(N):
  for j in range(1,math.ceil((N-i)/2)+1):
    
    if i+j+j < N:
      if S[i] != S[i+j]:
        if S[i] != S[i+j+j]:
          if S[i+j] != S[i+j+j]:
            aa = int(aa + 1)
            
print(int(tc-aa))

Measured memory_bytes: 9248
#include<stdio.h>
    #include<string.h>
    int main(void){
    int A,B,C,a,b,c,d,e,k,i,j,cou,v[1000000];
    char S[100000];
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&d);
    scanf("%d",&e);
    scanf("%d",&k);
    if(e-a>k){
        printf(":(");
    }else{
        printf("Yay!");
    }
    return 0;
    }

Measured memory_bytes: 128
N = int(input())
xy = [[] for _ in range(N)]
for i in range(N):
    A = int(input())
    for _ in range(A):
        x,y = map(int,input().split())
        xy[i].append([x-1,y])

answer = 0
# 状態n
for n in range(2 ** N):
    # 正直者のリスト
    true_person = []
    index = 0
    copy_n = n
    while copy_n:
        if copy_n & 1:
            true_person.append(index)
        index += 1
        copy_n >>= 1

    # 矛盾が生じたときTrue
    flag = False

    # 人i
    for i in true_person:
        # iさんの証言
        for x,y in xy[i]:
            # 証言と状態が違う場合
            if (x in true_person and y == 0) or (not(x in true_person) and y == 1):
                flag = True
        if flag:
            break
    if flag:
        continue
    else:
        answer = max(answer, len(true_person))
    
print(answer)

Measured memory_bytes: 3316
import numpy as np
c = np.zeros((3, 3))
for i in range(3):
    c[i, :] = np.array(list(map(int, input().split())))

vert_sum = np.sum(c, axis=0)
horz_sum = np.sum(c, axis=1)

for a1 in range(101):
    a2 = (horz_sum[1] - horz_sum[0]) / 3 + a1
    a3 = (horz_sum[2] - horz_sum[0]) / 3 + a1
    for b1 in range(101):
        b2 = (vert_sum[1] - vert_sum[0]) / 3 + b1
        b3 = (vert_sum[2] - vert_sum[0]) / 3 + b1
        if (c[0, 0] == a1 + b1 and c[0, 1] == a1 + b2 and c[0, 2] == a1 + b3
            and c[1, 0] == a2 + b1 and c[1, 1] == a2 + b2
                and c[1, 2] == a2 + b3 and c[2, 0] == a3 + b1
                and c[2, 1] == a3 + b2 and c[2, 2] == a3 + b3):
            print('Yes')
            exit()
print('No')


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

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#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--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	ll A, B, C, ans = 0;

	cin >> A >> B >> C;

	if ((A % 2 == 0 && B % 2 == 0 && C % 2 == 0) && (A == B && B == C)) {
		cout << -1 << endl;
		return 0;
	}

	while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0) {
		ll pA = A, pB = B, pC = C;

		A = (pB + pC) / 2;
		B = (pC + pA) / 2;
		C = (pA + pB) / 2;

		ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}*/
// --------------------------------------------------</TEMPLATE>--------------------------------------------------

int dp[3005][3005];

void solve() {
	int x = 0, y = 0, Max = 0;
	string a, b, out;
	cin >> a >> b;
	for (int i = 1; i <= a.size(); ++i) {
		for (int j = 1; j <= b.size(); ++j) {
			if (a[i - 1] == b[j - 1]) {
				dp[i][j] = dp[i - 1][j - 1] + 1;
			} else {
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
			Max = max(Max, dp[i][j]);
		}
	}
//	for (int i = 0; i <= a.size(); ++i) {
//		for (int j = 0; j <= b.size(); ++j) {
//			cout << dp[i][j] << " ";
//		}
//		cout << "\n";
//	}
	x = a.size(); y = b.size();
	while(x>0 && y>0) {
		if(a[x - 1]==b[y - 1]) {
			out += a[x - 1];
			x--;
			y--;
		} else if( dp[x-1][y] > dp[x][y-1]) {
			x--;
		} else {
			y--;
		}
	}
	reverse(out.begin(),out.end());
	cout << out << endl;
}

int main() {
	IOS
	ll t=1;
	//cin>>t;
	while(t--) {
		solve();
	}
	return(0);
}

Measured memory_bytes: 38884
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010



int main(){
  int N, M, S[SIZE];

  scanf("%d%d", &N, &M);

  for (int i=0; i<=N; i++) {
    scanf("%1d", S+i);
  }

  priority_queue<pair<int,int>> pq;
  int back[SIZE];

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

  pq.push({0, 0});

  for (int i=1; i<=N; i++) {
    if (S[i]) continue;

    while(pq.size() && -pq.top().second < i - M) {
      pq.pop();
    }

    if (pq.empty()) continue;

    auto p = pq.top();

    back[i] = -p.second;

    pq.push({p.first-1, -i});
  }

  if (back[N] == -1) {
    puts("-1");
    return 0;
  }

  vector<int> ans;

  int now = N;

  while(now != 0) {
    ans.push_back(now);
    now = back[now];
  }

  reverse(ans.begin(), ans.end());

  now = 0;
  bool first = true;
  for (int pos : ans) {
    if (!first) printf(" ");
    printf("%d", pos - now);
    first = false;
    now = pos;
  }

  puts("");

  return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
 
//Write From this Line

// now += mint(2).pow(s) - 1; こんな感じで、2のs乗を求められrう
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//const ll mod = 1e9+7;
//const ll mod = 998244353;
int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	vector<int> s, t;
	rep(i,n){
		cin >> a[i];
		if(a[i] < 0) t.push_back(a[i]);
		else s.push_back(a[i]); 
	}

	int S = s.size();
	int T = t.size();
	bool ok = false;
	if(S > 0) {
		if (n == k) ok = (T%2==0);
		else ok = true;
	} else {
		ok = (k%2==0);
	}

	mint ans = 1;
	if (!ok) {
		// 答えが負になる場合
		sort(a.begin(),a.end(), [](int x, int y) {
			return abs(x) < abs(y);
		});
		rep(i,k) ans *= a[i];
	} else {
		sort(s.begin(),s.end());
		sort(t.rbegin(),t.rend());
		if( k%2 == 1) {
			ans *= s.back();
			s.pop_back();
		}
		vector<ll> p;
		while (s.size() >= 2){
			ll x = s.back(); s.pop_back();
			x *= s.back(); s.pop_back();
			p.push_back(x);
		}
		while (t.size() >= 2){
			ll x = t.back(); t.pop_back();
			x *= t.back(); t.pop_back();
			p.push_back(x);
		}
		sort(p.rbegin(),p.rend());
		rep(i,k/2) ans *= p[i];
	}
	cout << ans << endl;
}


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

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

constexpr int INF = INT_MAX;

void chmax(ll &a, ll b){
    a = max(a, b);
}

ll dp[2005][4005][2];

int main(){
    int n;
    cin >> n;
    vector<P> ls;
    vector<int> id(n), r(n), a(n), w(n), t(n);
    for(int i=0;i<n;i++){
        cin >> r[i] >> a[i] >> w[i] >> t[i];
        ls.push_back(P(r[i]+t[i], i));
    }
    sort(ls.rbegin(), ls.rend());
    for(int i=0;i<n;i++) id[i] = ls[i].second;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=4000;j++){
            dp[i][j][0] = -INF;
            dp[i][j][1] = -INF;
        }
    }
    dp[0][4000][0] = 0;
    for(int i=0;i<n;i++){
        for(int j=4000;j>0;j--){
            for(int k=0;k<2;k++){
                if(dp[i][j][k] == -INF) continue;
                if(j <= r[id[i]]) continue;
                if(k==0){
                    chmax(dp[i][min(j-r[id[i]],t[id[i]])][1], dp[i][j][k] + a[id[i]]);
                }
                else{
                    chmax(dp[i][j-r[id[i]]][1], dp[i][j][k] + w[id[i]]);
                }
            }
        }
        for(int j=0;j<=4000;j++){
            dp[i+1][j][0] = max(dp[i][j][0], dp[i][j][1]);
        }
    }
    ll ans = 0;
    for(int i=0;i<=4000;i++){
        ans = max({ans, dp[n][i][0], dp[n][i][1]});
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 128408
//#include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
//#include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T> using G = greater<T>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), G<type>())
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく、n=10が限界(500 ms)
#define ENDL cout << endl;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, G<T> >;

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

const int INF = 2e9;
const LL MOD = 1e9 + 7;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, W;
  cin >> N >> W;
  VI v(N), w(N);
  REP(int, i, N) cin >> v[i] >> w[i];
  VVI dp(N+1, VI(W+1, 0));
  REP(int, i, N) REP(int, j, W+1)
  {
    chmax(dp[i+1][j], dp[i][j]);
    if (j - w[i] >= 0) chmax(dp[i+1][j], dp[i][j-w[i]] + v[i]);
  }
  cout << dp[N][W] << endl;

  return 0;
}


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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

#define PB(N) push_back(N)

using namespace std;

using Graph = vector<vector<int>>;

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

  Graph AB(M+10,vector<int>());

  rep(i,M){
    int buffer_a,buffer_b;
    cin >> buffer_a >> buffer_b;
    AB[buffer_a-1].PB(buffer_b-1);
    AB[buffer_b-1].PB(buffer_a-1);
  }

  vector<int> dist(N+10,-1);
  queue<int> que;
  vector<int> pre(N+10,-1); //直前の頂点

  dist[0] = 0;
  que.push(0);

  //BFS開始
  while(!que.empty()){
    int v = que.front();
    que.pop();

    //vから辿れる頂点を全て調べる
    for(int next_v: AB[v]){
      if(dist[next_v] != -1) continue;//すでに探索済み

      //新たな頂点next_vについて距離情報を取得してキューに追加
      dist[next_v] = dist[v] + 1;
      pre[next_v] = v;
      que.push(next_v);
    }
  }

  cout << "Yes" << endl;
  rep(i,N){
    if(i==0)continue;
    int ans = pre[i]; //一個前の場所を表示しておけば良い
    ++ans;
    cout << ans << endl;
  }
  return 0;
}


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

int main(void){

  int n[3];
  int a = sizeof(n)/sizeof(n[0]);

  for(int i=0; i<a; i++)
    cin >> n[i];

  for(int i=0; i<a - 1; i++){
     for(int j=a-1; j>i; j--){
        if(n[j] < n[j-1]){
          int temp = n[j];
          n[j] = n[j-1];
          n[j-1] = temp;
        }
     }
  }

  cout << n[0] << " " << n[1] << " " << n[2] << endl;
  
  return 0;
}

Measured memory_bytes: 3056
from collections import deque
n = input()
G = [[] for i in xrange(n)]
for i in xrange(n-1):
    s, t, w = map(int, raw_input().split())
    G[s].append((t, w))
    G[t].append((s, w))

deq = deque()
def bfs(s):
    used = {s: 0}
    deq.append(s)
    while deq:
        s = deq.popleft()
        for t, w in G[s]:
            if t in used:
                continue
            used[t] = used[s] + w
            deq.append(t)
    return used.items()[used.values().index(max(used.values()))]
t, co = bfs(0)
print bfs(t)[1]

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

const ll mod = 1e9 + 7;

const ll INF = 1e15;

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> vs(n);
	rep(i, n) { 
		cin >> vs[i]; 
		vs[i]--;
	}
	map<ll, ll> ms;
	vector<ll> traverse(n + 1, 0);
	ll c = 0;
	ms[c] = 0;	
	if (k == 1) {
		cout << vs[0] + 1 << endl;
		return 0;
	}
	else if (k <= n) {
		for (ll i = 1; i <= k; i++) {
			c = vs[c];
		}
		cout << c + 1 << endl;
		return 0;
	}
	else {
		for (ll i = 1; i <= n; i++) {
			c = vs[c];
			if (ms.count(c)) {
				ll loop = i - ms[c];
				ll rest = ms[c];
				ll diff = k - rest;
				diff %= loop;
				ll ans = traverse[rest + diff];
				cout << ans + 1 << endl;
				return 0;
			}
			ms[c] = i;
			traverse[i] = c;
		}
		return 0;

	}

}


Measured memory_bytes: 16300
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include<iomanip>
using namespace std;

int N;
string S, T;

int main() {
    cin >> N >> S >> T;
    for (int i = 0; i < N; i++) {
        cout << S[i] << T[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
n, m, k = map(int, input().split())


class Combination:
    """
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv


mod = 998244353
total = 0
comb = Combination(n, mod)

v2 = [0] * (k+1)
v2[k] = (m * pow(m-1, n-k-1, mod)) % mod
for i in range(k-1, -1, -1):
    v2[i] = (v2[i+1] * (m-1)) % mod

for i in range(k+1):
    v = comb(n-1, i)
    total += (v * v2[i]) % mod
    total %= mod

print(total)

Measured memory_bytes: 101972
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>
#include <bitset>
#include <stdlib.h>


//動的計画
//最小化問題
// template<class T>
// bool chmin(T& a,T b){if(a >  b) {a = b;return true;}return false;}
template<class T> 
bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX_INDEX = 100010;
ll dp[MAX_INDEX];
const ll INF = 1LL << 60;
int main(){
    
    ll x;
    cin >> x;

    double r = 1.01;
    double a = 100;
    ll n = 0;
    ll s = a;
    for(ll i = 0;i <= INF;i++){
        //ll s = a * (1 - pow(r,i))/(1-r);
        if(i == 0) if(x <= s){n = i;break;}
        if(i > 0){
            ll add = s / 100;
            s = s + add;
            if(x <= s){n = i;break;}

        }
        
    }

    cout << n << endl;



    return 0;

}

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

int main(void)
{
	char a[101]; 
	char b[101];
	
	scanf("%s", a);
	scanf("%s", b);
	
	if( strlen(a) > strlen(b) )
		printf("GREATER\n");
	else if( strlen(a) < strlen(b) )
		printf("LESS\n");
	else{
		if(a[0] > b[0])
			printf("GREATER\n");
		else if(a[0] < b[0])
			printf("LESS\n");
		else
			printf("EQUAL\n");
	}
	
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<utility>
#include<algorithm>
using namespace std;
using ll = long long int;

int n, q, K;
vector<pair<int, ll>> tree[100001];
ll dis[100001];
bool visited[100001] = {false};

void dfs(int a) {
	visited[a] = true;
	vector<pair<int, ll>> tmp = tree[a];
	for (size_t i = 0; i < tmp.size(); i++) {
		if (!visited[tmp[i].first]) {
			dis[tmp[i].first] = dis[a] + tmp[i].second;
			dfs(tmp[i].first);
		}
	}
}


int main(void) {
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		int ai, bi;
		ll ci;
		cin >> ai >> bi >> ci;
		tree[ai].emplace_back(bi, ci);
		tree[bi].emplace_back(ai, ci);
	}
	cin >> q >> K;
	dfs(K);
	ll ret[100001];
	for (int i = 0; i < q; i++) {
		int xi, yi;
		cin >> xi >> yi;
		ret[i] = dis[xi] + dis[yi];
	}
	for (int i = 0; i < q; i++) {
		cout << ret[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 19840
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            string s = io.r<string>();
            if (s == "0") { break; }
            int i = 0;
            foreach (char c in s)
            {
                i += util.parse<int>(c) - 48;
            }
            io.w(i);
        }
        io.wflush();
    }
}

namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
}

Measured memory_bytes: 9276
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] + a[1] == a[2])
		cout << "Yes";
	else
		cout << "No";
}


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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    int num = 0;
    for (auto& i : a) cin >> i;
    for (int i = 0; i < n; i++) {
        if (i + 1 == a[i]) {
            num++;
            if (i != n - 1) swap(a[i], a[i + 1]);
        }
    }
    cout << num << '\n';
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int MOD = 1e9+7
        ;
int main() {
    IO;
   int n ;
   cin>>n ;
   vector<int>vec(n);
   ll sum = 0 ;
   for(int i = 0 ;i<n ; i++){
       cin>>vec[i];
       sum+=vec[i];
       sum%=MOD;
   }
   ll ans = 0;
   for(int i = 0;i<n ; i++){
       sum-=vec[i];
       if(sum<0)sum+=MOD;
       ans+=(sum*vec[i]);
       ans%=MOD;
   }
   cout<<ans<<endl;

}

Measured memory_bytes: 3988
#include<stdio.h>
int main(){
    int x,y,z,MAX_K;
    scanf("%d%d",&x,&y);
    if((0 <= x && x <= 1000000000) && (0 <= y && y <= 1000000000)){
     z = x % y;
     while(z != 0){
         x = y;
         y = z;
         z = x % y;
     }
     printf("%d\n",y);
    }
    else printf("制約の範囲外です\n");
    return 0;
}




Measured memory_bytes: 2096
h,w=map(int,input().split())
grid=[None]*h

for i in range(h):
  grid[i]=input()

yoko=[[0 for i in range(w)] for j in range(h)]
tate=[[0 for i in range(w)] for j in range(h)]

for i in range(h):
  s=grid[i]
  left=0
  right=0
  while left<len(s):
    if s[left]=="#":
      left+=1
      right=left
      continue
    while right+1<w and s[right+1]==".":
      right+=1
  
    for j in range(left,right+1):
      yoko[i][j]=right-left
      
    left=right+1
    right=left
    
for i in range(w):
  up=0
  down=0
  while up<h:
    if grid[down][i]=="#":
      up+=1
      down=up
      continue
    while down+1<h and grid[down+1][i]==".":
      down+=1
    for j in range(up,down+1):
      tate[j][i]=down-up
    up=down+1
    down=up
    
ans=0
for i in range(h):
  for j in range(w):
    if grid[i][j]==".":
      ans=max(ans,tate[i][j]+yoko[i][j])
      
print(ans+1)


Measured memory_bytes: 126552
import java.util.*;

public class Main {

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

        int h = sc.nextInt();
        int w = sc.nextInt();
        int n = sc.nextInt();

        int result = 0;
        int black = 0;
        int large = h;
        if (w > h) large = w;
        for (int i = 0; i < large; i++) {
            black += large;
            result++;
            if (black >= n) break;
        }

        System.out.println(result);
    }

}

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

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

  if (s.length() <= k) {}
  else {
    s = s.substr(0, k);
    s += "...";
  }

  cout << s << endl;
  return 0;
}


Measured memory_bytes: 3628
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    a.sort(reverse=True)
    t = 0
    for i in range(1, 2 * n, 2):
        t += a[i]
    print(t)


if __name__ == '__main__':
    slove()


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    vi v1,v2,v3;
    v1 = {1,3,5,7,8,10,12};
    v2 = {4,6,9,11};
    v3 = {2};

    int x,y; cin >> x >> y;

    bool res = ((binary_search(all(v1),x) && binary_search(all(v1),y)));
    res |= ((binary_search(all(v2),x) && binary_search(all(v2),y)));
    res |= ((binary_search(all(v3),x) && binary_search(all(v3),y)));

    cout << (res ? "Yes" : "No\n");

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,YL=1e9+7;
inline int MO(const int &x){return x>=YL?x-YL:x;}
inline int in(){int k;cin>>k;return k;}
inline int low(int x){return x&(-x);}
int n,tot;
typedef std::pair<int,int> P;
#define mk make_pair
std::vector<P>ans;
int head[N],to[N<<1],nxt[N<<1],cnt,vis[N],du[N],m;
multiset<int>G[N];
inline void add(int u,int v){G[u].insert(v),G[v].insert(u),++du[u],++du[v];}
void work()
{
	int sum=0;
	for(int i=1;i<=n;++i)
		if(!vis[i]&&G[i].size()==2)
		{
			multiset<int>::iterator itl,itr;
			itr=itl=G[i].begin();++itr;vis[i]=1;
			G[*itl].erase(G[*itl].find(i));
			G[*itr].erase(G[*itr].find(i));
			if(*itl==*itr)++sum;
			else G[*itl].insert(*itr),G[*itr].insert(*itl);
		}
	int mx=0,res=0;
	for(int i=1;i<=n;++i)
		if(!vis[i])++res,mx=std::max(mx,(int)G[i].size());
	sum+=mx>>1;if(res>=3||sum>=3)puts("Yes");
	else puts("No");
}
int main()
{
	ios::sync_with_stdio(0);cin>>n>>m;
	for(int i=1;i<=m;++i)add(in(),in());
	for(int i=1;i<=n;++i)if(du[i]&1)return puts("No"),0;
	work();
	return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};






int main(){
  
  string s;
  cin >> s;
  bool flag = true;
  if(s[0] == s[1] || s[1] == s[2] || s[2] == s[0])flag = false;
  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  

int main(){

    ll N, M; cin >> N >> M;
    vector<string > A;
    vector<string > B;

    for(ll i = 0; i < N; i++){
        string s; cin >> s;
        A.push_back(s);
    }

    for(ll i = 0; i < M; i++){
        string s; cin >> s;
        B.push_back(s);
    }

    if(N == M){
        if(A[0] == B[0]) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    }

    for(ll i = 0; i < N - M; i++){
        for(ll j = 0; j < N - M; j++){
            bool f = true;
            for(ll row = 0; row < M; row++){
                for(ll col = 0; col < M; col++){
                    if(A[i+row][j+col] != B[row][col]){
                        f = false;
                        break;
                    }
                }
                if(f == false){
                    break;
                }
            }
            if(f == true){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int H = 200000 + 11;
    static int W = 200000 + 11;
    static List<TreeSet<Integer>> heights = new ArrayList<>(H);

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int n = sc.nextInt();
        for (int i = 0; i < w; i++) {
            if (i >= heights.size()) {
                heights.add(new TreeSet<Integer>());
            } else {
                heights.get(i).clear();
            }
            heights.get(i).add(h);
        }
        for (int i = 0; i < n; i++) {
            int h_i = sc.nextInt();
            int w_i = sc.nextInt();
            h_i -= 1;
            w_i -= 1;
            heights.get(w_i).add(h_i);
        }
        int current_h = 0, current_w = 0;
        int ans = h;
        while (current_h < h && current_w < w) {
            int hh = heights.get(current_w).higher(current_h);
            ans = Math.min(ans, hh);
            current_h += 1;
            if (heights.get(current_w).contains(current_h)) {
                break;
            }
            if (current_w + 1 >= w) {
                break;
            }
            if (!heights.get(current_w + 1).contains(current_h)) {
                current_w += 1;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 157932
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstring>
#include<vector>
using namespace std;

bool cmp1(const string& a,const string& b)
{
  int size_a,size_b;
  int start_a,start_b;
  start_a = start_b = 0;
  size_a = a.size(),size_b = b.size();
  if(a[0] == '0')
    for(int i=0;i<a.size() && a[i] == '0';i++)
      size_a--,start_a++;

  if(b[0] == '0')
    for(int i=0;i<b.size() && b[i] == '0';i++)
      size_b--,start_b++;

  if(size_a != size_b)
    return size_a < size_b;

  for(int i=0;i<size_a;i++)
    {
      if(a[start_a+i] != b[start_b+i])
	return a[start_a+i] < b[start_b+i];
    }
  return true;
}

bool cmp2(const string& a,const string& b)
{
  if(a.size() != b.size())
    return a.size() < b.size();
  for(int i=0;i<a.size();i++)
    {
      if(a[i] != b[i])
	return a[i] < b[i];
    }
  return true;
}

int main()
{

  int W,H;
  while(cin >> W >> H,W|H)
    {
     
      vector<vector<string> > G;
      G.resize(H);
      for(int i=0;i<H;i++)
	{
	  G[i].resize(W);
	  string line;
	  cin >> line;

	  for(int j=0;j<W;j++)
	    {
	      G[i][j] = line[j];
	    }
	}

      string G2[H][W];
      string ans = "";
      for(int i=0;i<H;i++)
	{
	  for(int j=0;j<W;j++)
	    {
	      if(isalpha(G[i][j][0]))
		continue;
	    
	      G2[i][j] = max(G2[i][j],G[i][j],cmp1);
	      string A,B;
	      A = B = G2[i][j];
	      if(j-1 >= 0 && !isalpha(G[i][j-1][0]))
		A = max(G2[i][j],G2[i][j-1]+G2[i][j],cmp1);

	      if(i-1 >= 0 && !isalpha(G[i-1][j][0]))
		B = max(G2[i][j],G2[i-1][j]+G2[i][j],cmp1);
	      G2[i][j] = max(A,B,cmp1);
	      ans = max(G2[i][j],ans,cmp1);
	    
	    }
	}
    
      
      for(int i=0;i<ans.size()&&ans[i] == '0';i++)
	ans[i] = ' ';
      stringstream ss;
      ss << ans;
      ss >> ans;
      
     cout << ans << endl;

      }
    
  return 0;
}

Measured memory_bytes: 1432
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main(){
	int X, Y, Z;
	cin >> X >> Y >> Z;

	swap(X, Y);
	swap(X, Z);

	cout << X << " " << Y << " " << Z << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();// 500
        int b = sc.nextInt();// 100
        int c = sc.nextInt();// 50
        int x = sc.nextInt();
        int count = 0;
        for (int i = 0; i <= c; i++) {
            for (int j = 0; j <= b; j++) {
                for (int k = 0; k <= a; k++) {
                    if ((50 * i) + (100 * j) + (500 * k) == x) {
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 22612
h,w,k=map(int,input().split())
s=[]
for i in range(h):
    s.append(input())
cut=[[0]*w for i in range(h)]
L=[]
H=[]
buf=k
c=0
for i in range(h):
    c=0
    for j in range(w):
        if s[i][j]=='#':
            c+=1
    if c==0:
        L.append(i)
        continue
    else:
        H.append(i)
    for j in range(w):
        if s[i][j]=='.':
            cut[i][j]=buf
        else:
            cut[i][j]=buf
            if c!=1:
                c-=1
                buf-=1
    buf-=1
while L!=[]:
    for col in L:
        if col+1 in H:
            cut[col]=cut[col+1]
            L.remove(col)
            H.append(col)
            continue
        elif col-1 in H:
            cut[col]=cut[col-1]
            L.remove(col)
            H.append(col)
            continue

for i in range(h):
    for j in range(w):
        print(cut[i][j],end=' ')
    print()

Measured memory_bytes: 49496
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	string j = "JPY";
	string b = "BTC";
	string s;
	
	double d,sum = 0;
	
	for(int i=0; i<n; i++)
	{
		cin>>d>>s;
		if(s==j){
		sum+=d;
	}
		else{
		sum+=(d*380000.0);
	}
}
	printf("%.8lf\n",sum);
	return 0;
	}
	
		


Measured memory_bytes: 256
(defmacro input []
  '(concat
     (->> (clojure.string/split (read-line) #"\s")
       (map #(Integer/parseInt %)))
     (clojure.string/split (read-line) #"\s")))

(defn PostalCode [[A B S]]
  (let [r1 (and (<= 1 A) (<= B 5))
        r2 (= (+ 1 A B) (count S))
        r3 (= \- (nth S A))
        r4 (nil? (re-seq #"[^0-9]" (str (apply str (take A S)) (apply str(drop (inc A) S)))))]
    (if (and r1 r2 r3 r4) "Yes" "No")))


(-> (input)
  PostalCode
  println)

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    char b,ans; cin >> b;
    if(b=='A') ans='T';
    else if(b=='C') ans='G';
    else if(b=='G') ans='C';
    else if(b=='T') ans='A';
    cout << ans << endl;
    
 }    


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	vector<int> a;
	set<int> p;
	int pos[200005];
	long long ans = 0;

	cin >> n;
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		pos[t] = i;
		a.push_back(t);
	}

	p.insert(-1);
	p.insert(n);
	for(int i=1; i<=n; i++){
		//printf("%d %d %d\n", lpos[i], rpos[i], i* ((abs(lpos[i] + 1 - pos[i]) + 1) * (abs(rpos[i] - 1 - pos[i]) + 1)));
		auto l = --p.lower_bound(pos[i]);
		auto r = p.upper_bound(pos[i]);
		//cout << (*l) << ' ' << (*r) << endl;
		ans += (long long)i* (pos[i] - (*l)) * ((*r) - pos[i]);
		//cout << ((abs((*l) - pos[i])) * (abs((*r) - pos[i]) )) << endl;
		p.insert(pos[i]);
	}

	cout << ans<< endl;

	

	return 0;
}


Measured memory_bytes: 11124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e5;
const ll LINF = 1e18;
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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n, m, Q;
    cin >> n >> m >> Q;
    auto v = make_vec<char>(n, n);
    rep(i, m) {
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        v[l][r]++;
    }

    auto s = make_vec<int>(n + 1, n + 1);
    rep(i, n) rep(j, n) {
        s[i + 1][j + 1] = s[i][j + 1] + s[i + 1][j] - s[i][j] + v[i][j];
    }

    while (Q--) {
        int p, q;
        cin >> p >> q;
        p--;
        cout << s[q][q] - s[q][p] - s[p][q] + s[p][p] << endl;
    }
}

Measured memory_bytes: 2176
#!/usr/bin/env perl

use strict;
use warnings;

chomp(my $input = <STDIN>);
my ($n, $h, $w) = split(/ /, $input);
my @alloys;
for (1..$n){
    $input = <STDIN>;
    my @size = split(/ /, $input);
    push(@alloys, \@size);
}

my $count = 0;
for my $alloy (@alloys){
    if ($alloy->[0] >= $h && $alloy->[1] >= $w){
        $count++;
    }
}
print "$count\n";


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

int a[10];

int main()
{
    rep(i, 4) {
        int n;
        cin >> n;
        a[n]++;
    }
    if(a[1] == 1 && a[4] == 1 && a[7] == 1 && a[9] == 1) {
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
long euclid(long a,long b) {
	long r;
	while(1){
		r = a%b;
		if(r==0)break;
		a = b;
		b = r;
	}
	return b;
}
int main(){
	long n,x;
	scanf("%ld %ld",&n,&x);
	printf("%ld\n",3*(n-euclid(n,x)));
}



Measured memory_bytes: 128