akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)








int main() {
    string s;
    cin >> s;
    REP(i, 8){
        if(s.substr(0, i) + s.substr(s.size() - (7 - i), 7 - i) == "keyence"){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
// ProblemURL : https://atcoder.jp/contests/abc072/tasks/arc082_b
// ---------------------------------------------
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ps := make([]int, n)
	for i := range ps {
		fmt.Scan(&ps[i])
		ps[i]--
	}
	ps = append(ps, -1)

	ct := 0
	for i := 0; i < n; i++ {
		if ps[i] == i {
			ps[i], ps[i+1] = ps[i+1], ps[i]
			ct++
		}
	}
	fmt.Println(ct)
}


Measured memory_bytes: 7340
#include<stdio.h>
int main() {
	int a,b,c,d,e,f;
	scanf("%d %d %d %d %d %d", &a,&b,&c,&d,&e,&f);
	scanf("%d", 1 * a);
	scanf("%d", 5 * b);
	scanf("%d", 10 * c);
	scanf("%d", 50 * d);
	scanf("%d", 100 * e);
	scanf("%d", 500 * f);
	if (1*a+5*b+10*c+50*d+100*e+500*f< 1000) {
		printf("0\n");
	}
	else{
		printf("1\n");
	}
	return 0;
}


Measured memory_bytes: 2668
import java.util.Scanner;
import java.util.Comparator;
import java.util.Arrays;
import java.util.ArrayList;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int sum = 0;
		for (int i = 0; i < S.length(); i++) {
			if(S.charAt(i) == 'x') {
				sum++;
				if(sum >= 8) {
					break;
				}
			}
		}
		if(sum>=8) {
			System.out.println("NO");
		}
		else {
			System.out.println("YES");
		}
		
		

	}
}	



Measured memory_bytes: 23892
#include<iostream>
using namespace std;
long p;
long A[3000];
long B[3000][3000];
long power(long a,long b){return b?power(a*a%p,b/2)*(b%2?a:1)%p:1;}
main()
{
	cin>>p;
	for(int i=0;i<p;i++)cin>>A[i];
	B[0][0]=1;
	B[p-1][0]=p-1;
	for(int i=1;i<p;i++)
	{
		B[p-1][i]=p-1;
		for(int j=p-2;j>0;j--)B[j][i]=B[j+1][i]*i%p;
	}
	for(int i=0;i<p;i++)
	{
		long now=0;
		for(int j=0;j<p;j++)(now+=B[i][j]*A[j])%=p;
		cout<<now<<endl;
	}
}


Measured memory_bytes: 70528
#include <bits/stdc++.h>
#define rep(i,a,b) for(auto i=(a);i<(b);i++)
#define per(i,a,b) for(auto i=(a);i>=(b);i--)
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define int_inf 0x3f3f3f3f
#define int_max 2147483647
#define ll_max 9223372036854775807
#define ull_max 18446744073709551615
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lowbit(x) (x)&(-x)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const ll mod=1e9+7;
template<class T>
inline T read()
{
	T x=0,f=1;char s=getchar();
	while(s<'0'||s>'9') {if(s=='-')f=-1;s=getchar();};
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();};
	return x*f;
}
template<typename T>
inline void wri(T x)
{
	if(x<0){x=-x;putchar('-');};
	if(x/10) wri(x/10);
	putchar(x%10+48);
}
template<typename T>
inline void print(T x,char s)
{
	wri(x);
	putchar(s);
}
template<typename T>
T gcd(T a,T b)
{
	return b==0?a:gcd(b,a%b);
}
//关闭流同步就不能手写读入优化啦
string s;
int k;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>k>>s;
    if(s.size()<=k){
    	cout<<s<<endl;
	}
	else{
		rep(i,0,k)cout<<s[i];
		cout<<"...";
	}
    return 0;
}


