akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
	int m,f,b;
	cin >> m >> f >> b;
	if(m>=b) cout << 0 << endl;
	else if(m+f>=b) cout << b - m << endl;
	else cout << "NA" << endl;
	return 0;
}


Measured memory_bytes: 3108
l = gets.chomp.to_i
nums = gets.split(' ').map(&:to_i)

score = 0
c_score = 0
current = nil

nums.each do |i|
  if current.nil?
    current = i
    next
  end

  if current >= i
    c_score += 1
  else
    c_score = 0
  end
  score = c_score if c_score > score
  current = i
end

p score

Measured memory_bytes: 8580
#include <stdio.h>

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

Measured memory_bytes: 596
#include<stdio.h>

int A[1000000], n;


int binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
		while ( left < right ) {
			mid = (left+right) / 2;
			if ( key == A[mid] ) return 1;
			if ( key >A[mid] ) left = mid + 1;
			else if ( key < A[mid] ) right = mid;
		}
			return 0;
		}
	

  
  int main(){
   int i, q, k, sum = 0;
  
   scanf("%d", &n);
   for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
   
   scanf("%d", &q);
   for ( i = 0; i < q; i++ ){
    scanf("%d", &k);
    if ( binarySearch( k ) ) sum++;
    }
    printf("%d\n", sum);
    
    return 0;
   }
    



Measured memory_bytes: 2096
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = Integer.parseInt(scanner.nextLine());
		String[] tmp  = scanner.nextLine().split(" ");

		for(int i = 0; i < n; i++) {

			int now = Integer.parseInt(tmp[i]);

			if(now % 2 == 0) {

				if(now % 3 != 0 && now % 5 != 0) {

					System.out.println("DENIED");
					return;

				}
			}
		}
		System.out.println("APPROVED");
	}
}

Measured memory_bytes: 35720
import sys
from math import ceil

def input():
    return sys.stdin.readline().strip()

def check(k):
    tmp = list(h)
    for i in range(N):
        tmp[i] -= B*k
    if sum([int(i<=0) for i in tmp]) == N:
        return True

    lf = 0
    for i in tmp:
        if i > 0:
            lf += ceil(i/(A-B))

    if lf <= k:
        return True
    else:
        return False

N,A,B = map(int,input().split())
h = tuple(int(input()) for _ in range(N))

left = -1
right = 1e9

while abs(left-right) > 1:

    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid

print(int(right))

Measured memory_bytes: 122716
import java.util.Scanner;
public class Main {
	boolean[] dp = new boolean[1000000];//falseが素数
	
	void initialize(int num) {
		for(int r = 2; r * r <= num; r++) {
			for(int c = 2; r * c <= num; c++) {
				dp[r * c] = true;
			}
		}
	}
	
	void doIt() {
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext()) {
			int num = stdIn.nextInt();
			int ans = 0;
			initialize(num);
			for(int r = 2; r <= num; r++)
				if(!dp[r]) ans++;
			System.out.println(ans);
		}	
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().doIt();
	}
}

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

int main()
{
    short k,a,b;
    bool f = false;
    cin >> k;
    cin >> a >> b;
    for (int i = a; i<=b; i++) {
        if (i%k == 0){
            f = true;
            break;
        }
    }
    if (f){
        cout << "OK" << endl;
    }
    else {
        cout << "NG" << endl;
    }
}

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

using namespace std;

struct L{
    L(){}
    L(double o, double p, double q, double r){
	xa = o;
	ya = p;
	xb = q;
	yb = r;
	a = r - p;
	b = o - q;
	c = -(a*o+b*p);
    }
    
    double f(double x, double y){
	return a*x + b*y + c;
    }
    double xa, ya, xb, yb, a, b, c;
};

bool cross(L a, L b){
    return (a.f(b.xa, b.ya) * a.f(b.xb, b.yb) < 0 && 
	    b.f(a.xa, a.ya) * b.f(a.xb, a.yb) < 0);
}

