akhauriyash/Code-Regression huggingface dataset:
mod = 10**9+7
H, W = map(int, input().split())
G = [input() for i in range(H)]
dp = [[0]*W for i in range(H)]
dp[0][0] = 1
for i in range(H):
    for j in range(W):
        if G[i][j] == '.':
            if i - 1 >= 0:
                if j - 1 >= 0:
                    dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod
                else:
                    dp[i][j] = dp[i-1][j]
            elif j - 1 >= 0:
                dp[i][j] = dp[i][j-1]
print(dp[H-1][W-1])

Measured memory_bytes: 53488
import sys
from collections import deque

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    G = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b, c = map(int, readline().split())
        G[a - 1].append((b - 1, c))
        G[b - 1].append((a - 1, c))

    Q, K, *XY = map(int, read().split())
    K -= 1

    stack = deque([K])
    dist = [INF] * N
    dist[K] = 0
    while stack:
        v = stack.pop()
        for nv, cost in G[v]:
            if dist[nv] == INF:
                dist[nv] = dist[v] + cost
                stack.append(nv)

    ans = [0] * Q
    for i, (x, y) in enumerate(zip(*[iter(XY)] * 2)):
        ans[i] = dist[x - 1] + dist[y - 1]

    print(*ans, sep='\n')
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 65404
from collections import deque
s=list(str(input()))
s=deque(s)
q=int(input())
cnt=0
for i in range(q):
    que=list(input().split())
    if len(que)==1:
        cnt+=1
    if len(que)!=1 and cnt%2==0:
        if int(que[1])==1:
            s.appendleft(que[2])
        elif int(que[1])==2:
            s.append(que[2])
    if len(que)!=1 and cnt%2!=0:
        if int(que[1])==1:
            s.append(que[2])
        elif int(que[1])==2:
            s.appendleft(que[2])
if cnt%2!=0:
    s.reverse()
print(''.join(s)) 

