akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100000;

ll a[MAX_N];
vector<int> G[MAX_N];
bool flag = false;
int n;

ll dfs(int p,int r)	//p:現在いる頂点,r:親の頂点
{
	if(G[p].size() == 1){	//葉なら
		return a[p];
	}
	ll sum = 0;
	ll maxa = -1;
	rep(d,G[p].size()){
		if(G[p][d] == r){
			continue;
		}
		ll u = dfs(G[p][d],p);
		sum += u;
		maxa = max(maxa,u);
	}
	ll rem = a[p]*2-sum;
	maxa = max(maxa,rem);
	if(rem<0){
		flag = true;
		return 0;
	}
	if(a[p]*2-maxa < maxa){
		flag = true;
		return 0;
	}
	return rem;
}

bool solve()
{
	if(n==2){
		return a[0] != a[1];
	}
	int r = -1;
	rep(i,n){
		if(G[i].size() >= 2){
			r = i;
			break;
		}
	}
	if(dfs(r,-1)){
		flag = true;
	}
	return flag;
}

int main()
{
	cin >> n;
	rep(i,n){
		scanf("%lld",&a[i]);
	}
	rep(i,n-1){
		int p,q;
		scanf("%d%d",&p,&q);
		p--;	q--;
		G[p].push_back(q);
		G[q].push_back(p);
	}
	if(!solve()){
		cout << "YES" << "\n";
	}else{
		cout << "NO" << "\n";
	}
}

Measured memory_bytes: 13184
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin >> n;
    int ans = 0;
    int res = 0;
    if (n==1) {
        ct(1);
        return 0;
    }
    for(int i=1; i<=n; ++i) {
        int tmp = 0;
        int t = i;
        while(t%2==0) {
            t/=2;
            tmp++;
        }
        if (tmp>ans) {
            ans = tmp;
            res = i;
        }
    }
    ct(res);
}


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

using namespace std;
//using namespace atcoder;

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

    int conv='A'-'a';

    s[k-1]-=conv;

    cout<<s<<endl;
}


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