int main(){
    double xa1, ya1, xa2, ya2, xb1, yb1, xb2, yb2;
    while(cin >> xa1 >> ya1 >> xa2 >> ya2 >> xb1 >> yb1 >> xb2 >> yb2){
	L a[4], b[4];
	a[0] = L(xa1, ya1, xa1, ya2);
	a[1] = L(xa1, ya2, xa2, ya2);
	a[2] = L(xa2, ya1, xa2, ya2);
	a[3] = L(xa2, ya1, xa1, ya1);
	b[0] = L(xb1, yb1, xb1, yb2);
	b[1] = L(xb1, yb2, xb2, yb2);
	b[2] = L(xb2, yb1, xb2, yb2);
	b[3] = L(xb2, yb1, xb1, yb1);
	bool res = (xa1 <= xb1 && xb1 <= xa2) && (ya1 <= yb1 && yb1 <= ya2);
	res = res || (xa1 <= xb1 && xb1 <= xa2) && (ya1 <= yb2 && yb2 <= ya2);
	res = res || (xa1 <= xb2 && xb2 <= xa2) && (ya1 <= yb2 && yb2 <= ya2);
	res = res || (xa1 <= xb2 && xb2 <= xa2) && (ya1 <= yb1 && yb1 <= ya2);
	res = res || (xb1 <= xa1 && xa1 <= xb2) && (yb1 <= ya1 && ya1 <= yb2);
	res = res || (xb1 <= xa1 && xa1 <= xb2) && (yb1 <= ya2 && ya2 <= yb2);
	res = res || (xb1 <= xa2 && xa2 <= xb2) && (yb1 <= ya2 && ya2 <= yb2);
	res = res || (xb1 <= xa2 && xa2 <= xb2) && (yb1 <= ya1 && ya1 <= yb2);
				
	for(int i = 0;i < 4;i++){
	    for(int j = 0;j < 4;j++){
		if(cross(a[i], b[j]))res = true;
	    }
	}
	if(res)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1220
N,K = map(int,input().split())
P = list(map(lambda x:int(x)-1,input().split()))
C = list(map(int,input().split()))

ans = -float('inf')
for i in range(N):
    visited = set()
    tmp = 0
    for k in range(K):
        if P[i] in visited: break
        tmp += C[P[i]]
        i = P[i]
        visited.add(i)
        ans = max(ans, tmp)
    if tmp < 0: continue
    l = len(visited)
    rem = K-l
    d,m = divmod(rem,l)
    if m==0 and d > 0:
        m = l
        d -= 1
    tmp *= (d+1)
    for k in range(m):
        tmp += C[P[i]]
        i = P[i]
        ans = max(ans, tmp)

print(ans)

Measured memory_bytes: 111904
#include <iostream>
using namespace std;
int main(void){
    int n,mx,mn;
    cin >>n;
    int A[n];
    for(int i = 0;i < n;i++){
        cin>> A[i];
    }
    
    mn = A[0];
    for(int i = 0;i < n-1;i++){
        int t;
        t = min(A[i],A[i+1]);
        if(t < mn){
            mn = t;
        }
    }
    
    mx = A[0];
    for(int i = 0;i < n-1;i++){
        int t;
        t = max(A[i],A[i+1]);
        if(t > mx){
            mx = t;
        }
    }
    
    cout << abs(mx - mn) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
int fa[301],sizes[301];
int root(int node){
    while(node!=fa[node]){
        fa[node]=fa[fa[node]];
        node=fa[node];
    }
    return(node);
}
void link(int i,int j){
    i=root(i);j=root(j);
    if(i==j) return;
    if(sizes[i]>sizes[j]) swap(i,j);
    sizes[j]+=sizes[i];
    fa[i]=j;
    return;
}

vector<pll> adj[100001];
bool vis[100001];
int ans[100001];
void dfs(ll node){
    vis[node]=true;
    for(auto next:adj[node]){
        if(!vis[next.first]){
            if(next.second%2==1) ans[next.first]=1-ans[node];
            else ans[next.first]=ans[node];
            dfs(next.first);
        }
    }
}
void solve(){
    ll n;
    cin>>n;
    for(ll i=0;i<n-1;i++){
        ll a,b,w;
        cin>>a>>b>>w;
        adj[a].push_back(pll(b,w%2));
        adj[b].push_back(pll(a,w%2));
    }
    memset(vis,false,sizeof vis);
    ans[1]=1;
    dfs(1);
    for(ll i=1;i<=n;i++)
        cout<<ans[i]<<endl;
    return;
}
int main(){
    IO
    //TEST
    solve();
    return(0);
}


Measured memory_bytes: 8960
import Control.Monad
main=do
 [n,m,c]<-map read.words<$>getLine
 b<-map read.words<$>getLine
 a<-replicateM n (map read.words<$>getLine)
 print(f n a b c 0)
  where f 0 _ _ _ i = i
        f n (v:a) b c i = f (n-1) a b c (i+(if(g v b)+c>0 then 1 else 0))
        g a b = (sum(map (\(a,b)->a*b) (zip a b)))

Measured memory_bytes: 1020
class Node():
    def __init__(self, v):
        self.d = 0
        self.f = 0
        self.v = v

    def __repr__(self):
        return "Node({},{},{})".format(
            self.d, self.f, self.v)


def read_node():
    n = int(input())
    adj_list = [[] for _ in range(n + 1)]

    for _ in range(n):
        id, _, *v = [int(x) for x in input().split()]
        adj_list[id] = Node(v)

    return adj_list


def depth_first_search(adj_list):
    def dfs(id):
        nonlocal adj_list, timestamp

        adj_list[id].d = timestamp
        for adj_id in adj_list[id].v:
            if adj_list[adj_id].d == 0:
                timestamp += 1
                dfs(adj_id)
        timestamp += 1
        adj_list[id].f = timestamp

    timestamp = 1
    for id in range(1, len(adj_list)):
        if adj_list[id].d == 0:
            dfs(id)
            timestamp += 1


def print_result(adj_list):
    for id in range(1, len(adj_list)):
        print(id, adj_list[id].d, adj_list[id].f)


def main():
    adj_list = read_node()
    depth_first_search(adj_list)
    print_result(adj_list)


if __name__ == '__main__':
    main()



Measured memory_bytes: 5664
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    print((n-1)//2)


if __name__ == '__main__':
    main()


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

const int M = 1000000007;
int cnt = 0;

void merge(vector<int>& A, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> L(n1 + 1), R(n2 + 1);
    for (int i = 0; i < n1; ++i) {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; ++i) {
        R[i] = A[mid + i];
    }
    L[n1] = M;
    R[n2] = M;
    int l = 0, r = 0;
    for (int k = left; k < right; ++k) {
        ++cnt;
        if (L[l] <= R[r]) {
            A[k] = L[l];
            ++l;
        }
        else {
            A[k] = R[r];
            ++r;
        }
    }
}

void mergeSort(vector<int>& A, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    mergeSort(v, 0, n);
    for (int i = 0; i < n; ++i) {
        cout << v[i];
        if (i < n - 1)
            cout << " ";
    }
    cout << "\n";
    cout << cnt << "\n";

    return 0;
}

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	int a, b, c;
	cin >> a >> b >> c;
	if (c <= a - b) cout << 0 << '\n';
	else cout << c - (a - b) << '\n';

	return 0;
}

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

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define debug(x) cout << #x << ": " << x << endl

//using ll = long long;
//#define int ll


//**********

int H, W;

signed main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> H >> W;
    int a[50][50] = {};
    int C[50][50] = {};
    int black = 0;
    
    REP(i,H){
        REP(j,W){
            char temp;
            cin >> temp;
            if (temp == '#'){
                a[i][j] = 1;
                black++;
            }
        }
    }

    int ans = -1;
    
    REP(i,H){
        REP(j,W){
            C[i][j]=9999;
        }
    }
    C[0][0]=1;
    
    
    REP(k,H*W){
    REP(i,H){
        REP(j,W){
            //cout << "i: " << i << " j: " << j <<endl;
            if(a[i][j]==0){
                //debug(a[i][j]);
                if(i!=0 && C[i-1][j]+1 < C[i][j] && a[i-1][j]==0){
                    C[i][j] = C[i-1][j] + 1;
                }
                if(j!=0 && C[i][j-1]+1 < C[i][j] && a[i][j-1]==0){
                    C[i][j] = C[i][j-1] + 1;
                }
                if(i<H-1 && C[i+1][j]+1 < C[i][j] && a[i+1][j]==0){
                    C[i][j] = C[i+1][j] + 1;
                }
                if(j<W-1 && C[i][j+1]+1 < C[i][j] && a[i][j+1]==0){
                    C[i][j] = C[i][j+1] + 1;
                }
                //debug(C[i][j]);
            }
        }
    }
    }
    
    
    if(C[H-1][W-1]==9999) ans=-1;
    else ans = H*W - C[H-1][W-1] - black;
    printf("%d\n",ans);
    
    return 0;
}






Measured memory_bytes: 256
/*
CODED BY : Super_KAZAKH(-:  >---->  Yedige Ashirbek
 _____     _____         _______________                 ___        _______           ________________      _______________
/\    \   /\    \       /\              \               /\   \     /\      \         /                \    /\              \
\ \    \  \ \    \      \ \    __________\              \ \   \    \ \      \       /\     ____________\   \ \    __________\
 \ \    \  \ \    \      \ \   \_________/               \ \   \    \ \      \      \ \    \                \ \   \_________/
  \ \    \  \ \    \      \ \   \                         \ \   \    \ \      \      \ \    \                \ \   \
   \ \    \  \ \    \      \ \   \                         \ \   \    \ \      \      \ \    \                \ \   \
    \ \    \__\_\    \      \ \   \__________        _______\_\   \    \ \      \      \ \    \     ______     \ \   \__________
     \ \              \      \ \    _________\      /              \    \ \      \      \ \    \    \     \     \ \    _________\
      \ \____      ____\      \ \   \________/     /\    ________   \    \ \      \      \ \    \    \__   \     \ \   \________/
       \/___ \     \           \ \   \             \ \   \     \ \   \    \ \      \      \ \    \      \   \     \ \   \
            \ \     \           \ \   \             \ \   \     \ \   \    \ \      \      \ \    \      \   \     \ \   \
             \ \     \           \ \   \             \ \   \     \ \   \    \ \      \      \ \    \      \   \     \ \   \
              \ \     \           \ \   \___________  \ \   \     \ \   \    \ \      \      \ \    \_____/    \     \ \   \___________
               \ \     \           \ \              \  \ \   \_____\_\   \    \ \      \      \ \              /      \ \              \
                \ \_____\           \ \______________\  \ \_______________\    \ \______\      \ \____________/        \ \______________\
                 \/_____/            \/______________/   \/_______________/     \/______/       \/___________/          \/______________/
                                                                                                                                            */
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};

int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<(a-c)*(b-d);
    exit(0);
}


