akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

ll dp[105][100005];


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t,n,W;
    
    memset(dp,0,sizeof(dp));

    cin>>n>>W;
    
    ll *v = new ll[n+1]{0};
    ll *w = new ll[n+1]{0};
    
    for(ll i=1;i<=n;++i)
    {
        cin>>w[i]>>v[i];
    }

    for(int i=w[1];i<=W;++i)
    {
        dp[1][i] = v[1];
    }

    for(ll i=2;i<=n;++i)
    {
        for(ll x = 1;x<=W;++x)
        {
            dp[i][x] = dp[i-1][x];
            if(w[i] > x)
                continue;
            dp[i][x] = max(dp[i][x],dp[i-1][x-w[i]] + v[i]);
        }
    }
    cout<<dp[n][W]<<endl;
    return 0;
}

Measured memory_bytes: 82304
#include <cstdio>
#include <string.h>
#include <algorithm>
using namespace std;

#define N 810000

int n, m;
int l[N], r[N], tx[N], mi[N], add[N];
int ans;

bool cmp(int x, int y) {
	return l[x] < l[y];
}

void mkt(int k, int q, int h) {
	if (q < h) {
		mkt(k * 2, q, (q + h) / 2);
		mkt(k * 2 + 1, (q + h) / 2 + 1, h);
		mi[k] = min(mi[k * 2], mi[k * 2 + 1]);
	}else {
		mi[k] = m + 1 - q;
	}
}

void modify(int k, int q, int h, int l, int r, int c) {
	if (l <= q && h <= r)
		add[k] += c;
	else {
		if (r <= (q + h) / 2)
			modify(k * 2, q, (q + h) / 2, l, r, c);
		else if ((q + h) / 2 < l)
			modify(k * 2 + 1, (q + h) / 2 + 1, h, l, r, c);
		else
			modify(k * 2, q, (q + h) / 2, l, r, c), modify(k * 2 + 1, (q + h) / 2 + 1, h, l, r, c);
		mi[k] = min(mi[k * 2] + add[k * 2], mi[k * 2 + 1] + add[k * 2 + 1]);
	}
}

int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &l[i], &r[i]);
	ans = max(0, n - m);
	ans = - ans;
	for (int i = 1; i <= n; i++)
		tx[i] = i;
	sort(tx + 1, tx + n + 1, cmp);
	mkt(1, 1, m + 1);
	for (int i = 1; i <= n; i++) {
		modify(1, 1, m + 1, 1, r[tx[i]], -1);
		ans = min(ans, l[tx[i]] + mi[1] + add[1]);
		// printf("?? %d %d\n", i, ans);
	}
	printf("%d\n", -ans);
}


Measured memory_bytes: 14464
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<long long> map(4);
  
  for (int i = 0; i < 4; i++)
    cin >> map.at(i);
  
  long long ans = -1000000000000000000000000000000;
  
  //for (int i = 0;i < 4; i++)
  //cout<<map.at(i);
  
  for (int i = 0; i < 2; i++) {
    long long count = 0;
    for (int j = 2; j < 4; j++) {
      ans = max(ans,map.at(i)* map.at(j));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;
typedef array<int,3> B;

int A[300][300];
LL ds[300][300];
vector<B> vs;
int main() {
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			scanf("%d",A[i]+j);
			ds[i][j]=1e9+1;
			if(i<j){
				vs.push_back(B{{A[i][j],i,j}});
			}
		}
		ds[i][i]=0;
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			for(int k=0;k<N;k++){
				if(A[i][j]>A[i][k]+A[k][j]){
					puts("-1");
					return 0;
				}
			}
		}
	}
	sort(vs.begin(),vs.end());
	LL ret=0;
	for(auto v:vs){
		int i=v[1];
		int j=v[2];
		int d=v[0];
		if(ds[i][j]>d){
			//cerr << i << ", " << j << ": " << ds[i][j] << ", " << d << endl;
			ret+=d;
			for(int p=0;p<N;p++){
				for(int q=p+1;q<N;q++){
					ds[p][q]=ds[q][p]=min({ds[p][q],ds[p][i]+d+ds[j][q],ds[p][j]+d+ds[i][q]});
				}
			}
		}
	}
	printf("%lld\n",ret);

	return 0;
}



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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    int maxH = 0;
    for(int i = 0; i < N; i++) {
        cin >> H[i];
        if(maxH < H[i]) {
            maxH = H[i];
        }
    }
    int water = 0;
    bool water_flag;
    for(int nowH = maxH; 0 < nowH; nowH--) {
        water_flag = false;
        for(int i = 0; i < N; i++) {
            if(H[i] == nowH){
                H[i]--;
                if(water_flag == false){
                    water_flag = true;
                    water++;
                }
            }else{
                water_flag = false;
            }
        }
    }

    cout << water << endl;

    return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

template <typename T>
using vec = vector<T>;

template <typename T>
using vec2 = vector<vector<T>>;

