akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
//#include <cmath>
//#include <iomanip>
//#include <map>
//#include <unordered_map>
//#include <cstring>
#include <queue>

using namespace std;
using ll = long long;
// using pint = pair<int, int>;
// ll INF = 1LL << 60;

int main() {
	int n;
	cin >> n;
	vector<ll> fib(n);
	fib[0] = 1;
	fib[1] = 2;
	for (int i = 2; i < n; i++) {
		fib[i] = fib[i - 1] + fib[i - 2];
	}
	cout << fib[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>

int main() {
	int i=1, tmp1=1, tmp2=1;
	int n;
	scanf("%d", &n);
	while (tmp1) {
		int x=i;
		if (x%3==0) {
			if (i<=n) printf(" %d", i);
			tmp1=0;
		}
		if (tmp1) {
			for (tmp2=1;tmp2;) {
 				if ( x % 10 == 3 ){
 					if (i<=n) printf(" %d", i);
 			   		tmp1=0, tmp2=0;
  				}
  				x /= 10;
  				if (!x) tmp2=0;
  			}
		}
		if (++i <= n) tmp1=1;
	}
	printf("\n");
	return 0;
}

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

int main(){
    int N, K, R, S, P;
    cin >> N >> K >> R >> S >> P;
    string T;
    cin >> T;
    bitset<100000> win;
    for(int i=0; i<N; i++){
        if(i<K || T[i-K] != T[i] || !win[i-K]) win[i] = 1;
    }
    int64_t ans = 0;
    for(int i=0; i<N; i++) if(win[i]){
        if(T[i] == 'r') ans += P;
        if(T[i] == 's') ans += R;
        if(T[i] == 'p') ans += S;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int a[110], b[110];
int main()
{
  int n, finans = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%d", a + i);
  }
  for (int i = 0; i < n; i++)
  {
    scanf("%d", b + i);
  }
  int cnt = n;
  while (cnt > 0)
  {
    int ans = 0;
    for (int i = cnt - 1; i >= 0; i--)
    {
      ans += a[i];
    }
    for (int i = cnt - 1; i < n; i++)
    {
      ans += b[i];
    }
    finans = MAX(finans, ans);
    cnt--;
  }
  printf("%d\n", finans);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
	int arr[100], tmp, i, j, n = 10;
	
	for(i = 0;i < n;i++)
		scanf("%d", &arr[i]);
	for(j = 0;j < n - 1; j++){
		for(i = 0;i < (n - 1) - j;i++){
			if(arr[i] > arr[i +1]){
				tmp = arr[i];
				arr[i] = arr[i + 1];
				arr[i + 1] = tmp;
			}
		}
	}
	
	printf("%d\n", arr[n - 1]);
	printf("%d\n", arr[n - 2]);
	printf("%d\n", arr[n - 3]);
	
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  for(int i=1;i<=9;++i){
    for(int j=1;j<=9;++j){
      cout<<i<<"x"<<j<<"="<<i*j<<endl;
    }
  }
}




Measured memory_bytes: 2992
n=int(input())
d=[int(j) for j in input().split()]
if d[0]!=0:
    print(0)
    exit()
mod=998244353
import collections
c=collections.Counter(d)
l=c.most_common()
l.sort()
ans=1
tmp=0
for i in range(len(l)):
    if i==0:
        if l[i][1]!=1:
            print(0)
            exit()
        tmp=1
        continue
    if l[i][0]!=i:
        print(0)
        exit()
    ans=(ans*pow(tmp,l[i][1],mod))%mod
    tmp=l[i][1]
print(ans)

Measured memory_bytes: 21276
def main():
    # n = int(input())
    # n, m = map(int, input().split())
    # a = list(map(int, input().split()))
    s = list(input())
    # h = [int(input()) for _ in rane(n)]
    count0 = 0
    count1 = 0
    for i in s:
        if i == "0":
            count0 += 1
        else:
            count1 += 1

    print(min(count0, count1)*2)


if __name__ == '__main__':
    main()


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

int main()
{
    int n;

    cin>>n;
    double odd=0,even=0;
    for(int i=1;i<=n;i++)
        if(i%2==1)
            odd++;
        else
            even++;
    if(even==0)
        cout<<fixed<<setprecision(10)<<odd;
    else
        cout<<fixed<<setprecision(10)<<odd/n;
    return 0;
}


Measured memory_bytes: 256
import sys


def solve(A: int, B: int, C: int, K: int):
    ans  = 0
    card = 0
    if K<=A:
        print(K)
    elif K <= A+B:
        print(A)
    else:
        print(A-K+A+B)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
N = int(input())
W = list(map(int,input().split()))

ans = []
for i in range(1,N):
    s1=0
    s2=0
    S1 = W[:i]
    S2 = W[i:]
    for u in S1:
        s1 += u
    for v in S2:
        s2 += v
    ans.append(abs(s1-s2))
    ans.sort()
print(ans[0])

Measured memory_bytes: 3064
S = list(input())

if len(S) % 2 == 1:
    print("No")
    exit()

i = 0
while i < len(S):
    if S[i] == 'h' and S[i+1] == 'i':
        i += 2
    else:
        print("No")
        exit()

print("Yes")


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

int main() {
  int N;
  cin >> N;
  int a[N],b[N];
  // read
  for (int i=0; i < N; ++i) cin >> a[i];

  int s = 0;
  // caliculate
  for (int i=0; i < N; ++i){
    for (int j=i; j < N; ++j){
      if (a[i] <= a[j]) {
        s = a[j];
        a[j] = a[i];
        a[i] = s;
//      cout << " i:" << i << " j:" << j << " a[i]:" << a[i] << " s:" << s << endl;
      }
    }
  }
  
  int t = 0;
  for (int i=0; i < N; ++i) {
    if (i%2 == 0) t += a[i];
    else t -= a[i];
//    cout << a[i] << endl;
  }
  cout << t << endl;
  return 0;
}
//      cout << " i:" << i << " k:" << k << " s[i]:" << s[i] << " cnt:" << cnt << endl;


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int h,w;

bool in(int x, int y){
  if(1<=x && x<h-1 && 1<=y && y<w-1) return true;
  else return false;
}

int main(void) {
  int i,j,k;
  int n;
  cin>>h>>w>>n;
  map<pii,int> mp;
  int d[3]={-1,0,1};
  rep(i,n){
    int a,b;
    cin>>a>>b;
    a--,b--;
    rep(j,3)rep(k,3)
      if(in(a+d[j],b+d[k]))mp[pii(a+d[j],b+d[k])]++;
  }

  vector<ll> ans(10,0);
  i=0;
  for(auto itr = mp.begin(); itr != mp.end(); ++itr){
    ans[itr->second]++;
  }

  ll sum=0;
  rep(i,10)sum+=ans[i];
  
  ans[0]=(ll)(h-2)*(w-2)-sum;

  rep(i,10)
    cout<<ans[i]<<endl;
}


Measured memory_bytes: 56576
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = nextInt();

        double Answer = 0;

        int test = N / 2;
        int test2 = N % 2;

        int test3 = test + test2;

        Answer = (double)test3 / (double)N;

        println(Answer);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}

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

#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

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

int main() {
    lli n;
    cin >> n;
    lli d[n];
    REP(i, 0, n) {
        cin >> d[i];
    }
    sort(d, d+n);
    //REP(i, 0, n)
    //    cout << d[i] << " " << endl;

    if (n % 2 == 0) {
        lli a = d[n/2-1];
        lli b = d[n/2];
        if (a == b)
            cout << 0 << endl;
        else
            cout << b - a << endl;
    }
    else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 1024
#include<iostream>
#include<queue>
#include<map>
#define LEN 100
#define BASE 25

using namespace std;

int maps[LEN][LEN];
int off[LEN][LEN];

int checker[4];
int ncheck[4];

map<int, int> points[LEN];

class State {
public:
	char where;
	int enemy;
	int budget;
	int check[4];
	State() {check[0]=0;check[1]=0;check[2]=0;check[3]=0;}
	State(char w, int e, int b ) {
		where = w;
		enemy = e;
		budget = b; 
		check[0] = ncheck[0];
		check[1] = ncheck[1];
		check[2] = ncheck[2];
		check[3] = ncheck[3];
	}
};

bool operator< ( const State& a, const State& b) {
	if( a.enemy == b.enemy )
		return a.budget < b.budget;
	return a.enemy < b.enemy;
}

bool operator> ( const State& a, const State& b) {
	if ( a.enemy == b.enemy )
		return a.budget > b.budget;
	
	return a.enemy > b.enemy;
}

priority_queue<State, vector<State>, greater<State> > status;

inline void copy ( State now ) {
	checker[0] = now.check[0];
	checker[1] = now.check[1];
	checker[2] = now.check[2];
	checker[3] = now.check[3];
}

inline void ncopy ( ) {
	ncheck[0] = checker[0];
	ncheck[1] = checker[1];
	ncheck[2] = checker[2];
	ncheck[3] = checker[3];
}

inline bool check ( int i ) {
	return 0 == ((1<<(i%25)) & checker[i/BASE]);
}

inline void add ( int i ) {
	ncheck[i/BASE] = ((1<<(i%25)) | checker[i/BASE]);
}

inline void insert ( int i, int e, int b ) {
	
	map<int,int>::iterator itr = points[i].find(e);
	if ( itr == points[i].end() ) {
		points[i][e] = b;
		status.push(State(i,e,b));
	} else if ( (*itr).second < b ) {
		(*itr).second = b;
		status.push(State(i,e,b));
	}
}

int main () {


	while ( true ) {
		int n,m,l;
		cin >> n >> m >> l;

		if ( n == 0 )
			break;

		for ( int i=0; i<n; i++ ) {
			for ( int j=0; j<n; j++ ) {
				maps[i][j] = -1;
				off[i][j] = 0;
			}
			points[i].clear();
		}

		for ( int i=0; i<m; i++ ) {
			int a,b,d,e;
			cin >> a >> b >> d >> e;

			maps[a-1][b-1] = maps[b-1][a-1] = d;
			off[a-1][b-1] = off[b-1][a-1] = e;
		}

		for ( int i=0; i<4; i++ ) {
			ncheck[i] = 0;
			checker[i] = 0;
		}
		priority_queue<State, vector<State>, greater<State> > empty;
		status = empty;


		/*
		while( !status.empty() ) {
			status.pop() ;
		}	
		*/

		ncheck[0] = 1;
		status.push(State(0,0,l));
		int count = 0;
		while(!status.empty()) {
			State now = status.top();
			status.pop();
			if ( now.where == n-1 ) {
				cout << now.enemy << endl;
				break;
			}

			copy(now);

			for ( int i=0; i<n; i++ ) {
				if ( maps[now.where][i] > 0 ) {
					if ( check( i ) ) {
						ncopy();
						add(i);
						int e, b;
						if ( off[now.where][i] == 0 ) {
							e = now.enemy;
							b = now.budget;
							insert(i,e,b);
						} else {
							if ( now.budget - maps[now.where][i] >= 0 ) {
								e = now.enemy;
								b = now.budget - maps[now.where][i];
								insert(i,e,b);
							}
							e = now.enemy + off[now.where][i];
							b = now.budget;
							insert(i,e,b);
						}
					}
				}
			}
		}
	}
}

		

Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll md = 1000000007;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
vl p, fac(2, 1), ifac(2, 1);

ll add(ll a, ll b) {
    return (a%md + b%md + md) % md;
}

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

ll power(ll x, ll n, ll mod = md) {
    ll res = 1;
    x %= mod;
    while (n) {
        if (n & 1)  res = ((res%mod) * (x%mod))%mod;
        n = (n >> 1);
        x = ((x%mod) * (x%mod))%mod;
    }
    return res;
}

void cachefact(ll lim, ll mod = md) {
    for(int i = 2; i <= lim; i++) {
        ifac.push_back((ifac[mod%i] * (mod - mod/i) % mod)%mod);
    }
    for(ll i = 2; i <= lim; i++) {
        fac.push_back((fac[i-1] * i)%mod);
        ifac[i] = (ifac[i-1] * ifac[i])%mod;
    }
}

ll C(int n, int r) {
    if(n < r) return 0;
    return mul(fac[n], mul(ifac[r], ifac[n-r]));
}

ll P(int n, int r) {
	if(n < r) return 0;
	return mul(fac[n], ifac[n-r]);
}

ll mod_fac(ll n, ll p) {
	return fac[n] * power(power(p, n/p), md - 2) % md * power(fac[n/p], md - 2) % md;
}

void sieve(ll n) {
	vector<bool> prime(n+1, true);
    for(int i = 2; i*i <= n; i++) {
        if(prime[i]) {
            for(int j = 2*i; j <= n; j += i) {
                prime[j] = false;
            }
        }
    }
    p.push_back(2);
    for(int i = 3; i <= n; i += 2) {
        if(prime[i]) {
            p.push_back(i);
        }
    }
}

ll Phi(ll n) {
    ll res = n;
    for (int i = 0; p[i]*p[i] <= n; i++) {
    	short cnt = 0;
        while (n%p[i]== 0) {
           	n /= p[i];
           	cnt++;
        }
        if(cnt) res -= (res / p[i]);
    }
    if (n > 1) res -= (res / n);
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    sieve(1e7+1);
    ll k;
    cin >> k;
    if(k%2 == 0 || k%5 == 0) {
    	cout << "-1\n";
    } else {
    	if(k%7 == 0) {
	    	k /= 7;
	    }
	    k *= 9;
	    ll phi = Phi(k);
	    ll lo = phi;
	    for(ll i = 1; i * i <= phi; i++) {
	    	if(phi%i == 0) {
	    		if(power(10, i, k)%k == 1) {
	    			lo = min(lo, i);
	    		}
	    		if(i*i != phi && power(10, phi/i, k)%k == 1) {
	    			lo = min(lo, phi/i);
	    		}
	    	}
	    }
	    cout << lo << "\n";
    }
    return 0;
}

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

int main() {
    int cnt = 0;
    ll x, price = 100;
    cin >> x;
    while (price < x) {
        price += price / 100;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3584
import sys
input = sys.stdin.readline


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

    ans = 0
    b = {}
    for i in range(N):
        l = A[i] + (i+1)
        r = (i+1) - A[i]
        if r in b:
            ans += b[r]
        if l in b:
            b[l] += 1
        else:
            b[l] = 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 40108
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
int tmpmin=1e9;
int main(int argc,char const* argv[])
{
  string s;
  cin >> s;
  int n=stoi(s);
  int sn=0;
  for(int i=0;i<s.size();i++)
    {
      sn+=(int)(s[i]-'0');
    }
  if(n%sn==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  bool b = false; 
  for(int i = 0; i < 100; i++) {
    for(int j = 0; j < 100; j++) {
      if(4*i + 7*j == N) {
        b = true;
        break;
      }
    }
  }
  if(b == true) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define pb push_back
using namespace std;
const int DN=2e5+5,M=1e9+7;
long long n,k,f,g,a[55][55],r[55][55],p,aux[55][55],sum;
void solve()
{
	p=1;
	for(int i=1;i<=n;i++)
		r[i][i]=1;
	while(p<=k)
	{
		if(p&k)
		{
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++)
				{
					aux[i][j]=r[i][j];
					r[i][j]=0;
				}
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++)
					for(int h=1;h<=n;h++)
						r[i][j]=(r[i][j]+aux[i][h]*a[h][j])%M;
		}
		p*=2;
		for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++)
				{
					aux[i][j]=a[i][j];
					a[i][j]=0;
				}
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++)
					for(int h=1;h<=n;h++)
						a[i][j]=(a[i][j]+aux[i][h]*aux[h][j])%M;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			sum=(sum+r[i][j])%M;
	cout<<sum;
}
int main() 
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>a[j][i];
	solve();
}

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

int main()
{
	int n;
	while(cin>>n,n)
	{
		int data[n],dp[n+1];
		int tmp=0,ans;
		for (int i = 0; i < n; ++i)
		{
			cin>>data[i];
		}
		dp[0]=data[0];
		for (int i = 1; i < n; ++i)
		{
			dp[i]=max(dp[i-1]+data[i],data[i]);
		}
		sort(dp,dp+n);
		cout<<dp[n-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
  for(;;) {
    int n;
    cin >> n;
    if(n == 0) break;
    vector<int> ls;
    for(int i = 0; i < n; i++) {
      string s;
      cin >> s;
      ls.push_back(s.length());
    }
    for(int i = 0; i < n; i++) {
      int j = i, k = 0;
      int tls[] = {5,7,5,7,7};
      for(;;) {
        if(ls[j] <= tls[k]) {
          tls[k]-=ls[j];
          j++;
        } else {
          break;
        }
        if(tls[k] == 0) k++;
        if(k == 5) {
          cout << (i+1) << endl;
          i = n;
          break;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll a[4], n;
    for (int i = 0; i < 4; ++i)
        cin >> a[i];
    cin >> n;
    n *= 4;
    ll sol = 1e18;
    for (int i = 0; i < (1 << 4); ++i)
    {
        ll r = n;
        ll ns = 0;
        for (int j = 3; j >= 0; --j)
        {
            if (i & (1 << j))
            {
                ll k = (1 << j);
                ns += a[j] * (r / k);
                r %= k;
            }
        }
        if (r == 0)
            sol = min(sol, ns);
    }
    cout << sol;
}


Measured memory_bytes: 256
s = str(input())
s = s.replace('BC', 'D')
#print(s)
S = []
temp = []
for c in s:
    if c == 'A' or c == 'D':
        temp.append(c)
    else:
        if temp:
            S.append(temp)
            temp = []
else:
    if temp:
        S.append(temp)
#print(S)
ans = 0
for s in S:
    cnt = 0
    for j in range(len(s)):
        if s[j] == 'A':
            cnt += 1
        else:
            ans += cnt
print(ans)


Measured memory_bytes: 84840
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

using namespace std;

long long a,b,c;
int main(){
  cin>>a>>b>>c;
  int k;cin>>k;
  long long tmp = max(a,max(b,c));
  for(int i=0;i<k;i++){
    tmp *= 2;
  }
  cout<<(tmp+a+b+c-max(a,max(b,c)))<<endl;
  return 0;
}


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

int main() {
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> data(q);
  for(int i = 0; i < q; i++){
    cin >> data.at(i);
  }
  vector<int> a(n);
  for(int i = 0; i < q; i++){
    int j = data.at(i);
    a.at(j - 1) += 1;
  }
  for(int i = 0; i < n; i++){
    a.at(i) += -1 * q + k;
  }
  for(int i = 0; i < n; i++){
    if(a.at(i) <= 0){
      cout << "No" <<endl;
    }
    else{
      cout << "Yes" << endl;
    }
  }
}


Measured memory_bytes: 1408
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

main :-
    get_number(N),
    X is 48 - N,
    writeln(X).


Measured memory_bytes: 8184
#include<bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
 
int main()
{
	int a,b;
	sf("%d%d",&a,&b);
	if(a==b||-a==b||a==-b){
		pf("0\n");
	}
	if(a>b){
		swap(a,b);
	}
	for(int i=a;i<b;i++){
		if(-(a-i)==(b-i)){
		
			pf("%d\n",i);
			return 0;
		}
	}
	pf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fo(i,a,n) for(i=a;i<n;i++)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define sortrev(x) sort(all(x),greater<int>())
#define pi 3.1415926535897932384626

typedef pair<int,int> pii;
typedef pair<ll, ll> pl;
typedef vector<int>	vi;
typedef vector<bool> vb;
typedef vector<ll>	vl;
typedef vector<pii>	vpii;
typedef vector<pl>	vpl;
typedef vector<vi>	vvi;
typedef vector<vl>	vvl;
typedef vector<double> vd;


const int mod = 100000007;
const int inf = 100000005;
const int N = 200007, M = N;
int i,j,idx,cnt,par;


void solve() {
  ll n;
  cin>>n;

  ll x,ans = 0,cnt = 0 , minn = INT_MAX;
  fo(i,0,n) {
    cin>>x;
    if(x < 0) cnt++;
    ans+=abs(x);
    minn = min(minn , abs(x));
  }
  if(cnt & 1) ans -= (2*abs(minn));
  cout<<ans<<"\n";
}

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

    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }

    return 0;
}




Measured memory_bytes: 3664
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;



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

	vector<int>v(3);
	for (auto &i : v)cin >> i;
	sort(v.begin(), v.end());
	if (v[0] == v[1] && v[1] != v[2]) {
		cout << "Yes\n";
		return 0;
	}
	if (v[1] == v[2] && v[0] != v[2]) {
		cout << "Yes\n";
		return 0;
	}
	cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int mem[31] = {};
    int x;
    for(int i = 1; i <= 28; i++){
        cin >> x;
        mem[x]++;
    }
    for(int i = 1; i <= 30; i++){
        if(mem[i] == 0){
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 2996
H,W=map(int,input().split())
X=[0 for i in range(26)]
a=[list(input()) for i in range(H)]
for i in range(H):
    for j in range(W):
        X[ord(a[i][j])-97]+=1
A=[i%4 for i in X]
B=[i%2 for i in X]
if H%2==0 and W%2==0:
    if sum(A)==0:
        print("Yes")
    else:
        print("No")
elif H%2==1 and W%2==1:
    if sum(B)==1 and sum(A)<=H+W-1:
        print("Yes")
    else:
        print("No")
else:
    if H%2==0:
        H,W=W,H
    #H:odd
    if sum(B)==0 and sum(A)<=W:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 64992
using System;

class Program {
    static void Main() {
        var classes = new int[6];

        var n = int.Parse(Console.ReadLine());
        for (var i = 0; i < n; i++) {
            var tall = double.Parse(Console.ReadLine());
            classes[GetClass(tall)]++;
        }

        for (var i = 0; i < 6; i++) {
            Console.WriteLine("{0}:{1}", i + 1, new string('*', classes[i]));
        }
    }

    static int GetClass(double tall) {
        var cls = (tall - 160) / 5;
        if (cls < 1)
            return 0;
        if (cls >= 5)
            return 5;
        return (int)cls;
    }
}

Measured memory_bytes: 9196
#include <stdio.h>

int main()
{
  int k, x, start, end, i;
  
  scanf("%d %d", &k, &x);
  
  start = x - k + 1;
  end = x + k - 1;
  
  for(i = start; i <= end; i++)
    printf("%d ", i);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
/*
░░░░░░░░░░░░░░░░░░░░░░░░░
░░█▀▀▄░░░░░░░░░░░▄▀▀█░░░░
░░█░░░▀▄░▄▄▄▄▄░▄▀░░░█░░░░
░░░▀▄░░░▀░░░░░▀░░░▄▀░░░░░
░░░░░▌░▄▄░░░▄▄░▐▀▀░░░░░░░
░░░░▐░░█▄░░░▄█░░▌▄▄▀▀▀▀█░
░░░░▌▄▄▀▀░▄░▀▀▄▄▐░░░░░░█░
░▄▀▀▐▀▀░▄▄▄▄▄░▀▀▌▄▄▄░░░█░
░█░░░▀▄░█░░░█░▄▀░░░░█▀▀▀░
░░▀▄░░▀░░▀▀▀░░▀░░░▄█▀░░░░
░░░░█░░░░░░░░░░░▄▀▄░▀▄░░░
░░░░█░░░░░░░░░▄▀█░░█░░█░░
░░░░█░░░░░░░░░░░█▄█░░▄▀░░
░░░░█░░░░░░░░░░░████▀░░░░
░░░░▀▄▄▀▀▄▄▀▀▄▄▄█▀░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░
*/
 
// I want to be the very best, like no one ever was, I will battle everyday to claim my rightful place
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 1e5 + 10;
ll leftt[MAXN],rightt[MAXN];
ll ans[MAXN];
ll n;
string s; 
map<ll,ll> anss;

void solve(){
    cin>>s;
    n = s.length();

    s = '{' + s;
    
    FOR(i,1,n){
        if(s[i] == 'L'){
            if(leftt[i-1] == 0) leftt[i] = i;
            else leftt[i] = leftt[i-1];
        }
    }

    RFOR(i,1,n){
        if(s[i] == 'R'){
            if(rightt[i+1] == 0) rightt[i] = i;
            else rightt[i] = rightt[i+1];
        }
    }

    FOR(i,1,n){
        if(leftt[i]){
            ll moves = i - leftt[i];
            if(moves%2) anss[leftt[i] - 1]++;
            else anss[leftt[i]]++;
        }else{
            ll moves = rightt[i] - i;
            if(moves%2) anss[rightt[i] + 1]++;
            else anss[rightt[i]]++;
        }
    }

    FOR(i,1,n) cout<<anss[i]<<" ";
} 
 
signed main(){
 
   FastRead;    
 
    ll t;
    t = 1; 
    //cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 8428
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#include <map>
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
#define ll long long
constexpr ll MOD = 1e9 + 7;
ll gcd(ll a, ll b) {return b % a ? gcd(b % a, a) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
using namespace std;
using P = pair<ll, ll>;
using VI = vector<ll>;

int main() {
    int n;
    string s;
    cin >> n >> s;
    VI ws(n,0);
    VI es(n,0);
    
    REPI(i,1,n) {
        if (s[i-1] == 'W') {
            ws[i] = ws[i-1] + 1;
        } else {
            ws[i] = ws[i-1];
        }
    }
    for (int i = n - 2; i >= 0; i--) {
        if (s[i+1] == 'E') {
            es[i] = es[i+1] + 1;
        } else {
            es[i] = es[i+1];
        }
    }
    
    long m = 1e9;
    REP(i,n) {
//        cout << ws[i] << " " << es[i] << endl;
        m = min(m, long(ws[i] + es[i]));
    }
    
    cout << m << endl;
}



Measured memory_bytes: 5380
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <cmath>
using namespace std;

#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647

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

	long long countTails = 0;
	if (N == 1 && M == 1) {
		countTails = 1;
	}
	else if (N < 3 && M < 3 || (N == 2 || M == 2)) {
		countTails = 0;
	}
	else {
		countTails = max(1ll, N - 2) * max(1ll, M - 2);
	}

	cout << countTails << endl;

	return 0;
}

Measured memory_bytes: 3548
N = int(input())
B = list(map(int,input().split()))

A = [0 for i in range(N)]
A[0] = B[0]
A[1] = B[0]

for i in range(1,len(B)):
    if(B[i] < A[i]):
        A[i] = B[i]
    
    A[i+1] = B[i]

print(sum(A))




Measured memory_bytes: 3064
local n = io.read("*n")
io.read("*l")
local str = io.read("*l")
local ans = 1
for i = 1, #str - 1 do
  if string.sub(str, i, i) ~= string.sub(str, i+1, i+1) then
    ans = ans + 1
  end
end
print(ans)


Measured memory_bytes: 504
#include <iostream>
using namespace std;
int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (a >= k) {
		cout << k << endl;
	}
	else if (a + b >= k) {
		cout << a << endl;
	}
	else {
		cout << a - (k - (a + b)) << endl;
	}
}

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

int main()
{
  int n;
  cin >> n;
  int h[n];
  for (int i = 0; i < n; ++i) cin >> h[i];
  
  int flag = 0;
  int min = h[n-1];
  for (int i = n - 2; i >= 0; --i) {
    if (h[i] > min + 1) {
      flag = 1;
      break;
    }
    else if (h[i] < min) {
      min = h[i];
    }
  }
  if (flag == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
 
  return 0;
}

Measured memory_bytes: 640
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	vector<LL> A(3);
	for(int i=0;i<3;++i){
		cin >> A[i];
	}
	LL ans = LINF;
	for(int i=0;i<3;++i){
		LL men = A[i]*A[(i+1)%3];
		LL mid = A[(i+2)%3];
		if( mid&1 ){
			ans = min(ans,men);
		}else{
			cout << 0 << endl;
			return;
		}
	}
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


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

using namespace std;

int n, k;
int *w, maxw = 0, sumw = 0;

bool load(int p) {
	int truck = 1;
	int sum = 0;
	for (int i = 0; i < n; i++) {
		if (sum + w[i] > p) {
			sum = w[i];
			truck++;
		} else {
			sum += w[i];
		}
	}
	return truck <= k;
}

int main() {
	cin >> n >> k;
	w = new int[n];
	for (int i = 0; i < n; i++) {
		cin >> w[i];
		maxw = max(maxw, w[i]);
		sumw += w[i];
	}
	int l = maxw, r = sumw, mid, ans;
	while (l <= r) {
		mid = (l + r) / 2;
		if (load(mid)) {
			ans = mid;
			r = mid - 1;
		}
		else
			l = mid + 1;
	}
	cout << ans << endl;
	delete[] w;
	return 0;
}

Measured memory_bytes: 1532
/*
AizuOnline A0239
Title Calorie Counting
@kankichi573
*/
#include <stdio.h>
int n;
int idx[1001],p[1001],q[1000],r[1000],c[1000];
int P,Q,R,C;
//
main()
{
        int i,flag;

        while(EOF!=scanf("%d",&n) && n)
        {
                for(i=1;i<=n;i++)
                {
                        scanf("%d %d %d %d",&idx[i],&p[i],&q[i],&r[i]);
                        c[i]=p[i]*4+q[i]*9+r[i]*4;
                }
                scanf("%d %d %d %d",&P,&Q,&R,&C);
                flag=0;
                for(i=1;i<=n;i++)
                {
                        if(p[i]<=P && q[i]<=Q && r[i] <=R && c[i] <=C)
                        {
                                printf("%d\n",idx[i]);
                                flag=1;
                        }
                }
                if(flag==0)
                        printf("NA\n");
        }
        return(0);
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  vector<vector<int>> k(n,vector<int>(1,-1));
  int a[n];
  int b[n];
  int z[n];
  z[0]=0;
  rep(i,n-1){
    int c,d;
    cin >> c >> d;
    c--;
    d--;
    a[i]=c;
    b[i]=d;
    k[c].push_back(d);
    k[d].push_back(c);
  }  
    int c[n];
    c[0]=0;
    rep(i,n-1)c[i+1]=-1;
    int ma=(k[0].size()-1);
    rep(i,n){
      int ww=(k[i].size()-1);
      ma=max(ma,ww);
    }
    cout << ma << endl;
    queue<int> q;
    q.push(0);
    int oo=1;
    while(q.size()!=0){
      int y=q.front();
      z[y]=oo;
      oo++;
      q.pop();
      int cc=1;
      int pp=1;
      for(int u:k[y]){
        if(u==-1)continue;
        if(c[u]!=-1){
          pp++;
          continue;
        }
        if(cc==c[y])cc++;
        c[u]=cc;
        q.push(u);
        cc++;
      }
    }
  rep(i,n-1){
    int aa=a[i];
    int bb=b[i];
    if(z[aa]>z[bb])cout << c[aa] << endl;
    else cout << c[bb] << endl;
  }
}


Measured memory_bytes: 8064
import scala.io.StdIn

object Main extends App {

  val Array(n, m, l) = StdIn.readLine().split(' ').map(_.toInt)
  //http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2415390#1  
  //  val a = Array.fill(n, m)(0)
  //  val b = Array.fill(m, l)(0)
  //  val result = Array.fill(n, l)(0L)
  val a: Array[Array[Int]] = Array.ofDim[Int](n, m)
  val b: Array[Array[Int]] = Array.ofDim[Int](m, l)
  val result: Array[Array[Long]] = Array.ofDim[Long](n, l)
  
  (0 until n).foreach{ i =>
    a(i) = StdIn.readLine().split(' ').map(_.toInt)
  }
  (0 until m).foreach{ i =>
    b(i) = StdIn.readLine().split(' ').map(_.toInt)
  }

  val rout = (0 until n).map{ i =>
    (0 until l).foreach{ j =>
      result(i)(j) = (0 until m).foldLeft(0L){ (acc, k) =>
        acc + a(i)(k)*b(k)(j)
      }
    }
    result(i).mkString(" ")
  }.mkString(f"%n")

  println(rout)
}


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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

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

int n,k,h[100005],ans=2e9;

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

	cin >> n >> k;
	for(int i = 0; i < n; i++)
		cin >> h[i];
	sort(h, h + n);

	for(int i = 0; i + k - 1 < n; i++)
		ans = min(ans, h[i+k-1] - h[i]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
N=int(input())
import copy
inp=[]
for i in range(N):
    inp.append(list(map(int,input().split(" "))))

def compare(A,B):
    if A[0]>=B[0] and A[1]>=B[1]:
        return A
    else:
        if B[0]%A[0]!=0:
            i=B[0]//A[0]+1
        else:
            i=B[0]//A[0]
        if B[1]%A[1]!=0:
            j=B[1]//A[1]+1 
        else:
            j=B[1]//A[1]
        m=max(i,j)
        return [A[0]*m,A[1]*m]
st=inp[0]
for i in range(1,N):
    st=compare(inp[i],st)
print(sum(st))

Measured memory_bytes: 3700
package main

import (
	"fmt"
)

const mod = 1e9 + 7

var pows map[int]map[int]int

func main() {
	pows = make(map[int]map[int]int)
	var n, k int
	fmt.Scan(&n, &k)
	ps := make([]int, k+1)
	var ans int
	for i := k; i >= 1; i-- {
		cn := int(k / i)
		cnt := pow(cn, n)
		for j := 2; j <= cn; j++ {
			cnt -= ps[i*j]
			cnt %= mod
			if cnt < 0 {
				cnt += mod
			}
		}
		ps[i] = cnt
		ans += cnt * i
		ans %= mod
	}
	fmt.Println(ans)
}

func pow(a, b int) int {
	if r, ok := pows[a][b]; ok {
		return r
	}
	if b == 1 {
		return a
	}
	var r int
	if b%2 == 0 {
		r = pow(a, b/2) * pow(a, b/2) % mod
	} else {
		r = pow(a, b-1) * a % mod
	}
	if _, ok := pows[a][b]; !ok {
		pows[a] = make(map[int]int)
	}
	pows[a][b] = r
	return r
}


Measured memory_bytes: 5704
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define PB push_back
vvint vv;
bool vis1[1<<10];
int vis2[1<<10][1<<10];
int saiki(int a,int b,int c){
	if(vis2[a][b]>=0) return vis2[a][b];
	vis2[a][b]=2;
	for(int y:vv[a]){
		if(y==c) return vis2[a][b]=1;
		if(y+b!=(y|b)) continue;
		if(saiki(y,y|b,c)==1) return vis2[a][b]=1;
	}
	return 2;
}
int main(){
	int n;
	while(cin>>n,n){
		string s;
		cin>>s;
		vv=vvint(1<<10);
		rep(i,1<<10) vis1[i]=false;
		rep(i,1<<10) rep(j,1<<10) vis2[i][j]=-1;
		int state=0;
		vvint ww(1<<10);
		bool ans=false;
		rep(i,s.size()){
			if(s[i]=='u'){
				state=0;
				continue;
			}
			int t=s[i]-'0';
			if(state&(1<<t)) ans=true;
			if(s[i+1]=='u') continue;
			state|=1<<t;
			ww[state].PB(s[i+1]-'0');
		}
		rep(i,1<<10){
			for(int x:ww[i]){
				rep(j,1<<10){
					if(i==j) continue;
					if(!(j&(1<<x))) continue;
					if(i+j!=(i|j)) continue;
					vv[i].PB(j);
				}
			}
		}
		rep(i,1<<10){
			if(ww[i].size()==0) continue;
			if(saiki(i,i,i)==1) ans=true;
		}
		puts(ans?"UNSAFE":"SAFE");
	}
}

Measured memory_bytes: 11176
#include <stdio.h>
int main() {
	int a, b, c=0;
	int out[4];
	while (c<4) {
		scanf("%d %d",&a,&b);
		if (a==1) {
			out[c]=6*b;
		} else if (a==2) {
			out[c]=4*b;
		} else if (a==3) {
			out[c]=3*b;
		} else {
			out[c]=2*b;
		}
		c++;
	}
	for(c=0;c<4;c++) {
		if(out[c]==0) puts("0");
		else printf("%d000\n", out[c]);
	}
	return 0;
}

Measured memory_bytes: 612
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <ios>     // std::left, std::right
#include <iomanip> 
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;

int main(){
    int N;cin>>N;
    vector<int> A(N);
    REP(i,N) cin>>A[i];
    cout<<*max_element(A.begin(),A.end())-*min_element(A.begin(),A.end())<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define int long long

#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)

using namespace std;
using P = pair<int, int>;
using ll = long long;
using ld = double;

using bint = boost::multiprecision::cpp_int;

constexpr int MOD = 1e9 + 7;

template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}

// https://twitter.com/vane11ope ←フォローしましょう
// (ノ)>◡<(ヾ)ﾓﾁﾓﾁ
signed main(signed argc, char* argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    int mx=0,ans=0;
    rep(i,n){
        int a;
        cin>>a;
        mx=max(a,mx);
        ans+=max(0ll,mx-a);
    }
    cout<<ans<<endl;
}


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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    ll h;
    cin >> h;
    ll ans = 1;
    ll i = 1;
    while(h > 1) {
        h /= 2;
        ans += pow(2,i);
        i++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define mp make_pair
#define ft first
#define sd second
#define ue printf("what?\n");
#define pb push_back
#define oo 0x3F3F3F3F	
#define OO 3000000000000000000LL
#define EPS 0
#define maxn 200000
#define pi acos(-1)
#define mod 1000000007
#define mdc __gcd
#define N 100010
#define M 33
using namespace std;
typedef long long ll;
typedef vector<vector<ll> > mat;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;

main()
{
	int n, i, aux, tot = 0;
	scanf("%d", &n);
	for(i=0; i<n; i++)
		scanf("%d", &aux), tot += (aux - 1);
	printf("%d\n", tot);
}	


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

int main(){
  int day30[4] = {4,6,9,11};

  while(1) {
  int m,d;
  cin >> m >> d;
  if(m == 0 && d == 0) break;
  int a = 1,b = 1,count = 0;

  while(1) {

    if(a == m && b == d) break;
    
    b++;
    count++;

    if(a == 2 && b == 30) {
      a++;
      b = 1;
    }
    else if(b == 31) {
      for(int i=0;i<4;i++) 
	if(day30[i] == a) {
	  a++;
	  b = 1;
	  break;
	}
    }
    if( b == 32) {
      a++;
      b = 1;
    }
  }
  
  if(count % 7 == 4 ) cout <<"Monday"<<endl;
  else if(count % 7 == 5) cout << "Tuesday"<<endl;
  else if(count % 7 == 6) cout <<"Wednesday"<< endl;
  else if(count % 7 == 0) cout <<"Thursday"<< endl;
  else if(count % 7 ==1) cout << "Friday" << endl;
  else if(count % 7 ==2)cout << "Saturday" << endl;
  else if(count % 7 ==3) cout << "Sunday" << endl;
  
  }

  return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    string a[100];
    string ans="";
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(char i='a';i<='z';i++){
        int mcount=10000;
        for(int j=1;j<=n;j++){
            int count=0;
            for(int k=0;k<a[j].size();k++){
                if(a[j][k]==i)
                    count++;
            }
            if(count==0){
                mcount=10000;
                break;
            }
            mcount=min(mcount,count);
        }
        if(mcount!=10000){
            for(int k=1;k<=mcount;k++){
                ans+=i;
            }
        }
    }
    cout<<ans;
}

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

int n, q, r, mid, lo, hi;
bool check, brk;

int main() {
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++) cin >> a[i];
    cin >> q;
    for (int i=0; i<q; i++) {
        cin >> r;
        check = 0;
        brk = 0;
        mid = n/2;
        lo = 0;
        hi = n-1;
        while (!check) {
            if (r < a[mid]) {
                hi = mid;
            }
            else {
                if (r > a[mid]) lo = mid;
                else check = 1;
            }
            mid = (lo + hi)/2;
            if (lo + 1>= hi) break;
        }
        if (r == a[lo]) check = 1;
        if (r == a[hi]) check = 1;
        cout << check << endl;
    }
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double[] input = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
            Pt a = new Pt(input[0], input[1]);
            Pt b = new Pt(input[2], input[3]);

            Seg s = new Seg(a, b);

            int q = int.Parse(Console.ReadLine());

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < q; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
                Pt p = new Pt(input[0], input[1]);

                sb.AppendLine(Reflect(s, p).ToString());
            }
            Console.Write(sb);
        }

        static Pt Reflect(Seg s, Pt p)
        {
            return p + (Project(s, p) - p) * 2;
        }

        static Pt Project(Seg s, Pt p)
        {
            Pt b = s.p2 - s.p1;
            double r = (p - s.p1).Dot(b) / b.Norm;
            return s.p1 + b * r;
        }
    }

    struct Pt : IComparable<Pt>
    {
        static readonly double EPS = 1E-10;

        internal double x, y;

        public Pt(double x, double y)
        {
            this.x = x;
            this.y = y;
        }

        public double Abs { get { return Math.Sqrt(Norm); } }
        public double Norm { get { return x * x + y * y; } }

        public double Dot(Pt p) { return x * p.x + y * p.y; }
        public double Cross(Pt p) { return x * p.y - y * p.x; }

        public static Pt operator +(Pt a, Pt b) { return new Pt(a.x + b.x, a.y + b.y); }
        public static Pt operator -(Pt a, Pt b) { return new Pt(a.x - b.x, a.y - b.y); }
        public static Pt operator *(Pt p, double d) { return new Pt(p.x * d, p.y * d); }
        public static Pt operator /(Pt p, double d) { return new Pt(p.x / d, p.y / d); }
        public static bool operator <(Pt a, Pt b) { return Math.Abs(a.x - b.x) > EPS ? a.x < b.x : a.y < b.y; }
        public static bool operator >(Pt a, Pt b) { return Math.Abs(a.x - b.x) > EPS ? a.x > b.x : a.y > b.y; }
        public static bool operator ==(Pt a, Pt b) { return Math.Abs(a.x - b.x) < EPS && Math.Abs(a.y - b.y) < EPS; }
        public static bool operator !=(Pt a, Pt b) { return Math.Abs(a.x - b.x) >= EPS || Math.Abs(a.y - b.y) >= EPS; }

        public int CompareTo(Pt other)
        {
            return x != other.x ? (int)(x - other.x) : (int)(y - other.y);
        }

        public override bool Equals(object obj)
        {
            Pt other = (Pt)obj;
            return Math.Abs(x - other.x) < EPS && Math.Abs(y - other.y) < EPS;
        }

        public override int GetHashCode()
        {
            return x.GetHashCode() ^ y.GetHashCode();
        }

        public override string ToString()
        {
            return string.Format("{0:f10} {1:f10}", x, y);
        }
    }

    struct Seg
    {
        internal Pt p1, p2;

        public Seg(Pt a, Pt b)
        {
            p1 = a;
            p2 = b;
        }
    }
}

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


def gcd(a, b):
    if a == b:
        return a
    elif a > b:
        while a > b:
            a -= b
            return gcd(b, a)
    else:
        return gcd(b, a)


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors = sorted(divisors, reverse=True)
    return divisors


ans_list = make_divisors(gcd(a, b))
ans = ans_list[k-1]
print(ans)

Measured memory_bytes: 3188