Measured memory_bytes: 256
import numpy
N = int(input())
a = []
for i in range(N):
    a.append(list(input()))
nda = numpy.array(a)
count = 0
for i in range(N):
    rolled = numpy.roll(nda, i, axis=1)
    transed = rolled.T
    if numpy.all(rolled == transed):
        count += 1
print(count * N)

Measured memory_bytes: 14408
#include<cstdio>
const int MaxN=1000010,inf=1<<30;
int N,M,K,las[MaxN*2],nxt[MaxN*2];
char S[MaxN*2],T[MaxN*2];
void read(int&n,char*s){
	scanf("%s",s);
	for(int i=n;i--;)s[i]-='0';
	for(int i=0,j=n-1;i<j;i++,j--)if(s[i]^s[j])s[i]^=1,s[j]^=1;
}
void pr(int n,char*s){
	while(!s[n])n--;
	for(;n>=0;n--)printf("%d",s[n]);puts("");
}
void ins(int i,int j){
	las[j]=i;nxt[j]=nxt[i];
	nxt[i]=j;nxt[j]<inf?las[nxt[j]]=j:1;
}
void del(int i){
	if(las[i]>-1)nxt[las[i]]=nxt[i];
	if(nxt[i]<inf)las[nxt[i]]=las[i];
}
int add(char*s,char*t,int i,int&k){
	int j=i;t[j]=1;
	for(;s[j];s[j++]=0)if(!t[j])del(j);
	s[j]=1;
	if(t[j])k--;
	else ins(i,j),k=0;
	return j;
}
void mov(int i,int k){
	while(k){
		S[i]=T[i]=0;del(i);
		int j=nxt[i];
		if(k<j-i){
			ins(i,i+k);
			S[i+k]=T[i+k]=1;break;
		}
		k-=j-i-1;
		i=add(S[j]?S:T,S[j]?T:S,j,k);
	}
}
int main(){
	scanf("%d%d%d",&N,&M,&K);
	read(N,S);read(M,T);
	int la=-1;
	for(int i=0;i<N||i<M;i++)if(S[i]||T[i]){
		las[i]=la;nxt[i]=inf;
		if(la>-1)nxt[la]=i;
		la=i;
	}
	for(int i=N;i--;)if(S[i]&&T[i])mov(i,K);
	pr(N+K,S);pr(M+K,T);
}

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

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

  for (int i = 0; i < N; i++) {
    int l,r;
    cin >> l >> r;
	x += r - l + 1;
  }
    cout << x  << endl;
}


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