Measured memory_bytes: 3612
/*************************************************************************
> File Name: test.cpp
> Author: Akira 
> Mail: qaq.febr2.qaq@gmail.com 
************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
#define ALL(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back
using namespace std;

#define MaxN 100005
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
template<typename T> T abs(T val){return val>0?val:-val;}
inline int max2(int a, int b) {return ((a > b)? a : b);}
inline int min2(int a, int b) {return ((a < b)? a : b);}
inline int max3(int a, int b, int c) {return max2(a, max2(b, c));}
inline int min3(int a, int b, int c) {return min2(a, min2(b, c));}
template <class T> inline void read(T &ret) {char c; ret=0;while((c=getchar())<'0'||c>'9');while(c>='0'&&c<='9') ret=ret*10+(c-'0'),c=getchar();}
template <class T> inline void out(T x) {if(x>9) out(x/10);putchar(x%10+'0');}
int N;
char s1[60],s2[60];
LL dp[60];
void solve()
{
    for(int i=1;i<=N;i++)
    {
        if(i==1)
        {
            if(s1[i]==s2[i])
            {
                dp[1] = 3;
            }
            else
            {
                dp[1] = dp[2] = 6;
                i++;
            }
        }
        else
        {
            if(s1[i]==s2[i])
            {
                if(s1[i-1]==s2[i-1])
                {
                    dp[i] = 2LL*dp[i-1];
                    if(dp[i]>mod) dp[i]%=mod;
                }
                else
                {
                    dp[i] = dp[i-1];
                }
            }
            else
            {
                if(s1[i-1]==s2[i-1])
                {
                    dp[i] = dp[i+1] = 2LL*dp[i-1];
                    if(dp[i]>mod) dp[i]%=mod,dp[i+1]%=mod;
                }
                else
                {
                    dp[i] = dp[i+1] = dp[i-1]*3LL;
                    if(dp[i]>mod) dp[i]%=mod,dp[i+1]%=mod;
                }
                i++;
            }
        }
        
        // debug(i)
        // debug(dp[i])
    }
    LL ans = dp[N]%mod;
    out(ans);puts("");
}
int main()
{
    //std::ios::sync_with_stdio(false);
    while(~scanf("%d", &N))
    {
        scanf("%s%s", s1+1, s2+1);
        solve();
    }
    //system("pause");
    //printf("%lld\n", ((x)%mod+mod)%mod );
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
}


Measured memory_bytes: 256
taka_HP, taka_Power, aoki_HP, aoki_Power = map(int, input().split())

while True:
    aoki_HP -= taka_Power
    if aoki_HP <= 0:
        print('Yes')
        break

    taka_HP -= aoki_Power        
    if taka_HP <= 0:
        print('No')
        break

Measured memory_bytes: 9116
//  Created by liszt on 2019/07/24.
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,m; cin>>n >>m;
    vector<pair<long long,int>> ab(n);
    
    for(int i=0;i<n;i++)cin>>ab[i].first >>ab[i].second;
    
    sort(ab.begin(),ab.end());
    
    long long ans=0;
    int i=0;
    for(int i=0;i<n;i++){
        if(m<ab[i].second){
            ans+=m*ab[i].first;
            break;
        }
        ans+=ab[i].first*ab[i].second;
        m-=ab[i].second;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
s = input()
n = len(s)
s_1 = s[::-1]
s2 = s[0:int((n-1)/2)]
s_2 = s2[::-1]
s3 =s[int((n+3)/2)-1:]
s_3 = s3[::1]
if s==s_1 and s2==s_2 and s3==s_3:
  print('Yes')
else:
  print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define input_from_file  freopen("input.txt", "r", stdin);
using namespace std;

bool valid(int a, int n){
  if(a >= 0 && a < n) return true;
  return false;
}

int main()
{
FASTIO
//input_from_file

int n,k;
cin >> n >> k;

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

int dp[n];
dp[0] = 0;
if(n == 1){
  cout << 0;
  return 0;
}

for(int i = 1; i < n; i++){
  dp[i] = INT_MAX;
}

for(int i = 1; i < n; i++){
  for(int j = 1; j <= k && valid(i-j , n); j++){
    int temp = abs(a[i] - a[i-j]) + dp[i-j];
    if(temp < dp[i]) dp[i] = temp;
  }
}

cout << dp[n-1];
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		long[] array = new long[n];

		for(int i = 0; i < n; i++){
			array[i] = sc.nextLong();
		}

		long ans = array[0];

		for(int i = 0; i < n -1; i++){
			ans = lcm(ans, array[i+1]);
		}

		System.out.println(ans);
	}

	private static long gcd(long m, long n){
		if(n == 0) return m;
		return gcd(n, m % n);
	}

	private static long lcm(long m, long n){
		return m / gcd(m, n) * n;
	}
}

Measured memory_bytes: 22740
from collections import deque

h,w = map(int, input().split())
n = int(input())
al = list(map(int, input().split()))
ans = [ [0]*w for _ in range(h) ]

q = deque([])
for i,a in enumerate(al):
    c = i+1
    for _ in range(a):
        q.append(c)


for hi in range(h):
    for wi in range(w):
        if hi%2 == 0: ind = wi
        else: ind = ind = w-1-wi
        ans[hi][ind] = q.popleft()

for row in ans:
    print(*row)

Measured memory_bytes: 74832
#include<stdio.h>

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int arr[n];
    int sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        sum+=arr[i];
    }
    double min=(double)sum/(4*m);
    int count=0;
    for(int i=0;i<n;i++)
    {
        if(arr[i]>=min)
        count++;
        if(count==m)
        break;
    }
    if(count==m)
    printf("Yes");
    else 
    printf("No");
}


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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int d, g;
  cin >> d >> g;
  vi p(d), c(d);
  for (int i = 0; i < d; i++) {
    cin >> p[i] >> c[i];
  }

  int ans = INT_MAX;
  for (int i = 0; i < (1 << d); i++) {
    int sum = 0;
    int cnt = 0;
    // printf("i=%x\n", i);
    for (int j = 0; j < d; j++) {
      if (((i >> j) & 1) == 1) {
        sum += p[j] * (j + 1) * 100 + c[j];
        cnt += p[j];
      }
    }
    // printf("sum=%d\n", sum);
    if (sum >= g) {
      ans = min(ans, cnt);
      continue;
    }
    for (int j = d - 1; j >= 0; j--) {
      if (((i >> j) & 1) != 1) {
        // printf("j=%d\n", j);
        int rest = g - sum;
        int point = (j + 1) * 100;
        int tmp_cnt = min(p[j] - 1, (rest + point - 1) / point);
        // printf("rest=%d, point=%d, tmp_cnt=%d\n", rest, point, tmp_cnt);
        sum += tmp_cnt * (j + 1) * 100;
        cnt += tmp_cnt;
      }
      if (sum >= g) {
        break;
      }
    }
    if (sum >= g) {
      ans = min(ans, cnt);
    }
  }
  cout << ans << endl;
  return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int x,n;cin>>x>>n;
  map<int, int>m;
  rep(i, n){
    int t;cin>>t;
    m[t]++;
  }
  int result = 200;

  for(int i=101; i>=0; i--){
    if(m[i]==0 && abs(result-x)>=abs(i-x))result=i;
  }

  cout<<result<<endl;

  return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	if (n >= 1000) printf("ABD\n");
	else printf("ABC\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> L(N);
  for(int i=0; i<N; i++)
    cin >> L[i];
  int ans = 1000000;
  for(int i=0; i<pow(4,N); i++) {
    vector<int> As, Bs, Cs;
    int ii = i;
    for(int j=0; j<N; j++) {
      int jj = ii % 4;
      if(jj == 0)
	As.push_back(L[j]);
      else if(jj == 1)
	Bs.push_back(L[j]);
      else if(jj == 2)
	Cs.push_back(L[j]);
      ii /= 4;
    }
    if(As.size() != 0 && Bs.size() != 0 && Cs.size() != 0) {
      int tmp =
	abs(A - accumulate(As.begin(), As.end(), 0)) + 10 * (As.size() - 1) +
	abs(B - accumulate(Bs.begin(), Bs.end(), 0)) + 10 * (Bs.size() - 1) +
	abs(C - accumulate(Cs.begin(), Cs.end(), 0)) + 10 * (Cs.size() - 1);
      if(tmp < ans)
	ans = tmp;
    }
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
using namespace std;

int main(){
  ll A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;

  ll ans = 0;
  ll XY_min = min(X,Y);


  if(A+B >= 2*C){
    X -= XY_min;
    Y -= XY_min;
    ans += 2 * C * XY_min;
    //cout <<ans;
  }

  if(A >= 2*C){
    ans += 2 * C * X;
    X = 0;
  }else{
    ans += A * X;
    X =0;
  }
  if(B >= 2*C){
    ans += 2 * C * Y;
    Y= 0;
  }else{
    ans += B * Y;
    Y = 0;
  }

  cout<<ans;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		int m = sc.nextInt();
		int l = sc.nextInt();

		int A[][] = new int[n][m];
		int B[][] = new int[m][l];
		long C[][] = new long[n][l];

		// ??????A
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				A[i][j] = sc.nextInt();
			}
		}

		// ??????B
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < l; j++) {
				B[i][j] = sc.nextInt();
			}
		}

		// ???
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				for (int k = 0; k < l; k++) {
					C[i][k] += A[i][j] * B[j][k];
				}
			}
		}

		// ??????
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < l - 1; j++) {
				System.out.print(C[i][j] + " ");
			}
			System.out.println(C[i][l - 1]);
		}

	}

}

Measured memory_bytes: 53568
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin>>n;
  ll ch=(n+1000-1)/1000;
  ch=ch*1000;
  cout<<(ch-n)<<"\n";
  return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main() {
    ll x,y; cin >> x >> y;
    ll ans = x;
    ll count = 0;
    while (ans <= y){
        count++;
        ans *= 2;
    }
    print(count);
}

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

int main(){
  string S;
  cin >> S;
  if(S=="SUN"){
    cout << 7 << endl;
  }else if(S=="MON"){
    cout << 6 << endl;
  }else if(S=="TUE"){
    cout << 5 << endl;
  }else if(S=="WED"){
    cout << 4 << endl;
  }else if(S=="THU"){
    cout << 3 << endl;
  }else if(S=="FRI"){
    cout << 2 << endl;
  }else{
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int> > S(M, vector<int>(N, 0));
  vector<int> K(M);
  for(int i=0;i<M;i++){
    cin >> K[i];
    for(int j=0;j<K[i];j++){
      cin >> S[i][j];
    }
  }
  vector<int> P(M);
  for(int i=0;i<M;i++){
    cin >> P[i];
  }
  int count = 0;
  for(int i=0;i<pow(2,N);i++){
    bool flag = true;
    int tmp = i;
    vector<int> sign(N);
    for(int j=0;j<N;j++){
      sign[j] = tmp % 2;
      tmp = (tmp - tmp%2)/2;
      // cout << sign[j];
    }
    //cout << endl;
    for(int j=0;j<M;j++){
      // cout << "j=" << j << endl;
      int sum = 0;
      for(int k=0;k<K[j];k++){
        // cout << sign[S[j][k]-1] << endl;
        sum += sign[S[j][k]-1];
      }
      // cout << sum << endl;
      if(sum % 2 !=P[j]){
        flag = false;
        break;
      }
    }
    if(flag){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
#define ar array
const int mxN=2e5;
const int MOD=1e9+7;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
int main()
{

    ll i,j,k=0,c1=0,c2=0;
    ll n;
    cin>>n;
    unsigned long long sum=0;
    vector<ll>v(3*n);
    for(i=0;i<3*n;i++)
    {
        cin>>v[i];
    }
    sort(v.rbegin(),v.rend());
    if(debug)
    {
        for(auto x:v)
        {
            cout<<x<<" ";
        }
        cout<<endl;
    }
    for(i=0;i<v.size();i++)
    {
        if(c1==n)
            break;
        else
        {
           if(i%2)
                sum+=v[i],c1++;


        }
    }
    cout<<sum<<endl;


    //cout<<endl;
}


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

int w,h,n;

int main(void){
	scanf("%d%d%d",&w,&h,&n);
	int px,py,nx,ny,cnt=0;
	scanf("%d%d",&px,&py);
	for(int i=0;i<n-1;i++){
		scanf("%d%d",&nx,&ny);
		int sa=nx-px;
		int sa2=ny-py;
		if(sa>=0 && sa2>=0)cnt+=max(sa,sa2);
		else if(sa<0 && sa2<0)cnt+=max(-sa,-sa2);
		else cnt+=abs(sa)+abs(sa2);
		px=nx,py=ny;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

ll mod_p(ll x, int n, int m) {
        if (n == 0) {
                return 1ll;
        } else {
                ll rest = n % 2 ? x : 1ll;
                return mod_p(x * x % m, n / 2, m) * rest % m;
        }
}

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

        const int n = s.size(), x = 2019;

        vector<int> c(n + 1, 0), t(x, 0);
        ll ans = 0;
        t[0] = 1;

        reverse(s.begin(), s.end());
        rep (i, n) {
                c[i + 1] = c[i] + mod_p(10, i, x) * (s[i] - '0');
                c[i + 1] %= x;
                ans += t[c[i + 1]];
                t[c[i + 1]]++;
        }

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 4360
def main():
    A, B, C = map(int, input().split(' '))
    K = int(input())
    for i in range(K):
        if A >= B:
            B *= 2
        else:
            if B >= C:
                C *= 2
    if A < B and B < C:
        print('Yes')
    else:
        print('No')
main()

Measured memory_bytes: 9088
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
#include <stdexcept>
using namespace std;


#define abs(N) ((N>0)?N:-1*N)
#define lt(A,B) ((A>B)?B:A)
#define gt(A,B) ((A<B)?B:A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

template <typename T>
class stack{
public :
	const static int MAX = 10000;
	stack<T> (){
		pos = 0;
	}

	void empty(){
		pos = 0;
	}

	bool isEmpty(){
		return (pos == 0);
	}

	bool isFull(){
		return (pos == MAX);
	}

	T pop(){
		if(isEmpty()){
			throw exception();
		}
		return body[--pos];
	}

	void push(T el){
		if(isFull()){
			throw exception();
		}
		body[pos++] = el;
	}

	T top(){
		if(isEmpty()){
			throw exception();
		}
		return body[pos-1];
	}

private:
	T body[MAX];
	int pos;
};

int main(){
	string buf,str;
	char cstr[1000];
	cin.getline(cstr,sizeof(cstr));
	str = string(cstr);
	stringstream ss(str);
	stack<int> st;
	while(getline(ss,buf,' ')){
//		println("-----"+buf+"-----");
		if(buf=="+" || buf == "-" || buf == "*"){
			int r1,r2,ret;
			r1 = st.pop();
			r2 = st.pop();
			if(buf=="+"){
				ret = r1+r2;
			}
			if(buf=="-"){
				ret = r2-r1;
			}
			if(buf=="*"){
				ret = r1*r2;
			}
			st.push(ret);
		}else{
			st.push(atoi(buf.c_str()));
		}
	}
	println(st.top());

	return 0;
}



Measured memory_bytes: 3176
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int res = 0;
		Scanner scn = new Scanner(System.in);
		ArrayList<Integer> sticks = new ArrayList<Integer>();
		int amount = scn.nextInt();
		for (int i = 0; i < amount; i++) {
			sticks.add(scn.nextInt());
		}
		for (int i = 0; i < sticks.size(); i++) {
			for (int i1 = i+1; i1 < sticks.size(); i1++) {
				for (int i2 = i1+1; i2 < sticks.size(); i2++) {
					if (sticks.get(i).equals(sticks.get(i1)) || sticks.get(i).equals(sticks.get(i2)) || sticks.get(i1).equals(sticks.get(i2))) {
						continue;
					}
					if (sticks.get(i) > sticks.get(i1) && sticks.get(i) > sticks.get(i2)) {
						if (sticks.get(i) < sticks.get(i1) + sticks.get(i2)) {
							res++;
						}
						continue;
					}
					if (sticks.get(i1) > sticks.get(i) && sticks.get(i1) > sticks.get(i2)) {
						if (sticks.get(i1) < sticks.get(i) + sticks.get(i2)) {
							res++;
						}
						continue;
					}
					if (sticks.get(i2) > sticks.get(i) && sticks.get(i2) > sticks.get(i1)) {
						if (sticks.get(i2) < sticks.get(i) + sticks.get(i1)) {
							res++;
						}
						continue;
					}
				}
			}
		}
		System.out.println(res);
	}

}

Measured memory_bytes: 38956
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define inf 1000000000000000000
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
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; }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  
  ll h, w; cin >> h >> w;
  vector<vector<ll>> a(h, vector<ll>(w));
  vector<vector<ll>> b(h, vector<ll>(w));
  vector<vector<ll>> c(h, vector<ll>(w));
  rep(i, h) {
    rep(j, w) {
      cin >> a[i][j];
    }
  }
  rep(i, h) {
    rep(j, w) {
      cin >> b[i][j];
    }
  }
  rep(i, h) {
    rep(j, w) {
      c[i][j] = abs(a[i][j] - b[i][j]);
    }
  }
  ll max_value = 80 * (h + w);
  vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w,vector<bool>(max_value + 1, false)));
  dp[0][0][c[0][0]] = true;
  rep(i, h) {
    rep(j, w) {
      rep(k, max_value + 1) {
        if (i + 1 < h && dp[i][j][k]) {
          if (0 <= k + c[i + 1][j] && k + c[i + 1][j] <= max_value) dp[i + 1][j][k + c[i + 1][j]] = true;
          if (0 <= abs(k - c[i + 1][j]) && abs(k - c[i + 1][j]) <= max_value) dp[i + 1][j][abs(k - c[i + 1][j])] = true;
        }
        if (j + 1 < w && dp[i][j][k]) {
          if (k + c[i][j + 1] <= max_value) dp[i][j + 1][k + c[i][j + 1]] = true;
          if (abs(k - c[i][j + 1]) <= max_value) dp[i][j + 1][abs(k - c[i][j + 1])] = true;
        }
      }
    }
  }
  rep(k, max_value + 1) {
    if (dp[h - 1][w - 1][k]) {
      cout << k << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 14308
#include <bits/stdc++.h>
using namespace std;
const int BASE = 1e9 + 7;

long long fact[600600], invFact[600600];

long long power(long long x, long long y)
{
  if (!y)
    return 1;
  long long res = power(x, y >> 1);
  res = res * res % BASE;
  if (y & 1)
    res = res * x % BASE;
  return res;
}

long long c(int n, int k)
{
  return n < k ? 0 : fact[n] * invFact[k] % BASE * invFact[n - k] % BASE;
}

// m numbers >= x, rest <= y
long long calc(int n, int m, int r, int x, int y)
{
  long long res = 0;
  // i of n - m > y
  for (int i = 0; i <= n - m; i++)
  {
    int rem = r - x * m - i * (y + 1);
    if (rem < 0)
      break;
    long long ways = c(n + rem, n) * c(n - m, i) % BASE;
    if (i % 2) res = (res - ways + BASE) % BASE;
    else res = (res + ways) % BASE;
  }
  return res;
}

long long solve(int n, int m, int r)
{
  long long res = c(n + r, n), bad = 0;
  for (int x = 1; x * m <= r; x++)
    bad = (bad + calc(n, m, r, x, x - 1) - calc(n, m, r, x + 1, x - 1) + BASE) % BASE;
  bad = bad * c(n, m) % BASE;
  return (res - bad + BASE) % BASE;
}

int main()
{
  for (int i = 0; i <= 600000; i++)
  {
    fact[i] = i ? fact[i - 1] * i % BASE : 1;
    invFact[i] = power(fact[i], BASE - 2);
  }

  int m, n, l, r;
  cin >> n >> m >> l >> r;
  cout << (solve(n, m, r) - solve(n, m, l - 1) + BASE) % BASE << endl;
}


Measured memory_bytes: 9600
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt()
  val a = List.fill(m)((sc.nextInt, sc.next))
    .groupBy(_._1).map{ case (x, y) => x -> y.map(_._2)}
  val ac = a.filter{case (k, v) => v.contains("AC")}.size
  val wa = a.values.map(v => {
    val index = v.indexOf("AC")
    if (index == -1) 0 else index
  }).sum
  println(s"$ac $wa")
}

Measured memory_bytes: 101172
package main

import (
	"fmt"
	"math"
	"strconv"
)

func Return(args ...interface{}) int {
	return args[0].(int)
}

func main() {
	var S string
	fmt.Scan(&S)

	ans := math.MaxFloat64
	for i := 0; i <= len(S) -3; i++ {
		ans = math.Min(ans, math.Abs(float64(Return(strconv.Atoi(S[i:i+3])) - 753)))
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

class program
{
    static public int mod = 1000000007;
    static void Main()
    {
        int[] nmq = inta();
        int n = nmq[0], m = nmq[1], q = nmq[2];
        int[] a = Enumerable.Repeat(1, n).ToArray();
        int[][] abcd = new int[q][];
        for(int i = 0; i < q; i++)
        {
            abcd[i] = inta();
        }
        int ans = 0;
        while (a[0] == 1)
        {
            int p = 0;

            for(int i = 0; i < q; i++)
                if(a[abcd[i][1]-1] - a[abcd[i][0]-1] == abcd[i][2])
                    p += abcd[i][3];

            ans = Max(ans, p);
            int j = n - 1;
            while (a[j] == m && --j > 0) ;
            int v = ++a[j];
            while (++j < n)
                a[j] = v;
        }
      
        Write(ans);        
    }

    static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; }
    static string rstr() { return ReadLine(); }
    static int rint() { return int.Parse(ReadLine()); }
    static long rlong() { return long.Parse(ReadLine()); }
    static string[] stra() { return ReadLine().Split(' '); }
    static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); }
    static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; }
    static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; }
    static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = double.Parse(read_str_array[countup_i]); } return return_double_array; }
    static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } }
    static long LCM(long a, long b) { return a * b / GCD(a, b); }
    static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } }
    static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); }
}


Measured memory_bytes: 28296
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
    };
    let mut res = vec![0; n];

    for _i in 1..=k {
        input! {
            d: usize,
            a: [usize; d],
        };

        for &j in a.iter() {
            res[j-1] += 1;
        };
    }

    let mut ans = 0;

    for r in res {
        if r == 0 {
            ans += 1;
        }
    }

    println!("{}", ans);
}



Measured memory_bytes: 2172
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcoder115_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] price = new int[N];
            int result = 0;
            int maxprice = 0 ;
            for (int i = 0;i<N;i++)
            {
                price[i] = int.Parse(Console.ReadLine());
                result += price[i];
            }

            maxprice = price.Max()/2;
            result -= maxprice;

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13268
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

immutable inf = 10^^9 + 7;
alias Edge = Tuple!(int, "to", int, "cost");

void main() {
    int n, m, s;
    scan(n, m, s);

    auto adj = new Edge[][](n, 0);

    foreach (i ; 0 .. m) {
        int a, b, c;
        scan(a, b, c);
        adj[a] ~= Edge(b, c);
    }

    auto d = dijkstra(adj, s);

    foreach (i ; 0 .. n) {
        if (d[i] == inf) writeln("INF");
        else writeln(d[i]);
    }
}

int[] dijkstra(Edge[][] adj, int s) {
    alias Node = Tuple!(int, "num", int, "dist");

    auto n = adj.length.to!int;
    auto minhp = new BinaryHeap!(Array!Node, "a.dist > b.dist")();
    auto d = new int[](n);
    d[] = inf;
    d[s] = 0;
    minhp.insert(Node(s, 0));

    int rep = n - 1;

    while (rep && !minhp.empty) {
        auto v = minhp.front;
        minhp.popFront();

        if (d[v.num] < v.dist) continue;
        rep--;

        foreach (e ; adj[v.num]) {
            if (d[v.num] + e.cost < d[e.to]) {
                d[e.to] = d[v.num] + e.cost;
                minhp.insert(Node(e.to, d[e.to]));
            }
        }
    }

    return d;
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 53668
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){


int L,a;
int r=0,q=0;
while(1){
scanf("%d %d",&a,&L);if(L==0&&a==0)break;
int x[7]={};int n[22]={};
n[0]=a;
for(int iii=1;iii<21;iii++){

	for(int j=0;j<L;j++)
	{x[j]=a%10;a=a/10;}

	for(int j=0;j<L;j++)
	{	for(int k=L-1;k>j;k--)
			if(x[k]>x[k-1]){int t=x[k];x[k]=x[k-1];x[k-1]=t;}
	}
	int max=0,min=0;
	for(int j=0;j<L;j++){min*=10;max*=10;
		max+=x[j];min+=x[L-j-1];
		
	}
	a=max-min;
	n[iii]=a;
}


for(int i=0;i<21;i++){
bool f=false;
for(int j=i+1;j<21;j++){
if(n[i]==n[j]){
	
	r=i;q=j;
		f=true;
		break;
}
}

if(f==true)break;
}

printf("%d %d %d\n",r,n[q],q-r);

}
return 0;
}

Measured memory_bytes: 1188
//08, 09, 2018, 09:05:59 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

set< string > st;

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

    int n;

    cin >> n;

    char last;
    
    for(int i = 0 ; i < n ; i++){
        string s;

        cin >> s;

        if(st.find(s) != st.end()){
            cout << "No" << endl;
            return 0;
        }

        if(i != 0){
            if(s[0] != last){
                cout << "No" << endl;
                return 0;
            }
        }

        last = s[s.length() - 1];
        st.insert(s);
    }    

    cout << "Yes" << endl;
    
    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [input() for i in range(N)]
    ans = 0
    ba = 0
    b = 0
    a = 0
    for s in A:
        ans += s.count("AB")
        if s[0] == "B" and s[-1] == "A":
            ba += 1
        elif s[0] == "B":
            b += 1
        elif s[-1] == "A":
            a += 1
    ans += (ba - 1 if ba > 1 else 0)
    if ba > 0 and a > 0 and b > 0:
        b += 1
        a += 1
        ans += min(a, b)
    elif ba > 0 and a == 0 and b == 0:
        pass
    elif ba > 0 and a > 0:
        ans += 1
    elif ba > 0 and b > 0:
        ans += 1
    elif ba == 0:
        ans += min(a, b)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 44760
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int n = s.size();
    int *arr = new int [n];
    fill(arr, arr + n, 0);
    int *brr = new int [n];
	int pre=n-1;
	for(int i = n - 1; i >= 0; i--)
	{
		if(s[i]=='L')
		pre=i;
		else
		brr[i]=pre;
	}
	pre = 0;
	for(int i=0; i<n; i++)
	{
		if(s[i]=='R')
		pre=i;
		else
		brr[i]=pre;
	}
	for(int i=0; i<n; i++)
	{
		if(brr[i]>i)
		{
			int nn=brr[i]-i;
			if(nn%2==0)
			arr[brr[i]]++;
			else
			arr[brr[i]-1]++;
		}
		else
		{
			int nn=i-brr[i];
			if(nn%2==0)
			arr[brr[i]]++;
			else
			arr[brr[i]+1]++;
		}
	}
	for(int i = 0; i < n; i++)
		cout<<arr[i]<<" ";
    cout << endl;
	return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>

using namespace std;

typedef long long ll;

string s;
int k;

int ans[300][300][301];

int Solve(int l, int r, int k) {
  if (k < 0) return -1000;
  if (l > r) return 0;
  if (l == r) return 1;
  int& result = ans[l][r][k];
  if (result != -1) return result;

  result = 0;

  result = max(result, Solve(l + 1, r, k));
  result = max(result, Solve(l, r - 1, k));
  result = max(result, 2 + Solve(l + 1, r - 1, k - (s[l] == s[r] ? 0 : 1)));

  return result;
}

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

  memset(ans, -1, sizeof(ans));
  cout << Solve(0, s.size() - 1, k) << endl;
  
  return 0;
}


Measured memory_bytes: 106112
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>

using namespace std;
typedef long long int ll;

ll n,m,tw[]={1,2,4,8,16,32,64,128,256,512};



ll hsi(ll a,ll b){
    return (1900*a+100*b)*tw[a];
}

int main(){
    scanf("%lld %lld",&n,&m);
    
    printf("%lld\n",hsi(m,n-m));
}

Measured memory_bytes: 256
import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
for i, s in enumerate(list(itertools.permutations(list(range(1, n+1))))):
    if list(s) == p:
        a = i
    if list(s) == q:
        b = i
print(abs(a-b))


Measured memory_bytes: 80164
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.split(/ |\n/),
    cid = 0;

function next() {
    return +cin[cid++];
} // number一個取得
function nextstr() {
    return cin[cid++];
} // 文字列一個取得
function nextbig() {
    return BigInt(cin[cid++]);
} // BigInteger一個取得
// 長さnの配列として取得。aは文字列フラグ
function nexts(n, a) {
    return a ? cin.slice(cid, cid += n) : cin.slice(cid, cid += n).map(a => +a);
}
// 長さnのBigInt配列として取得。
function nextsbig(n) {
    return cin.slice(cid, cid += n).map(a => BigInt(a));
}
// w個ずつを組にして長さhの配列。aは文字列フラグ。
function nextm(h, w, a) {
    var r = [],
        i = 0;
    if (a)
        for (; i < h; i++) r.push(cin.slice(cid, cid += w));
    else
        for (; i < h; i++) r.push(cin.slice(cid, cid += w).map(a => +a));
    return r;
}
// 多次元配列。v,a1,a2,a3 なら、3次元。[[値vで長さa3の配列]をa2個並べた配列]をa1個並べた配列。
function xArray(v) {
    var a = arguments,
        l = a.length,
        r = "Array(a[" + --l + "]).fill().map(x=>{return " + v + ";})";
    while (--l) r = "Array(a[" + l + "]).fill().map(x=>" + r + ")";
    return eval(r);
}


console.log(main().toString());

function main() {
    let s = nextstr();

    return s.substr(0, 1) + (s.length - 2) + s.substr(-1)

}

Measured memory_bytes: 21192
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define ins insert
#define mk make_pair
#define fr first
#define sc second
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll s=0;
        if(k>a && a>0)
        {
            k=k-a;
            s=s+a;
            a=0;
        }
        else if(a>0)
        {
            cout<<k;
            return 0;
        }
        if(k>b && b>0)
        {
            k=k-b;
            b=0;
        }
        else if(b>0)
        {
            cout<<s;
            return 0;
        }
        if(k>0)
        {
            cout<<s-k;
            return 0;
        }
    
}

Measured memory_bytes: 3652
import java.util.Scanner;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Comparator;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        Long[][] a = new Long[N][3];
        for(int i =0;i<N;i++){
            a[i][0] = sc.nextLong();
            a[i][1] = sc.nextLong();
            a[i][2] = sc.nextLong();
        }
        PriorityQueue<Long> pq = new PriorityQueue<>(Comparator.reverseOrder());
        pq.add(Search(M,N,a,1L,1l,1l));
        pq.add(Search(M,N,a,1l,1l,-1l));
        pq.add(Search(M,N,a,1l,-1l,1l));
        pq.add(Search(M,N,a,1l,-1l,-1l));
        pq.add(Search(M,N,a,-1l,1l,1l));
        pq.add(Search(M,N,a,-1l,1l,-1l));
        pq.add(Search(M,N,a,-1l,-1l,1l));
        pq.add(Search(M,N,a,-1l,-1l,-1l));
        System.out.print(pq.poll());
        sc.close();
    }
    public static Long Search(int M,int N,Long[][] L,Long x,Long y,Long z){
        PriorityQueue<Long> pq2 = new PriorityQueue<>(Comparator.reverseOrder());
        Long ans = 0l;
        for(int i = 0; i<N;i++){
            pq2.add(L[i][0]*x+L[i][1]*y+L[i][2]*z);
        }
        for(int i = 0; i<M;i++){
            ans += pq2.poll();
        }
        return ans;
    }
}

Measured memory_bytes: 28268
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
    string s, t; cin >> s >> t;

    map<char, vector<int>> cnt;
    for(int i=0; i<s.size(); i++){
        cnt[s.at(i)].push_back(i);
    }

    for(char c : t){
        if(cnt[c].empty()){
            cout << -1 << endl;
            return 0;
        }
    }

    int p = 0, q = -1;
    for(char c : t){
        const auto& v = cnt[c];
        int a = upper_bound(v.begin(), v.end(), q) - v.begin();
        if(a != v.size()){
            q = v[a];
            continue;
        }
        p++;
        q = v[0];
    }

    cout << long(p) * s.size() + q + 1 << endl;
    return 0;
}


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

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

    int n, d, count = 0;
    cin >> n >> d;

    for(int i = 0; i < n; i++) {
        ll p, q;
        cin >> p >> q;
        ll x = p*p + q*q;
        double y = abs(sqrt(x));
        if(y <= d)
            count++;
    }
    cout << count << "\n";

    return 0;
}


Measured memory_bytes: 3680
#include<iostream>
#include<vector>
#include<algorithm>
#include<complex>
#include<string.h>
using namespace std;
typedef long long int llint;
int main() {
	char s[3][110];
	for (int i = 0;i < 3;i++) {
		cin >> s[i];
	}
	int abc[3] = {};
	int now = 0;
	int tmp;
	while (abc[0] <= strlen(s[0]) && abc[1] <= strlen(s[1]) && abc[2] <= strlen(s[2])) {
		if (s[now][abc[now]] == '\0') {
			abc[now]++;
			break;
		}
		while (s[now][abc[now]] == 'a' + now) {
			abc[now]++;
		}
		cerr << now << endl;
		cerr << abc[now] << endl;
		tmp = now;
		now = s[now][abc[now]] - 'a';
		abc[tmp]++;
		cerr << now << endl;
	}
	cerr << abc[0] << abc[1] << abc[2] << endl;
	if (abc[0] == strlen(s[0]) + 1) {
		cout << "A" << endl;
	}
	else if (abc[1] == strlen(s[1]) + 1) {
		cout << "B" << endl;
	}
	else {
		cout << "C" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = k / 2;
        int q = k % 2;
        if(q==0){
            System.out.println(n*n);
        }
        else{
            System.out.println(n*(n+1));
        }
    }
}

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

int main(){
	int n, a[10000];
	while(cin >> n, n){
		long long int ans = 0, tmp = 0;
		for(int i = 0;i < n;i++)cin >> a[i];
		sort(a, a+n);
		for(int i = 0;i < n-1;i++){
			tmp += a[i];
			ans += tmp;
		}
		cout << ans << endl;
		//cout << endl << ans << endl;
		//for(int i = 0;i < n;i++)cout << a[i] << " ";
		//cout << ans << endl;
	}
	return 0;
}
//23469
//2  2
//5  7
//9  16
//15 31

Measured memory_bytes: 3128
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

vector < pair < ll, pair < ll, char > > > pos, neg;

string str;

bool comp(pair < ll, pair < ll, char > > a, pair < ll, pair < ll, char > > b)
{
	return a.first - a.second.first < b.first - b.second.first;
}

bool solve()
{
	ll tot = 0;

	for(auto it: pos) tot += it.second.first;
	for(auto it: neg) tot += it.second.first;

	if(tot) return 0;

	sort(pos.rbegin(),pos.rend());

	tot = 0;

	for(auto it: pos)
	{
		if(tot + it.first < 0) return 0;

		tot += it.second.first;
	}

//	cout << tot << endl;

	sort(neg.begin(),neg.end(),comp);

	for(auto it: neg)
	{
		if(tot + it.first < 0) return 0;

		tot += it.second.first;
	}

	return 1;
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n)
    {
		pos.clear();
		neg.clear();

		for(i = 1; i <= n; i++)
		{
			cin >> str;

			ll mn = str.size();
			ll sum = 0;

			for(auto it: str)
				if(it == '(') sum++, mn = min(mn,sum);
				else sum--, mn = min(mn, sum);

			if(sum > 0) pos.push_back({mn,{sum,str.back()}});
			else neg.push_back({mn,{sum,str.back()}});
		}

		if(solve()) printf("Yes\n");
		else printf("No\n");
    }


}




Measured memory_bytes: 26836
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
#define inf 0x3f3f3f3f
using namespace std;
int land[205][205], sea[205][205], tar[1005], dp[1005][205];
int main()
{
	int n, m, i, j, k, r;
	while (scanf("%d%d",&n,&m),n+m)
	{
		memset(land, inf, sizeof(land));
		memset(sea, inf, sizeof(sea));
		memset(dp, inf, sizeof(dp));
		for (int i = 1; i <= m; i++)
		{
			int a, b, c;
			string str;
			scanf("%d%d%d", &a, &b, &c);
			cin >> str;
			if (str == "S")
				sea[a][b] = sea[b][a] = c;
			else
				land[a][b] = land[b][a] = c;
		}
		for (int i = 1; i <= n; i++)
			land[i][i] = sea[i][i] = 0;
		scanf("%d", &r);
		for (int i = 1; i <= r; i++)
			scanf("%d", tar + i);
		for(int k=1;k<=n;k++)
			for(int i=1;i<=n;i++)
				for (int j = 1; j <= n; j++)
				{
					land[i][j] = min(land[i][j], land[i][k] + land[k][j]);
					sea[i][j] = min(sea[i][j], sea[i][k] + sea[k][j]);
				}
		//dp[i][j]代表到达了第i个要求达到的小镇tar[i]，船停在j镇。所花费的最小时间
		dp[1][tar[1]] = 0;
		for(int i=1;i<=r;i++)
			for (int j = 1; j <= n; j++)
			{
				dp[i][j] = min(dp[i][j], dp[i - 1][j] + land[tar[i - 1]][tar[i]]);
				for (int k = 1; k <= n; k++)
					dp[i][k] = min((long long)dp[i][k], (long long)dp[i - 1][j] + land[tar[i - 1]][j] + sea[j][k] + land[k][tar[i]]);
			}
		int ans = inf;
		for (int i = 1; i <= n; i++)
			ans = min(ans, dp[r][i]);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 4392