akhauriyash/Code-Regression huggingface dataset:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    s = list(input())
    x, y = ns()

    axis = [[], []]

    cnt = 0
    sw = 0
    for si in s:
        if si == "F":
            cnt += 1
        else:
            axis[sw].append(cnt)
            cnt = 0
            sw ^= 1
    axis[sw].append(cnt)
    if len(axis[0]) > 0:
        x -= axis[0][0]
        del axis[0][0]

    x_cand = {0}
    y_cand = {0}

    for xi in axis[0]:
        if xi == 0:
            continue
        nxt = set()
        for xc in x_cand:
            nxt.add(xc + xi)
            nxt.add(xc - xi)
        x_cand = nxt

    for yi in axis[1]:
        if yi == 0:
            continue
        nxt = set()
        for yc in y_cand:
            nxt.add(yc + yi)
            nxt.add(yc - yi)
        y_cand = nxt

    if x in x_cand and y in y_cand:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 77268
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb(x) (x&-(x))
const int N = 101010;

int main(){

	int n;
	cin>>n;
	int m=n/10;
	if(n%10==9||m==9)
	cout<<"Yes"<<endl;
	else 
	cout<<"No"<<endl;
	


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >>n;
    vector<int> T(n+1);
    vector<int> X(n+1);
    vector<int> Y(n+1);
    T[0]=0, X[0]=0, Y[0]=0;
    REP(i,n)
        cin >> T[i] >> X[i] >> Y[i];
    
    bool is_ok =true;
    for(int i=0; i<=n-1;i++){
        int t = abs(T[i+1]-T[i]);
        int dist = abs(X[i+1]-X[i])+abs(Y[i+1]-Y[i]);
        // cout << t << " " << dist << endl;
        if( t>=dist  && t%2==dist%2) continue;
        else{
            is_ok=false;
            break;
        }
    }
    cout << (is_ok?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
void insertionSort(int,int*);
int main(){
  int i,j,array[100];
  scanf("%d",&i);
  for(j=0;j<i;j++){
    scanf("%d",&array[j]);
    //printf("array[%d],%d\n",j,array[j]);
    if(i<1 && i>100 && array[j]<0 && array[j]>1000)exit(0);
    //printf("j=%d",j);
  }
  insertionSort(i,array);
  return 0;
}
void insertionSort(int p, int* A){
  int j,v,k,i;
  for(k=0;k<p;k++){
    if(k>0) printf(" ");
    printf("%d",A[k]);
  }
  printf("\n");
  for(i=1; i <=p-1;i++){
    v = A[i];
    j = i-1;
    while(j>=0&&A[j]>v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
    for(k=0;k<p;k++){
      if(k>0) printf(" ");
      printf("%d",A[k]);
    }
    printf("\n");
  }
}



Measured memory_bytes: 2760
# -*- coding: utf-8 -*-
from collections import deque
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

N = int(input())
A = inpl()

L = deque()

for i in range(N):
    if i%2:
        L.append(A[i])
    else:
        L.appendleft(A[i])

if (N%2):
    print(*L)
else:
    print(*list(L)[::-1])

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000
#define _GLIBCXX_DEBUG

void chmaxl(ll &a,ll b){
	if(a<b){
		a=b;
	}
	return;
}

void chminl(ll &a,ll b){
	if(a>b){
		a=b;
	}
	return;
}

void chmaxi(int &a,int b){
	if(a<b){
		a=b;
	}
	return;
}

void chmini(int &a,int b){
	if(a>b){
		a = b;
	}
	return;
}



int main() {
  int N,K;
  cin >> N >> K;
  set<int> motsumono;
  for(int i=0;i<K;i++){
    int d;
    cin >> d;
    vector<int> vec(d);
    for(int j=0;j<d;j++){
      cin >> vec.at(j);
      motsumono.insert(vec.at(j));
    }
  }
  cout << (N-motsumono.size());
}

Measured memory_bytes: 3636
def main():
    n = int(input())
    ans = [0 for i in range(n)]
    m = 0
    for x in range(1,100):
        for y in range(1,100):
            for z in range(1,100):
                t = x**2+y**2+z**2+x*y+y*z+z*x
                if t>m:
                    m = t
                if t<n+1:
                    ans[t-1]+=1
    for i in range(n):
        print(ans[i])

if __name__ == "__main__":
    main()


Measured memory_bytes: 9248
import sys
def LI():
    return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,x = LI()
a = LI()

ans = 0

# 左から2番目以降貪欲に

if a[0] > x:
    ans += a[0]-x
    a[0] = x

for i in range(1,N):
    if a[i]+a[i-1] > x:
        ans += a[i]+a[i-1]-x
        a[i] -= a[i]+a[i-1]-x

print(ans)

Measured memory_bytes: 85544
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

int main() {
	char S[20];
	string T;
	string p;
	string Q;
	double m;
	int a = 0;
	int A = 0;
	int b = 0;
	int B = 0;
	int c = 0;
	int C = 0;
	int q, w, z;
	int n = 0;
	int x = 0;
	int y = 0;
	int ans = 0;
	cin >> x >> a >> b;
	x -= a;
	while (x >= 0) {
		x -= b;
	}
	cout << x + b;
}

Measured memory_bytes: 256
from collections import deque


N = int(input())
B = []
L = []
for i in range(N-1):
    ta,tb = map(int,input().split())
    B.append(ta)
    B.append(tb)
    L.append([ta,tb])
B =B[1::2]
E = [[] for _ in range(N + 1)]
for a, b in L:
    E[a].append(b)

Q = deque([1])
C = [0] * (N + 1)
while Q:
    v = Q.popleft()
    c = 0
    for u in E[v]:
        c += 1 + (c + 1 == C[v])
        C[u] = c
        Q.append(u)

print(max(C))
print("\n".join(str(C[b]) for b in B))


Measured memory_bytes: 37600
#include <stdio.h>
#include <string.h>
#define min(a, b) ((a) < (b)) ? (a) : (b)
#define max(a, b) ((a) > (b)) ? (a) : (b)

int main(int argc, const char *argv[])
{
  char s[100];
  scanf("%s", s);
  int m = 0, count = 0;
  for (int i = 0; i <= strlen(s); i++) {
    if (
        s[i] == 'A' ||
        s[i] == 'T' ||
        s[i] == 'C' ||
        s[i] == 'G'
        ) {
      count++;
    } else {
      m = max(m, count);
      count = 0;
    }
  }
  printf("%d\n", m);
  return 0;
}

Measured memory_bytes: 128
n,a = map(int,input().split())
x = list(map(int,input().split()))
for i in range(n):
    x[i] -= a
dp = [[0 for i in range(2*n*50+1)] for j in range(n+1)]
dp [0][n*50] = 1

for i in range(1,n+1):
    for j in range(2*n*50+1):
        if 0 <= j - x[i-1] < 2*n*50:
            dp[i][j] = dp[i-1][j] + dp[i-1][j-x[i-1]]
        else:
            dp[i][j] = dp[i-1][j]
    #print(dp[i])
print(dp[n][n*50] - 1) #全て選ばないを除く

# 4 8
# 7 9 8 9 のとき
# i = 1 で -1 0 が 1
# i = 2 で -1 1 が 1, 0 が2
# i = 3 で -1 1 が 2, 0 が4
# i = 4 で -1 2 が 2, 0 1 が 6

Measured memory_bytes: 42844
import math

while (True):
    n = int(input())
    if n == 0:
        break
    s = list(map(int, input().split(' ')))
    m = sum(s) / n
    ans = 0
    for i in range(n):
        ans += (s[i] - m) * (s[i] - m) / n
    print(math.sqrt(ans))



Measured memory_bytes: 5696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    ll n;cin>>n;
    string s;cin>>s;
    int q;cin>>q;
    while(q--){
        ll k;cin>>k;
        ll ans=0,dm=0,d=0,m=0;
        for(int i=0;i<n;i++){
            if(s[i]=='C')ans+=dm;
            else if(s[i]=='D')d++;
            else if(s[i]=='M'){
                dm+=d;
                m++;
            }
            if(i>=k-1){
                int p=i-k+1;
                if(s[p]=='D'){
                    dm-=m;
                    d--;
                }
                else if(s[p]=='M'){
                    m--;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1412
# author:  Taichicchi
# created: 20.09.2020 11:13:28

import sys

from math import factorial

from scipy.special import comb

MOD = 10 ** 9 + 7

S = int(input())

m = S // 3

cnt = 0

for n in range(1, m + 1):
    cnt += int(comb(S - 3 * n + 1, n - 1, exact=True, repetition=True)) % MOD

cnt %= MOD

print(cnt)


Measured memory_bytes: 42348
#include "bits/stdc++.h"
using namespace std;
using lli = long long int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
  int n, x = 0, res = 0;
  char c;

  cin >> n;

  rep(i, n) {
    cin >> c;
    if(c=='I') x++;
    if(c=='D') x--;

    res = max(res, x);
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = input()

Re = [False for _ in range(N)]
#Re[i]:i回目で勝った

def plus(t):
    if t == "r":
        return P
    elif t == "s":
        return R
    else:
        return S

ans = 0
for i in range(K):
    ans += plus(T[i])
    Re[i] = True

for i in range(K,N):
    if T[i] != T[i-K] or not Re[i-K]:
        ans += plus(T[i])
        Re[i] = True

print(ans)


Measured memory_bytes: 4212
#include<stdio.h>
#include<math.h>
struct Point{
  double x;
  double y;
};

void koch(int n, struct Point a,struct Point b){
  if(n==0) return;
  struct Point s,t,u;
  double th = M_PI * 60.0 / 180.0;

  s.x=(2.0 * a.x + 1.0 * b.x)/3.0;
  s.y=(2.0 * a.y + 1.0 * b.y)/3.0;
  t.x=(1.0 * a.x + 2.0 * b.x)/3.0;
  t.y=(1.0 * a.y + 2.0 * b.y)/3.0;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

  koch(n-1,a,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,b);
}

int main(){
  struct Point a,b;
  int n;

  scanf("%d",&n);

  a.x=0;
  a.y=0;
  b.x=100;
  b.y =0;

  printf("%.8f %.8f\n",a.x,a.y);
  koch(n,a,b);
  printf("%.8f %.8f\n",b.x,b.y);
  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
ll _power(ll a, int b)//计算a^b;
{
    ll ans=1, res=a;
    while(b){
        if(b&1) ans=ans*res%mod;
        res=res*res%mod;
        b>>=1;
    }
    return ans%mod;
}
ll n,a,b;
ll C(ll xx,ll yy){
    ll up=1,down=1;
    for(int i=n;i>=xx-yy+1;i--)up=up*i%mod;
    for(int i=1;i<=yy;i++)down=down*i%mod;
    return up*_power(down,mod-2)%mod;
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>a>>b;
    cout<<(_power(2,n)-1+mod-C(n,a)-C(n,b)+mod)%mod<<endl;
    return 0;
}

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

long long int arr[200005];

int main() {
	long long int k,n;
	
	cin>>k>>n;
	
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	
	long long int mx = 0;
	
	for(int i=1;i<n;i++){
		mx = max(mx, arr[i]-arr[i-1]);
	}
	
	mx = max(mx,k+arr[0]-arr[n-1]);
	
	cout<<k-mx<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

        ll n;
        cin>>n;
        ll a[n],i,sum1=0,sum2=0;
        float sum=0,ans=0;
        for(i=0;i<n;i++)
        {
            cin>>a[i];
            sum+=a[i];
        }
                ans=floor(sum/n);
        sum=ceil(sum/n);

       // cout<<sum<<endl<<ans<<endl;
        for(i=0;i<n;i++)
        {
            sum1+=((a[i]-sum)*(a[i]-sum));
            sum2+=((a[i]-ans)*(a[i]-ans));
        }
        cout<<min(sum1,sum2)<<endl;


}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 998244353;

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) cin >> a[i];
    vector<Int> b = a;
    sort(b.begin(), b.end());
    Int ma = b.back();
    Int ma2 = b[n - 2];
    for (Int i = 0; i < n; i++) {
        if (a[i] == ma) {
            dump(ma2);
        }
        else {
            dump(ma);
        }
    }
    return 0;
}

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    map<ll, ll> cnt;
    rep(i, 3) {
        ll x; cin >> x;
        cnt[x]++;
    }
    each(p, cnt) {
        if (p.second == 1) {
            cout << p.first << endl;
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
#include<bitset>
typedef long long ll;
using namespace std;

int main(){
  ll N,K;
  cin>>N>>K;
  cout<<(N-2)/(K-1)+1<<endl;

}

Measured memory_bytes: 384
<?php
  $n = trim(fgets(STDIN));
  $s = str_split(trim(fgets(STDIN)));
  $ans = 0;
  $index = 0;
  for ($i = 0; $i < $n; $i++) {
    if ($i == 0) {
      $ans++;
      continue;
    } else if ($s[$i] == $s[$i - 1]) {
      continue;
    }
    $ans++;
  }
  echo $ans . PHP_EOL;

Measured memory_bytes: 10744
L,R=map(int,input().split())
mod=2019

if R>=L+2020:
    print(0)
else:
    D=list(range(L,R+1))

    L=len(D)

    ANS=1<<40

    for i in range(L-1):
        for j in range(i+1,L):
            ANS=min(ANS,D[i]*D[j]%mod)

    print(ANS)
            

Measured memory_bytes: 42476
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
long long n,m,i,j,a[105],s;
int main()
{
	cin>>n>>m;
	rep(i,n)cin>>a[i];
	sort(a+1,a+n+1);
	rep(i,n){
		m-=a[i];
		if(m>=0)s++;
	}
	if(m!=0)s=min(s,n-1);
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ans = []
l = [a[0]*2]
for i in range(1,n):
    l.append( a[i]*2 - l[-1] )

x = a[-1] - ( l[-2]//2 )
ans.append(x)
for i in range(1,n):
    if i % 2 == 0:
        ans.append(l[i-1]+x)
    else:
        ans.append(l[i-1]-x)
print(*ans)

Measured memory_bytes: 17724
# coding: utf-8
H,W = map(int, input().split())

ODD = list()
RESULT = list()
BEFORE = [0, 0]

for i  in range(H):
    a_list = list(map(int, input().split()))
    w_range = range(W)
    
    if i%2 == 1:
        w_range = w_range[::-1]
    for j in w_range:
        if a_list[j] % 2 == 1:
            if ODD:
                ODD.pop()
                RESULT.append(BEFORE+[i+1,j+1])
            else:
                ODD.append([i+1, j+1])
        else:
            if ODD:
                RESULT.append(BEFORE+[i+1, j+1])
        BEFORE = [i+1, j+1]
print(len(RESULT))
for result in RESULT:
    print(" ".join([str(s) for s in result]))

Measured memory_bytes: 27604
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n , k ;
    cin >> n >> k;
vector< int  > p(n) ; 
    for( int i = 0; i< n; i++ ){
        cin>>p[i];
}
sort(p.begin(),p.end());
int ans = 0;
for(int i = 0 ; i < k ; i ++){
    ans+=p[i];
}
cout<<ans;
 
}







Measured memory_bytes: 3584
#include <stdio.h>
#include <string.h>

int main(void) {
    char s[100];
    char t[100];

    scanf("%s", s);
    scanf("%s", t);

    
    if(strncmp(s, t, strlen(s)) == 0) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
  
    return 0;
}

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

using namespace std;
typedef long long ll;
ll mod = 1e9+7;

int main(void)
{
  ll N;cin>>N;
  vector<string> Title(N);
  vector<ll> Len(N);
  for(ll i=0;i<N;i++){
    cin>>Title[i]>>Len[i];
  }
  string stopTitle;cin>>stopTitle;
  bool sleep = false;
  ll res=0;
  for(ll i=0;i<N;i++){
    if(sleep){
      res += Len[i];
    }
    if(Title[i]==stopTitle){
      sleep = true;
    }
  }
  cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  int n = in();
  int m = in();
  vector<P> v(n);
  REP(i,n) {
    int price = in();
    int n_of_drink = in();
    v[i] = P(price, n_of_drink);
  }
  SORT(v);
  int ans = 0;
  REP(i,n) {
    int price = v[i].first;
    int n_of_drink = v[i].second;
    if(m > n_of_drink) {
      m -= n_of_drink;
      ans += price * n_of_drink;
    } else {
      ans += price * m;
      break;
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 1024
N, M, Q = gets.split.map(&:to_i)

matrix = Array.new(N + 1) { Array.new(N + 1, 0)}

M.times do
  l, r = gets.split.map(&:to_i)
  matrix[l][r] += 1
end

1.upto(N) do |i|
  1.upto(N) do |j|
    matrix[i][j] += matrix[i][j - 1]
  end
end

1.upto(N) do |i|
  1.upto(N) do |j|
    matrix[i][j] += matrix[i - 1][j]
  end

end

Q.times do
  p, q = gets.split.map(&:to_i)
  puts matrix[q][q] + matrix[p - 1][p - 1] - matrix[p - 1][q] - matrix[q][p - 1]
end


Measured memory_bytes: 4732
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof x)
#define copy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

inline int read()
{
	int sc = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

const int MAXN = 100005;
const int mod = 1e9 + 7;

int n, m, ans = 1, a[MAXN], b[MAXN];

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = read();
	for (int i = 1; i <= n; i ++) a[i] = read();
	b[m = 1] = 1;
	for (int i = 2; i <= n; i ++)
		if (a[i] ^ b[m] + 1)
			b[m + 1] = b[m] + 2, m ++;
		else ans = 1LL * ans * (m + 1) % mod;
	for (int i = 1; i <= m; i ++) ans = 1LL * ans * i % mod;
	return printf("%d\n", ans), 0;
}


Measured memory_bytes: 1024
#include <boost/multiprecision/cpp_int.hpp>
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int N;
vector<long long int >A;
 
int main()
{
	cin >> N;
	boost::multiprecision::cpp_int  ans = 1;
	rep(i, N)
	{
		long long int a;
		cin >> a;
		A.push_back(a);
	}
	auto result = std::find(A.begin(), A.end(), 0);
	if (result != A.end()) cout << 0<<endl;
	else
	{
		rep(i, N)
		{
			ans *= A[i];
			if (ans > 1000000000000000000)
			{
				cout << -1 << endl;
				break;
			}
		}
		if (ans <= 1000000000000000000)  cout << ans << endl;
	}
	return 0;
}


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

using ll = long long;

int main () {

    int h, w;

    cin >> h >> w;

    vector<vector<int>> dp(h, vector<int>(w, 99999));
    vector<vector<char>> tile(h, vector<char>(w));

    for(int i = 0; i < h; ++i)
        for(int j = 0; j < w; ++j)
            cin >> tile[i][j];


    if(tile[0][0] == '.')
        dp[0][0] = 0;
    else
        dp[0][0] = 1;

    int di[] = {1, 0};
    int dj[] = {0, 1};

    for(int i = 0; i < h; ++i) {
        for(int j = 0; j < w; ++j) {
            for(int k = 0; k < 2; ++k) {

                int ni = i + di[k], nj = j + dj[k];

                if(ni >= h || nj >= w)
                    continue;

                int add = 0;
                if(tile[i][j] == '.' && tile[ni][nj] == '#')
                    add = 1;

                dp[ni][nj] = min(dp[ni][nj], dp[i][j] + add);

            }
        }
    }

    cout << dp[h - 1][w - 1] << endl;

    return 0;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define MOD 1000000007
#define pb push_back
using namespace std;
const int nmax=112;

long long k,a,b,flg,tmp,res;

int main()
{
    cin>>k>>a>>b;
    if(b-a<=2 || k<a+1)
        res=k+1;
    else{
        k-=a+1;
        res+=b;
        tmp=k/2;
        res+=tmp*(b-a);
        if(k%2==1){
            ++res;
        }
    }
    cout<<res;

    return 0;
}

Measured memory_bytes: 256
import itertools
N=int(input())
d=list(map(int,input().split()))
total=0
nlis=[i for i in range(1,N+1)]
com=list(itertools.combinations(nlis,2))


for j in range(len(com)):
  total+=d[com[j][0]-1]*d[com[j][1]-1]
print(total)

Measured memory_bytes: 3064
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    S = INPUT()

    cnt = 1
    for i in range(N-1):
        if S[i+1] != S[i]: cnt += 1

    print(cnt)

if __name__ == '__main__':
    main()

Measured memory_bytes: 39280
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(c, b/a) << endl;
    return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;
using ll=long long;

#define rep(i, a, n) for (int i = (a); i < (n); ++i)

void Main(){
  int n,k;
  cin>>n>>k;
  ll ans=k;
  rep(i,1,n) ans*=(k-1);
  cout<<ans<<endl;
}

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  Main();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){
    int n,i;
    cin >> n >> i;
    if(n%i==0) cout << 0 << endl;
    else cout << 1 << endl;
}

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


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut cnt = 0;
    for i in 1..n {
        cnt += (n - 1) / i;
    }
    println!("{}", cnt);
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long int;
 
int main () {
  ll X, K, D;
  cin >> X >> K >> D;
 
  ll ans = 0;
  if (X < 0) {
    X = abs(X);
  }
  if (K >= X / D) {
    K -= X / D;
    X -= (X / D) * D;
    if (K % 2 == 0) {
      ans = X;
    } else {
      ans = abs(X - D);
    }
  } else {
    ans = X - K * D;
  }
  cout << ans;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

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
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const [n, s] = stdin.split('\n')

const getCount = (ar1, ar2) => {
  const s1 = ar1.filter(e=>ar2.indexOf(e) > -1)
  const s2 = ar2.filter(e=>ar1.indexOf(e) > -1)

  const uniq = new Set([...s1], [...s2])

  return uniq.size
}

const ans = _ => {
  const strArr = s.split('')

  let count = 0
  for (let i = 1; i < n; i++) {
    const firstHalf = strArr.slice(0, i)
    const lastHalf = strArr.slice(i)

    let tmpCount = getCount(firstHalf, lastHalf)

    count = Math.max(tmpCount, count)
  }

  console.log(count)
}

ans()


Measured memory_bytes: 11596
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          998244353
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -1e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

 typedef tree<pii, null_type, less<pii>, rb_tree_tag,  
            tree_order_statistics_node_update>  odst; 


void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   
    #endif
}

int rs(int a,int b)
{
  int an = 1;
  while(b>0)
  {
    if(b%2!=0) an = an*a;
    b/=2;
    a=a*a;
  }
  return an;
}


void solve()
{
 
 int a,b,x;
 a= big,b=big;
 cin >> x ;

 for(int i=-1000;i<=1000;i++)
 {
  for(int j=-1000;j<=1000;j++)
  {
    if(rs(i,5)-rs(j,5)==x)
    {
      a = i;
      b = j;
      break;
    }
  }
  if(a!=big) break;
 }
 cout<<a<<" "<<b<<endl;
}

int32_t main()
{
 pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl; 

 }

Measured memory_bytes: 3568
/*
sample in out

1 2 0 1
0 3 0 1
4 1 1 0

1 2 3 0

1*1 + 2*2 + 0*3 + 1*0 = 5
0*1 + 3*2 + 0*3 + 1*0 = 6
4*1 + 1*2 + 1*3 + 0*0 = 9

*/
#include<stdio.h>
int main()
{
    int a, b, c;
    int i, j, k, l, m;
    int x[100][100], y[100];
    scanf("%d%d", &a, &b);
    for(i=0;i<a;i++){
        for(j=0;j<b;j++){
            scanf("%d", &x[i][j]);
        }
    }
    for(k=0;k<b;k++){
        scanf("%d", &y[k]);
    }
    for(l=0;l<a;l++){
        c = 0;
        for(m=0;m<b;m++){
            c += x[l][m] * y[m];
        }
        printf("%d\n", c);
    }
    return 0;
}

Measured memory_bytes: 640
N = int(input())

lst = [[0, 0, 0, 0] for _ in range(N)]
p = [0] * N
m = [0] * N

for i in range(N):
  x, y = map(int, input().split())
  lst[i][0] = x
  lst[i][1] = y
  p[i] = x+y
  m[i] = x-y
  
d = max( max(p) - min(p), max(m) - min(m) )
print(d)

Measured memory_bytes: 58260
from collections import deque
h,w=map(int,input().split())
s=deque([deque(input()) for _ in range(h)])
s.appendleft(deque([0]*w))
s.append(deque([0]*w))
s=list(s)
for i in range(h+2):
  s[i].appendleft(0)
  s[i].append(0)
  s[i]=[0 if j==0 or j=='.' else '#' for j in tuple(s[i])]
for i in range(1,h+1):
  for j in range(1,w+1):
    if s[i][j]=='#':
      for a in range(3):
        for b in range(3):
          x=s[i-1+a][j-1+b]
          x=x+1 if type(x)==int else '#'
          s[i-1+a][j-1+b]=x
for i in range(1,h+1):
  print(''.join([str(j) for j in s[i]][1:-1]))

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

typedef unsigned long long  ULL;
typedef long long LL;

#define PB push_back
#define MP make_pair
#define RESET(a, b) memset(a, b, sizeof(a))
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define F first 
#define S second

 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int x;
    cin>>x;
    
    int c500=0, c5=0;
    while(x>=500){
        x-=500;
        c500++;
    }
    while(x>=5){
        x-=5;
        c5++;
    }
    cout<<c500*1000+c5*5;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef complex<int> P;
int f,p;
string s;
bool x(P p){
  if(abs(p.real())>10000||abs(p.imag())>10000)return 1;
  return 0;
}
P bns1();
P g_A(){
  P r;
  if(s[p]=='('){
    p++;
    r=bns1();
    p++;
  }
  else if(s[p]=='i'){
    p++;
    r=P(0,1);
  }
  else{
    while(isdigit(s[p])){
      r=r*10+(s[p]-'0');
      p++;
      if(x(r))f++;
    }
  }
  return r;
}
P bns2(){
  P res=g_A();
  while(s[p]=='*'){
    int t=p++;
    if(s[t]=='*')res*=g_A();
    if(x(res))f++;
  }
  return res;
}
P bns1(){
  P res=bns2();
  while(s[p]=='+'||s[p]=='-'){
    int t=p++;
    if(s[t]=='+')res+=bns2();
    if(s[t]=='-')res-=bns2();
    if(x(res))f++;
  }
  return res;
}
int main(){
  while(cin>>s){
    p=f=0;
    P ans=bns1();
    int a=ans.real(),b=ans.imag();
    if(f)cout<<"overflow"<<endl;
    else{
      if(!a&&!b)cout<<0<<endl;
      if(!a&&b)cout<<b<<'i'<<endl;
      if(a&&!b)cout<<a<<endl;
      if(a&&b){
        cout<<a;
        if(b>0)cout<<'+';
        cout<<b<<'i'<<endl;
      }
    }
  }
}

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

int main() {
  int n;
  while (cin >> n) {
    int a, b, c, d, cnt = 0;
    for (a = 0; a < 10; a++)
      for (b = 0; b < 10; b++)
	for (c = 0; c < 10; c++)
	  for (d = 0; d < 10; d++)
	    if (a + b + c + d == n)
	      cnt++;
    cout << cnt << endl;
  }
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    vector<int> l(n, 0), r(n, 0);
    int cnt = 0;
    rep(i,n){
        if(s[i] == 'o'){
            l[i] = ++cnt;
            i += c;
        }
        if(cnt == k) break;
    }
    for(int i = n-1; i >= 0; --i){
        if(s[i] == 'o'){
            r[i] = cnt--;
            i -= c;
        }
    }
    rep(i,n){
        if(l[i] == r[i] && l[i] != 0) cout << i+1 << endl;
    }
	return 0;
}

Measured memory_bytes: 5200
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
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;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int a,b;
    cin >> a >> b;
    if(a == b) {
        cout << 2*a;
    }else {
        cout << max(a,b)+max(a-1,b-1);
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define VEC_TYPE			int
#define INF					1e5+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmaxE(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; }
template<class T> inline bool chminE(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
template<typename T> inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T> inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }

int main()
{
	int ans = 0;
	int n;
	cin >> n;
	vdef a(n, 0);
	for (int i = 0; i < n; ++i) cin >> a[i];

	int cnt = 0;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] != i + 1) ++cnt;
	}
	if (cnt <= 2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	//cout << ans << endl;
	return 0;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    if (A == B){
        cout << "Draw" << endl;
    }else if(A == 1){
        cout << "Alice" << endl;
    }else if(B == 1){
        cout << "Bob" << endl;
    }else if(A > B){
        cout << "Alice" << endl;
    }else{
        cout << "Bob" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int A,B;
  cin >> A >> B;
  long long int ANS = A*B;
  // 最大公約数
  int gcd = 1;
  int n = min(A,B);

  for(int i=2;i<n+1;i++){
    if(A%i==0 && B%i==0)gcd = i;
  }

  // 最小公倍数 = A*B / 最大公約数
  cout << ANS/gcd << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int N,i,sum = 0; cin >> N;
    vector<int> p(11,10001);
    for(i = 0;i < N;i++){
        cin >> p.at(i);
        sum += p.at(i);
    }
    sort(p.begin(),p.end());
    cout << sum - p.at(N-1)/2 << endl;
}

Measured memory_bytes: 256
S = input()
ans = ""
now = 0
for i in range(0,len(S)//2):
  ans += S[2*i]
  ans += S[2*i+1]
  if ans[0:i+1] == ans[i+1:len(ans)]:
    if 2*(i+1) == len(S):
      continue
    else:
      now = 2*(i+1)
print(now)

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

int main(){
    long long n;
    cin >> n;
    long long a[n];
    long long ans=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        ans+=a[i]-1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//bismillahir rahmanir rahim            //Author:Fayed Anik

#include <bits/stdc++.h> 

using namespace std;


#define         ll                         long  long
#define         lf                         double 
#define         pb(x)                      push_back(x)
#define         ull                        unsigned long long
#define         sfl(a)                     scanf("%lld",&a)
#define         sf(a)                      scanf("%d",&a)
#define         pf(a)                      printf("%d\n",a)
#define         pfl(a)                     printf("%lld\n",a)
#define         pdl(a)                     printf("%llf\n",a)
#define         FOR(x,n)                   for(ll x=1;x<=n;++x)
#define         vii                        vector< ll > v
#define         pi                         3.14159265359
#define         mex                        10000000
#define         pii                        pair< ll , ll >
#define         mem(m,a)                   memset( m, a,sizeof m)
#define         mp(a,b)                    make_pair(a,b)
#define         maxn                       100000
#define         mod                        1000000007
#define         INF                        1e17
#define         f1                         first
#define         f2                         second
#define         all(v)                     v.begin(),v.end()
#define         PI                         acos(-1)
#define         printminusone              printf("-1\n")
#define         bug                        printf("bug")

ll a[200005],b[200005];
vector <ll> ans;
int main(){
	ll n;
	sfl(n);
	for(ll i=1;i<=n;i++){
		sfl(a[i]);
		b[i]=a[i];
	}
	ll cnt=0;
	for(ll i=n/2;i>=1;i--){
		cnt=0;
		for(ll j=i+i;j<=n;j+=i){
			cnt += b[j];
		}

		ll m=cnt%2;
		if(m != a[i]){
			b[i]=1;
		}
		else{
			b[i]=0;
		}
	}

	for(ll i=1;i<=n;i++){
		if(b[i]==1) ans.pb(i);
	}

	cout << ans.size() << endl;

	for(ll i=0;i<ans.size();i++)
	{
		cout << ans[i] << " ";
	}

	return 0;
}



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

int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int ary[3];
    ary[0]=a;
    ary[1]=b;
    ary[2]=c;
    //for(int i=0;i<3;i++)scanf("%d",&ary[i]);
    sort(ary,ary+3);
    //for(int i=0;i<3;i++)printf("%d ",ary[i]);
    if(ary[0]==ary[1])printf("%d\n",ary[2]);
    else printf("%d\n",ary[0]);
}


Measured memory_bytes: 256
def gcd(lhs, rhs)
  return lhs if rhs == 0
  return gcd(rhs, lhs) if lhs < rhs

  mod = lhs % rhs
  div = (lhs - mod) / rhs

  return gcd(rhs, mod)
end

s_length, t_length = gets.split.map(&:to_i)
s = gets.chomp
t = gets.chomp

gcd_res = gcd(s_length, t_length)
x_length = s_length * t_length / gcd_res

ok = true
gcd_res.times do |i|
  if s[i * s_length / gcd_res] != t[i * t_length / gcd_res]
    ok = false
    break
  end
end

if ok
  puts x_length
else
  puts -1
end


Measured memory_bytes: 2044
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <sstream>
#include <deque>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <utility>   // std::pair, std::make_pair
#include <stdlib.h>  //atoi
using namespace std;
typedef long long ll;
const  double PI = 3.141592654;
#define rep(i,x) for(int(i)=0;(i)<(ll)(x);(i)++)
#define all(s)      (s).begin(),(s).end()
#define allv(v)      (v).begin(),(v).end()
#define pb          push_back
#define sz          s.size()
#define vz          v.size()
//x = atoi(a.c_str())
void fast()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL), cout.tie(NULL);
}
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
int main()
{
	fast();
	int x, y;
	cin >> x >> y;
	map<int, int>mp;
	rep(i, x)
	{
		int a;
		cin >> a;
		mp[a]++;
	}
	int h = mp.size();
	if (h <= y)
	{
		cout << 0 << endl;
		return 0;
	}
	multiset<int>st;
	for (auto e : mp)
	{
		st.insert(e.second);
	}
	x = abs(y - h);
	int sum = 0;
	for (auto e : st)
	{
		sum += e;
		x--;
		if (x == 0)
			break;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 19072
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define SZ(x) ((int)(x).size())
#define rep(i,n) for(int i=0;i<(n);++i)
#define fore(i,a) for(auto &i:a)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define answer cout << ans << endl;
signed _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
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; }
template<class T> using v = vector<T>;
template<class T> using vv = vector<v<T>>;
const int MOD=1e9+7;
const long long INF = 1LL << 60;

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



Measured memory_bytes: 3232
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

char** table;

void func(int height){

	for(int i = 0; i < height; i++){
		for(int k = 0; k <= 1049; k++)table[i][k] = '#';
	}

	int most_right = 0;

	for(int i = 0; i < height; i++){
		scanf("%s",table[i]);

		for(int k = 0;table[i][k] != '\0';k++){
			if(table[i][k] == '.' && table[i][k+1] != '\0' && table[i][k+1] != '.'){
				table[i][k] = '+';
				most_right = max(most_right,k);
				for(int p = 0; p < k; p++)table[i][p] = ' ';
				break;
			}
		}
	}


	int top,bottom;

	for(int col = 0; col <= most_right; col++){
		top = 0;
		while(true){
			for(;top <= height-1 && table[top][col] != '+';top++);
			if(top == height)break;

			for(bottom = top+1;bottom <=height-1 && table[bottom][col] == ' ';bottom++);
			if(bottom == height)break;

			if(table[bottom][col] == '+'){
				for(int i = top+1; i <= bottom-1; i++)table[i][col] = '|';
			}
			top = bottom;
		}
	}

	for(int i = 0; i < height; i++)printf("%s\n",table[i]);
}

int main(){

	table = new char*[1000];
	for(int i = 0; i < 1000; i++){
		table[i] = new char[1051];
	}

	int height;
	while(true){
		scanf("%d",&height);
		if(height == 0)break;

		func(height);
	}
	return 0;
}

Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int h[n];
    for(int i = 0;i<n;i++){
        cin >> h[i]; 
    }
    long dp[n+5];
    dp[1] = 0;
    for(int i = 2;i<=min(k+1,n);i++){
        dp[i]=abs(h[i-1]-h[0]);
    }
    long tem;
    for(int i = k+2;i<=n;i++){
        tem = dp[i-1]+abs(h[i-1]-h[i-2]);
        for(int j = 2;j<=k;j++){
            tem = min(tem,dp[i-j]+abs(h[i-1]-h[i-j-1]));
        }
        dp[i]=tem;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 1408
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout<<fixed<<setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll n = in();
	ll sum = 0;
	vector<ll>p(n);
	REP(i, n) {
		ll foo = in();
		sum += foo;
		p[i] = foo;
	}
	sort(ALL(p));
	sum -= p.back() / 2;
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>

int main()
{
    int n;
    scanf("%d¥n", &n);

    int cnt = 0;
    for(int i = 1; i<= n; ++i)
    {
        for(int j = 2; j <= 10; ++j)
        {
            int m = 1;
            for(int k = 0; k < j; ++k)
            {
                m *= i;
            }
            if(m <= n && cnt < m)
            {
                cnt = m;
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
N,K = map(int,input().split())
sunuke = [0]*(N+1)
for i in range(K):
  d = int(input())
  A = list(map(int,input().split()))
  for j in range(d):
    sunuke[A[j]] = 1
cnt = 0
for i in range(1,N+1):
  if sunuke[i] == 0:
    cnt += 1
  
print(cnt)

Measured memory_bytes: 9204
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    string s;
    string ans = "Three";
    for(int i=0; i<N; i++){
        cin >> s;
        if(s == "Y") ans = "Four";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256