#define forn(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;

double dp[3000];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);	
        int n;cin>>n;
        double a;cin>>a;
        dp[0]=1-a;
        dp[1]=a;
        for(int i=1;i<n;i++){
            double x;cin>>x;
            for(int j=i+1;j>0;j--){
                dp[j]=dp[j]*(1-x) + dp[j-1]*x;
            }
            dp[0]=dp[0]*(1-x);
        }
        double ans=0.0;
        for(int i=n/2+1;i<=n;i++)ans+=dp[i];
        printf("%0.10f",ans);
        cout<<endl;
        //for(double i:dp)cout<<i<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#define ll long long

using namespace std;

const long long mod = 1e9+7;

int main(){
    string o, e;
    cin >> o >> e;
    const char* ochar, *echar;
    ochar = o.c_str();
    echar = e.c_str();

    for(int i = 0; i < strlen(ochar) + strlen(echar); i++){
        if(i&1){
            cout << echar[i/2];
        }else{
            cout << ochar[i/2];
        }
    }
}

Measured memory_bytes: 256
n = int(input())
i = 0
while i < len(str(n))-1:
    x = int(str(n)[len(str(n))-1-i])
    if x == 9 :
        i += 1
    else:
        n = n-(x+1)*10**i
        i += 1
ans = 0
for i in range(len(str(n))):
    ans += int(str(n)[i])
print(ans)

Measured memory_bytes: 38296
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N, C;
    cin >> N >> C;
    vector<vector<ll>> D(C, vector<ll>(C));
    Rep (i, C) {
        Rep (j, C) {
            cin >> D[i][j];
        }
    }
    vector<vector<ll>> c(N, vector<ll>(N));
    vector<vector<ll>> zone(3);
    Rep (i, N) {
        Rep (j, N) {
            cin >> c[i][j];
            c[i][j]--;
            zone[(i+j)%3].push_back(c[i][j]);
        }
    }

    // それぞれのzoneを各色に変えるときの違和感を求めておく
    vector<vector<ll>> cost(3, vector<ll>(C, 0));
    Rep (i, 3) {
        auto e = zone[i];
        Rep (j, C) {
            for (auto f : e) {
                cost[i][j] += D[f][j];
            } 
        }
    }

    // debug
    // for (auto e : cost) {
    //     for (auto f : e) {
    //         cout << f << " ";
    //     }
    //     cout << endl;
    // }

    ll ans = 1e18;
    Rep (i, C) {
        Rep (j, C) {
            Rep (k, C) {
                ll sub = cost[0][i] + cost[1][j] + cost[2][k];
                if (i != j && j != k && k != i) {
                    ans = min(ans, sub);
                } 
            }
        }
    }

    cout << ans << "\n";
}