template <typename T>
using vec3 = vector<vector<vector<T>>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    Int n;
    cin >> n;
    vector<Int> a(n), b(n), c(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    vec2<Int> abc{a, b, c};

    vec2<Int> dp(n + 1, vec<Int>(3, 0));

    for (Int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j == k) {
                    continue;
                }

                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + abc[k][i]);
            }
        }
    }

    Int ans = 0;
    for (int i = 0; i < 3; i++) {
        ans = max(ans, dp[n][i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 10448
def isPrime(n):
    """素数判定
    """
    if n < 2:
        return 0
    elif n == 2:
        return 1
    if n%2 == 0:
        return 0
    for i in range(3, int(n**0.5)+1, 2):
        if n%i == 0:
            return 0
    return 1


Q = int(input())
like2017 = [0]*(10**5+1)  # like2017[x]: 1以上x以下の2017に似た数の個数
res = 0

for i in range(1, 10**5):
    if i % 2 == 1:
        if isPrime(i) and isPrime((i+1)//2):
            res += 1
    like2017[i] = res

for _ in range(Q):
    l, r = map(int, input().split())
    print(like2017[r] - like2017[l-1])


Measured memory_bytes: 4212
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort()
if n<k:
    print(0)
else:
    if k==0:
        a=h
    else:
        a=h[:-k]
    summ=0
    for i in a:
        summ+=i
    print(summ)

Measured memory_bytes: 26764
#include <iostream>

 

using namespace std;

 

int main()
{
    int i, x;
    for(i=1; i<=10000; i++)
    {
        cin >> x;
        if (x==0)
        break;
        cout << "Case " << i << ": "<< x << endl;
        
    }  
    
}



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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

inline int to_value(char c)
{
    if(c=='A') return 14;
    if(c=='K') return 13;
    if(c=='Q') return 12;
    if(c=='J') return 11;
    if(c=='T') return 10;
    return c-'0';
}

int main()
{
    char trump;
    while(scanf(" %c", &trump),(trump!='#'))
    {
        string s[4][13];
        rep(i,4)rep(j,13) cin >>s[i][j];

        int ns=0,ew=0;
        int dealer=0;

        rep(game,13)
        {
            // printf(" GAME %d: dealer = %d\n",game,dealer);

            int v=to_value(s[dealer][game][0]);
            char lead=s[dealer][game][1];
            if(lead==trump) v+=100;

            int idx=dealer;

            for(int i=1; i<4; ++i)
            {
                int nx=(dealer+i)%4;
                if(s[nx][game][1]!=trump && s[nx][game][1]!=lead) continue;

                int tmp=to_value(s[nx][game][0]);
                if(s[nx][game][1]==trump) tmp+=100;

                // printf(" nx= %d, tmp= %d\n", nx,tmp);
                if(tmp>v)
                {
                    v=tmp;
                    idx=nx;
                }
            }
            
            dealer=idx;
            if(idx%2==0) ++ns;
            else ++ew;
        }

        if(ns<ew) printf("EW %d\n", ew-6);
        else printf("NS %d\n", ns-6);
    }
    return 0;
}

Measured memory_bytes: 3200
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy
from time import time

N,M=map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
update = []

for _ in range(M):
    temp = list(map(int, input().split()))
    update.append(temp)

# C_i の値をkeyにしてソートする
update = sorted(update,key = lambda x:x[1], reverse=True)

idx = 0
for b, c in update:
    for i in range(b):
        if idx >= N:
            break
        if A[idx] < c:
            A[idx] = c
            idx += 1
        else:
            break

print(sum(A))

Measured memory_bytes: 42680
#include <bits/stdc++.h>
using namespace std;
int constexpr N = 200005, MOD = 1e9 + 7;

int mpow(int a, int b) {
    if(b == 0)
        return 1;
    int h = mpow(a, b / 2);
    h = 1ll * h * h % MOD;
    if(b & 1) h = 1ll * h * a % MOD;
    return h;
}

int n, m, a, b, f[N];

int ans(int h, int w) {
    h--, w--;
    int res = 1ll * f[h + w] * mpow(f[h], MOD - 2) % MOD;
    res = 1ll * res * mpow(f[w], MOD - 2) % MOD;
    return res;
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> a >> b;
    f[0] = 1;
    for(int i = 1; i < N; ++i)
        f[i] = 1ll * i * f[i - 1] % MOD;

    long long t = ans(n, m);
    for(int j = 1; j <= b; ++j) {
        t -= 1ll * ans(n - a, j) * ans(a, m - j + 1) % MOD;
    }
    t %= MOD;
    if(t < 0) t += MOD;
    cout << t << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define lp(i, x, n) for (int i = x; i < (int)n; ++i)
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()
#define ll long long
#define N 123451

int n, el[111], mn = 1e9;

int main(){
        scanf("%d", &n);
        lp (i, 0, n) scanf("%d", el + i);
        for (int i = -100; i <= 100; i++) {
                int sm = 0;
                lp (j, 0, n) sm += (el[j] - i) * (el[j] - i);
                mn = min(sm, mn);
        }
        printf("%d\n", mn);
        return 0;
}


Measured memory_bytes: 256
while gets do
  @n,@s=$_.split(' ').map(&:to_i)
  break if @n==0 and @s==0
  @a=Array.new
  @c=0

  def dfs(i)
    if @a.size == @n
      @c+=1 if @a.inject(:+)==@s
    end

    (i..9).each do |j|
      @a.push(j)
      dfs(j+1)
      @a.pop
    end
  end
  dfs(0)
  puts @c
end

Measured memory_bytes: 6104
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=505;
const int M=4*N;
const int S=10000;
int pr[M],psz;
bool sieve[S];
ll val[N][N];
vector<pair<int,int> > id;
int Find(pair<int,int> x){ return lower_bound(id.begin(),id.end(),x)-id.begin()+1;}
int main()
{
	int i,j;
	for(i=2;i<S;i++) if(!sieve[i]){ pr[++psz]=i;for(j=i;j<S;j+=i) sieve[j]=1;}
	int n;
	scanf("%i",&n);
	if(n==2) return 0*printf("4 7\n23 10\n");
	for(i=1;i<=n;i++) for(j=1;j<=n;j++) if((i+j)&1)
	{
		int a=i+j,b=i-j;
		id.pb(mp(1,a));
		id.pb(mp(2,b));
	}
	sort(id.begin(),id.end());
	id.erase(unique(id.begin(),id.end()),id.end());
	for(i=1;i<=n;i++) for(j=1;j<=n;j++) if((i+j)&1)
	{
        int a=Find(mp(1,i+j));
        int b=Find(mp(2,i-j));
        val[i][j]=(ll)pr[a]*pr[b];
	}
	for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(!((i+j)&1))
	{
		val[i][j]=1;
		if(i-1>0 || j+1<=n) val[i][j]*=pr[Find(mp(2,i-j-1))];
		if(i+1<=n || j-1>0) val[i][j]*=pr[Find(mp(2,i-j+1))];
		if(i-1>0 || j-1>0) val[i][j]*=pr[Find(mp(1,i+j-1))];
		if(i+1<=n || j+1<=n) val[i][j]*=pr[Find(mp(1,i+j+1))];
		val[i][j]++;
	}
	for(i=1;i<=n;i++) for(j=1;j<=n;j++) printf("%lld%c",val[i][j],j==n?'\n':' ');
	return 0;
}

Measured memory_bytes: 7152
#include <iostream>
using namespace std;
int main(void){
    int a, b, c;
    cin >> a >> b >>c;
    if( a < b && b < c){
        cout <<"Yes"<< endl;
    }
    else{
        cout <<"No"<< endl;
    } 
    
    
    return 0;
    
}


Measured memory_bytes: 3104
import sys

lines = []
for line in sys.stdin:
    lines.append(line)

word = "".join(lines)
alphabet = "abcdefghijklmnopqrstuvwxyz"
cnt = {key: 0 for key in alphabet}
for ch in word:
    ch = ch.lower()
    if ch not in alphabet:
        continue
    cnt[ch.lower()] += 1

for key, value in cnt.items():
    print(f"{key} : {value}")


Measured memory_bytes: 5580
// Igorjan94, template version from 13 October 2017. C++17 version, modified 18 march 2020 (writeln<tuple>, whole->all) {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <iomanip>

using namespace std;

#define FOR(i, m, n) for (int i = m; i <  (int) (n); ++i)
#define ROF(i, m, n) for (int i = m; i >= (int) (n); --i)
#define forn(i, n)   for (int i = 0; i < (int) (n); ++i)
#define  fori1(n)    for (int i = 1; i < (int) (n); ++i)
#define  forj1(n)    for (int j = 1; j < (int) (n); ++j)
#define   fori(n)    for (int i = 0; i < (int) (n); ++i)
#define   forj(n)    for (int j = 0; j < (int) (n); ++j)
#define     SZ(a)    int(size(a))

typedef  pair<int, int>   pii;
typedef   vector<int>     vi;
typedef    long long      ll;

#define pb push_back
#define all(a) begin(a), end(a)
#define ints(a...) int a; readln(a)

[[maybe_unused]] const int MOD = 1000000007;
[[maybe_unused]] const int INTMAX = numeric_limits<int>::max();

//Igorjan
//}}}

void run()
{
    int n;
    cin >> n;
    ll sum = 0;
    fori1(n + 1)
        if (i % 3 && i % 5)
            sum += i;
    cout << sum << endl;
        
}

//{{{
int main()
{
    ios_base::sync_with_stdio(false);
    run();
    cerr << fixed << setprecision(0) << "Execution time = " << 1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

const int mod = 1000000007;

int mpow(int a, int b)
{
    if (b == 0) return 1;

    if (b % 2) {
        return 1LL * a * mpow(a, b - 1) % mod;
    }
    else {
        int d = mpow(a, b / 2);
        return 1LL * d * d % mod;
    }
}
int main()
{
    int h, w, a, b;
    cin >> h >> w >> a >> b;

    int fact[200010] = {1,1};
    for (int i = 1; i < 200010; i++) {
        fact[i] = 1LL * fact[i - 1] * i % mod;
    }
    
    int ans = 0;
    for (int i = 1; i <= h - a; i++) {
        int t = 1;
        t = 1LL * t * fact[b + i - 2] % mod * mpow(1LL * fact[b - 1] * fact[i - 1] % mod, mod - 2) % mod;
        t = 1LL * t * fact[h - i + w - b - 1] % mod * mpow(1LL * fact[h - i] * fact[w - b - 1] % mod, mod - 2) % mod;
        ans = (ans + t) % mod;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

unit = 100000;

main = do
	[ x, y ] <- readInts
	let
		a = max 0 $ ( 4 - x ) * unit
		b = max 0 $ ( 4 - y ) * unit
		bonus = if x == 1 && y == 1 then unit * 4 else 0
        print $ a + b + bonus	

Measured memory_bytes: 380
n, m = map(int, input().split())
ls = []
rs = []
for i in range(m):
    l, r = map(int, input().split())
    ls.append(l)
    rs.append(r)
n_all = min(rs) - max(ls) + 1
if n_all < 0: n_all =0
print(n_all)


Measured memory_bytes: 10996
#include <stdio.h>

int main(){
    int X,judge=0,i=0;
    scanf("%d",&X);
    while(1){
        X;
        for(i=2;i<X;i++){
            if(X%i == 0)judge++;
        }
        if(judge==0)break;
        judge=0;
        X++;
    }
    printf("%d",X);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    a();
  }

  public static void a() {
    try (Scanner sc = new Scanner(System.in)) {
      int[] a = new int[5];
      a[0] = Integer.parseInt(sc.next());
      a[1] = Integer.parseInt(sc.next());
      a[2] = Integer.parseInt(sc.next());
      a[3] = Integer.parseInt(sc.next());
      a[4] = Integer.parseInt(sc.next());

      int count = 0;

      for (int b : a) {
        if (b == 0) {
          if (count == 4) {
            System.out.println(a[3] + 1);
          } else {
            System.out.println(a[count + 1] - 1);
          }
        }
        count++;
      }
    }
  }
}

Measured memory_bytes: 35616
#include<iostream>
using namespace std;
int main(){
	int a[100][6];
	int n=0;
	int k=0;
	int c[100];
	int d[100];
	int i=0;
	int j=0;
	int s=0;
	int r=0;
	int h=0;
	
	for(i=0;i<100;i++){
		c[i]=0;
		d[i]=0;
	}
	cin>>n;
	cin>>k;
	for(i=0;i<k;i++){
		cin>>c[i];
		cin>>d[i];
	}
	for(i=0;i<k;i++){
		if(c[i]==1){
			r=1;
			for(j=0;j<6;j++){
				if(j==d[i]*2-2){
					a[0][j]=1;
				}else{
					a[0][j]=0;
				}
			}
		}
	}
	if(r==0){
		a[0][0]=1;
		a[0][1]=0;
		a[0][2]=1;
		a[0][3]=0;
		a[0][4]=1;
		a[0][5]=0;
	}                                                        //ok!
	r=0;
	for(i=1;i<n;i++){
		a[i][0]=a[i-1][2]+a[i-1][3]+a[i-1][4]+a[i-1][5];
		a[i][1]=a[i-1][0];
		a[i][2]=a[i-1][0]+a[i-1][1]+a[i-1][4]+a[i-1][5];
		a[i][3]=a[i-1][2];
		a[i][4]=a[i-1][2]+a[i-1][3]+a[i-1][0]+a[i-1][1];
		a[i][5]=a[i-1][4];
		for(j=0;j<k;j++){
			if(c[j]==i+1){
				for(h=0;h<6;h++){
					if(d[j]-1!=h/2){
						a[i][h]=0;
					}
				}
			}
		}
		for(j=0;j<6;j++){
			if(a[i][j]>10000){
				a[i][j]=a[i][j]%10000;
			}
		}
	}
	for(i=0;i<6;i++){
		s=s+a[n-1][i];
	}
	if(s>=10000){
		s=s%10000;
	}
	cout<<s<<endl;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
int n,m,i,j,a[300005];
long long s[300005],s0,s1,l,r,mid,ans;
bool check(long long x){
	long long mi=0;
	int i;
	for(i=2;i<=n;i+=2){
		if(s[i-1]-mi>=x){
			mi=min(mi,s[i]);
		}
	}
	return s[n]-mi>=x;
}
int main(){
	cin>>n;
	rep(i,n){
		cin>>a[i];
		s[i]=s[i-1];
		if(i&1) s[i]+=a[i]; else s[i]-=a[i];
		if(i&1) s1+=a[i]; else s0+=a[i];
	}
	if(n%2==0){
		cout<<max(s0,s1)<<' '<<min(s0,s1)<<endl;
		return 0;
	}
	l=-(s0+s1);r=s0+s1;
	while(l<r){
		mid=((l+r)>>1);
		if(check(mid)){
			l=mid+1;
			ans=mid;
		}
		else r=mid;
	}
	cout<<s0+ans<<' '<<s1-ans<<endl;
	return 0;
}

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

vector<int64_t> vec(100, 0);

int64_t lucas(int n){
  if (n == 0) {
    vec.at(0) = 2;
    return vec.at(0);
  }
  else if (n == 1){
    vec.at(1) = 1;
    return vec.at(1);
  }
  else if (vec.at(n) != 0) {
    return vec.at(n);
  }
  else {
    vec.at(n) = lucas(n-1) + lucas(n-2);
    return vec.at(n);
  }
}

int main(){
  int N ;
  cin >> N;
  cout << lucas(N) << endl;
}


Measured memory_bytes: 256
//题目意思简单说一下 给你字符串SS 求 下标为i<j<k的三个字母不一样并且j-i！=k-j的有多少个
//显然3层for循环会TLE，所以这个可以使用前缀和
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=4010;
int n,pre[maxn][3],suf[maxn][3];
char s[maxn];
int d[maxn];
ll ans;
int main() {
	scanf("%d",&n);
	scanf("%s",s+1);
	for (int i=1;i<=n;i++) {
		if (s[i]=='R') d[i]=0;
		else if (s[i]=='G') d[i]=1;
		else d[i]=2;
	}
	for (int i=1;i<=n;i++) {  //前缀和 
		for (int j=0;j<3;j++) pre[i][j]=pre[i-1][j];
		pre[i][d[i]]++;
	}
	for (int i=n;i>=1;i--) {  //后缀和 
		for (int j=0;j<3;j++) suf[i][j]=suf[i+1][j];
		suf[i][d[i]]++;
	}
	for (int i=1;i<=n;i++) {
		for (int j=0;j<3;j++)
		for (int k=0;k<3;k++)
			if (d[i]!=j&&j!=k&&k!=d[i])  //3个字母不同   i为中间的字母，j为前面的，k为后面的。然后相乘组合就可以了
				ans+=pre[i-1][j]*suf[i+1][k];
	}
	for (int i=1;i<=n;i++)
	for (int j=i+1,k;j<=n;j++) {  //处理j-i==k-j的情况 
		k=j*2-i;
		if (j<k&&k<=n) {
			if (d[i]!=d[j]&&d[j]!=d[k]&&d[k]!=d[i]) ans--;
		}
	}
	printf("%lld\n",ans);
	return 0;
}
 


Measured memory_bytes: 3832
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

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

    std::sort(s.begin(), s.end());
    std::sort(t.begin(), t.end(), std::greater<int>());

    /*
    rep(i,s.size()){
        if(s[i]<t[i]){
            std::cout << "Yes" << "\n";
            return 0;
        }
    }
    if(s[s.size()-1]==t[s.size()-1] && s.size()<t.size()){
        std::cout << "Yes" << "\n";
        return 0;
    }
    std::cout << "No" << "\n";
    */
    if(s<t) std::cout << "Yes" << "\n";
    else std::cout << "No" << "\n";

    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define int long long
#define dd second
#define mp make_pair
#define pb push_back
#define ff first
#define dd second
#define pp pair<int,int>
using namespace std;

void wyp(int x)
{
    for(int i = 0; i < 26; ++i) cout << (x >> i & 1);
    cout << endl;
}

main()
{
    ios_base::sync_with_stdio(false);
    int mask = 0;
    string s; cin >> s;
    map<int,int> tt;
    tt[0] = 0;
    int ans = 1e9;
    for(int i = 0; i < s.size(); ++i)
    {
       // cout << " sprawdzam " << i << endl;
        mask ^=  (1ll << (s[i]-'a'));
        //wyp(mask);
        if(tt.count(mask) == 0)tt[mask] = 1e9;
        int res = tt[mask]+1;
        for(int bit = 0; bit < 26; ++bit)
        {
            int num = 1ll << bit;
            int pyt = mask ^ num;
            if(tt.count(pyt) > 0)
            {
                res = min(res, tt[pyt]+1);
            }
        }
        tt[mask] = min(tt[mask],res);
        if(i == s.size()-1) ans = res;
        //cout << "res " << res << endl;
    }
    cout << ans << endl;

}



Measured memory_bytes: 12948
import functools
a = int(input())
S = input()
l = [0] * (a+1)
r = [0] * (a+1)
for i, s in enumerate(S):
  l[i+1] = l[i] + 1 if s=="W" else l[i]
for i,s in enumerate(S[::-1]):
  r[i+1] = r[i] + 1 if s=="E" else r[i]
b = [l[i]+r[a-1-i] for i in range(a)]
c = functools.reduce(lambda x, y: min(x, y), b)
print(c)

Measured memory_bytes: 30312
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define F first
#define S second
#define ll long long
using namespace std;
ll h,tms=0,ans=0;
int main(){
	ll i;
	cin>>h;
	while(h>0)
	{
		tms++;
		h/=2;
	}
	for(i=0;i<tms;i++)
	{
		ans=(ans+1)*2;
	}
	cout<<ans/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int, int> p;
p ink1[4] = { p(0, 1), p(0, -1), p(1, 0), p(-1, 0) };
p ink2[4] = { p(1, 1), p(-1, -1), p(1, -1), p(-1, 1) };
p ink3[4] = { p(0, 2), p(0, -2), p(2, 0), p(-2, 0) };

int table[10][10];

int main()
{
	int x, y, size;
	while (scanf("%d,%d,%d", &x, &y, &size) != -1)
	{
		table[x][y]++;
		for (int i = 0; i < 4; i++)
		{
			int X = x + ink1[i].first;
			int Y = y + ink1[i].second;
			if (0 <= X && X <= 9 && 0 <= Y && Y <= 9) table[X][Y]++;
		}

		if (size == 1) continue;
		for (int i = 0; i < 4; i++)
		{
			int X = x + ink2[i].first;
			int Y = y + ink2[i].second;
			if (0 <= X && X <= 9 && 0 <= Y && Y <= 9) table[X][Y]++;
		}

		if (size == 2) continue;
		for (int i = 0; i < 4; i++)
		{
			int X = x + ink3[i].first;
			int Y = y + ink3[i].second;
			if (0 <= X && X <= 9 && 0 <= Y && Y <= 9) table[X][Y]++;
		}
	}

	int n = 0;
	int Max = 0;
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			if (table[i][j] == 0) n++;
			Max = max(Max, table[i][j]);
		}
	}
	printf("%d\n%d\n", n, Max);

	return 0;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
  static inline int64 Normalize(int64 x) {
    if (0 <= x && x < P) return x; x %= P; if (x < 0) x += P; return x;
  }
 public:
  FiniteField(int64 x) : x(Normalize(x)) {}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

ostream& operator<<(ostream& s, const FiniteField& v) { s << v.Value(); return s; }

tuple<vector<FiniteField>, vector<FiniteField>> MakeFactorialTables(int n) {
  vector<FiniteField> factorials(n + 1);
  vector<FiniteField> inverse_factorials(n + 1);
  factorials[0] = 1;
  for (int i = 1; i <= n; i++) {
    factorials[i] = factorials[i - 1] * i;
  }
  inverse_factorials[n] = FiniteField(1) / factorials[n];
  for (int i = n; i >= 1; i--) {
    inverse_factorials[i - 1] = inverse_factorials[i] * i;
  }
  return make_tuple(factorials, inverse_factorials);
}

template<typename T>
vector<vector<T>> MakeVector2D(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

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

  int n, k;
  cin >> n >> k;
  vector<int> xs(k);
  for (int i = 0; i < k; i++) {
    cin >> xs[i];
  }

  vector<FiniteField> fs, i_fs;
  tie(fs, i_fs) = MakeFactorialTables(n + 1);
  auto c_fn = [&fs, &i_fs](int a, int b) -> FiniteField {
    if (b < 0 || b > a) return 0;
    return fs[a] * i_fs[b] * i_fs[a - b];
  };

  auto dp = MakeVector2D<FiniteField>(k + 1, n + 1, 0);
  dp[0][0] = 1;
  for (int i = 0; i < k; i++) {
    int x = xs[i];
    for (int j = 0; j <= n; j++) {
      for (int a = 0; a <= n - j; a++) {
        dp[i + 1][j + a] += dp[i][j] * c_fn(n - j, a) * c_fn(x, a) / c_fn(n, a);
      }
    }
  }
  FiniteField ans = dp[k][n];
  for (int x : xs) {
    ans *= c_fn(n, x);
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int,int>
#define pll pair<ll,ll>
using namespace std;

int n; 
char s[105];
int main(){
	scanf("%d\n%s",&n,&s);
	if (n%2 == 1)
	printf("No\n");
	else
	{
		for (int i=0;i<n/2;i++){
			if (s[i] != s[i+n/2]){
				printf("No\n");
				return 0;
			}
		}
		printf("Yes\n");
	}
	return 0;
}

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

using namespace std;

// 上下左右の移動のため
vector<int> dx = { -4, 4, -1, 1 };

map<string, int> cache;

// ゴールから移動可能な文字列すべてへの移動距離を計算してキャッシュする
void create_cache() {
  queue<string> q;
  
  const string goal = "01234567";
  cache[goal] = 0;
  q.push(goal);
  
  while (q.size()) {
    string current = q.front(); q.pop();
        
    // '0' の位置
    int x = current.find('0');
          
    // 交換
    for (int i = 0; i < 4; i++) {
      int nx = x + dx[i];
      // 範囲内
      if (0 <= nx && nx < 8) {
        
        // 上段右端のときは右移動不可
        if (x == 3 && dx[i] == 1) continue;
        // 下段左端のときは左移動不可
        if (x == 4 && dx[i] == -1) continue;
        
        // 文字の入れ替え
        string next = current;          
        next.at(x) = current.at(nx);
        next.at(nx) = current.at(x);

        // 未訪問なら Queue に積む
        if (!cache.count(next)) {
          cache[next] = cache.at(current) + 1;
          q.push(next);
        }
      }
    }
  }  
}

int main() {
  create_cache();
  
  while (true) {   
    string numbers(8, '0');
    
    for (int i = 0; i < 8; i++) {
      cin >> numbers.at(i);
    }
    
    if (!cin.good()) break;
    
    cout << cache.at(numbers) << endl;
  }
}



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

int main() {

	string res;
	string s;
	cin >> s;
	string slen;

	int len = s.length();

	slen = to_string(len - 2);

	res = s[0] + slen + s[len - 1];

	cout << res << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
const int inf = 1001001000;
const long long int Inf = 1001001001001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}
//セグメント木のテンプレ.RMQ.
//findでは[a,b)の範囲で返す.[a,b]でないことに注意.
class SegmentTree{
	public:
		int n;
		vector<int> node;
		int inf = (1LL << 31) - 1;
		
		SegmentTree(vector<int> v){
			int sz = v.size();
			this->n = 1;
			while(n < sz)
				n = n * 2;
			this->node.resize(2 * n - 1, this->inf);
			for (int i = 0; i < sz; i++)
				node[i + n - 1] = v[i];
			for (int i = n - 2; i >= 0; i--)
				node[i] = min(node[2 * i + 1], node[2 * i + 2]); 
		}
		void update(int x, int val){
			x += n - 1;
			node[x] = val;
			while(x > 0){
				x = (x - 1) / 2;
				node[x] = min(node[2 * x + 1], node[2 * x + 2]);
			}
		}
		int find(int a, int b, int k = 0, int l = 0, int r = -1){
			if (r < 0)
				r = n;
			if (r <= a || b <= l)
				return this->inf;
			if (a <= l && r <= b)
				return node[k];
			int lv = this->find(a, b, 2 * k + 1, l, (l + r) / 2);
			int rv = this->find(a, b, 2 * k + 2, (l + r) / 2, r);
			return min(lv, rv);

		}
};

int main()
{
	int n,q;
	cin >> n >> q;
	SegmentTree st(vector<int>(n, (1LL << 31) - 1));
	rep(i,q){
		int c, x, y;
		cin >> c >> x >> y;
		if (c == 0){
			st.update(x, y);
		} else {
			cout << st.find(x, y+1) << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 4060
package main

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

func main() {
	sc = initScanner(os.Stdin)
	a, b := scanInt(sc), scanInt(sc)
	s := scanString(sc)

	fmt.Println(resolve(a, b, s))
}

func resolve(a int, b int, s string) string {
	ss := strings.Split(s, "")

	if ss[a] != "-" {
		return "No"
	}

	_, err := strconv.Atoi(strings.Join(ss[:a], ""))
	if err != nil {
		return "No"
	}

	_, err = strconv.Atoi(strings.Join(ss[a+1:], ""))
	if err != nil {
		return "No"
	}

	return "Yes"
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i := 0; i < n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}

func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

using namespace std;


int main(){

    int n;
    cin >> n;
    
    map<int,int> ans;

    rep(i,n){
        int tmp;
        cin >> tmp;
        cerr << tmp << endl;

        ans[tmp] = i + 1;
    }

    rep(i,n){
        cout << ans[i + 1] << " ";
    }
    cout << endl;

    

    return 0;
}


Measured memory_bytes: 5504
using System;

class Program {
  static void Main(string[] args) {
    while(true) {
      int N = int.Parse(Console.ReadLine());
      if(N == 0) break;
      if(N % 1111 == 0) {
        Console.WriteLine("NA");
        continue;
      }
      int ans = 0;
      while(N != 6174) {
        char[] S = string.Format("{0:0000}", N).ToCharArray();
        Array.Sort(S);
        char[] L = new char[4];
        for(int i = 0; i < 4; i++) L[i] = S[3 - i];
        N = int.Parse(new string(L)) - int.Parse(new string(S));
        ans++;
      }
      Console.WriteLine(ans);
    }
  }
}

Measured memory_bytes: 5968
#include<iostream>
    #include<string>
    using namespace std;
    int main(){
        int n,k;
        string S;
        cin>>n>>k;
        cin>>S;
        if(S[k-1]=='A') S[k-1]='a';
        if(S[k-1]=='B') S[k-1]='b';
        if(S[k-1]=='C') S[k-1]='c';
        cout<<S;
    }

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

struct P { 
   int num, kosu;
   char c;
   // デフォルト(昇順)
   bool operator<(const P &p) const {
      return kosu < p.kosu;
   }
   // greater(降順)
   bool operator>(const P &p) const {
      return kosu > p.kosu;
   }
};

signed main() {
   int n;
   cin >> n;
   map<int, int> a, b;
   vec<int> v(n);
   rep (i, n) {
      int p; cin >> p;
      v[i] = p;
      if (i%2) {
         a[p]++;
      } else {
         b[p]++;
      }
   }

   using pii = pair<int, int>;
   vec<pii> A, B;
   vec<P> C;
   for (auto x : a) { C.push_back({x.first, x.second, 'A'}); }
   for (auto x : b) { C.push_back({x.first, x.second, 'B'}); }
   sort(all(C)); reverse(all(C));

   if (count(all(v), v[0]) == n) {
      cout << n/2 << endl;
      return 0;
   }

   using pii = pair<int, int>;
   int ans1 = n;
   int num1 = 0;
   for (auto x : C) {
      if (x.c == 'A') {
         num1 = x.num;
         ans1 -= x.kosu;
         break;
      }
   }
   for (auto x : C) {
      if (x.num == num1) continue;
      if (x.c == 'B') {
         ans1 -= x.kosu;
         break;
      }
   }

   int ans2 = n;
   int num2 = 0;
   for (auto x : C) {
      if (x.c == 'B') {
         num2 = x.num;
         ans2 -= x.kosu;
         break;
      }
   }
   for (auto x : C) {
      if (x.num == num2) continue;
      if (x.c == 'A') {
         ans2 -= x.kosu;
         break;
      }
   }

   cout << min(ans1, ans2) << endl;

   return 0;
}

Measured memory_bytes: 11252
def main():
    ss = list(input())
    n = len(ss)
    ans = [0]*n
    cnt = 0
    for i, lr in enumerate(ss):
        if lr == "R":
            cnt += 1
            continue
        else:
            even_num = cnt//2
            odd_num = cnt - even_num
            ans[i] += even_num
            ans[i-1] += odd_num
            cnt = 0

    for i in range(n-1, -1, -1):
        if ss[i] == "L":
            cnt += 1
            continue
        else:
            even_num = cnt//2
            odd_num = cnt - even_num
            ans[i] += even_num
            ans[i+1] += odd_num
            cnt = 0
    print(*ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 7096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
	int n,k;cin>>n>>k;cout<<n-k+1<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans=0;
  int l = 0, r = n/2;
  while(r-l>10){
	int i=(l+r+1)/2;
    bool flag = true;
	for(int j=0;j+i*2<=n;j++){
      string t = s.substr(j, i);
	  if(s.find(t,j+i)<n){
	    ans = i;
        l=i;
        flag=false;
	    break;
	  }
	}
    if(flag)r=i;
  }
  for(int i=l;i<=r;i++){
	for(int j=0;j+i*2<=n;j++){
	  string t=s.substr(j,i);
	  if(s.find(t,j+i)<n){
	    ans=i;
		break;
      }
	}
	if(ans<i)break;
  }
  cout << ans << endl;
  return 0;
}

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

#define MOD 10000007
#define f first
#define s second
#define es " "
#define pb push_back
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define sz(x) (int)x.size()
typedef pair<int, int> pii;

int main(){
    fastio;
    int a, b, c, x;
    string at1, at2;
    cin >> at1;
    if(at1=="Sunny"){
        cout << "Cloudy" << endl;
    }
    if(at1=="Cloudy"){
        cout << "Rainy" << endl;
    }
    if(at1=="Rainy"){
        cout << "Sunny" << endl;
    }
    return 0;
}

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

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);

    cout << a << ' ' << b << ' ' << c << endl;

    return 0;
}


Measured memory_bytes: 3576
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define     int 	    long long
#define 	pb 	        push_back
#define 	mp 	        make_pair
#define 	pi 	        2*acos(0.0)
#define     scan(i)     scanf("%d",&i)
#define     loop(i,n) 	for(int i = 0 ; i <n ; i++)
#define 	vect 	    vector<int>
#define 	vec_it 	    vector<int>::iterator vi
#define     sorta(v)    sort(v.begin(),v.end())
#define     sortd(v)    sort(v.begin(),v.end(),greater<>())
#define 	mapp 	    map<int,int>
#define 	pairr 	    pair<int,int>
#define 	sett	    set<int>s
#define 	set_it 	    set<int>::iterator si
#define     map_it      map<int,int> :: iterator mi
#define 	yes 	    cout<<"Yes"<<endl
#define 	no 	        cout<<"No"<<endl
#define 	ff 	        first
#define 	ss 	        second
#define     mx          INT_MAX
#define     lmx         LLONG_MAX
#define     mn          INT_MIN
#define     lmn         LLONG_MIN
#define     GCD         __gcd(a,b)
#define     LCM         (a/GCD)*b
template <typename T> T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
int modulo (int a, int b) { return a >= 0 ? a % b : ( b - abs ( a%b ) ) % b; }

void solve()
{
  // freopen ("(input).txt" , "r",  stdin) ;
  // string st,stt ;
  // int low=0,high=0;
  // int l,r;
    int n,k,t,b,c,x,y,z,d=0,temp=0,cnt=mx,sum=0,f=0;
    cin>>n  ; vect v(n) ,a  ; sett ; set_it ; mapp m,mp; pairr p; map_it;
    loop(i,n) cin>>v[i]; sorta(v);
    if(v[0]==v[n-1])
        cout<<0<<endl;
    else
    {

        for(int i=v[0];i<=v[n-1];i++)
        {
            for(int j=0;j<n;j++)
            {
                temp=abs(i-v[j]);
                sum+=temp*temp;
            }
            cnt=min(sum,cnt);
            sum=0;
        }
        cout<<cnt<<endl;
    }




}

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


Measured memory_bytes: 3588
def main():
  while True:
    w, h = map(int, input().split())
    if w == 0:
      break
  
    mp = [[-1] + list(map(int, input().split())) + [-1] for _ in range(h)]
    mp.insert(0, [-1] * (w + 2))
    mp.append([-1] * (w + 2))
  
    for y in range(1, h + 1):
      for x in range(1, w + 1):
        if mp[y][x] == 2:
          start = (x, y)
        if mp[y][x] == 3:
          goal = (x, y)
  
    vec = ((0, -1), (0, 1), (-1, 0), (1, 0))
    
    def search(now, goal, num):
      if num <= 0:
        return -1
      bx, by = now
      ret = -1
      for dx, dy in vec:
        if mp[by + dy][bx + dx] in (-1, 1):
          continue
        nx, ny = bx, by
        while mp[ny + dy][nx + dx] not in (-1, 1):
          nx += dx
          ny += dy
          if (nx, ny) == goal:
            ret = max(ret, num - 1)
            break
        else:
          if mp[ny + dy][nx + dx] == 1:
            mp[ny + dy][nx + dx] = 0
            ret = max(ret, search((nx, ny), goal, num - 1))
            mp[ny + dy][nx + dx] = 1
  
      return ret
  
    
    score = search(start, goal, 10)
    if score == -1:
      print(-1)
    else:
      print(10 - score)

main()


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

// 1 つの証言を表す構造体
using pint = pair<int,int>; // 「人」と「0 or 1」

// 入力
int N;
vector<vector<pint>> v;

// 整数 bit に対応する「決め打ち」が整合しているかを判定
bool judge(int bit) {
    
    // i 人目の証言を検証する
    for (int i = 0; i < N; ++i) {
        
        // i 人目が「不親切」だったら、証言はすべて無意味
        if ( !(bit & (1 << i)) ) continue;

        // それぞれ確認
        for (pint xy : v[i]) {
            int x = xy.first; // x が
            int y = xy.second; // y = 1: 正直、y = 0: 不親切

            // y = 1 なのに「不親切」だったらダメ
            if (y == 1 && !(bit & (1 << x))) return false;

            // y = 0 なのに「正直者」だったらダメ
            if (y == 0 && (bit & (1 << x))) return false;
        }
    }
    return true;
}


int main() {
    cin >> N;
    v.resize(N);
    for (int i = 0; i < N; ++i) {
        int A; cin >> A;
        v[i].resize(A);
        for (int j = 0; j < A; ++j) {
            cin >> v[i][j].first >> v[i][j].second;
            --v[i][j].first; // 0-indexed に
        }
    }

    int res = 0;
    for (int bit = 0; bit < (1 << N); ++bit) {
        
        // 矛盾 check
        if (judge(bit)) {
            
            // bit に含まれる人数を数える
            int count = 0;
            for (int i = 0; i < N; ++i) {
                if (bit & (1 << i)) ++count;
            }
            res = max(res, count);
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 3552
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int n,a[100];
bool done[100100],memo[100100];

bool solve(int x){
	int i;
	if(done[x]){
		return memo[x];
	}
	done[x] = true;
	for(i=0; i<n; ++i){
		if(x<a[i]){
			continue;
		}
		if(!solve(x-a[i])){
			memo[x] = true;
			return memo[x];
		}
	}
	memo[x] = false;
	return memo[x];
}

int main(void){
	int k,i;
	fill(done,done+100100,false);
	cin >> n >> k;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	cout << ((solve(k))?"First":"Second") << endl;
	return 0;
}


Measured memory_bytes: 5120
import bisect

# https://docs.python.org/ja/3/library/bisect.html

DBG = False

def find_lt(a, x):
    i = bisect.bisect_left(a, x)
    if i:
        return i-1, a[i-1]
    else:
        return 0, a[0]

def readlist(n):
    return list(map(int, (input() for _ in range(n))))

def main():
    A, B, Q = map(int, input().split(' '))
    S = readlist(A)
    T = readlist(B)
    X = readlist(Q)
    if DBG: print(S)
    if DBG: print(T)
    def get_right(lst, left, x):
        if lst[left] > x:
            # x is smaller than lst[0]
            return left, lst[left]
        right = left + 1
        if right < len(lst):
            return right, lst[right]
        else:
            # x is bigger than lst[-1]
            return left, lst[left]
    def print_status(sl_i, sl_v, sr_i, sr_v, tl_i, tl_v, tr_i, tr_v):
        def tostr(i, v):
            return str(i) + " (" + str(v) + ")"
        print("S: " + tostr(sl_i, sl_v), tostr(sr_i, sr_v),
                " T: " + tostr(tl_i, tl_v), tostr(tr_i, tr_v))
    def solve(x):
        if DBG: print("Q:", x)
        sl_i, sl_v = find_lt(S, x)
        sr_i, sr_v = get_right(S, sl_i, x)
        tl_i, tl_v = find_lt(T, x)
        tr_i, tr_v = get_right(T, tl_i, x)
        if DBG: print_status(sl_i, sl_v, sr_i, sr_v, tl_i, tl_v, tr_i, tr_v)
        def distance(p0, p1):
            # first, go to p0 from x.
            d = abs(p0 - x)
            # second, goto p1 from p0.
            d = d + abs(p1 - p0)
            if DBG: print(p0, p1, "->", d)
            return d
        # choose l->l l->r r->l r->r
        #        l<-l l<-r r<-l r<-r
        dists = []
        dists.append(distance(sl_v, tl_v))
        dists.append(distance(tl_v, sl_v))
        dists.append(distance(sl_v, tr_v))
        dists.append(distance(tl_v, sr_v))
        dists.append(distance(sr_v, tl_v))
        dists.append(distance(tr_v, sl_v))
        dists.append(distance(sr_v, tr_v))
        dists.append(distance(tr_v, sr_v))
        if DBG: print(dists)
        return min(dists)
    for x in X:
        print(solve(x))

main()


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

int main(){
  int N, count = 0;
  cin >> N;

  for(int i = 1; i < N; i++){
      int p;
      cin >> p;
      if(p != i){
          count++;
        }
    }
    if(count <= 2){
       cout << "YES";
    }
    else{
        cout << "NO";
    }
}

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

#define ll long long
#define ar array
 
using namespace std;

int main() {
	
	int a,b;
	
	cin >> a >> b;
	
	if(a%2==0 || b%2==0){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	
   	return 0;
}
   

Measured memory_bytes: 256