akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
string shuffle(string str,int h){
    string head=str.substr(0,h);
    string tail=str.substr(h,str.size()-h);
    return tail+head;
    
}
int main(){
    string cards;
    int m,h;
    while(1){
        cin >> cards;
        if(cards=="-")break;
        cin >> m;
        for(int i=0;i<m;i++){
            cin >> h;
            cards = shuffle(cards,h);
        }
        cout << cards <<endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
    string S;
    cin >> S;
    sort(S.begin(),S.end());
    if(S[0] == S[1] && S[2] == S[3] && S[1] != S[2]) cout <<"Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  l=sort(pM(split(readline())))
  ans=0
  i=fld(l[3]-l[1],2)
  ans+=i
  l[1]+=2i
  j=fld(l[3]-l[2],2)
  ans+=j
  l[2]+=2j
  c=count(x->x==l[3],l)
  if c==1
    ans+=1
  elseif c==2
    ans+=2
  end
  println(ans)
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

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

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define Itr(i, c) for(typeof(c.begin()) i = c.begin(); i != c.end(); i++)
#define pb push_back

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MAX = 510000;
const int INF = 999999999;
const int MOD = 1000000007;

int main(){
	string s, t; cin >> s >> t;
	int l = s.size(), a[26], b[26];
	Rep(i, 26){
		a[i] = 0; b[i] = 0;
	}
	Rep(i, l){
		a[s[i] - 'a'] += 1;
		b[t[i] - 'a'] += 1;
	}
	Rep(i, l){
		if(a[s[i] - 'a'] != b[t[i] - 'a']){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 776
#include <stdio.h>

int main(void){
	int x,i,j=1;
	
	for(i=1;;i++){
		scanf("%d", &x);
		if(x!=0){
			printf("Case %d: %d\n", j,x);
			j++;
		}
		else break;
	}
	return 0;
}

Measured memory_bytes: 600
from collections import defaultdict, deque
n,m = map(int,input().split())
d = defaultdict(list)
deg = [0]*n  # 各頂点の入次数

for i in range(m):
    x,y = map(int,input().split())
    d[x-1].append(y-1)
    deg[y-1] += 1

que = deque([])
for v in range(n):
    if deg[v] == 0:
        que.append(v)

dp = [0]*100100

while que:
    v = que.popleft()
    for nv in d[v]:
        deg[nv] -= 1  # エッジ(v,nv)を破壊
        if deg[nv] == 0:
            que.append(nv)  # 入次数が0になったらキューに追加
            dp[nv] = max(dp[nv],dp[v]+1)  # ソースからnvまでの最長距離を確定

res = 0
for v in range(n):
    res = max(res,dp[v])
print(res)

Measured memory_bytes: 97612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;


int main(){

int a,b,c;
cin >> a >> b >> c;

if(a<=c and c<=b)cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}



Measured memory_bytes: 256
L, R = [int(x) for x in input().split(' ')]

if L <= 2019 and 2019 <= R:
    print(0)
    exit(0)
if 2018 <= (R - L):
    print(0)
    exit(0)

min_val = 2020
for i in range(L, R + 1):
    for j in range(i + 1, R + 1):
        val = (i * j) % 2019
        min_val = min(min_val, val)
print(min_val)

Measured memory_bytes: 3064
import math

a, b, h, m = map(int, input().split())

# the degree of hour hand
x = 30 * h + 0.5 * m
# the degree of minute hand
y = 6 * m

dif = max(x-y, y-x)
if dif > 180:
    theta = math.radians(360 - dif)
else:
    theta = math.radians(dif)

ans = math.sqrt(a*a + b*b - 2*a*b*math.cos(theta))
print("{:.9f}".format(ans))


Measured memory_bytes: 9504
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int i=0,j=0,n,m,x,c[20000],a[200][200],saisyo=999999999999,u=0,g[100],k,q=0,i2,cc=0;
    string b,b2;
    cin >> n >> m >> x;
    for(i=0;i<n;i++)
    {
        cin >> c[i];
        for(j=0;j<m;j++)
        {
            cin >> a[i][j]; 
        }
    }
 for (int bit = 0; bit < (1<<n); ++bit)
    {
        q=0;
        u=0;
        for(k=0;k<m;k++)
        {
            g[k]=0;
        }
        for(i=0;i<n;i++)
        {
            if(((bit >> i)&1)==0)
            {
                continue;
            }
            for(j=0;j<m;j++)
            {
                g[j]+=a[i][j];
            }
            q+=c[i];
        }
        for(i2=0;i2<m;i2++)
        {
            if(g[i2]>=x)
            {
                u++;
            }
        }
        if(u==m && saisyo>q)
        {
            saisyo=q;
            cc++;
        }
    }
    if(cc==0)
    {
        cout << "-1" << endl;
        return 0;
    }
    cout << saisyo << endl;   
    return 0;
}

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

int main(){
  int64_t n, p, q;
  cin >> n;
  for(int64_t i = 1; i * i <= n; i++){
    if(n % i == 0){
      p = i;
      q = n / i;
    }
  }
  cout << p + q - 2 << endl;
}


Measured memory_bytes: 256
#include <cstdio>

typedef long long LL;
const int MN = 205;

int N;
LL A[MN];
char s[MN];
LL B[64];

int main() {
	int Tests;
	scanf("%d", &Tests);
	while (Tests--) {
		scanf("%d", &N);
		for (int i = 1; i <= N; ++i) scanf("%lld", &A[i]);
		scanf("%s", s + 1);
		int ok = 1;
		for (int j = 0; j < 60; ++j) B[j] = 0;
		for (int i = N; i >= 1; --i) {
			if (s[i] == '1') {
				LL x = A[i];
				for (int j = 59; j >= 0; --j) if (x >> j & 1) {
					if (B[j]) x ^= B[j];
					else break;
				}
				if (x) { ok = 0; break; }
			} else {
				LL x = A[i];
				for (int j = 59; j >= 0; --j) if (x >> j & 1) {
					if (!B[j]) B[j] = x;
					x ^= B[j];
				}
			}
		}
		puts(ok ? "0" : "1");
	}
	return 0;
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int h,w,n; cin>>h>>w>>n;
	vector<vector<int>>ans(h,vector<int>(w));
	for(int i=1,y=0,x=0;i<=n;++i){
		int a; cin>>a;
		while(a){
			if(x==w)x=0,++y;
			ans.at(y).at(x)=i;
			--a,++x;
		}
	}
	for(int i=0;i<h;++i){
		if(i&1)reverse(ans.at(i).begin(),ans.at(i).end());
	}
	for(int y=0;y<h;++y){
		for(int x=0;x<w;++x){
			cout<<ans.at(y).at(x);
			if(x!=w-1)cout<<" "s;
		}
		cout<<"\n"s;
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

int n;
ll a[20];

ll dp[20][20][3 << 8][3 << 8];

ll f(int l, int r, int xl, int xr) {
    if(l + 1 >= r) return 0;
    if(dp[l][r][xl][xr]) return dp[l][r][xl][xr];
    ll res = inf;
    const ll x = xl + xr;
    FOR(i, l + 1, r)
    chmin(res, f(l, i, xl, x) + a[i] * x + f(i, r, x, xr));
    return dp[l][r][xl][xr] = res;
}

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

    cin >> n;
    rep(i, n) cin >> a[i];

    cout << a[0] + f(0, n - 1, 1, 1) + a[n - 1] << endl;

    return 0;
}

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

int main() {
	int N;
	cin >> N;
	int c = 0;
	for(int i = 0; i < N; i++){
		int d1, d2;
		cin >> d1 >> d2;
		if(d1 == d2){
			c++;
		}else{
			c = 0;
		}
		if(c == 3){
			cout << "Yes" << endl;
			return(0);
		}
	}

	cout << "No" << endl;
	return(0);
}


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

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

  string s; cin>>s;
  int n=s.size();
  stack<char> stk;
  int cur=0;
  for (int i=0; i<n; i++) {
    char ch=s[i];
    if(ch=='S') stk.push(ch);
    else {
      if(!stk.empty()) stk.pop(), cur+=2;
    }
  }
  cout << n-cur << endl;
  return 0;
}

Measured memory_bytes: 1228
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
def main():
    x,y,z = map(int, input().split())
    tmp = x
    x = y
    y = tmp
    tmp = x
    x = z
    z = tmp
    print(x, y, z)
if __name__ == "__main__":
    main()

Measured memory_bytes: 38256
#include<iostream>
#include<cstdlib>
#include<stack>
#include<queue>
#include<string>
#include<algorithm>
using namespace std;
 
int main(){
    long long int n,q[100];
    int d[100];
    int i=0;
    cin>>n;
 
    for(;;){
        i++;
        q[i]=n%10;
        n-=q[i];
        n/=10;
        if(n==0)break;
    }
    int max=0;
 
    for(int j=1;j<=i-1;j++){
        if(q[j]<=8){
            //if(0<q[j+1]){
                q[j]=9;
                q[j+1]--;
            //}
        }
    }
    for(int j=1;j<=i;j++){
        max+=q[j];
    }
 
    cout<<max;
    
 
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
    long long int n, a, b;
    scanf("%lld %lld %lld", &n, &a, &b);

    if ((b - a) % 2 == 0)
    {
        printf("%lld", (b - a) / 2);
    }
    else
    {
        printf("%lld", ((a - 1)<(n - b)?(a - 1):(n - b)) + (b - a + 1) / 2);
    }
    return 0;
}


Measured memory_bytes: 128
import math

nab_list = [int(num) for num in list(input().split(" "))]
n = nab_list[0]
a = nab_list[1]
b = nab_list[2]

all_sum = 0
for i in range(1,n+1):
    digit_sum = 0
    num = i
    while(num>0):
        digit_sum+=num%10
        num = math.floor(num/10)
    if a <= digit_sum and digit_sum <= b:
        all_sum += i
print(all_sum)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define CLR(A, X) memset(A, X, sizeof(A))
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
const double eps = 1e-10;
int dcmp(double x){if(fabs(x)<eps) return 0; return x<0?-1:1;}
const LL INF = 0x3f3f3f3f;
const LL MOD = 1e9+7;
const int N = 1e6+5;

LL a[50];

int main() {
    LL k;
    scanf("%lld", &k);
    for(int i = 0; i < 50; i++) a[i] = i+k/50LL;
    int x = (int)(k%50LL);
    for(int i = 0; i < x; i++) {
        a[i] += 51;
        for(int j = 0; j < 50; j++) a[j]--;
    }
    puts("50");
    for(int i = 0; i < 50; i++) printf("%lld%c", a[i], i==49?'\n':' ');
    return 0;
}


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

typedef long long ll;

const ll mod = 1e9 + 7;
const int maxn = 1e5 + 5;

int a[maxn];

ll fast_mod(ll base, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * base % mod;
		base = base * base % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	int n, num;
	cin >> n;
	memset(a, 0, sizeof(a));
	for (int i = 1; i <= n; i++) {
		cin >> num;
		a[num]++;
		if (a[num] > 2 || a[0] > 1 || (n - 1 + num) % 2) {
			printf("0\n"); return 0;
		}
	}
	cout << fast_mod(2, n / 2) << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

bool IsACGT(string s){
  for (int i=0; i<s.size(); i++) {
    if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
      continue;
    }else{
      return false;
    }
  }
  return true;
}

int main(int argc, const char * argv[]) {
  
  string S, s;
  cin >> S;
  int ans = 0;
  for (int i=0; i<=S.size(); i++) {
    for (int j=1; j<=S.size()-i; j++) {
      s = S.substr(i, j);
      if (IsACGT(s)) {
        ans = max(ans, j);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<long long> v(n);
    for(int i=0;i<n;i++){ cin>>v[i];}
    int q;
    cin>>q;
    while(q--){
            long long a;cin>>a;
        if(binary_search(v.begin(),v.end(),a)){
            cout<<"1\n";
        }
        else cout<<"0\n";
    }
}




Measured memory_bytes: 3604
N,M = map(int,input().split())
S = input()
T = input()
#良い文字列は存在するならば長さはN,Mの最小公倍数になる
#異なる文字が同じ場所に来たらダメ
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
def lcm(a,b):
  return a*b //gcd(a,b)
L = lcm(N,M)
n = N//gcd(N,M)
m = M//gcd(N,M)
for k in range(gcd(N,M)):
    if S[k*n] != T[k*m]:
        print(-1)
        exit()
print(L)


Measured memory_bytes: 39536
li = map(int, raw_input().split())
a,b,c = li

gu = filter(lambda x: x%2==0 ,li)
ki = filter(lambda x: x%2!=0 ,li)

if len(ki) == 1:
    gu = map(lambda x:x+1 , gu)
    maxx = max(ki+gu)
    re = map(lambda x:(maxx-x)/2 ,ki+gu)
    print sum(re)+1

if len(gu) == 1:
    ki = map(lambda x:x+1 , ki)
    maxx = max(ki+gu)
    re = map(lambda x:(maxx-x)/2 ,ki+gu)
    print sum(re)+1


if len(ki) == 3:
    maxx = max(ki+gu)
    re = map(lambda x:(maxx-x)/2 ,ki+gu)
    print sum(re)


if len(gu) == 3:
    maxx = max(ki+gu)
    re = map(lambda x:(maxx-x)/2 ,ki+gu)
    print sum(re)

Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = 10000000;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

typedef int Weight;
typedef int Flow;
struct Edge {
	int src, dest, rev;
	Flow cap;
	Weight cost;
	bool operator < (const Edge &rhs) const
	{
		return cost > rhs.cost;
	}
	Edge(int s, int d) : src(s), dest(d) { ; }
	Edge(int s, int d, int c) : src(s), dest(d), cost(c) { ; }
	Edge(int s, int d, int r, Flow cp, Weight cst) : src(s), dest(d), rev(r), cap(cp), cost(cst) { ; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int src, int dest, Flow cap)
{
	g[src].push_back(Edge{ src, dest, (int)g[dest].size(), cap, 0 });
	g[dest].push_back(Edge{ dest, src, (int)g[src].size() - 1, 0, 0 });
}

void add_edge(Graph &g, int from, int to, Flow cap, Weight cost)
{
	g[from].push_back(Edge(from, to, (int)g[to].size(), cap, cost));
	g[to].push_back(Edge(to, from, (int)g[from].size() - 1, 0, -cost));
}

Weight mincost_flow(Graph &g, int s, int t, Flow f)
{
	const int n = g.size();
	Weight res = 0;
	Array dist(n);
	vi prevv(n), preve(n);
	while (f > 0)
	{
		REP(i, n) dist[i] = (i == s) ? 0 : INF;
		bool update = true;
		while (update)
		{
			update = false;
			for (int v = 0; v < n; v++)
			{
				if (dist[v] == INF) continue;
				REP(i, g[v].size())
				{
					Edge& e = g[v][i];
					if (e.cap > 0 && dist[e.dest] > dist[v] + e.cost)
					{
						dist[e.dest] = dist[v] + e.cost;
						prevv[e.dest] = v;
						preve[e.dest] = i;
						update = true;
					}
				}
			}
		}
		if (dist[t] == INF) return -1; // cannot flow
		Flow d = f;
		for (int v = t; v != s; v = prevv[v])
		{
			d = min(d, g[prevv[v]][preve[v]].cap);
		}
		f -= d;
		res += d * dist[t];
		for (int v = t; v != s; v = prevv[v])
		{
			Edge &e = g[prevv[v]][preve[v]];
			e.cap -= d;
			g[v][e.rev].cap += d;
		}
	}
	return res;
}


int main()
{
	int n; cin >> n;
	vi a(n), b(n);
	map<int, int> mp;
	int wid = 0;
	REP(i, n)
	{
		cin >> a[i]>> b[i];
		if (!mp.count(a[i])) mp[a[i]] = wid++;
		if (!mp.count(b[i])) mp[b[i]] = wid++;
	}
	Graph g(n + mp.size() + 2);
	int V = g.size();
	REP(i, n)
	{
		add_edge(g, V - 2, i, 1, 0);
		add_edge(g, i, V - 1, INF, 0);
		add_edge(g, i, n + mp[a[i]], 1, -b[i]);
		add_edge(g, i, n + mp[b[i]], 1, -a[i]);
	}
	REP(i, wid) add_edge(g, n + i, V - 1, 1, 0);
	cout << -mincost_flow(g, V - 2, V - 1, n) << endl;
	return 0;
}

Measured memory_bytes: 3508
// ~maqsat~
/*
```````````````````````¶¶
````````````````````¶¶¶¶¶¶¶¶
```````````````````¶¶¶¶¶¶¶¶¶¶
```````````````````¶¶¶¶¶¶``¶¶¶
``````````````````¶````¶````¶¶
``````````````````¶```¶¶¶```¶¶¶
`````````````````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
````````````````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶```````````¶¶
```````````````¶¶¶¶¶````¶¶¶¶¶`¶¶¶¶¶``````¶¶¶¶¶¶¶¶¶
`````````````¶¶¶¶¶````````````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶`
`````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶```¶¶¶
```¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
`¶¶``¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
``````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
```````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
```````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
`````````¶¶``````¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶¶
```````````````````¶¶¶¶¶¶¶¶¶¶¶¶¶¶
```````````````````¶¶¶¶¶¶¶¶¶¶¶¶¶¶
````````````````````¶¶¶¶¶¶¶¶¶¶¶¶
`````````````````````¶¶¶¶¶¶¶¶¶¶¶
``````````````````````¶¶¶¶¶¶¶¶¶
````````````````````````¶¶¶¶¶
                 ready for halloween
*/

// #pragma GCC target ("avx2")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define in insert
#define pb push_back
#define eb emplace_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define count1 __builtin_popcountl
#define debug(x) cerr << (#x) << " = " << (x) << "\n"
#define ACCELERATE ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T> inline void cmin(T &a, T b) { a = min(a, b); }
template <class T> inline void cmax(T &a, T b) { a = max(a, b); }

const int oo = 0x3f3f3f3f;
const ll N = 1e5 + 345;
const ll MOD = 1e9 + 7;
const ll INF = 1e10 + 9;
const db EPS = 1e-9;
const db PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

ll dp[105][N];
int main() {
    fre("");
    ACCELERATE;
    
    int n, w;
    cin >> n >> w;
    
    pll a[n+5];
    for(int i = 1; i <= n; i++) {
    	cin >> a[i].F;
    	cin >> a[i].S;
	}
	
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= w; j++) {
			if(j >= a[i].F)
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-a[i].F] + a[i].S);
			else
				dp[i][j] = dp[i-1][j];
		}
	}
    
    cout << dp[n][w];
    return 0;
}
/*
 
*/

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

int main() {
  string s;
  cin >> s;
  int cnt = 0, n = s.size();
  rep(i, n / 2) if (s[i] != s[n - 1 - i]) cnt++;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3600
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

constexpr int MOD = 1000000007;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int main() {
    int H, W;
    string g[8], m[8];
    cin >> H >> W;
    for (int j = 0; j < H; ++j) {
        cin >> g[j];
        m[j] = string(W, '.');
    }

    int h, w;
    h = 0; w = 0;
    while (! (h == H-1 && w == W-1)) {
        m[h][w] = '#';
        if (h < H-1 && g[h+1][w] == '#') {
            ++h;
        } else if (w < W-1 && g[h][w+1] == '#') {
            ++w;
        } else {
            break;
        }
    }

    if (h == H-1 && w == W-1) {
        m[H-1][W-1] = '#';
        bool ok = true;
        for (int j = 0; j < H; ++j) {
            if (g[j] != m[j]) {
                ok = false;
            }
        }
        cout << (ok ? "Possible" : "Impossible") << endl;
    } else {
        cout << "Impossible" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
def main():
  num = int(input())
  x = {}
  for i in range(num):
    s = input()
    if s in x:
      x[s] += 1
    else:
      x[s] = 1
  sl = []
  max_cnt = 0
  for key in x:
    if x[key] > max_cnt:
      max_cnt = x[key]
      sl = []
    if x[key] == max_cnt:
      sl.append(key)
#  print(x)
#  print(sl)
  sl.sort()
  for s in sl:
    print(s)


main()


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

int main()
{	
	
	long long int n,c=0,x=0,i; cin>>n;
	

	long long int l[n]={};

	l[0]=2,l[1]=1;

	for(int i=2;i<n+1;i++)
		l[i] = l[i-1]+l[i-2];

	cout<<l[n];



			
	
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll fac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
    int n,m,count=0;cin >> n >> m;
    vector<pl> p(m);
    rep(i,m){
        int a,b;cin >> a >> b;
        a--;b--;
        p[i]=mp(a,b);
    }
    rep(i,m){
        UnionFind uf(n);
        rep(j,m){
            if(j==i)continue;
            uf.merge(p[j].fi,p[j].se);
        }
        int cnt=0;
        rep(j,n){
            if(uf.par[j]<0)cnt++;
        }
        if(cnt>1)count++;
    }   
    cout << count << endl;
}

Measured memory_bytes: 256
class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

r1, c1, r2, c2 = map(int, input().split())
MOD = 10**9 + 7
comb = Combination(r2 + c2 + 10)

ans = 0

for c in range(c1, c2 + 1):
    ans += comb.ncr(r2 + c + 1, c + 1) - comb.ncr(r1 + c, c + 1)

print(ans % MOD)

Measured memory_bytes: 104688
program main
implicit None
integer::n,i,s,t
integer,allocatable::a(:)

	read *,n
	allocate(a(n))
	read *,a
	
	t = 0
	i = 1
	
	do while(i <= n)
		call count(a,n,i,s)
		t = t + s/2
		i = i + s
	enddo
	
	print 101,t
	
101 format(i0)
end program main

subroutine count(a,n,i,s)
implicit None
integer::n,i,s,t,k
integer::a(n)

k = i
t = a(i)
s = 1

do while(a(k+1) == t .and. i < n +1)
k = k + 1
s = s + 1
enddo

end subroutine count

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int d, t, s;
    cin >> d >> t >> s;
    cout << (d <= t * s ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n;
    cin >> n;
    VL h(n);
    FOR(i, 0, n)cin >> h[i];

    int ans = 0;
    int cnt = 1;
    FOR(i, 0, n -1) {
        if (h[i] >= h[i + 1])cnt++;
        else {
            chmax(ans, cnt - 1);
            cnt = 1;
        }
    }
    cout << max(ans, cnt - 1) << "\n";
}


Measured memory_bytes: 1024
N=int(input())
A=list(map(int,input().split()))
total = sum(A)
arai = 0
sunuke = 0
ans = float('inf')

for i in range(N-1):
    sunuke += A[i]
    arai = total - sunuke
    ans = min(ans,abs(sunuke-arai))

print(ans)
   

Measured memory_bytes: 30708
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int n,m,sum=0;
  long t[110],p[110],x[110];
  std::cin >> n;
  for(int i=0; i<n; i++){
     std::cin >> t[i];
     sum+=t[i];
   }
  std::cin >> m;
  for(int i=0; i<m; i++) std::cin >> p[i] >> x[i];

  for(int i=0; i<m; i++){
    int ans=sum;
    std::cout << ans-(t[p[i]-1]-x[i]) << '\n';
  }
  return 0;
}


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

int main(){
  int a,b,c,d=0;
  cin >> a >> b >> c >> d;
  if(a+b > c+d)
    cout << "Left" << endl;
  else if(a+b < c+d)
    cout << "Right" << endl;
  else
    cout << "Balanced" << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

ap, am = [], []
for i in range(n):
    ap.append(i + 1 + a[i])
    am.append(i + 1 - a[i])

from collections import Counter
dicp = Counter(ap)
dicm = Counter(am)

ans = 0
for i, j in dicp.items():
    if i in dicm:
        ans += j * dicm[i]
print(ans)

Measured memory_bytes: 63692
function move(d1,d2,d3,d4,d5,d6){
   var x=this.toString();
   if(x=="s")return [d2,d6,d3,d4,d1,d5];
   else if(x=="n")return [d5,d1,d3,d4,d6,d2];
   else if(x=="w")return [d4,d2,d1,d6,d5,d3];
   else if(x=="e")return [d3,d2,d6,d1,d5,d4];
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var n=arr.shift()-0;
   if(n==0)break;
   var dice=[1,2,3,4,5,6];
   while(n--){
      var str=arr.shift();
      dice=move.apply(str[0],dice);
   }
   console.log(dice[0]);
}

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

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

  for (int i=0; i < n; i++) {
    string color;
    cin >> color;
    if (color == "Y") {
      cout << "Four" << endl;
      return 0;
    }
  }
  cout << "Three" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a[10],i,j,work;
	for(i=0;i<10;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<3;i++){
		for(j=i+1;j<10;j++){
			if(a[i]<a[j]){
				work=a[i];
				a[i]=a[j];
				a[j]=work;
			}
		}
	}
	printf("%d\n",a[0]);
	printf("%d\n",a[1]);
	printf("%d\n",a[2]);
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
 
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;
 
int run_test(){
      ll n;
      cin >> n;
      int k = floor(sqrt(n));
      int visited[k];
      fill(visited, 0);
      int ans = 0;
      for(int i=2; i<=k; i++){
            if(visited[i]) continue;
            int count = 0;
            while(n % i == 0){
                  count++;
                  n /= i;
            }
            for(int j = i; j<=k; j+=i){
                  visited[j] = 1; 
            }
            ans += ((sqrt(1 + 8*count) - 1)/2);
      }
      if(n != 1){
            ans++;
      }
      cout << ans;
      return 0;
}
 
int main(){
    FAST;
    ll t;
    t = 1;
 
    while(t--){
        run_test();
    }
}

Measured memory_bytes: 7508
#include <stdio.h>


int main() {
  int input;
  long output = 0;
  scanf("%d", &input);

  for (int i = 1; i <= input; i += 1) {
    // incase FizzBuzz
    if (i % 3 == 0 && i % 5 == 0) {
      continue;
    // incase Fizz
    } else if (i % 3 == 0) {
      continue;
    // incase Buzz
    } else if (i % 5 == 0) {
      continue;
    }
    output = output + i;
  }

  printf("%ld\n", output);
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(ll i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

int main() {
	int n, m; cin >> n >> m;
	vector<int>v;
	rep(i, m) {
		int a, b; cin >> a >> b;
		v.push_back(a);
	}
	sort(v.begin(), v.end(), greater<>());
	int cnt = 0;
	rep(i, m - 1) {
		if (v[i] < n)cnt += n - v[i];
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3136
#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>
#include<complex>
using namespace std;

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

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#define double long double

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

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}

const double PI=acos(-1);
const double EPS=1e-15; //うまくいかなかったらゆるめる
typedef complex<double> P;
typedef vector<P> G;
#define shosu(x) fixed<<setprecision(x)
#define diff(P,i) (P[(i+1)%P.size()] - P[i])

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
  L(){;}
};
struct C {
  P c;double r;
  C(const P &c,double r):c(c),r(r){}
};

namespace std{//演算子の定義
  bool operator < (const P& a,const P& b) {
    return real(a)!= real(b) ? real(a) < real(b) : imag(a) < imag(b);
    //return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b)
  }
  bool operator == (const P& a,const P& b) {
    return a.real()==b.real() && a.imag()==b.imag();
  }
}



double dot(P a,P b) {
  return real(conj(a)*b);
}

double cross(P a,P b) {
  return imag(conj(a)*b);
}


bool isorthogonal(const L &l, const L &m) { //2直線の直交判定
  return fabs(dot(l[0]-l[1], m[0]-m[1])) < EPS;
}


P inP(){
  double x,y;
//  scanf("%lf,%lf", &x, &y);
  cin >> x >> y;
  P p(x,y);
  return p;
}


L inL(){
  P p1 = inP();
  P p2 = inP();
  L l(p1,p2);
  return l;
}

signed main(void) {
    double a,b;
    while(cin >> a >> b){
        P p1(a,b);
        P p2 = inP();
        L l1(p1,p2);
        L l2 = inL();
        if(isorthogonal(l1,l2))cout << "YES" << endl;
        else cout << "NO" << endl;
    }

}



Measured memory_bytes: 3184
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;

ll r1, c1, r2, c2, M=1e9+7;

ll pow(ll p, ll q) {
	if(q==0) return 1;
	ll t = pow(p, q/2);
	return t * t % M * (q%2 ? p : 1) % M;
}

ll C(ll p, ll q) {
	ll x=1, y=1;
	for(ll i=0; i<q; i++) {
		x = x * (p-i) % M;
		y = y * (i+1) % M;
	}
	return x * pow(y, M-2) % M;
}

int main() {
	cin >> r1 >> c1 >> r2 >> c2;
	r2++; c2++;
	cout << (C(r2+c2, r2) - C(r2+c1, c1) - C(r1+c2, r1) + C(r1+c1, r1) + 2*M) % M;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4

int main(){
  int N; cin >> N;
  int A[N+1];
  int x[N+1][N];
  bool y[N+1][N];
  
  for (int i=1;i<=N;i++){
    cin >> A[i];
    for (int j=1;j<=A[i];j++) cin >> x[i][j] >> y[i][j];
  }

  int shojiki = 0;
  for (int tmp=0;tmp < (1<<N);tmp++){
    bitset<20> s(tmp);
    bool flag = true;

    for (int i=1;i<=N;i++){ //人について探索
      for (int j=1;j<=A[i];j++){
        if (s.test(i-1) && s.test(x[i][j]-1)==!y[i][j]) flag = false;
        /*
        else{
          if(s.test(x[i][j]-1)==y[i][j]) flag = false;
        }
        */
       //if (s.test(i-1)^s.test(x[i][j]-1)==y[x[i][j]][j]) flag = false;
       //if (s.test(x[i][j]-1)==y[x[i][j]][j]) flag = false;
        
      }
    }

    if (flag) shojiki = max(shojiki, (int)s.count());
  }
  
  cout << shojiki << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

int main()
{
    int n;
    cin>>n;
    vector<int> a(n,0);
    rep(i,n)
    {
        cin>>a[i];
    }
    double bunbo=0.0;
    rep(i,n)
    {
        bunbo+=1.0/a[i];
    }
    cout<<setprecision(9)<<1.0/bunbo;
       
}

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

#define REP(i,n,m) for(int i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)

#define EPS (1e-10)

typedef complex<double> P;

int main(void){
	int n;

	while(cin>>n && n){
		P p[n];
		rep(i,n) cin>>p[i].real()>>p[i].imag();

		int ans = 0;
		rep(i,n-1)REP(j,i+1,n){
			P v = p[i] - p[j];
			if(abs(v) > 2) continue;

			P q = P((p[i].real()+p[j].real())/2, (p[i].imag()+p[j].imag())/2);
			double dist = sqrt(1 - pow(abs(p[i]-p[j])/2, 2));
			P n1 = (v * P(0,+1)) / abs(v);
			P n2 = (v * P(0,-1)) / abs(v);
			P o1 = q + n1 * dist;
			P o2 = q + n2 * dist;

			int sum = 0;
			rep(k,n){
				if(abs(o1 - p[k]) < 1 + EPS) sum++;
			}

			ans = max(ans,sum);
			sum = 0;

			rep(k,n){
				if(abs(o2 - p[k]) < 1 + EPS) sum++;
			}
			ans = max(ans,sum);
		}

		cout<<(ans==0?1:ans)<<endl;
	}

	return 0;
}

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

alphabets = ["a", "b", "c", "d", "e", "f", "g", "h",
"i", "j", "k", "l", "m", "n", "o", "p","q", "r", "s",
"t", "u", "v", "w", "x", "y", "z"]

i = 0
while i in range(len(alphabets)):
    if alphabets[i] in S:
        i += 1
    else:
        print(alphabets[i])
        break
else:
    print ("None")


Measured memory_bytes: 3956
let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let () =
  let l = read_line () in
  match List.map int_of_string (split l ' ') with
  | [] | [_] | _::_::[]-> exit 1
  | a :: b :: c :: _ ->
      let str = if (compare a b = -1) && (compare b c = -1) then "Yes"
                else "No" in
      Printf.printf "%s\n" str

Measured memory_bytes: 2200
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

string ads(){
  string res;
  rep(i, 60){
    if((i/3) % 2 == 0) res.push_back('.');
    else res.push_back('#');
  }
  return res;
}

void f1(int a, int b){
  a -= 10; b -= 10;
  vector<string> ans;
  ans.push_back(ads());
  while(a != 0 || b != 0){
    ans.push_back(ads());
    auto now = &ans.back();
    for(int i = 1; i < now->size() && b > 0; i += 6){
      now->at(i) = '#';
      b--;
    }
    for(int i = 4; i < now->size() && a > 0;  i+= 6){
      now->at(i) = '.';
      a--;
    }
    ans.push_back(ads());
  }
  cout << ans.size() << " 60" << endl;
  for(string s : ans){
    cout << s << endl;
  }
}

void f2(int a, int b){
  vector<string> a1(2, string(18, '#'));
  vector<string> b1(2, string(18, '.'));
  a--; b--;
  for(int i = 0; i < 18 && a > 0; i += 2){
    a1.at(0).at(i) = '.';
    a--;
  }
  for(int i = 0; i < 18 && b > 0; i += 2){
    b1.at(1).at(i) = '#';
    b--;
  }
  cout << "4 18" << endl;
  for(string s : a1) cout << s << endl;
  for(string s : b1) cout << s << endl;
}

string mks(char x, char y, int co){
  string res;
  rep(i, 6*co-3){
    if((i/3) % 2 == 0) res.push_back(x);
    else res.push_back(y);
  }
  for(int i = res.size(); i < 100; i++) res.push_back(res.at(i-1));
  return res;
}

void f3(int a, int b){
  char x, y;
  if(a < b){
    x = '.', y = '#';
  }else{
    x = '#', y = '.';
    swap(a, b);
  }
  vector<string> ans;
  int sz = min(a, b);
  ans.push_back(mks(x, y, sz));
  b -= a-1;
  cerr << a << " " << b << endl;
  while(b != 0){
    ans.push_back(mks(x, y, sz));
    auto &now = ans.back();
    for(int i = 1; i < now.size() && b != 0; i += 6){
      now.at(i) = y;
      b--;
    }
    ans.push_back(mks(x, y, sz));
  }
  cout << ans.size() << " " << ans.front().size() << endl;
  for(string s : ans){
    cout << s << endl;
  }
}

int main(){
  int a, b;
  cin >> a >> b;
  if(a >= 10 && b >= 10){
    f1(a, b);
  }else if(a < 10 && b < 10){
    f2(a, b);
  }else{
    f3(a, b);
  }
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
#define ARR(...) vector<int>({__VA_ARGS__})
#define ARS(...) vector<string>({__VA_ARGS__})
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<double> base;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifdef ONLINE_JUDGE
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

constexpr ll MOD = 998244353;

int N;
ll fact[5000001] = {1};
ll invf[5000001] = {1};
ll ccom[5000002];
ll csum[5000002];

ll comb(ll a, ll b) {return fact[a]*invf[b]%MOD*invf[a-b]%MOD;}
ll mpow(ll a, ll b){
    ll res = 1;
    for (; b; b >>= 1) {
        if (b&1) res = res*a%MOD;
        a = a*a%MOD;
    }
    return res;
}
ll inv(ll v) {return mpow(v, MOD-2);}

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

    cin >> N;
    repp(i, 1, N/2+1) fact[i] = fact[i-1]*i%MOD;
    invf[N/2] = inv(fact[N/2]);
    repr(i, N/2, 1) invf[i] = invf[i+1]*(i+1)%MOD;
    rep(i, N/2+1) ccom[i] = comb(N/2, i);
    repr(i, N/2+1, 0) csum[i] = (csum[i+1]+ccom[i]*mpow(2, N/2-i))%MOD;

    ll res = mpow(3, N);
    repp(i, 1, N/2+1) {
        res -= ccom[i]*csum[N/2+1-i]%MOD*mpow(2, N/2-i+1);
        res = (res%MOD+MOD)%MOD;
    }

    cout << res << endl;
}

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

const ll MAXN = 200000;

ll N, ans=0, tmp=0;
string S, T;
vector<ll> abc[26];
map<ll,ll> MS, MT;
signed main(){
    cin >> S >> T;
    for(int i=0;i<S.size();i++) {
        ll num = S[i]-'a';
        abc[num].push_back(i);
        MS[num]++;
    }
    for(int i=0;i<T.size();i++) {
        ll num = T[i]-'a';
        MT[num]++;
    }
    for(map<ll,ll>::iterator itr=MT.begin();itr!=MT.end();itr++) {
        pair<ll,ll> p = *itr;
        if(p.second>0&&MS[p.first]==0) {
            cout << -1 << endl;
            return 0;
        }
    }
    ll id = 0;
    for(int i=0;i<T.size();i++) {
        ll id1 = lower_bound(abc[T[i]-'a'].begin(), abc[T[i]-'a'].end(), id%S.size())-abc[T[i]-'a'].begin();
        if(id1==abc[T[i]-'a'].end()-abc[T[i]-'a'].begin()) {
            id = ceil((double)id/(double)S.size())*S.size();
            i--;
            //cout << "OK1" << id << endl;
        }
        else {
            id = floor((double)id/(double)S.size())*S.size()+abc[T[i]-'a'][id1]+1;
            //cout << "OK2" << id << endl;
        }
    }
    cout << id << endl;
    return 0;
}

Measured memory_bytes: 1724
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}

int main(void){
	char d[][10]={"thu","fri","sat","sun","mon","tue","wed"};
	int x=in();
	puts(d[x%7]);
	return 0;
}

Measured memory_bytes: 1776
#include<bits/stdc++.h>
#define MAX 100005
using namespace std;
 
int dis[2][MAX];

int main(){
  int n, a, b, x, i, sum = 0;
  vector<int> node[MAX];
  queue<int> p;
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d%d", &a, &b);
    node[a].push_back(b);
    node[b].push_back(a);
  }
  for(i = 0; i < 2; i++){
    dis[0][1] = 1;
    dis[1][n] = 1;
    p.push(i ? n : 1);
    while(!p.empty()){
      x = p.front(); p.pop();
      for(vector<int>::iterator it = node[x].begin(); it != node[x].end(); it++){
        if(!(dis[i][*it])){
        dis[i][*it] = dis[i][x] + 1;
        p.push(*it);
        }
      }
    }
  }
  
  for(i = 1; i <= n; i++) if(dis[0][i] > dis[1][i]) sum++;
  cout << (sum >= (n+1)/2 ? "Snuke" : "Fennec") << endl;
}

Measured memory_bytes: 6656
script [] _ = 0
script _ [] = 0
script (x:xs) (y:ys)
 | x ==y =  script xs ys
 | otherwise = 1+ script xs ys

main = do
 str <- getLine
 let slen = length str
 let (f,b) = splitAt (div slen 2) str
 print $ script f $ reverse b

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 4005
#define MAX_T 4005

typedef long long ll;
#define INF (1LL<<60)

struct data{
  ll t,p,f;
  bool operator < (const data &p)const{
    return f<p.f;
  }
};

int N,T;
data a[MAX_N];

ll dp[MAX_T][MAX_N];
ll dm[MAX_T][MAX_N];

ll calc(int x,int y){
  if(y==0)return 0;
  return (a[x].f-a[y].f)*(a[x].f-a[y].f);
}

int main(){
  for(int i=0;i<MAX_T;i++){
    for(int j=0;j<MAX_N;j++){
      dp[i][j]=(j==0?0:-INF);
      dm[i][j]=(i==0||j==0?0:-INF);
    }
  }
  
  cin>>N>>T;
  a[0]=(data){0,0,0};
  
  for(int i=1;i<=N;i++){
    cin>>a[i].t>>a[i].p>>a[i].f;
  }
  sort(a+1,a+N+1);

  ll ans=0;
  
  for(int i=1;i<=T;i++){

    deque<int> deq;
    deq.push_back(0);
    
    for(int j=1;j<=N;j++){
      dp[i][j]=max(dp[i][j],dp[i-1][j]);
      if(i-a[j].t>=0){
        dp[i][j]=max(dp[i][j],dm[i-a[j].t][j]+a[j].p);
      }
      ans=max(ans,dp[i][j]);


      
      while(deq.size()>=2){
        int a=deq.front();deq.pop_front();
        int b=deq.front();
        if( dp[i][a]-calc(j,a) > dp[i][b]-calc(j,b) ){
          deq.push_front(a);
          break;
        }
      }
      
      int key=deq.front();
      dm[i][j]=dp[i][key]-calc(j,key);

      while(!deq.empty()){
        int a=deq.back();deq.pop_back();
        if( dp[i][a]-calc(j,a) > dp[i][j] ){
          deq.push_back(a);
          break;
        }
      }
      deq.push_back(j);
    }
  }

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

Measured memory_bytes: 253868