Measured memory_bytes: 5028
#include<bits/stdc++.h>
using namespace std;
int n,k,p[200010];
double each[200010],now,ans=0;
int main() {
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&p[i]);
	for(int i=1;i<k;i++) {
		each[i]=(double)(1+p[i])*p[i]/2.0/p[i];
		now+=each[i];
	}
	for(int i=k;i<=n;i++) {
		each[i]=(double)(1+p[i])*p[i]/2.0/p[i];
		ans=max(ans,now);
		now+=each[i];
		now-=each[i-k];
	}
	ans=max(ans,now);
	cout<<fixed<<setprecision(9)<<ans;
	return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <map>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
set <int> st;
int h,w,n,a,b;
vector<ll> black(10);
map<pll,ll> m;
int main(int argc,char const* argv[])
{
  cin >> h >> w >> n;
  for(int i=0;i<n;i++)
    {
      cin >> a >> b;
      for(int j=b-2;j<=b;j++)
	{
	  for(int k=a-2;k<=a;k++)
	    {
	      if(1<=k && k<=h-2 && 1<=j && j<=w-2) m[pll(k,j)]++;
	    }
	}
    }
  for(auto it=m.begin();it !=m.end();it++)
    {
      black[it->second]++;
    }
  black[0]=(ll)(h-2)*(w-2)-m.size();
  for(int i=0;i<=9;i++)
    {
      cout << black[i] << endl;
    }
    return 0;
}


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

ll pm(vector<int> a){
    ll ans=0, sum = 0;
    int len = a.size();
    for(int i = 0; i < len; i+=2)
    {
        sum += a[i];
        if(sum <= 0){
            ans += abs(1-sum);
            sum = 1;
        }
        if(i+1 > len-1) break; 
        sum += a[i+1];
        if(sum >= 0){
            ans += abs(-1-sum);
            sum = -1;
        }
    }
    
    return ans;    
}

ll mp(vector<int> a){
    ll ans=0, sum = 0;
    int len = a.size();
    for(int i = 0; i < len; i+=2)
    {
        sum += a[i];
        if(sum >= 0){
            ans += abs(-1-sum);
            sum = -1;
        }
        if(i+1 > len-1) break;
        sum += a[i+1];
        if(sum <= 0){
            ans += abs(1-sum);
            sum = 1;
        }
    }
    return ans;    
}


int main(){
	ll n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    ll ans = min(pm(a), mp(a));

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

Measured memory_bytes: 1408
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
    int ar[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

    int n;
    cin >> n;

    cout << ar[n-1] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int n;
    int num[200000];
    int i, j;
    int count = 0;
    int judge = 0;
    int blue = 1;
    int min;

    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d",&num[i]);
    }
    min = num[0];
    for(i=0;i<n;i++){
        if(num[i] <= min){
            min = num[i];
            count++;
        }
    }
        

    printf("%d\n", count);
    return 0;

}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define ms(s, n) memset(s, n, sizeof(s))
#define rp(i,l,m) for(int i=l; i<m; ++i)
#define Rp(i,l,m) for(int i=l; i<=m; i++)
#define rpD(i,l,m) for(int i=m; i>l; i--)
#define RpD(i,m,l) for(int i=m; i>=l; i--)
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define sz(a) int((a).size())
#define is insert
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD = (int) 1e9 + 7;
const ld PI = acos((ld) -1);
inline ll gcd(ll a, ll b) {ll r; while (b) {r=a%b;a=b;b=r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p=MOD){ll r=1; for(;k;k>>=1){if(k&1)r=r*n%p;n=n*n%p;}return r;}
inline ll Pow(int n, int k){int r=1; for(;k;k>>=1){if(k&1)r=r*n;n=n*n;}return r;}
#define N 5005

int n, k;

inline void input(){
    cin >> n >> k;
    cout << max(0, n-k+1);
}

inline void solve(){
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    input();
    solve();
  return 0;
}












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

int64_t pairs(string s, int n) {
    int64_t sum = 0;
    
    int64_t r = 0;
    int64_t g = 0;
    int64_t b = 0;
    for (int i = 0; i < n; i++) {
        if (s.at(i) == 'R') {
            r++;
        } else if (s.at(i) == 'G') {
            g++;
        } else if (s.at(i) == 'B') {
            b++;
        }
    }

    int64_t no = 0;
    for (int i = 0; i < n - 2; i++) {
        for (int d = 1; ; d++) {
            if (i + 2 * d >= n) {
                break;
            }
            if (s.at(i) != s.at(i + d) && s.at(i + d) != s.at(i + 2 * d) && s.at(i + 2 * d) != s.at(i)) {
                no++;
            }
        }
    }
    sum = r * g * b - no;

    return sum;
}

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

    cout << pairs(s, n) << endl;
}

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