Measured memory_bytes: 76008
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    a, b = input().split()
    b = b.replace(".", "")
    print(int(a)*int(b)//100)   
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 27208
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int n,ans;
    string s,t;
    cin >> n >> s >> t;
    ans = 2*n;
    for(int i = 0;i < n;i++){
        if(s.substr(i) == t.substr(0,n-i)){
            ans = n+i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N,M,C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]

cnt=0
for i in range(N):
    sum=C
    for j in range(M):
        sum+=A[i][j]*B[j]
    if sum>0:
        cnt+=1
print(cnt)


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;

int main() {
	ll a, b, k;
	cin >> a >> b >> k;

	for (ll i = 0; i < k && a <= b; i++)
	{
		cout << a++ << endl;
	}

	a = b - k + 1 < a ? a : b - k + 1;
	for (ll i = a; i <= b; i++)
	{
		cout << i << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, x, y, z;
const int maxn = 1e5 + 7;
int exc[maxn];
int l, r, d;
int main()
{
    int ans = 0;
    cin >> l >> r >> d;
    for (int i = l; i <= r; i++)
        if (i % d == 0)
            ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
char A[1000005],B[10005];
int Next[10001];
void getNext(int lb){
	int j=0, k=-1;
	Next[0] = -1;
	while(j < lb)
		if(k==-1 || B[k]==B[j])
			Next[++j] = ++k;
		else k = Next[k];
}
void Find(int la, int lb){
	int i=0, j=0;
	while(i<la)
		if(j==-1 || A[i]==B[j]){
			i++, j++;
			if(j == lb){
				cout << i - j << endl;
				j = Next[j];
			}
		}
		else 
			j = Next[j];
}
int main()
{	
	scanf("%s%s",A,B);
	int la=strlen(A), lb=strlen(B);
	getNext(lb);
	Find(la, lb);
	return 0;
}



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

int main() {
    int N, K;
    double ans = 0;
    cin >> N >> K;
    int p[N+1] = {};
    rep(i, N) {
        cin >> p[i+1];
    }
    rep(i, N) {
        p[i+1] = p[i+1] + 1;
    }
    rep(i, N) p[i+1] += p[i];
    for (int r = K; r <= N; r++) {
        double now = (p[r] - p[r - K]) / 2.0;
        ans = max(ans , now);
    }
    //cout << ans << endl;
    printf("%f\n", ans);
    // 3 3
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n,m;
  cin>>n>>m;
  int a[m];
  for(int i=0;i<m;i++) a[i]=0;
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int q;
      cin>>q;
      a[q-1]++;
    }
  }
  int ans=0;
  for(int i=0;i<m;i++){
    if(a[i]==n) ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(b % a == 0) cout << a + b << endl;
  else cout << b - a << endl;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define LL long long
#define ULL unsigned long long

VPII students, coords;

int n, m;
void solve()
{
    for(int i = 1; i <= n; ++i)
    {
        int sx = students[i].first, sy = students[i].second;

        int minval = INT_MAX, idx = -1;
        for(int j = 1; j <= m; ++j)
        {
            int cx = coords[j].first, cy = coords[j].second;
            int dist = abs(sx - cx) + abs(sy - cy);
            if(dist < minval){
                idx = j;
                minval = dist;
            }
        }
        printf("%d\n", idx);
    }
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
    cin >> n >> m;

    students = VPII(n + 1); coords = VPII(m + 1);
    for(int i = 1; i <= n; ++i)
        cin >> students[i].first >> students[i].second;
    
    for(int i = 1; i <= m; ++i)
        cin >> coords[i].first >> coords[i].second;

    solve();

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAXN 200000
#define LL long long
#define INF 1000000000000000000
int n,top;
char s[MAXN+5],stk[MAXN+5];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='T')
		{
			if(stk[top]=='S')top--;
			else stk[++top]='T';
		}
		else stk[++top]='S';
	}
	printf("%d",top);
}

Measured memory_bytes: 760
from scipy.misc import comb
def modpow(a, n, p):
  if n == 1:
    return a % p 
  elif n % 2 == 1:
    return a * modpow(a, n-1, p) % p
  else:
    return modpow(a, n//2, p) **2 % p
x, y = map(int, input().split())
t = (2*y-x)/3
s = (2*x-y)/3
if not t.is_integer() or t<0 or not s.is_integer() or s<0:
  print(0)
else:
  t = int(t)
  s = int(s)
  bunsi = 1
  for i in range(s+t-s+1, s+t+1):
    bunsi = bunsi * i % 1000000007
  bunbo = 1
  for i in range(1, s+1):
    bunbo = bunbo * i % 1000000007
  ans = bunsi * modpow(bunbo, 1000000007-2, 1000000007) % 1000000007
  print(ans)

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

typedef long long ll;

int main() {
    ll K;
    cin >> K;
    ll L;
    if (K%7 == 0) {
        L = 9 * K / 7;
    }else{
        L = 9 * K;
    }
    ll amari;
    amari = 10 % L;
    bool Flag = false;
    if (amari == 1) {
        cout << 1 << endl;
        exit(0);
    }else{

    for(int i=2;i<=10e7;i++) {
        amari = (10 * amari) % L;
        if (amari == 1) {
            cout << i << endl;
            Flag = true;
            break;
        }
    }
    }
    if (Flag==false) {
        cout << "-1" << endl;
    }
}


Measured memory_bytes: 3644
#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()
    
int main(){
    int n;
    cin >> n;
    cout << n + n*n + n*n*n << endl;

}

Measured memory_bytes: 3628
import collections
import itertools
import math


def eratosthenes(n):
    sieve = [True for _ in range(n + 1)]
    sieve[0] = False
    sieve[1] = False

    def _update(p):
        if sieve[p]:
            for i in range(p * 2, n + 1, p):
                sieve[i] = False

    _update(2)
    p = 3
    while p * p <= n:
        _update(p)
        p += 2
    return sieve


n, m = map(int, input().split())
m2 = math.ceil(math.sqrt(m)) + 1
sieve = eratosthenes(m2)
counter = collections.Counter()

mm = m
for k in range(2, m2):
    if sieve[k] and m % k == 0:
        while mm % k == 0:
            mm //= k
            counter[k] += 1
if mm > 1:
    counter[mm] += 1

es = [range(k + 1) for k in counter.values()]
res = 1
for ks in itertools.product(*es):
    x = 1
    for p, k in zip(counter.keys(), ks):
        x *= p**k
    if x <= m // n:
        res = max(res, x)
print(res)

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
typedef long long ll;
int main(){
    int n;cin>>n;
    vector<vector<int>> x(n);
    vector<vector<bool>> y(n);
    rep(i,n){
        int a;cin>>a;
        rep(j,a){
            int tx,ty;cin>>tx>>ty;tx--;
            x[i].emplace_back(tx);
            y[i].emplace_back(ty);
        }
    }
    int maxv=0;
    rep(bit,(1<<n)){
        vector<bool> s(n,false);
        rep(i,n)if(bit&(1<<i))s[i]=true;
        bool flag=true;
        rep(i,n){
            if(s[i]==true)
                rep(j,x[i].size())if(y[i][j]!=s[x[i][j]])flag=false;
        }
        if(flag==true){
            int cnt=0;
            rep(i,n)if(s[i]==true)cnt++;
            maxv=max(maxv,cnt);
        }
    }
    cout<<maxv<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
F = [0]*n
P = [0]*n
for i in range(n):
    F[i] = list(map(int,input().split()))
for i in range(n):
    P[i] = list(map(int,input().split()))

ans = -float("Inf")
for i in range(1,2**10):
    L = []
    b = 0
    for j in range(10):
        if (i>>j)&1:
            L.append(j)
    for j in range(n):
        c = 0
        for x in L:
            if F[j][x] == 1:
                c += 1
        b += P[j][c]
        
    ans = max(ans, b)


print(ans)

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(n) ((int)(n).size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

const int NEUT = 0, MAXN = 3e5;
ll tree[4*MAXN], h[MAXN], v[MAXN];

ll op(ll a, ll b){
  return max(a,b);
}

void update(int pos, ll value, int node = 1, int start = 1, int end = MAXN){
  int mid = (start+end)/2;
  if(start == end){
    tree[node] = op(tree[node],value);
    return;
  }
  if(start <= pos && pos <= mid){
    update(pos, value, 2*node, start, mid);
  }
  else{
    update(pos, value, 2*node+1, mid+1, end);
  }
  tree[node] = op(tree[2*node], tree[2*node+1]);
}

ll query(int l, int r, int node = 1, int start = 1, int end = MAXN){
  if(start > r || end  < l){
    return NEUT;
  }
  if(l <= start && end <= r){
    return tree[node];
  }
  int mid = (start+end)/2;
  return op(query(l, r, 2*node, start, mid), query(l, r, 2*node+1, mid+1, end));
}

set<ll> s;
map<ll,ll> mp;

bool cmp(pair<ii,ll> &x, pair<ii,ll> &y){
  if(x.fst.fst == y.fst.fst) return x.fst.snd > y.fst.snd;
  return x.fst.fst < y.fst.fst;
}

int main(){FIN;
  ll n,t=0; cin >> n;
  fore(i,0,n) cin >> h[i], s.insert(h[i]);
  for(auto x : s) mp[x]=t++;
  fore(i,0,n) h[i] = mp[h[i]];
  fore(i,0,n) cin >> v[i];
  vector<pair<ii,ll>> aux;
  fore(i,0,n) aux.pb({{h[i], i},v[i]});
  sort(ALL(aux),cmp);
  fore(i,0,n){
    ll now = query(1,aux[i].fst.snd);
    update(aux[i].fst.snd+1,now+aux[i].snd);
  }
  cout << query(1,n) << endl;
}

Measured memory_bytes: 39788
//I am so vegetable
//#define err
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define pb push_back
#define in insert
#define er erase
#define ct count
#define ep empty
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const double eps = 1e-6;
const double pi = acos(-1.0);
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll qpow(ll x, ll y, int MOD) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans = ans*x%MOD; x = x*x%MOD; }return ans; }
void exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){x=1;y=0;return;}
    exgcd(b,a%b,x,y);
    ll X=x;
    x=y; y=X-a/b*y;
}
ll inv(ll x, int mod = MOD) { return qpow(x, mod - 2,mod); }
ll m_m(ll a){ return (a%MOD+MOD)%MOD; }


signed main() {
    //ifstream cin("E:\\acm dream\\in.in");
	//ofstream cout("E:\\acm dream\\out.out");
	FIO;
    #ifdef err
	double be = clock();
    #endif

    string s;cin>>s;s+='S';
    int a=0,ans=0;
    _sfor(it,s){
        if(it=='R')++a;
        else ans=max(a,ans),a=0;
    }
    cout<<ans;
    
    #ifdef err
	double en = clock();
    cout<<"time: "<<fixed<<setprecision(8)<<en-be;
    #endif
	return 0;
}

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<VB> VVB;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef pair<LL,LL> PLL;
typedef vector<PII> VPII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define FORR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REPR(i,n) RFOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = INT_MAX;
const LL LINF = LLONG_MAX;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

VI dx = {1,0,-1,0};
VI dy = {0,1,0,-1};

LL Gcd(LL a, LL b) {
  return __gcd(a,b);
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}


LL RepSqu(LL N, LL P, LL M) {
  if(P == 0) {
    return 1;
  }
  if(P%2 == 0) {
    LL t = RepSqu(N, P/2, M);
    return t*t % M;
  }
  return (N * RepSqu(N, P-1, M)) % M;
}


typedef pair<LL,LL> PIL;
typedef vector<PLL> VPIL;

VLL Dfs(vector<VPIL> ttp, int K, int N){
  VLL ans(N+1);
  VB sen(N+1,false);
  stack<PIL> dfs;
  dfs.push(MP(K,0));
  while(SZ(dfs)){
    PIL p = dfs.top();
    dfs.pop();
    int no = p.FI;
    LL ln = p.SE;
    ans.at(no) = ln;

    sen.at(no)=true;
    int si = SZ(ttp.at(no));
    REP(i,si){
      PIL nex = ttp.at(no).at(i);
      if(!sen.at(nex.FI)){
      	dfs.push(MP(nex.FI,nex.SE+ln));
      }
    }
    
  }
  return ans;
}

int main() {
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N,a,b;
  LL c;
  cin >> N;
  
  vector<VPIL> ttp(N+1);
  
  REP(i,N-1){
    cin >> a >> b >> c;
    
    ttp.at(a).PB(MP(b,c));
    ttp.at(b).PB(MP(a,c));
    
  }
  
  int Q,K,x,y;
  cin >> Q >> K;
  
  VLL lo = Dfs(ttp,K,N);
  
  
  REP(i,Q){
    cin >> x >> y;
    cout << lo.at(x)+lo.at(y) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 16752
#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>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int main()
{
	
    string s;
    cin >> s;
    int res = 0;
    if (s == "RRR") res = 3;
    else if (s == "RRS") res =  2;
    else if (s == "RSS") res =  1;
    else if (s == "RSR") res =  1;
    else if (s == "SRS") res =  1;
    else if (s == "SSR") res =  1;
    else if (s == "SRR") res =  2;
    else if (s == "SSS") res =  0;
    cout << res << endl;
}

Measured memory_bytes: 3560
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;

int main(){

	string in;
	string tmp;
	int cal;
	int cnt=0;
	vector<int> sq[100];

	while(cin>>in){
		cnt++;
		for(int i=0;i<=in.size();i++){
			if(i==in.size()||in[i]==','){
				if(tmp.size()==1) cal=tmp[0]-'0';
				else cal=tmp[1]-'0'+10*(tmp[0]-'0');
				sq[cnt-1].push_back(cal);
				tmp="";
			}
			else{
				tmp+=in[i];
			}
		}
	}

	for(int i=1;i<cnt;i++){
		for(int j=0;j<sq[i].size();j++){
			if(cnt/2+1>i){
				if(j==0){
					sq[i][j]+=sq[i-1][j];
				}
				else if(j==sq[i].size()-1){
					sq[i][j]+=sq[i-1][j-1];
				}
				else{
					sq[i][j]+=max(sq[i-1][j],sq[i-1][j-1]);
				}
			}
			else{
				sq[i][j]+=max(sq[i-1][j],sq[i-1][j+1]);
			}
		}
	}

	cout<<sq[cnt-1][0]<<endl;
}

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


int main(){
    int n;
    cin>>n;
    map<int,int>mp;
    for(int k=2;k<=n;k++){
        int i=k;
        for(int j=2;j+j<=i;j++){
            while(i%j==0){
                mp[j]++;
                i/=j;
            }
        }
        if(i!=1){
            mp[i]++;
        }
    }
    // for(auto &itr:mp){
    //     cout<<itr.first<<" "<<itr.second<<endl;
    // }
    // cout<<"sss"<<endl;
    int ans=0;
    vector<int>a(80,0);
    for(int i=2;i<=74;i++){
        for(auto itr:mp){
            if(itr.second>=i){
                a[i]++;
            }
        }
    }
    // for(int i=1;i<=6;i++){
    //     cout<<i<<" "<<a[i]<<endl;
    // }
    ans+=a[74];
    ans+=a[24]*(a[2]-1);
    ans+=(a[4]-1)*a[14];
    ans+=(a[2]-2)*a[4]*(a[4]-1)/2;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int M, D;
	cin >> M >> D;
	int c=0, d1=0, d10=0,i,j;
	for (i = 1; i <= M; i++) {
		for (j = 1; j <= D; j++) {
			d1 = j % 10;
			d10=j/10;
			if ((i == (d1*d10))&&(d1>=2&&d10>=2)) {
				c++;
			}
		}
	}
	cout << c << endl;
	return 0;
}

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (a > d) cout << 0 << endl;
  else if (c > b) cout << 0 << endl;
  
  else if ((a <= c) && (b >= d)) cout << d - c << endl;
  else if ((a >= c) && (b <= d)) cout << b - a << endl;

  else if ((a <= c) && (b <= d)) cout << b - c << endl;
  else if ((a >= c) && (b >= d)) cout << d - a << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
typedef long long ll;
typedef long double lld;
typedef long long int lli;
using namespace std;
const int N = 1000001;
const bool DEBUG = 1;
#define sd(x) scanf("%d", &x)
#define sd2(x, y) scanf("%d%d", &x, &y)
#define sd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define LET(x, a) __typeof(a) x(a)
#define foreach(it, v) for (LET(it, v.begin()); it != v.end(); it++)
#define MEMS(a, b) memset(a, b, sizeof(a))
#define _			\
    ios_base::sync_with_stdio(false);			\
    cin.tie(NULL);			\
    cout.tie(NULL);
#define __ 			\
    freopen("input.txt", "r", stdin);			\
    freopen("output.txt", "w", stdout);
#define all(c) c.begin(), c.end()
#define inf 1000000000000000001
#define epsilon 1e-6
#define int ll
#define RUN_T			 \
    int _t; 			 \
    cin >> _t;			 \
    while (_t--)			 
#define tr(...)				\
if (DEBUG) {				\
cout << __FUNCTION__ << ' ' << __LINE__ << " = ";				\
trace(#__VA_ARGS__, __VA_ARGS__);				\
}
template <typename S, typename T>
ostream &operator<<(ostream &out, pair<S, T> const &p) {
    out << '(' << p.fi << ", " << p.se << ')';
    return out;
}
template <typename T>
ostream &operator<<(ostream &out, set<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, map<T, V> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << "\n" << (i->first) <<  ":"  << (i->second);
    return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, unordered_map<T, V> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << "\n" << (i->first) <<  ":"  << (i->second);
    return out;
}
template <typename T>
ostream &operator<<(ostream &out, multiset<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T>
ostream &operator<<(ostream &out, unordered_set<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T>
ostream &operator<<(ostream &out, unordered_multiset<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T> ostream &operator<<(ostream &out, vector<T> const &v) {
    ll l = v.size();
    for (ll i = 0; i < l - 1; i++)
        out << v[i] << ' ';
    if (l > 0)
        out << v[l - 1];
    return out;
}
template <typename T> void trace(const char *name, T &&arg1) {
    cout << name <<  ":"  << arg1 << endl;
}
template <typename T, typename... Args>
void trace(const char *names, T &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cout.write(names, comma - names) <<  ":"  << arg1 <<  "|" ;
    trace(comma + 1, args...);
}
int gcd(int a, int b) {
     if (b == 0)
        return a;
    return gcd(b, a % b);
}
int32_t main() {
    char n;
    cin>>n;
    cout<<++n;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        //PrintWriter out = new PrintWriter(System.out);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        //String[] buf = reader.readLine().split(" ");
        int H = sc.nextInt(), W = sc.nextInt(), n = sc.nextInt();
        int SR = sc.nextInt(), SC = sc.nextInt();
        char[] s = sc.next().toCharArray(), t = sc.next().toCharArray();
        boolean res = help(H,W,n,s,t,SR,SC);
        String ans = res?"YES":"NO";
        System.out.println(ans);
    }
    static boolean help(int H, int W, int n, char[] s, char[] t, int sr, int sc){
        HashMap<Character,Character> opp = new HashMap<>();
        opp.put('U','D');
        opp.put('D','U');
        opp.put('L','R');
        opp.put('R','L');
        int hi=1, lo=H,le=1,ri=W;
        if(s[n-1]=='U') hi++;
        else if(s[n-1]=='D') lo--;
        else if(s[n-1]=='L') le++;
        else ri--;
        if(le>ri||lo<hi||le>W||ri<1||lo<1||hi>H) return false;

        for(int i=n-2;i>=0;i--){
            /*char cur = s[i];
            if(t[i]==opp.get(cur)) continue;
            if(cur=='L') le++;
            else if(cur=='R') ri--;
            else if(cur=='U') hi++;
            else lo--;
            if(t[i]=='L') ri=Math.min(W,ri+1);
            else if(t[i]=='R') le=Math.max(1,le-1);
            else if(t[i]=='U') lo = Math.min(lo+1,H);
            else hi = Math.max(hi-1,1);
            if(le>ri||lo<hi) return false;
            if(hi>sr||sr>lo||sc<le||sc>ri) return false;*/
            if(t[i]=='L') ri=Math.min(W,ri+1);
            else if(t[i]=='R') le=Math.max(1,le-1);
            else if(t[i]=='U') lo = Math.min(lo+1,H);
            else hi = Math.max(hi-1,1);

            char cur = s[i];
            if(cur=='L') le++;
            else if(cur=='R') ri--;
            else if(cur=='U') hi++;
            else lo--;
            if(le>ri||lo<hi||le>W||ri<1||lo<1||hi>H) return false;
        }
        return le<=sc&&sc<=ri&&hi<=sr&&sr<=lo;
    }
}

Measured memory_bytes: 30040
#include <algorithm>
#include <cstdio>
typedef long long lld;
int A;
lld B, N;

lld f(lld x) {
  return (A * x) / B - A * (x / B);
}

int main() {
  scanf(" %d%lld%lld", &A, &B, &N);
  printf("%lld\n", f(std::min(B-1, N)));
  return 0;
}

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

int main() {
 int kinds, amount;
 cin >> kinds >> amount;
  
 vector<int> fruits(kinds);
 for( int i = 0; i < kinds; i++) {
	cin >> fruits.at(i);
 }
 
 sort(fruits.begin(), fruits.end());
 
 int ans = 0;
 for( int i = 0; i < amount; i++) {
  ans += fruits.at(i); 
 }
 cout << ans << endl;
  
  return 0;
}

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

using namespace std;
typedef pair<int, int> P;
typedef pair<P, P> PP;


void solve()
{
	int n, m, h, k;
	while(cin >> n >> m >> h >> k, n || m || h || k)
	{
		vector<int> point(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> point[i];
		}
		vector<PP> side_bar;
		for(int i = 0; i < m; ++i)
		{
			int a, b;
			cin >> a >> b;
			a--;
			side_bar.push_back(PP(P(b, a), P(-1,-1)));
		}
		sort(side_bar.begin(), side_bar.end());
		vector<int> v(n);
		for(int i = 0; i < n; ++i)
		{
			v[i] = i;
		}
		for(int i = 0; i < m; ++i)
		{
			int idx = side_bar[i].first.second;
			side_bar[i].second.first = v[idx];
			side_bar[i].second.second = v[idx + 1];
			int t = v[idx];
			v[idx] = v[idx + 1];
			v[idx + 1] = t;
		}
		int sum = 0;
		vector<int> v_rev(n);
		for(int i = 0; i < n; ++i)
		{
			v_rev[v[i]] = i;
			if(v[i] < k)
			{
				sum += point[i];
			}
		}
		int ans = sum;
		for(int i = 0; i < m; ++i)
		{
			int a = side_bar[i].second.first;
			int b = side_bar[i].second.second;
			if(a > b)
			{
				swap(a, b);
			}
			if(a < k && k <= b)
			{
				ans = min(ans, sum - point[v_rev[a]] + point[v_rev[b]]);
			}
		}
		cout << ans << endl;
	}
}
int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 3152
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
using namespace std;
int main(){
  typedef long long int ll;
string A, B, C,D;
cin >> A;
for(int i = 0;i < A.size();i++){
if(A[i] == ',')A[i] = ' ';
}
cout << A << endl;
        return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  int A,B,ans;
  scanf("%d %d",&A,&B);
  if(A+B > A-B)ans = A+B;
  else ans = A-B;
  if(A*B > ans)ans = A*B;
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    
    ll sum=0, n;
    rep1(i,N){
        sum+=i;
        if(sum==N){
            n=i;
            break;
        }
        if(sum>N){
            cout1("No");
            return 0;
        }
    }
    vector<int> G[n+1];
    int now=1;
    rep(i,n){
        rep(j,n-i) G[i].push_back(now+j);
        rep(j,n-i) G[i+j+1].push_back(now+j);
        now += n-i;
    }
    cout1("Yes");
    cout1(n+1);
    rep(i,n+1){
        cout<<G[i].size();
        rep(j,n){
            cout<<" ";
            cout<<G[i][j];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 2304
#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 perl(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 pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
//#define at(x,i) get<i>(x);//
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll a,b;cin >> a >>b;
    a--;
    ll x=0,y=0;
    ll p=a%4;
    if(p==1||p==2)x++;
    p=b%4;
    if(p==1||p==2)y++;
    rep(i,60){
        ll d=i+1;
        ll z=pow((ll)2,d+1);
        p=a%z;
        if(p>z/2-1&&p%2==0)x+=((ll)1<<d);
        p=b%z;
        if(p>z/2-1&&p%2==0)y+=((ll)1<<d);
    }
    cout << (x^y) <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define s(x, n) memset(x, n, sizeof(x));
#define pb(x) push_back(x)
#define NIL -1
#define MAXN 11

void solve()
{
    int n;
    cin >> n;
    int d1[n], d2[n];
    bool flag = false;
    for (int i = 0; i < n; i++)
    {
        cin >> d1[i] >> d2[i];
    }
    for (int i = 2; i < n; i++)
    {
        if (d1[i] == d2[i] && d1[i - 1] == d2[i - 1] && d1[i - 2] == d2[i - 2])
            flag = true;
    }
    if (flag)
        cout << "Yes\n";
    else
    {
        cout << "No\n";
    }
}
int main()
{
#ifdef WIN32
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

#ifndef WIN32
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#endif
    int t;
    t = 1;
    /// cin >> t;
    for (int I = 1; I <= t; I++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
using namespace std;
#define sci(x) int x;scanf("%d",&x);
#define scii(x, y) int x,y;scanf("%d%d",&x,&y);

int main() {
  scii(a,b) sci(c)
  puts(b-a==c-b?"YES\n":"NO\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	int h, w, n;
	cin >> h >> w >> n;
	h = max(h, w);
	cout << (n + h - 1) / h << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
#define INF 70000000
typedef pair < int , int > P;
int toint(int* n){
  return n[0] * 1000000 + n[1] * 100000 + n[2] * 100000 +
    n[3] * 10000 + n[4] * 1000 + n[5] * 100 + n[6] * 10 + n[7];
}
int main(){
  int p[8], sum, num, ret[8];
  while(~scanf("%d %d %d %d %d %d %d %d",p,p+1,p+2,p+3,p+4,p+5,p+6,p+7)){

    sum = 0;
    num = INF;

    int man[] = { 4, 1, 4, 1, 2, 1, 2, 1 };
    for(int i = 0 ; i < 8 ; i++ ){
      rotate( man, man + 7, man + 8);

      int res = 0;
      for(int j = 0 ; j < 8 ; j++ ){
        res += min( man[j], p[j]);
      }

      if( res > sum ){ // resの方が大きかったらHappy
        num = toint(man);
        memcpy( ret, man, sizeof man);
        sum = res;
      } else if( res == sum ){ // 小さい方
        if(num > toint(man)){
          num = min( num, toint(man));
          memcpy( ret, man, sizeof man);
        }
      }
    }
    for(int i = 0 ; i < 8 ; i++ ){
      cout << ( i ? " " : "" ) << ret[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;
 
int main() {
    int n;
    scanInt(n);
    char s[n+1];
    scanf("%s", s);
    int count = 0;
    for (int i = 0; s[i] != '\0'; ++i) {
        if (i+2 < n &&
            s[i] == 'A' && 
            s[i+1] == 'B' && 
            s[i+2] == 'C')
            count++;
    }
    printInt(count);
    return 0;
}

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

int main(){
    string s;cin>>s;
    rep(i,4)s[i]-='0';
    
    rep(i,1<<3){
        int ans = s[0];
        rep(j,3)ans += (1&i>>j)?s[j+1]:(-s[j+1]);
        if(ans!=7)continue;
        
        cout<<(int)s[0];
        rep(j,3)printf("%c%d",(1&i>>j)?'+':'-',s[j+1]);
        cout<<"=7\n";
        return 0;
    }
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
#define re register
#define int long long
inline int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0'){
		t=(t<<3)+(t<<1)+v-48;
		v=getchar();
	}
	return t;
}
using namespace std;
int n,a,b;
signed main(){
	n=read();
	a+=n/500*1000;
	n%=500;
	a+=n/5*5;
	printf("%lld",a);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define SZ(n)  (int)n.size()
#define dump(x) cerr<<#x<<" = "<<(x)<<endl;
#define debug(x)cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define MP make_pair
#define PB push_back
	


	int dx[]={1,1,0,-1,-1,-1,0,1},dy[]={0,1,1,1,0,-1,-1,-1};
	string _or(string a,string b){
		if(SZ(a)>SZ(b))return a;
		if(SZ(a)<SZ(b))return b;
		return min(a,b);
	}
	char ta[50][50];
	int main(){
	int w,h;
	while(cin>>h>>w,(h||w)){
	map<string,int>ans;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>ta[i][j];
	string tmp;

	for(int ni=0;ni<h;ni++){
		for(int nj=0;nj<w;nj++){
			for(int p=0;p<8;p++){
				tmp.clear();
				int i=ni,j=nj;
				tmp.push_back(ta[ni][nj]);
					while(true){
					i+=dy[p],j+=dx[p];
					if(i<0)i=h-1;
					if(j<0)j=w-1;
					if(i>h-1)i=0;
					if(j>w-1)j=0;
					if(i==ni&&j==nj)break;
					tmp.push_back(ta[i][j]);

					if(SZ(tmp)>=2){
					ans[tmp]++;
					}
					}
			}
		}
	}
	string tans="";
	for(map<string,int>::iterator it=ans.begin();it!=ans.end();it++){
	if((*it).second>=2){tans=_or(tans,(*it).first);}
	}
	if(SZ(tans)<2)cout<<"0"<<endl;
	else cout<<tans<<endl;
	for(int i=0;i<50;i++)for(int j=0;j<50;j++)ta[i][j]=' ';
	}
	return 0;
} 

Measured memory_bytes: 36020
#include<bits/stdc++.h>
using namespace std;
int main(){
    double N,K; cin>>N>>K;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    int ans=0;
    if(N<=K){
        ans=1;
    }
    else{
        ans=1+ceil((N-K)/(K-1));
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	string S[3];
	REP(i, 3) cin >> S[i];
	string c = "abc";
	string C = "ABC";
	int k[3] = { 0 };
	int t = 0;
	while (1) {
		if (k[t] == S[t].size()) {
			cout << C[t] << "\n";
			return 0;
		}
		REP(i, 3) {
			if (S[t][k[t]] == c[i]) {
				k[t]++;
				t = i;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var s string
	con.Scan(&s)
	for {
		s = s[:len(s)-1]
		if len(s)%2 != 0 {
			continue
		}
		h := len(s) / 2
		ok := true
		for i := 0; ok && i < h; i++ {
			ok = s[i] == s[i+h]
		}
		if ok {
			con.Println(len(s))
			break
		}
	}
	return nil
}


Measured memory_bytes: 640
// JOI 2012-2013 予選2
#include<iostream>
#include<string>

int main()
{
	int N;
	std::string shop;
	int ans = 0;

	std::cin >> N >> shop;
	for( int i = 0; i != N; ++i )
	{
		std::string s;
		std::cin >> s;

		std::string::size_type p;
		while( ( p = s.find( shop[0] ) ) != std::string::npos )
		{
			for( int j = 0; p + j * ( shop.size() - 1 ) < s.size(); ++j )
			{
				bool f = true;

				int c = 0;
				for( int k = p; k < s.size() && c < shop.size(); k += j + 1 )
					f &= s[k] == shop[c++];

				if( f && c == shop.size() )
				{
					++ans;

					goto end;
				}
			}

			s = s.substr( p + 1 );
		}

end:;
	}

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 1220
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define LL long long
using namespace std;

const int maxn=210,inf=1e8;
int n,m,dl[maxn][maxn],ds[maxn][maxn],r,city[1010],dp[1010][maxn];

int main(void){
    while(scanf("%d %d",&n,&m)!=EOF && (n+m)){
        int i,j,k;
        for(i=1;i<=n;i++){
            for(j=1;j<=n;j++){
                dl[i][j]=ds[i][j]=inf;
            }
            dl[i][i]=ds[i][i]=0;
        }
        for(i=1;i<=m;i++){
            int u,v,t;
            char c;
            scanf("%d %d %d %c",&u,&v,&t,&c);
            if(c=='L'){
                dl[u][v]=min(dl[u][v],t);
                dl[v][u]=dl[u][v];
            }
            else{
                ds[u][v]=min(ds[u][v],t);
                ds[v][u]=ds[u][v];
            }
        }
        scanf("%d",&r);
        for(i=1;i<=r;i++) scanf("%d",&city[i]);
        for(k=1;k<=n;k++){
            for(i=1;i<=n;i++){
                for(j=1;j<=n;j++){
                    dl[i][j]=min(dl[i][j],dl[i][k]+dl[k][j]);
                    ds[i][j]=min(ds[i][j],ds[i][k]+ds[k][j]);
                }
            }
        }
        for(i=1;i<=r;i++){
            for(j=1;j<=n;j++){
                dp[i][j]=inf;
            }
        }
        for(k=1;k<=n;k++){
            dp[1][k]=ds[city[1]][k]+dl[k][city[1]];
        }
        for(i=2;i<=r;i++){
            for(k=1;k<=n;k++){
                for(j=1;j<=n;j++){
                    if(j!=k){
                        dp[i][k]=min(dp[i][k],dp[i-1][j]+dl[city[i-1]][j]+ds[j][k]+dl[k][city[i]]);
                    }
                    else{
                        dp[i][k]=min(dp[i][k],dp[i-1][k]+dl[city[i-1]][city[i]]);
                    }
                }
            }
        }
        int ans=inf;
        for(i=1;i<=n;i++){
            ans=min(ans,dp[r][i]);
        }
        printf("%d\n",ans);
    }
    return 0;
}





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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    for(int i = 0; i < N; i++){
        cin >> p[i];
    }
    int count = 0;
    for(int i = 0; i < N; i++) if(p[i] != i + 1) count++;
    if(count <= 2) cout << "YES\n";
    else cout << "NO\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*  Writen by : AS7
 *  "JUST KEEP GOING..."
 */
#define endl			'\n'
#define ll				long long
#define all(v)			((v).begin()), ((v).end())
#define allr(v)			((v).rbegin()), ((v).rend())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define For(i,s)        for(auto i:s)
#define Forr(i,s)        for(auto &i:s)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define vi				vector <int>
#define vl				vector <ll>
#define ii				pair <int,int>
#define vii				vector <ii>
#define vll				vector <pair<ll,ll>>
#define PI				double PPPPPP = 3.14159265358979323846;
#define bit(mask,i) ((mask>>i)&1)
const int N = 2e5+5;
map<int,int> pos;
ll sum=0;
void solve(){
   int n,m,k,ans=0;
   cin>>n>>m>>k;
   set<int> ss;
   vi A(n),B(m);
   Forr(i,A)cin>>i;
   int ind=0;
   Forr(i,B){
       ss.insert(sum);
       pos[sum]=ind;
       cin>>i;
       sum+=i;
       ind++;
   }
   ss.insert(sum);
   pos[sum]=m;
   sum=0;
    for (int i = 0; i <n ; ++i) {
          int rem=k-sum;
          if(rem<0)
              break;
          auto it=ss.lower_bound(rem);
          if(*it>rem)--it;
          ans=max(i+pos[*(it)],ans);
          sum+=A[i];
    }
    int rem=k-sum;
    if(rem>=0) {
        auto it = ss.lower_bound(rem);
        if(*it>rem)--it;
        ans = max(n + pos[*(it)], ans);
    }
    cout<<ans<<endl;
}
int main() {
    int t = 1;
  //  cin>>t;
    while (t--)solve();
}

Measured memory_bytes: 23516
#include <stdio.h>

int area(int,int);
int perimeter(int,int);

int main(){
   int a,b;
   int i_area,i_perimeter;
   scanf("%d %d",&a,&b);
   i_area = area(a,b);
   i_perimeter = perimeter(a,b);
   printf("%d %d\n",i_area,i_perimeter);
   return 0;
}

int area(int a,int b){
   int result;
   result = a*b;
   return result;
}

int perimeter(int a,int b){
   int result;
   result = a*2+b*2;
   return result;
}


Measured memory_bytes: 2056
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
  
int main(void){
    int n,a[100] = {0};
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
      
    cout << a[n-1];
    for(int i = n-2; i >= 0; i--){
        cout << " " << a[i];
    }
    cout << endl;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
  int n,l;
  cin >> n >> l;
  int sum = 0;
  int m = 1000;
  rep1(i,n){
    sum += l+i-1;
    if(abs(m)>abs(l+i-1))m=(l+i-1);
  }
  cout << sum-m << endl;
}


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

int main(){
  string a, b;
  cin >> a >> b;
  int x = stoi(a+b);
  for (int i = 1; i <= 1000; i++){
    if (i*i == x){
      cout << "Yes";
      return 0;
    }
  }
  cout << "No";
}


Measured memory_bytes: 3596
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;

int main(){
    int x,n;cin>>x>>n;
    int d=1000;
    int ans=1000;
    vector<int> p(102,0);
    for(int i=0;i<n;i++){
        int idx;cin>>idx;
        p[idx]=1;
    }
    for(int i=101;i>=0;i--){
        if(p[i]) continue;
        if(abs(i-x)<=d){
            ans=i;
            d=abs(i-x);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
n = int(input())
d = {}
for i in range(n):
    a = list(input())
    a.sort()
    a = str(a)
    if a in d:
        d[a] += 1
    else:
        d[a] = 1
ans = 0
for i in d:
    ans += d[i]*(d[i]-1)//2
print(ans)

Measured memory_bytes: 22048