using namespace std;

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

    vector<int> vt(26, 3000);
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < 26; ++j) {
            vt[j] = min(vt[j], (int) count(s.begin(), s.end(), 'a' + j));
        }
    }

    for (int i = 0; i < 26; ++i) {
        for (int j = 0; j < vt[i]; ++j) {
            cout << char(i + 'a');
        }
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


int main() {
  int n, d, x;
  cin >> n >> d >> x;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int sum = x;
  rep(i, n){
    for(int j = 1; j <= d; j += a[i]){
      sum++;
    }
  }

  cout << sum << ln;
}
  


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

#define DEBUG(x) cerr << #x << ": " << x << endl;

int main() {
    int n; // number of balls
    cin >> n; 
    int k;// Bのx座標
    cin >> k;
    int ans = 0;
    for (int i = 0; i < n ; i++) {
        int x;
        cin >> x;
        ans += min( x*2 , (k-x)*2 );
    }
    cout << ans << endl;


    return 0;
}

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

using ll = long long int;

int main() {
    #ifdef LU_SERIOUS
        freopen( "in.txt", "r", stdin );
    #endif // LU_SERIOUS
    ll n, k, x, y, ans;
    while( cin >> n >> k >> x >> y ) {
        ans = min( n, k ) * x;
        n -= k;
        if( n > 0 ) {
            ans += n * y;
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
S = list(input())
T = list(input())

dict1 = {}
for s in S:
  if(s in dict1): dict1[s] += 1
  else: dict1[s] = 1   
dict2 = {}
for t in T:
  if(t in dict2): dict2[t] += 1
  else: dict2[t] = 1

list1,list2 = [],[]
for k, v in sorted(dict1.items(), key=lambda x: x[1]):
  list1.append(v)
for k, v in sorted(dict2.items(), key=lambda x: x[1]):
  list2.append(v)

#結局,要素の種類と個数が一致していたらOK
if(list1 == list2):
 print('Yes')
else:
 print('No')

Measured memory_bytes: 6704
fun main(args: Array<String>) {
    val s = readLine()!!.toCharArray()
    val t = readLine()!!.toCharArray()
    val s1 = s.sorted().joinToString()
    val t1 = t.sortedDescending().joinToString()
    if (s1 < t1) {
        println("Yes")
    } else {
        println("No")
    }
}


Measured memory_bytes: 35952
#include<bits/stdc++.h>
#define N 200005
using namespace std;
typedef long long ll;
ll n, T, t[N], s=0;
int main() {
    cin>>n>>T;
    for(int i=1; i<=n; i++) cin>>t[i];
    for(int i=1; i<n; i++) {
        s+=min(T, t[i+1]-t[i]);
    }
    cout<<s+T;
    return 0;
}


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

using namespace std;

#define forn(i, x, n) for (int i = int(x); i <= int(n); ++i)
#define for1(i, n, x) for (int i = int(n); i >= int(x); --i)
#define F first
#define S second
#define pb push_back

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

const int N = 2e6 + 1;
const ll INF = 1e18 + 9;
const int B = 1e9 + 7;

int n, m;
int a[N];
ll s[N], p[N];

int main() {
    #ifdef black
    freopen("in", "r", stdin);
    #endif // black
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> m;
    ll ans = 0, mx = 0;
    forn(i, 1, n) {
        cin >> a[i];
        if (i == 1) continue;
        #define g(x) (x == m ? 1 : x + 1)
        int dist = (a[i] + m - a[i - 1]) % m;
        ans += dist;
        if (a[i] == g(a[i - 1])) continue;
        if (a[i] > a[i - 1]) {
            ++s[a[i - 1] + 2];
            --s[a[i] + 1];
            s[a[i] + 1] -= (dist - 1);
            s[a[i] + 2] += (dist - 1);
        }
        else {
            ++s[a[i - 1] + 2];
            p[1] += (m - a[i - 1] - 1);
            ++s[1];
            p[a[i] + 1] -= (m - a[i - 1] - 1);
            --s[a[i] + 1];
            s[a[i] + 1] -= a[i];
            s[a[i] + 2] += a[i];
        }
    }
    forn(i, 1, m) {
        p[i] += p[i - 1];
        s[i] += s[i - 1];
    }
    forn(i, 1, m) {
        s[i] += s[i - 1];
        p[i] += s[i];
        mx = max(mx, p[i]);
    }
    cout << ans - mx << "\n";

    return 0;
}


Measured memory_bytes: 7168
import sys
import math
import fractions
input = lambda: sys.stdin.readline().rstrip()

mod = 10**9 + 7


def factorize(n):
    b = 2
    fct = dict()
    while b * b <= n:
        while n % b == 0:
            n //= b
            if b in fct:
                fct[b] += 1
            else:
                fct[b] = 1
        b = b + 1
    if n > 1:
        if b in fct:
            fct[n] += 1
        else:
            fct[n] = 1
    return fct


def divmod(x, mod=10**9 + 7):
    return pow(x, mod - 2, mod)


def solve():

    N = int(input())
    A = list(map(int, input().split()))
    B = [[1] for _ in range(N)]

    fac_list = dict()
    for i in range(N):
        d = factorize(A[i])
        for k, v in d.items():
            fac_list[k] = max(fac_list.get(k, 0), v)

    lcm = 1
    for k, v in fac_list.items():
        lcm *= (k**v)
        lcm %= mod

    ans = 0
    for i in range(N):
        ans += divmod(A[i])
        ans %= mod

    ans *= lcm
    ans %= mod
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 73048
#include <bits/stdc++.h>
////////////////////////////////////////////////////////////
#define all(x) (x).begin(), (x).end()
const int inf = 1e9;
const long long INF=1e15;
#define endl '\n'
#define rep(i, n) for(int i=0;i<(n);++i)
#define repp(i, a, b) for(int i=(a);i<=(b);++i)
#define pb push_back
#define eb emplace_back
#define fastio ios::sync_with_stdio(false);cin.tie(0); //cout.tie(0);

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

void solve() {
	ll n, x, y;
	cin >> n >> x >> y;
	// O(n^2) works
	vll ans(n, 0);
	auto dist = [&](ll i, ll j) {
		ll one = abs(i-j);
		ll two = abs(i-x) + abs(y-j) + 1;
		ll thr = abs(i-y) + abs(x-j) + 1;
		return min({one,two,thr});
	};
	repp(i, 1, n) repp(j, 1, n) if(i < j) {
		ans[dist(i,j)]++;
	}
	repp(i, 1, n-1) cout << ans[i] << endl;
}
int main() {
	fastio;
	solve();
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int S, h, m, s;

  scanf("%d", &S);

  h = S / 3600;
  m = (S - 3600 * h) / 60;
  s = S - 3600 * h - 60 * m;

  printf("%d:%d:%d\n", h, m, s);

  return 0;
}

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

int main() {
  int N, Y;
  cin >> N >> Y;
  
  for (int i=0; i<=N; i++) {
    for (int j=0; j<=(N-i); j++) {
      int k=N-i-j;
      if (10000*i+5000*j+1000*k == Y) {
    	cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n;
struct Edge {
	int to;
	int next;
}edge[N * 2];
int head[N];
int cnt;
void AddEdge(int fr, int to) {
	edge[++cnt].to = to;
	edge[cnt].next = head[fr];
	head[fr] = cnt;
}
int d[N];
int DFS(int x, int fa) {
	int t = d[x] - 1;
	if (fa != 0) t--;
	int re = 0;
	for (int i = head[x]; i; i = edge[i].next) {
		if (edge[i].to != fa) {
			int tmp = DFS(edge[i].to, x);
			re += tmp;
			if (tmp) t--;
		}
	}
	re += max(t, 0);
	//cerr << x << " " << re << endl;
	return re;
}
int main() {
	scanf("%d", &n);
	for (int a, b, i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		d[++a]++;
		d[++b]++;
		AddEdge(a, b);
		AddEdge(b, a);
	}
	for (int i = 1; i <= n; i++) {
		if (d[i] > 2) {
			printf("%d\n", DFS(i, 0));
			return 0;
		}
	}
	printf("1\n");
	return 0;
}

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

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String str=br.readLine();
			if(str.equals("0"))break;
			int sum=0;

			for(int i=0;i<str.length();i++){

				sum += Character.getNumericValue(str.charAt(i));
			}
			System.out.println(sum);

		}
	}
}

Measured memory_bytes: 24428
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    a, b = map(int, input().split())
    dif = b - a
    print((1 + dif) * dif // 2 - b)


resolve()

Measured memory_bytes: 3060
import sys

n,m=map(int,input().split())
l=0
r=n+1
for i in range(m):
    a,b=map(int,input().split())
    l=max(l,a)
    r=min(r,b)
    if l>r:
        print(0)
        sys.exit()
print(r-l+1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0, K = 0, Q = 0, M = 0;
  cin >> N >> K >> Q;
  vector<ll>A(N);
  rep(i,Q){
    cin >> M;
    A[M - 1]++;
  }
  rep(i,N){
    if(A[i] + K - Q > 0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define gc getchar()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define Rep(i,v) rep(i,0,(int)v.size()-1)
#define lint long long
#define db long double
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
using namespace std;
typedef pair<int,int> pii;
typedef set<int>::iterator sit;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
const int N=200010;int a[N],b[N];
inline int gabs(int x) { return x<0?-x:x; }
int main()
{
	int n=inn();rep(i,1,n) a[i]=inn();
	if(n&1)
	{
		lint s1=0,s2=0;
		sort(a+1,a+n+1);
		int m=n/2+1;
		rep(i,1,m) s1+=a[i];
		rep(i,m+1,n) s2+=a[i];
		lint ans=s2*2-(s1*2-a[m]-a[m-1]);
		s1=0,s2=0;
		m=n/2;
		rep(i,1,m) s1+=a[i];
		rep(i,m+1,n) s2+=a[i];
		ans=max(ans,s2*2-a[m+1]-a[m+2]-s1*2);
		return !printf("%lld\n",ans);
	}
	else{
		lint s1=0,s2=0;
		sort(a+1,a+n+1);
		int m=n/2;
		rep(i,1,m) s1+=a[i];
		rep(i,m+1,n) s2+=a[i];
		lint ans=s2*2-a[m+1]-(s1*2-a[m]);
		return !printf("%lld\n",ans);
	}
	return 0;
}

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

int main(){
    vector<int> v(10);
    for(int i=0;i<10;i++)cin >> v[i];
    sort(v.rbegin(), v.rend());
    for(int i=0;i<3;i++)cout << v[i] << endl;
    return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using ll = long long;
#define vc vector
using namespace std;
int main() {
  int N,a[100];
  cin>>N;
  for (int i(0);i<N;i++) cin>>a[i];
  int maxi(0),mini(100000);
  for (int i(0);i<N;i++){
    mini=min(mini,a[i]);
    maxi=max(maxi,a[i]);
  }
  cout << maxi-mini<<endl;
  return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <queue>
#include <time.h>

using namespace std;

#define INT_MAX 2147483647
typedef long long ll;

ll gcd(ll m, ll n);		//最大公倍数
ll lcm(ll m, ll n);		//最小公倍数

int main(void) {

	string ans = "No";

//	int n;
//	cin >> n;
//	vector<int> v;
	string a, b;
	cin >> a;
	cin >> b;
	for (int i = 0; i < a.size(); i++) {
		if (a == b) {
			ans = "Yes";
			break;
		}
		b = b.back() + b;
		b.pop_back();
	}


	cout << ans << endl;

	return 0;

}

// 2番目から3要素だけ抜き出した部分文字列を取得する
//std::string result = s.substr(2, 3);  

#if 1
//最大公倍数
ll gcd(ll m, ll n)
{
	ll temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
#endif

Measured memory_bytes: 256
#include <iostream>
#include <set>

using namespace std;

int main() {
  int N;
  set<int> s;

  cin >> N;
  int d;
  for (int i = 0; i < N; ++i) {
    cin >> d;
    s.insert(d);
  }
  cout << s.size() << endl;
  return 0;
}


Measured memory_bytes: 256
SUITS = ('S', 'H', 'C', 'D')
cards = {suit:{i for i in range(1, 14)} for suit in SUITS}

n = input() # 読み捨て
for i in range(int(n)): 
    suit, number = input().split()
    cards[suit].discard(int(number))

for suit in SUITS:
    for i in cards[suit]:
        print(suit, i)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b) {if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b) {if(a<b) a=b;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> l(n);
    REP(i,n) cin >> l[i];
    sort(ALL(l));
    int ans = 0;
    for(int i = n-1; i>=0; --i) for(int j = i-1; j>=0; --j) {
        auto d = l.end() - lower_bound(ALL(l),l[i]+l[j]);
        ans += n - 1 - i - d;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define prime 1000000007
#define INF 2147483647
int dx8[8]={-1,0,1,1,1,0,-1,-1};
int dy8[8]={1,1,1,0,-1,-1,-1,0};
int dx4[4]={-1,0,1,0};
int dy4[4]={0,-1,0,1};
int solve(int n){
    int res=0;
    for(int i=1;i<=n;i++){
        if(n%i==0)res++;
    }
    return res;
}
signed main(void){
    int n;cin>>n;
    int ans=0;
    for(int i=1;i<=n;i+=2){
        if(solve(i)==8)ans++;
    }
    cout<<ans<<endl;
}
        


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

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] an = new int[n];

    for (int i=0; i<n; i++) {
      int a = sc.nextInt();
      an[i]=a;
    }
    sc.close();

    Arrays.sort(an);
    long a1=0,a2=0;
    for (int i=n-1;i>0;i--) {
      if (an[i]==an[i-1]) {
        a2=a1;
        a1=an[i];
        i--;
      }
      if (a2!=0)
        break;
    }
    System.out.println(a1*a2);
  }
}

Measured memory_bytes: 50772
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, ii> iii;

int n,k;

int main(){
	cin >> n >> k;
	int ans = 0;
	while(n){
		n /= k;
		ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int x = scan.nextInt();
		int y = scan.nextInt();
		
		int tmp;
		
		if(x > y) {
			while ((tmp = x % y) != 0) {
	            x = y;
	            y = tmp;
	        }
			System.out.println(y);
		}else if(x < y) {
			while ((tmp = y % x) != 0) {
	            y = x;
	            x = tmp;
	        }
			System.out.println(x);
		}else System.out.println(y);
	}
}

Measured memory_bytes: 26272
S=list(input())
S.reverse()
i=0
l=len(S)
while True:
    if i==l:
        print("YES")
        break
    elif ''.join(S[i:i+5])=="esare":
        i=i+5
    elif ''.join(S[i:i+5])=="maerd":
        i=i+5
    elif ''.join(S[i:i+6])=="resare":
        i=i+6
    elif  ''.join(S[i:i+7])=="remaerd":
        i=i+7
    else:
        print("NO")
        break

Measured memory_bytes: 3956
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = min(a) + min(b)
for _ in range(M):
    x, y, c = map(int, input().split())
    x -= 1
    y -= 1
    ans = min(ans, a[x] + b[y] - c)
print(ans)


Measured memory_bytes: 18684
#include <iostream>
#include <vector>
#define X second
#define Y first
#define A 26
#define N 500
using namespace std;
typedef pair<int,int> P;
vector<P> v[A];
string s[N];
int m,n,ans;
bool used[A],erased[A];
/*. a
b   d
  c .
    
  a .
b   d
. c*/
bool func(int x){
  if(!v[x].size()) return false;
  if(used[x]) return false;
  used[x]=true;
  int y1=v[x][0].Y,x1=v[x][0].X,y2=v[x][1].Y,x2=v[x][1].X;
  int f=0,fa=1,fb=1,fc=1,fd=1;
  if(x1>x2) swap(x1,x2),f=1;
  for(int i=x1;i<=x2;i++){
    char c=s[y1][i];
    int nx=c-'A';
    if(nx==x) continue;
    if(c!='.'&&!erased[nx]&&!func(nx)) fa=0;
  }
  for(int i=y1;i<=y2;i++){
    char c=s[i][x1];
    int nx=c-'A';
    if(nx==x) continue;
    if(c!='.'&&!erased[nx]&&!func(nx)) fb=0;
  }
  for(int i=x1;i<=x2;i++){
    char c=s[y2][i];
    int nx=c-'A';
    if(nx==x) continue;
    if(c!='.'&&!erased[nx]&&!func(nx)) fc=0;
  }
  for(int i=y1;i<=y2;i++){
    char c=s[i][x2];
    int nx=c-'A';
    if(nx==x) continue;
    if(c!='.'&&!erased[nx]&&!func(nx)) fd=0;
  }
  if(!f) f=(fa&fd)|(fb&fc);
  else f=(fa&fb)|(fc&fd);
  if((y1==y2&&x1+1==x2)||(x1==x2&&y1+1==y2)) f=0;
  if(!f) return false;
  erased[x]=true;
  return true;
}

int main(){
  cin>>m>>n;
  for(int i=0;i<m;i++) cin>>s[i];
  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++)
      if(s[i][j]!='.') v[s[i][j]-'A'].push_back(P(i,j));
  for(int i=0;i<A;i++){
    for(int j=0;j<A;j++) used[j]=false;
    func(i);
  }
  for(int i=0;i<A;i++) ans+=erased[i]*2;
  cout<<ans<<endl;
  return 0;
}

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

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int K = scanner.nextInt();
    int[] l = new int[N];
    for (int i = 0; i < N; i++) {
      l[i] = scanner.nextInt();
    }
    Arrays.sort(l);
    long sum = 0;
    for (int i = 0; i < K; i++) {
      sum += l[N - i - 1];
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N=pow(10,9)+7;

ll mod_pow(ll a, ll n){
    ll ans;
    if(n==0) return 1;
    else{
        if(n%2==0){
            ans = (mod_pow(a,n/2) * mod_pow(a,n/2))%N;
            return ans;
        }
        else{
            ans = (mod_pow(a,(n-1)/2) * mod_pow(a,(n-1)/2))%N;
            ans = (ans * a) %N;
            return ans;
        }
    }
}

ll combi(ll n, ll k){
    ll up=1;
    ll down=1;
    for(ll i=0; i<k; i++){
        up = (up * (n-i))%N;
    }
    for(ll i=1; i<=k; i++){
        down = (down*i)%N;
    }
    ll ans = mod_pow(down, N-2);
    return (ans * up)%N;
}


int main(){
    ll n, k;
    cin >> n >> k;
    for(ll i=1; i<=k; i++){
        ll ans;
        ans = combi(n-k+1, i);
        ans = (ans* combi(k-1,i-1))%N;
        cout << ans << endl; 
    }
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int main() {
   ll a[6],i,k;
   for(i=1;i<=5;i++)
    cin>>a[i];
    cin>>k;
   for(i=1;i<=5;i++){
    for(int j=1;j<=5;j++){
        if(a[i]-a[j]>k){
            cout<<":(";
            return 0;
        }
    }
   }
   cout<<"Yay!";
    return 0;
}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;



public class Main {

    public static void main(String[] args) {

        Scanner cin = new Scanner(System.in);

        int n = cin.nextInt();
        int x = cin.nextInt();

        if(n*500>=x)
            System.out.println("Yes");
        else
            System.out.println("No");

    }
}


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

int main(){
	int n, c, k;
	cin >> n >> c >> k;
	vector<int>t(n);
	for (int i = 0;i < n;i++) {
		cin >> t[i];
	}

	sort(t.begin(), t.end());
	int ans = 0;
	int i = 0;
	while (i < n) {
		ans++;
		int start = t[i];
		int num = 1;
		i++;
		while (i < n&&t[i] <= start + k && num < c) {
			i++;
			num++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class BTAKOYAKIFESTIVAL2019 {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        vector<int> d(n);
        rep(i,n){
            in >> d[i];
        }
        ll ans=0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                ans+=(ll)d[i]*d[j];
            }
        }
        out << ans << endl;
	}
};


int main() {
	BTAKOYAKIFESTIVAL2019 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 100005;

int n, tab[N], kol[N], ind, l, r, i, sup[2*N];
LL x, c;
bool bat[N];

bool cmp(int a, int b) {
	if (tab[a] == tab[b]) return a < b;
	return tab[a] < tab[b];
}

LL cou(int x) {
	int i, j, act1, act2, lin;
	LL act, res;
	int w = kol[x];
	for (i=0;i<n;i++) bat[i] = (tab[i] < tab[w] || (tab[i] == tab[w] && i < w));
	for (i=0;i<=2*n;i++) sup[i] = 0;
	act1 = act2 = 0;
	res = 0;
	for (i=0;i<n;i++) {
		if (bat[i]) act1++; else act2++;
		sup[act1 - act2 + n]++;
		if (act1 - act2 > 0) res++;
	}
	act = res;
	//cout << " " << act << " " << act1 << " " << act2 << endl;
	lin = n + 1;
	for (i=0;i<n;i++) {
		if (bat[i]) {
			act -= sup[lin];
			sup[lin]--;
			lin++;
			act1--;
		} else {
			lin--;
			sup[lin - 1]--;
			act += sup[lin];
			act2--;
		}
		//cout << " " << act << endl;
		res += act;
	}
	return res;
}

int main() {
scanf("%d", &n);
for (i=0;i<n;i++) {
	scanf("%d", &tab[i]);
	kol[i] = i;
}
sort(kol, kol + n, cmp);
x = (n * 1LL * (n + 1)) / 2;
x /= 2;
l = 0;
r = n - 1;
//int counter = 0;
while (l <= r) {
	ind = (l + r) / 2;
	//cout << l << " " << r << " " << ind << endl;
	c = cou(ind);
	//cout << c << endl;
	if (c == x) {
		printf("%d\n", tab[kol[ind]]);
		return 0;
	}
	if (c < x) l = ind + 1; else r = ind - 1;
	//counter++;
	//if (counter > 6) break;
}
printf("%d\n", tab[kol[r]]);
return 0;
}

Measured memory_bytes: 1920
#include"bits/stdc++.h"
using namespace std;

void Main() {
  int N;
  cin >> N;
  int A[N];
  int MAX = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    MAX = max(MAX, A[i]);
  }
  sort(A, A + N);

  MAX += 1;
  vector<bool> dp(MAX, true);

  for (int i = 0; i < N; i++) {
    if (dp[A[i]] == false) continue;
    if (i > 0 && A[i] == A[i - 1]) {
      dp[A[i]] = false;
      continue;
    }
    for (int p = A[i] + A[i]; p < MAX; p += A[i]) dp[p] = false;
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (dp[A[i]]) ans++;
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



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

using namespace std;

typedef long long ll;
const ll INF = INT32_MAX;

int main()
{
    ll n, W; cin>>n>>W;
    
    vector<ll> w(n), v(n);

    for(ll i=0; i<n; i++) {cin>>w[i]>>v[i];}

    ll v_sum=0;
    for(ll i=0; i<n; i++) v_sum+=v[i];

    vector<ll> dp(v_sum+1, INF);
    dp[0] = 0;

    for(ll i=0; i<n; i++)
    {
        for(ll v_already=v_sum-v[i]; v_already>=0; --v_already)
        {
            dp[v_already+v[i]] = min(dp[v_already+v[i]], dp[v_already]+w[i]);
        }
    }

    ll ans=0;
    for(ll i=0; i<v_sum+1; i++)
    {
        if(dp[i]<=W && i>ans) ans=i;
    }

    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 1024
// Shift-JIS（シフトジス）

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

int gcd(int a, int b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

int main()
{
    int N, K;
    cin >> N >> K;
    if (N % K == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define CMAX(m, x)  m = max(m,x);
#define CMIN(m, x)  m = min(m,x);
#define itn int
typedef long long lint;
const int INF = 1e9;
const lint LINF = 1e18;
int main(){
    int r;
    cin >> r;
    cout << 2 * r * 3.1415926535 << endl;
    return 0;
}

Measured memory_bytes: 3776
#include <stdio.h>

int linear_search(int a[], int n, int key) {
	int i = 0;
	a[n] = key;
	while (a[i] != key) ++i;
	return i != n;
}

int main() {
	int i, n, a[10001], q, key, sum = 0;

	scanf("%d", &n);
	for (i = 0; i < n; ++i) scanf("%d", &a[i]);
	scanf("%d", &q);
	for (i = 0; i < q; ++i) {
		scanf("%d", &key);
		if (linear_search(a, n, key)) sum++;
	}

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

	return 0;
}


Measured memory_bytes: 2132
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;

#define ll long long
#define ull unsigned long long

int main()
{
	long n, m;
	cin >> n >> m;

	long result;

	if (n == 1)
		result = m;
	else
		for (long i = 1; n * i <= m; i++)
			if (m % i == 0)
			{
				if (m / i % n  == 0 && m / i / n >= 2)
					i = (m / i / n) * i;
				result = i;
			}

	printf("%ld", result);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int w = sc.nextInt();
        int[] num = new int[w];
        for(int i=0;i<w;i++) num[i] = i + 1;
        int n = sc.nextInt(),a,b,tmp;
        String tmpstr;
        for(int i=0;i<n;i++){
            tmpstr = sc.next();
            String[] str = tmpstr.split(",");
            a = Integer.parseInt(str[0]);
            b = Integer.parseInt(str[1]);
            tmp = num[a-1];
            num[a-1] = num[b-1];
            num[b-1] = tmp;
        }
        for(int i=0;i<w;i++) System.out.println(num[i]);
    }
}


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

int main(){
  string s;
  cin >> s;
  bool can = false;
  if(s[0]==s[1] && s[2]==s[3]) can = true;
  if(s[0]==s[2] && s[1]==s[3]) can = true;
  if(s[0]==s[3] && s[2]==s[1]) can = true;
  if(s[0]==s[1] && s[1]==s[2] && s[2]==s[3]) can = false;
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

typedef pair<ll, ll> P;

ll N, M;

class ModuloCombination {
    using ll = long long;
    ll mod, len;
    vector<ll> f, rf;

    ll inv(ll x) {
        ll res = 1;
        ll k = mod - 2;
        ll y = x;
        while (k) {
            if (k & 1) res = (res * y) % mod;
            y = y * y % mod;
            k /= 2;
        }
        return res;
    }

public:
    ModuloCombination(long long modulo = 1000000007)
        : mod(modulo), len(101010), f(vector<ll>(len)), rf(vector<ll>(len)) {
        f[0] = 1;
        for (int i = 0; i < len - 1; i++) f[i + 1] = f[i] * (i + 1) % mod;
        for (int i = 0; i < len; i++) rf[i] = inv(f[i]);
    }
    ll c(int n, int k) {
        ll a = f[n];
        ll b = rf[n - k];
        ll c = rf[k];
        ll bc = (b * c) % mod;
        return (a * bc) % mod;
    }
    ll getMod() { return mod; }
};

// n+x-1 C x

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

    cin >> N >> M;

    ll orig_m = M;
    unordered_map<ll, ll> mp;

    while (true) {
        if (M % 2 != 0) break;
        mp[2]++;
        M /= 2;
    }

    int min = 3;
    bool find = true;
    while (find) {
        find = false;
        for (ll i = min; i <= sqrt(orig_m); i += 2) {
            if (M % i == 0) {
                mp[i]++;
                min = i;
                M /= i;
                find = true;
                break;
            }
        }
    }

    if (M != 1) mp[M]++;

    ll ans = 1;
    ModuloCombination comb;
    ll mod = comb.getMod();
    for (auto elem : mp)
        ans = ans * comb.c(N + elem.second - 1, elem.second) % mod;

    print(ans);

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


Measured memory_bytes: 1792
// B - Kleene Inversion
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007

int main(){
	ll N,K; cin>>N>>K;
	vector<ll> A(N);
	ll L = 0, M = 0;
	for(int i=0; i<N; i++){
		cin>>A[i];
		for(int j=i-1; j>=0; j--) if(A[i]<A[j]) L++;
	}

	for(int i=0; i<N; i++)
		for(int j=0; j<N; j++) if(i!=j && A[i]>A[j]) M++;

	ll KC2 = K*(K-1)/2 % MOD;
	ll a = L * K % MOD;
	ll b = M * KC2 % MOD;
	cout<< (a+b) % MOD << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main()
{
  cin.tie(0);
  int d;
  cin >> d;
  if (d == 25) cout << "Christmas" << endl;
  if (d == 24) cout << "Christmas Eve" << endl;
  if (d == 23) cout << "Christmas Eve Eve" << endl;
  if (d == 22 ) cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
N,A,B=map(int,input().split())
c=[]
for i in range(N+1):
    
    b=0
    a=i
    while (a!=0):
        b+=a%10
        a=int(a/10)
    if A<=b and b<=B:
        c.append(i)
print(sum(c))
       

Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<vector<char>> s(n, vector<char>(n, 0));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      char tmp;
      cin >> tmp;
      s[i][j] = tmp;
    }
  }
  int ans = 0;
  for (int k = 0; k < n; k++) {
    bool flag = false;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (s[i][(j + k) % n] != s[j][(i + k) % n]) {
          flag = true;
        }
      }
    }
    if (!flag) {
      ans += n;
    }
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	int n, k;
	cin >> n >> k;
	if (k == 1) {
		cout << 0 << endl;
		return 0;
	}
	n -= k;
	cout << n << endl;
		
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int n;
int p[200000];
int main() {
    cin >> n;
    rep(i, n) cin >> p[i];
    int count = 1;
    int min = p[0];
    for (int i = 1; i < n; i++) {
        if (min >= p[i]) {
            min = p[i];
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
char field[8][8];
char tempfield[8][8];

void rot() {
  for(int i=0;i<8;i++) {
    for(int j=0;j<8;j++) {
      tempfield[j][7-i] = field[i][j];
    }
  }

  for(int i=0;i<8;i++) {
    for(int j=0;j<8;j++) {
      field[i][j] = tempfield[i][j];
    }
  }

}

int main() {
  for(int i=0;i<8;i++) {
    for(int j=0;j<8;j++) {
      cin >> field[i][j];
    }
  }
  rot();
  cout << 90 << endl;
  for(int i=0;i<8;i++) {
    for(int j=0;j<8;j++) {
      cout << field[i][j];
    }
    cout << endl;
  }
  rot();
  cout << 180 << endl;
  for(int i=0;i<8;i++) {
    for(int j=0;j<8;j++) {
      cout << field[i][j];
    }
    cout << endl;
  }
  rot();
  cout << 270 << endl;
  for(int i=0;i<8;i++) {
    for(int j=0;j<8;j++) {
      cout << field[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 0
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
    var N = parseInt(input[0][0], 10);
    var W = parseInt(input[0][1], 10);
    var arr_vw = [];
    var arr_dp = [Array.from({length: W + 1}, () => 0)];
    var tmpW;
    for (var i = 0; i < N; i++){
        arr_vw.push(input[i + 1].map(e => parseInt(e, 10)));
        arr_dp.push([]);
        tmpVw = arr_vw[i];
        for (var j = 0; j <= W; j++){
            if (j < tmpVw[1]) arr_dp[i + 1].push(arr_dp[i][j]);
            if (j >= tmpVw[1]){
                arr_dp[i + 1].push(Math.max(arr_dp[i][j], arr_dp[i + 1][j - tmpVw[1]] + tmpVw[0]));
            }
        }
    }
    console.log(arr_dp[N][W]);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 


Measured memory_bytes: 38604
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
using namespace std;
//typedef pair<long, long> pair;
int main(){
  int N, M;
  cin >> N >> M;

  pair<long,long> p;
  vector<pair<long, int> > AB;

  long a;
  int b;
  for(int i=0;i<N;i++){
    cin >> a >> b;
    p = make_pair(a,b);
    AB.push_back(p);
  }

  sort(AB.begin(), AB.end());

  //cout << AB[0].first <<endl;
  long cost = 0;
  int count = M;
  int i = 0;

  while(count >= AB[i].second){    
    count -= AB[i].second;
    cost += (AB[i].first)*(AB[i].second);
    i++;    
  }

  cost += (AB[i].first)*count;

  cout << cost <<endl;

  return 0;
}


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

string str;

long long ans=0;

void func(int num)
{
    for(int i=0;i<=str.length()-1;i++)
    {
        if(str.length()-i<num) break;
        string s="";
        for(int k=i,t=0;t<num;k++,t++)s+=str[k];
        stringstream ss;
        ss<<s;
        long long nn;
        ss>>nn;
        long long temp=0;
        if(i==0||i==str.length()-num)temp=nn*(long long)pow(2,str.length()-num-1);
        else   temp=nn*(long long)pow(2,str.length()-num-2);
        ans+=temp;
    }
}








int main()
{
     cin>>str;
     stringstream sss;
     sss<<str;
     long long an=0;
     sss>>an;
     ans=0;
     for(int i=1;i<=str.length()-1;i++)func(i);
     cout<<an+ans<<endl;

}


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

using namespace std;
int dp[40001];

void solve()
{
	int n;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; ++i)
	{
		cin >> vec[i];
	}
	fill(dp, dp + 40000, 0);
	dp[0] = 1;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 40000; j >= vec[i]; --j)
		{
			if (dp[j - vec[i]] > 0)
			{
				dp[j] = dp[j - vec[i]];
			}
		}
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i)
	{
		int m;
		cin >> m;
		if (dp[m] > 0)
		{
			cout << "yes" << endl;
		}
		else
		{
			cout << "no" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1344
#include <iostream>
#include <cmath>

using namespace std;

int calc(int x, int s, int t){
    return s*(100+x)/100 + t*(100+x)/100;
}

int main(){
    int x, y, s;
    while(cin >> x >> y >> s, x+y+s){
        int ans = 0;
        for(int i=1; i < s; i++){
            for(int j=1; j < s; j++){
                if(calc(x, i, j) == s && ans < calc(y, i, j)) ans = calc(y, i, j);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
#include <stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b && b<c)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }

	return 0;
}



Measured memory_bytes: 2028
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
#define ALL(a) (a).begin(), (a).end()
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

unsigned GetDigit(unsigned num) { return to_string(num).length(); }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{

    int N; cin >> N;
    int res[N]={0};
    REP(i,N-1){
        int a; cin >> a;
        a--;
        res[a]++;
    }

    REP(i,N){
        cout << res[i] << endl;

    }

    return 0;
}


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

int solver(int n,int a[],int b[],int c[],int dp[][3],int r)
{
    if(n==0){return 0;}
    if(dp[n][r]!=-1){return dp[n][r];}
    if(r==0)
    {
        dp[n][r]=max(solver(n-1,a,b,c,dp,1),solver(n-1,a,b,c,dp,2))+a[n];
    }
    if(r==1)
    {
        dp[n][r]=max(solver(n-1,a,b,c,dp,0),solver(n-1,a,b,c,dp,2))+b[n];
    }
    if(r==2)
    {
        dp[n][r]=max(solver(n-1,a,b,c,dp,0),solver(n-1,a,b,c,dp,1))+c[n];
    }
    return dp[n][r];
}

int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);
   int n;
   cin>>n;
   int a[n+1],b[n+1],c[n+1],dp[n+1][3];
   for(int x=1;x<=n;x++)
   {
       cin>>a[x]>>b[x]>>c[x];
   }
   for(int x=0;x<n+1;x++)
   {
       for(int y=0;y<3;y++)
       {
           dp[x][y]=-1;
       }
   }
   /*dp[0][0]=dp[0][1]=dp[0][2]=0;
   for(int x=1;x<=n;x++)
   {
       dp[x][0]=max(dp[x-1][1]+a[x],dp[x-1][2]+a[x]);
       dp[x][1]=max(dp[x-1][0]+b[x],dp[x-1][2]+b[x]);
       dp[x][2]=max(dp[x-1][0]+c[x],dp[x-1][1]+c[x]);
   }*/
   cout<<max(max(solver(n,a,b,c,dp,0),solver(n,a,b,c,dp,1)),solver(n,a,b,c,dp,2))<<endl;;
}








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

#define REP(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < ll(n); ++i)
#define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if (a < 10 && b < 10)cout << a * b << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 256
def isCorrect(n):
    l = [int(x) for x in list(str(n))]
    prev = l.pop(0)

    for num in l:
        if num != prev:
            return False
        prev = num
    return True

if __name__ == '__main__':
    n = int(input())

    for m in range(n, 100000):
        if isCorrect(m):
            print(m)
            break


Measured memory_bytes: 3060
#include<stdio.h>
int main(void){
  int x,y;
  do{
  scanf("%d", &x);
  scanf("%d", &y);
  if(x == 0 && y == 0){
    return 0;
  }
  else if(x <= y){
    printf("%d %d\n", x, y);
  }
  else if(x > y){
    printf("%d %d\n", y, x);
  }
  }while(x !=0 || y != 0);
  return 0;
}

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

vector<vector<char>>v(31,vector<char>(31,'.'));
int h,w,n;
bool simulate(vector<vector<char>>graph){
    
    vector<vector<bool>>flag(h+1,vector<bool>(w+1,true));
    rep(i,h)rep(j,w)if(graph[i][j]=='.')flag[i][j]=false;
    vector<vector<char>>temp(h+1,vector<char>(w+1,'.'));
    for(int dx=w-1; dx>=0;dx--){
        int index=h-1;
        for(int dy=h-1;dy>=0&&index>=0;dy--)if(flag[dy][dx])temp[index--][dx]=graph[dy][dx];
    }
    graph=temp;
    //rep(i,h){rep(j,w){cout<<graph[i][j];}cout<<endl;}cout<<endl;
    while(true){
        bool changeble=false;
        vector<vector<bool>>init(h+1,vector<bool>(w+1,true));
        flag=init;
        rep(i,h)rep(j,w)if(graph[i][j]=='.')flag[i][j]=false;
        for(int y=0; y<h;y++){
            for(int x=0; x<w;x++){
                if(graph[y][x]=='.')continue;
                int cnt=0;
                for(int dx=x; dx<w;dx++){
                    //if(graph[y][dx]=='.')continue;
                    if(graph[y][dx]==graph[y][x])cnt++; else break;
                }
                if(cnt>=n){
                    for(int dx=x;cnt>0&&dx<w;dx++){
                        if(graph[y][dx]=='.')continue;
                        flag[y][dx]=false;
                        --cnt;
                        changeble=true;
                    }
                }
                cnt=0;
                for(int dy=y; dy<h;dy++){
                    //if(graph[dy][x]=='.')continue;
                    if(graph[dy][x]==graph[y][x])cnt++; else break;
                }
                if(cnt>=n){
                    for(int dy=y;dy<h&&cnt>0;dy++){
                        if(graph[dy][x]=='.')continue;
                        flag[dy][x]=false;
                        --cnt;
                        changeble=true;
                    }
                }
            }
        }
        /*?????????????????¨???*/
        vector<vector<char>>temp(h+1,vector<char>(w+1,'.'));
        for(int dx=w-1; dx>=0;dx--){
            int index=h-1;
            for(int dy=h-1;dy>=0&&index>=0;dy--)if(flag[dy][dx])temp[index--][dx]=graph[dy][dx];
        }
        graph=temp;
        if(!changeble)break;
    }
    bool ans=true;
    rep(i,h)rep(j,w)if(graph[i][j]!='.')ans=false;
    return ans;
}
bool solve(){
    bool hoge=false;
    rep(i,h)rep(j,w){
        vector<vector<char>>y(31,vector<char>(31,'.'));
        vector<vector<char>>x(31,vector<char>(31,'.'));
        y=v; x=v;
        //if(i<h-1){swap(y[i][j],y[i+1][j]);if(simulate(y))hoge=true;}
        if(j<w-1){swap(x[i][j],x[i][j+1]);if(simulate(x))hoge=true;}
    }
    return hoge;
}
int main(){
    cin>>h>>w>>n;
    rep(i,h)rep(j,w)cin>>v[i][j];
    if(solve())cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 3140