int main(){
    int N, T, A;
    cin >> N;
    cin >> T >> A;
    vector<int> h(N + 1);
    int min = 10000000000;
    int res;
    for(int i = 1; i <= N; i++){
        cin >> h.at(i);
        int d = abs((T * 1000 - h.at(i) * 6) - A * 1000);
        if(d < min){
            min = d;
            res = i;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
/*
 It's better to sleep happy and tired rather than disappointed and frustrated
 There's only 1 thing that's impossible and that is defeating a man who doesn't give up
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;

const int inf=0x3f3f3f3f;
int n , ans , sum ,W,w[mx2],v[mx2];
ll dp[mx5];
string str;
 
int main() {
	ios::sync_with_stdio(false);
	//int t;cin>>t;while(t--)
	{
		cin>>n>>W;
		fo(i,n)
		{
			cin>>w[i]>>v[i];
		}
		memset(dp,inf,sizeof(dp));
		dp[0]=0;
		fo(i,n)
		{
			for(int j=mx5-5 ; j>=v[i] ; j--)
			{
				if(dp[j-v[i]]!=inf)
				{
					dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
				}
			}
		}
		for(int j=mx5-5 ; j>=0 ; j--)
		{
			if(dp[j]<=W)
			{
				cout<<j;
				break;
			}
		}
	
	}
	return 0;
}


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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  string s;
  cin >> s;

  int left = 0;
  int right = s.length() - 1;
  int cnt = 0;

  while (true) {
    if (s[left] != s[right]) {

      if (s[left] == 'x' && s[right] != 'x') {
        ++cnt;
        ++left;
      }

      else if (s[left] != 'x' && s[right] == 'x') {
        ++cnt;
        --right;
      }

      else {
        cout << -1 << "\n";
        return 0;
      }
    }

    else {
      ++left;
      --right;
    }

    if (left > right) {
      cout << cnt << "\n";
      return 0;
    }
  }

  return 0;
}

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

int findNumber(string s) {
	int tmp = 0, res = 0;
	for (int i = 0; i < s.size(); i++) {
		if (0 <= s[i] - '0' && s[i] - '0' < 10) {
			tmp *= 10;
			tmp += s[i] - '0';
		} else {
			res += tmp;
			tmp = 0;
		}
	}
	return res + tmp;
}

int main() {
	string s;
	int sum = 0;
	while (cin >> s) {
		sum += findNumber(s);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

#define Maxn 200010
#define LL long long

using namespace std;

const double d = 1e9;

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

LL n, cnt[60][60], ans, val[Maxn];

int main() {
    n = read();
    double input;
    for(int i = 1; i <= n; ++i) {
        scanf("%lf", &input);
        val[i] = d * input + 0.01;
    }
    for(int i = 1; i <= n; ++i) {
        LL v = val[i]; int a = 0, b = 0;
        while(!(v % 2)) v /= 2, ++a;
        while(!(v % 5)) v /= 5, ++b;
        for(int a0 = max(18 - a, 0); a0 <= 50; ++a0) 
            for(int b0 = max(18 - b, 0); b0 <= 30; ++b0)
                ans += cnt[a0][b0];
        ++cnt[a][b];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5316
#include<bits/stdc++.h>
using namespace std;
#define sz 100005
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
int pos[100];

int main()
{
    faster_io
    int n,x,y,cnt=0;

    cin>>n;
    int a[n+5];

    for(int i=0;i<n;i++) cin>>a[i],pos[a[i]] = i+1;

    for(int i=1;i<=n;i++){
        if(i != pos[i]) cnt++;
    }

    if(cnt<=2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}





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

#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n;
    cin>>n;
    ll h[n],dp[n+1];
    for(int i=1;i<=n;i++)
        cin>>h[i];
    dp[1]=0;dp[2]=abs(h[1]-h[2]);
    for(int i=3;i<=n;i++){
        dp[i]=min(abs(h[i]-h[i-1])+dp[i-1],dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n]<<endl;
}



Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.swing.text.Segment;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int M = sc.nextInt();
			
			ArrayList<HashSet<Integer>> adj = new ArrayList<HashSet<Integer>>();
			for(int i = 0; i < N; i++){
				adj.add(new HashSet<Integer>());
			}
			
			for(int i = 0; i < M; i++){
				final int a = sc.nextInt() - 1;
				final int b = sc.nextInt() - 1;
				
				adj.get(a).add(b);
				adj.get(b).add(a);
			}
			
			for(int i = 0; i < N; i++){
				if(adj.get(0).contains(i) && adj.get(i).contains(N - 1)){
					System.out.println("POSSIBLE");
					return;
				}
			}
			
			System.out.println("IMPOSSIBLE");
		}
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
		
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
		
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 129260
n = gets
a = gets.split.map(&:to_i)
a.each do |i|
  if i % 2 != 0
    next
  end
  
  if i % 3 == 0
    next
  end
  
  if i % 5 == 0
    next
  end
  puts "DENIED"
  exit
end
puts "APPROVED"




Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9 + 7;
 
int main() {
  		int N; cin >> N;
  		ll A[N];	
  		for (int i = 0; i < N; i++) cin >> A[i];
  		ll ans = 0;
  		for (int bit = 0; bit < 62; bit++) {
          		ll p = 0, q = 0;
          		for (int j = 0; j < N; j++) {
                  		if (A[j] >> bit & 1) p++;
                  		else q++;
                }
          		ll mult = (p * q) % mod;
          		for (int j = 0; j < bit; j++) {
                  	mult = (mult * 2)% mod;
                }
          		ans += mult;
          		ans %= mod;
        }
  		cout << ans << endl;
  		return 0;
}

Measured memory_bytes: 2560
package main

import "fmt"

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	if n < k {
		ans := 0
		if n*2 == k {
			ans++
		}
		fmt.Println(ans)
		return
	}

	remainders := make([]int, k)
	for x := 1; x <= n; x++ {
		r := x % k
		remainders[r]++
	}

	ans := 0
	for a := range remainders {
		b := (k - a) % k
		c := (k - a) % k

		if (b+c)%k != 0 {
			continue
		}

		ans += remainders[a] * remainders[b] * remainders[c]
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
a, b = map(int, input().split())
a_max = ( a + 1) // 0.08
b_max = ( b + 1) // 0.1
max = int(a_max) if a_max > b_max else int(b_max)
flg = 0
for i in range(1, max):
    if int(i * 0.08) == a and int(i * 0.1) == b:
        flg = 1
        print(i)
        break

if flg == 0:
    print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int N;
    cin >> N;
    while (N >= 0) {
        if (N % 4 == 0) {
            cout << "Yes" << endl;
            return 0;
        }
        N -= 7;
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s;
bool key1,key2,key3;
int main()
{
	while(cin>>s)
	{
		if(s=='C')key1=1;
		if(key1&&s=='F')
		{
			key3=1;
			break;
		}
	}
	if(key3)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long 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(void){
  int h,w,k; cin >> h >> w >> k;
  char c[h][w];
  char d[h][w];
  int bn = 0;
  rep(i,h){
    rep(j,w){
      cin >> c[i][j];
      d[i][j] = c[i][j];
    }
  }
  int count = 0;
  for(int i = 0; i < (1 << w); i++){
    for(int j = 0; j < (1 << h); j++){
      for(int l = 0; l < w; l++){
        if((i >> l) & 1){
          for(int x = 0; x < h; x++){
            if(d[x][l] == '#'){
              d[x][l] = '.';
            }
          }
        }
      }
      for(int l = 0; l < h; l++){
        if((j >> l) & 1){
          for(int x = 0; x < w; x++){
            if(d[l][x] == '#'){
              d[l][x] = '.';
            }
          }
        }
      }
      int check = 0;
      for(int x = 0; x < w; x++){
        for(int y = 0; y < h; y++){
          if(d[y][x] == '#') check++;
        }
      }
      if(check == k) count++;
      for(int x = 0; x < w; x++){
        for(int y = 0; y < h; y++){
          d[y][x] = c[y][x];
        }
      }
    }
  }
  cout << count << endl;
  return 0;
}


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

int main()
{
	while( 1 ) {
		int W, H;
		cin >> H >> W;
		if( W == 0 && H == 0 ) {
			break;
		}
		for( int i = 0; i < H; i++ ) {
			for( int j = 0; j < W; j++ ) {
				if( (i + j) % 2 ) {
					cout << '.';
				}
				else {
					cout << '#';
				}
			}
			cout << endl;
		}
		cout << endl;
	}
}



Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <chrono>
#include <ctime>
#include <queue>
#include <math.h>
#include <deque>
#include <stack>
#include <iomanip>
#include <assert.h>
#include <stdio.h>
#include <cstring>
#include <random>

using namespace std;
#define int long long
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
#define try tr
#define pii pair<int, int>
#define ti tuple <int, int, int>
#define vi vector <int>
#define vpi vector <pii>
#define umap unordered_map
#define uset unordered_set
#define left left11
#define right right11
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define sqr(a) ((a) * (a))
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define fs first
#define sc second

ld TL = 0.25;
bool is_tl = 0;
int CALLS = 0;

inline bool IS() {
    if (++CALLS == 1000) {
        CALLS = 0;
        is_tl |= clock() > (TL - 0.1) * CLOCKS_PER_SEC;
    }
    return is_tl;
}

template<typename T1, typename T2>
inline void amin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void amax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
    os << p.first << ' ' << p.second << endl;
    return os;
}

template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
    for (auto &u : v) os << u << ' ';
    os << endl;
    return os;
}

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const ll N = 1e6 + 7, NS = 2e3 + 7, lg = 19, sq = 550, inf = 1e18 + 7, SM = 1e2 + 7;
const ld eps = 1e-9;
int hash_mod[4] = {1000000007, 998244353, 1000000009, 999999937}, mod = hash_mod[rnd() % 4];
int hash_pows[4] = {179, 239, 1007, 2003}, P = hash_pows[rnd() % 4];
void solve() {
    int n, c1 = 0, c0 = 0;
    cin >> n;
     vi a(n);
     for (int i= 0; i < n; i++) {
         cin >> a[i];
         if(a[i] % 2)
             c1++;
         else
             c0++;
     }
     if(c1 % 2 == 0)
         cout << "YES\n";
     else
         cout << "NO\n";
}

signed main() {
    fast
    solve();
}


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

using namespace std;

const int INF = 1 << 30;

int solve(string A, string B)
{
  int sz = A.size();
  A += A;
  B += B;
  B += B;

  int ret = INF;

  int latte[3000], malta[3000];

  fill_n(latte, 3000, INF);
  fill_n(malta, 3000, INF);
  for(int i = 0; i < sz; i++) {
    for(int j = 0; j < sz; j++) {
      if(B[j] == '1') {
        latte[i] = min(latte[i], (i - j + sz) % sz);
        malta[i] = min(malta[i], (j - i + sz) % sz);
      }
    }
  }


  for(int st = 0; st < sz; st++) {
    int cost = 0;
    vector< pair< int, int > > shift;
    for(int i = 0; i < sz; i++) {
      const char c = A[st + i];

      if(c != B[i]) {
        ++cost;

        if(c == '1') {
          int latte1 = latte[(st + i) % sz], malta1 = malta[(st + i) % sz];
          if(latte1 == INF) {
            cout << -1 << endl;
            exit(0);
          }
          latte1 = max(0, latte1 - st);
          shift.emplace_back(latte1, malta1);
        }
      }
    }

    if(!shift.empty()) {
      sort(shift.rbegin(), shift.rend());
      int curr = INF, olt = 0;
      for(int i = 0; i <= shift.size(); i++) { // 左シフトの回数
        curr = min(curr, (i == shift.size() ? 0 : shift[i].first * 2) + olt * 2);
        olt = max(olt, shift[i].second);
      }
      cost += curr;
    }

    ret = min(ret, cost + st);
  }
  return (ret);
}

int main()
{
  string A, B;
  cin >> A;
  cin >> B;
  auto p = solve(A, B);
  reverse(begin(A), end(A));
  reverse(begin(B), end(B));
  cout << min(p, solve(A, B)) << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <string.h>
#define LL long long
using namespace std;
int n;
LL gcd(LL a,LL b){
    if(b==0) return a;
    else return gcd(b,a%b);
}
void solve(){
    LL ans = 1;
    LL gc =1;
    LL x;
    while(n--){
        scanf("%lld",&x);
        LL t = gcd(x,gc);
        gc = (x/t*gc);
    }
    cout<<gc<<endl;
}
int main()
{

    while(~scanf("%d",&n)){
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, M;
i64 X[1010], Y[1010], Z[1010];

i64 waf(i64 v, int s)
{
	return s == 0 ? v : -v;
}

int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; ++i) {
		scanf("%lld%lld%lld", X + i, Y + i, Z + i);
	}

	i64 ret = 0;

	for (int s = 0; s < 8; ++s) {
		vector<i64> bests;

		for (int i = 0; i < N; ++i) {
			bests.push_back(waf(X[i], s & 4) + waf(Y[i], s & 2) + waf(Z[i], s & 1));
		}

		sort(bests.begin(), bests.end());
		reverse(bests.begin(), bests.end());

		i64 tmp = 0;
		for (int i = 0; i < M; ++i) tmp += bests[i];

		ret = max(ret, tmp);
	}

	printf("%lld\n", ret);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define md (ll)(1e9+7)

const int M=1e6+6;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

vector<ll> adj[M],tope,rev[M];
ll vist[M],dp[M];

void dfs(ll u)
{
	ll i;
	vist[u]=1;
	for(i=0;i<adj[u].size();i++)
	{
		if(!vist[adj[u][i]])
			dfs(adj[u][i]);
	}
	tope.pb(u);
	return;
}

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

	ll n,m,i,u,v,ans = 0;

	cin >> n >> m;

	for(i=1;i<=m;++i)
	{
		cin >> u >> v;
		adj[v].pb(u);
		rev[u].pb(v);
	}

	for(i=1;i<=n;++i)
	{
		if(vist[i] == 0)
			dfs(i);
	}

	reverse(tope.begin(),tope.end());

	for(auto k:tope)
	{
		dp[k] = 0;
		for(auto j:rev[k])
			dp[k] = max(dp[k],dp[j]+1);
		ans = max(ans,dp[k]);
	}

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


Measured memory_bytes: 63480
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>   
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
//nCr mod m
#define MOD 998244353
#define M 1000000
vector<ll> fact;
bool h=false;
void init(){
	h=true;
	fact=vector<ll>(M);
	fact[0]=fact[1]=1;
	loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
	if(!h)init();
	if(n<0||r<0||n<r)return 0;//??????
	ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
	return out;
}
signed main(){
	ll n,a,b,k;
	cin>>n>>a>>b>>k;
	ll out=0;
	rep(i,n+1)if(k-a*i>=0&&(k-a*i)%b==0){
		int A=i,B=(k-a*A)/b;
		(out+=nCr(n,A)*nCr(n,B)%MOD)%=MOD;
	}
	cout<<out<<endl;
}











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

string S;
int main(){
    cin >> S;
    int ans = 0;
    for(int i=0;i<S.size();i++){
        int now = 0;
        for(int j=i;j<S.size();j++){
            if(S[j]=='A' || S[j]=='G' || S[j]=='C' || S[j]=='T') now++;
            else{
                ans = max(ans,now);
                break;
            }
        }
        ans = max(ans,now);
    }
    cout  << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b[100],e=0;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>b[i];
        if(b[i]!=i)
        {
            e++;
        }

    }
    if(e==2||e==0)
    {
        cout<<"YES"<<endl;
    }

    else
    {
        cout<<"NO"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256