akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int mountCnt = 0;
  
  
  cin >> mountCnt;
  int viewCnt = mountCnt;
  int z = mountCnt;
  vector<int> vec(mountCnt);
  for(int i=0;i<mountCnt;i++){
    cin >> vec.at(i);
  }
  for(int i=0;i<mountCnt;i++){
    if(i == 0)continue;
    for(int j=0;j<i;j++){
      if(vec.at(i) < vec.at(j)){
        viewCnt--;
        break;
      }
       }
    }
    
       cout << viewCnt << endl;
       
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int n = 8, size = 1;
	int MSP[100000]; MSP[0] = 6;
	while(n < 300000){
		bool flag = true;
		for(int i=0;MSP[i]*MSP[i]<=n&&i<size;i++){
			if(n%MSP[i]==0) { flag = false; break; }
		}
		if(flag) { MSP[size++] = n; }
		n += 5;
		flag = true;
		for(int i=0;MSP[i]*MSP[i]<=n&&i<size;i++){
			if(n%MSP[i]==0) { flag = false; break; }
		}
		if(flag) { MSP[size++] = n; }
		n += 2;
	}
	while(true){
		cin >> n;
		if(n==1) break;
		cout << n << ":";
		for(int i=0;i<size;i++){
			if(n%MSP[i]==0) cout << " " << MSP[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 1012
from collections import deque

n, k = map(int, input().split())
r, s, p = map(int, input().split())
ttt = input()

que = deque([], maxlen=k)

score = 0
for i, t in enumerate(ttt):
  if i >= k and ttt[i-k] == t:
    t_ = que.popleft()
    if t_ is not None:
      que.append(None)
      continue
      
  if t == 'r':
    score += p
  elif t == 's':
    score += r
  else:
    score += s
  
  que.append(True)
else:
  print(score)

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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

void solve() {
    int n, m;
    read(n, m);
    vt<string> a(n), b(m);
    
    read(a, b);
    
    FOR(i, n - m + 1) {
        FOR(j, n - m + 1) {
            bool ok = 1;
            FOR(k, m) {
                if (a[i + k].substr(j, m) != b[k]) {
                    ok = 0;
                    break;
                }
            }
            if (ok) {
                print("Yes");
                return;
            }
        }
    }
    
    print("No");
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
    //read(tt);
    FOR(tt) {
//        write("Case #", i + 1, ": ");
        solve();
    }
    
}



Measured memory_bytes: 3668
n, k = map(int, input().split())
data = [0 for i in range(n)]
for j in range(k):
  d = int(input())
  input_line = list(map(int, input().split()))

  for i in input_line:
    data[i-1] += 1

result = 0
for i in data:
  if i == 0:
    result += 1

print(result)

Measured memory_bytes: 9192
S = input()
SL = int(S[0:2])
SR = int(S[2:4])

if 1 <=SL <= 12:
    if 1<= SR<=12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
elif 1<=SR<=12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
/*
  Contest 071
  A - Meal Delivery
  Rakesh Kumar --> 09/09/2020
 */

#include <bits/stdc++.h>

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

    int x = 0, a = 0, b = 0;
    std::cin >> x >> a >> b;
    if (std::abs(x - a) < std::abs(x - b))
        std::cout << "A" << std::endl;
    else
        std::cout << "B" << std::endl;

    return 0;
}


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

#define rep(i,N) for(int i=0;i<(int)(N);i++)
#define REP(i,k,N) for(int i=k;i<(int)(N);i++)

#define vi vector<int>
#define pb push_back

#define pdd pair<double,double>
#define fi first
#define se second
const double  EPS = 1e-7;

double dist(double x,double y){
    return x*x+y*y;
};

int main(){
//    ifstream in("d_in.txt");
//    cin.rdbuf(in.rdbuf());
    int n;
    while(cin >> n,n){
        int ma = 1;
        pdd p[330];
        rep(i,n) cin >> p[i].fi >> p[i].se;
        rep(i,n-1){
            REP(j,i+1,n){

                double x1,y1,x2,y2,x3,y3;
                tie(x1,y1) = p[i];
                tie(x2,y2) = p[j];
                double cx1,cy1,cx2,cy2;
                if(dist(x1-x2,y1-y2)  > 4+EPS  ) continue;

                //はりまコーナー
//                double ax,ay,bx1,by1,bx2,by2,mx,my,dx,dy;
//                ax=x1-x2;ay=y1-y2;
//                mx=(x1+x2)/2;my=(y1+y2)/2;
//                by1 = (-0.5)*pow(ax,4)+pow(ax,2)+(-0.5)*pow(ax,2)*pow(ay,2)
//                        /dist(ax,ay);
//                by1 = sqrt(abs(by1));
//                by2 = -1*by1;
//                cy1= my+by1;
//                cy2= my+by2;
//                bx1= -1*(ay*by1)/ax;
//                bx2= -1*(ay*by2)/ax;
//                cx1=bx1+mx;
//                cx2=bx2+mx;


                //あじのりコーナー
                double mx=(x1+x2)/2,my=(y1+y2)/2;

                double ld = sqrt(1-dist((x1-x2),(y1-y2))/4);
                double theta = atan((y2-y1)/(x2-x1));
                cx1 = mx - sin(theta)*ld;
                cy1 = my + cos(theta)*ld;
                cx2 = mx + sin(theta)*ld;
                cy2 = my - cos(theta)*ld;

                int cnt1 = 0,cnt2=0;
                for(int k = 0;k<n;k++) {
                    tie(x3, y3) = p[k];
                    if (EPS + 1> dist((cx1 - x3), (cy1 - y3))) cnt1++;
                    if (EPS + 1> dist((cx2 - x3), (cy2 - y3))) cnt2++;
                }
                ma = max({cnt1,cnt2,ma});
            }
        }
        cout<< ma << endl;
    }
    return 0;
}


Measured memory_bytes: 3540
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
  	int N;
  	cin >> N;
  	double x[N];
  	string u[N];
  	double sum = 0;
  	for(int i = 0; i < N; ++i){
      cin >> x[i];
      cin >> u[i];
    }
    for(int i = 0; i < N; ++i){
      if(u[i] == "BTC")
      	sum += x[i] * 380000.0;
      else
        sum += x[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
"use strict";
function Main (input) {
const age = parseInt(input);
const yes = age === 3 || age === 5 || age === 7;
console.log(yes ? "YES" : "NO");
}

//標準入力から文字列を受け取ってMain関数を実行
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22964
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int res = 0;
		for(int i=0; i<n; i++) {
			res += f(sc.nextLong());
		}
		sc.close();
		System.out.println(res);
	}
	
	int f(long a) {
		if(a%2 != 0) return 0;
		else return f(a/2) + 1;
	}
}

Measured memory_bytes: 33936
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);


ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll a,b,k;
  cin>>a>>b>>k;
  rep(i,k){
    if(i%2==0){
      b+=a/2;
      a-=(a+1)/2;
    }else{
      a+=b/2;
      b-=(b+1)/2;
    }
  }
  cout<<a<<' '<<b<<endl;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
    
def main():
    n=inp()
    a=inpl()
    S=sum(a)
    pre = 0
    for i in range(n):
        pre+=a[i]
        if pre == S/2:
            print(0)
            return
        if pre > S/2:
            x=pre
            y=pre-a[i]
            break
    x = abs(S-2*x)
    y= abs(S-2*y)
    print(min(x,y))
if __name__ == "__main__":
    main()

Measured memory_bytes: 83336
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};
lld ans = 0;
int dp[26];
struct trie{
	trie* next[26];
	int cnt[26];
	trie(){
		for(int e=0;e<26;e++) next[e] = NULL;
		for(int e=0;e<26;e++) cnt[e] = 0;
	}
	void add(string& now,int wh){
		for(int e=0;e<26;e++) if(dp[e]) cnt[e]++;
		if(sz(now)==wh) return;
		int nx = now[wh] - 'a';
		dp[nx]--;
		if(next[nx]==NULL) next[nx] = new trie();
		next[nx]->add(now,wh+1);
	}
	void find(string& now,int wh){
		int nx = now[wh]-'a';
		if(sz(now)==wh+1){
			ans += cnt[nx];
			return;
		}
		if(next[nx]==NULL) return;
		next[nx]->find(now,wh+1);
	}
};
string arr[222222];
trie* rt;
bool tmr(string& a,string& b){
	if(sz(a)!=sz(b)) return sz(a) > sz(b);
	return a < b;
}
int main(void){
	rt = new trie();
	int n;
	scanf("%d",&n);
	for(int e=0;e<n;e++){
		cin >> arr[e];
		reverse(all(arr[e]));
	}
	sort(arr,arr+n,tmr);
	for(int e=0;e<n;e++){
		memset(dp,0,sizeof(dp));
		for(int p=0;p<sz(arr[e]);p++) dp[(int)(arr[e][p]-'a')]++;
		rt->find(arr[e],0);
		rt->add(arr[e],0);
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 324232
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#define INF 1e8
using namespace std;

//firstにh、secondにwを入れる
typedef pair<int, int> PII;

//S、1...Nまでの座標を格納する
PII cheese[10];

const int MAX_H = 1010, MAX_W = 1010;
int H, W, N;
char field[MAX_H][MAX_W];
int d[MAX_H][MAX_W];

int dh[] = {1, 0, -1, 0};
int dw[] = {0, 1, 0, -1};

bool infield(int h, int w){
    return (0<=h && h<H && 0<=w && w<W);
}

//sからgまでの最短手数を返す
int bfs(PII s, PII g){
    queue<PII> que;
    //init
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++)
            d[i][j] = INF;
    }
    //fill(d, d+sizeof(d), INF);
    que.push(s);
    d[s.first][s.second] = 0;
    
    while(!que.empty()){
        PII p = que.front(); que.pop();
        if(p == g)
            break;
        for(int i=0; i<4; i++){
            int nh = p.first+dh[i];
            int nw = p.second+dw[i];
            
            if(infield(nh, nw) && field[nh][nw]!='X' && d[nh][nw]==INF){
                que.push(PII(nh, nw));
                d[nh][nw] = d[p.first][p.second] + 1;
            }
        }
    }
    
    return d[g.first][g.second];
}

void solve(){
    int ans = 0;
    
    //cheeseリストを作る
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(field[i][j] == 'S')
                cheese[0] = PII(i, j);
            
            for(char c='1'; c<='9'; c++){
                if(field[i][j] == c)
                    cheese[c-'0'] = PII(i, j);
            }
        }
    }
    for(int i=0; i<N; i++)
        ans += bfs(cheese[i], cheese[i+1]);
    printf("%d\n", ans);
}

int main(){
    scanf("%d%d%d", &H, &W, &N);
    for(int i=0; i<H; i++)
        scanf("%s", field[i]);
    solve();
    return 0;
}

Measured memory_bytes: 6028
#include <stdio.h>
void print(int A[],int n){
	int i;
	for(i=0;i<n;i++){
		printf("%d",A[i]);
		if(i<n-1)
		printf(" ");
	}
	printf("\n");
}

int main(void){

	int i,j,A[200],count=0,n,minj,temp;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&A[i]);
	for(i=0;i<n;i++){
		minj = i;
		for(j=i;j<n;j++){
			if(A[j] < A[minj]) minj = j;
		}
		if(A[i]!=A[minj])count++;
		temp = A[i];
		A[i]= A[minj];
		A[minj] = temp;
	}
	print(A,n);
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 1796
main = interact $ unlines . map (show' . gamble) . read' . lines
 where
  read' ("0 0 0":_) = []
  read' (nmp:xs) = ((n, m, fromIntegral p), votes) : read' (drop n xs)
   where
    [n,m,p] = map read (words nmp)
    votes = map read (take n xs)
  show' r = case r of {Nothing -> "0"; (Just e) -> show e}

gamble :: ((Int, Int, Double), [Int]) -> Maybe Int
gamble ((n,m,p), vs)
 | vs!!(m-1) == 0 = Nothing
 | otherwise = Just $ floor $ fromIntegral (sum vs * 100) * (100.0-p) / (100 * fromIntegral (vs!!(m-1)))

Measured memory_bytes: 5188
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = lc()
ans = []

for si in s:
    if si == "1":
        ans.append("9")
    else:
        ans.append("1")
        
print("".join(ans))

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

int main(){
  char S[3],T[3];
  cin >> S[0] >> S[1] >> S[2] >> T[0] >> T[1] >> T[2];
  int ans=0;
  if(S[0]==T[0]) ans++;
  if(S[1]==T[1]) ans++;
  if(S[2]==T[2]) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

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

N = int(input())
x1 = y1 = t1 = 0

for _ in range(N):
	t2,x2,y2 = inpl()
	dt = t2 - t1
	d = abs(x2 - x1) + abs(y2 - y1)
	if dt < d:
		print('No')
		sys.exit()
	else:
		if (dt-d)%2 != 0:
			print('No')
			sys.exit()
	x1,y1,t1 = x2,y2,t2

print('Yes')

Measured memory_bytes: 4080
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,m = list(map(int, input().split()))
ans = -1
for i in range(1,m+1):
    if i*i>m+10:
        break
    if m%i==0:
        if m//i>=n:
            ans = max(ans, i)
        if i>=n:
            ans = max(ans, m//i)
print(ans)

Measured memory_bytes: 63376
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;

int main(int argc, const char * argv[]) {

    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    
    if(x-r < 0 || x+r > W || y-r < 0 || y+r > H)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    
    return 0;
    
}



Measured memory_bytes: 3120
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main() {
	long i, n[1001] = { 0 }, n2[1001] = { 0 }, nn;
	string s;
	stringstream ss;
	while (getline(cin, s)) {
		if (s == "")
			break;
		ss.str("");
		ss << s;
		ss >> nn;
		n[nn]++;
	}
	while (getline(cin, s)) {
		if (s == "")
			break;
		ss.str("");
		ss << s;
		ss >> nn;
		n2[nn]++;
	}
	for (i = 1; i <= 1000; i++)
		if (n[i] * n2[i] > 0)
			cout << i << " " << n[i] + n2[i] << endl;
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) cin >> a.at(i);
	sort(a.begin(), a.end(), greater<int>());
  
	int ret = 0;
	for (int i = 0; i < N; i++) ret += a.at(i) * (i % 2 ? -1 : 1);
	cout << ret << endl;

    return 0;
}


Measured memory_bytes: 3648
//Ace
#include <bits/stdc++.h>
using namespace std;
using in = long long;
using str = string;
using pi = pair<in, in>;
using vi = vector<in>;
#define F first
#define S second
#define pb push_back
#define rep(i, k, n) for (in i = k; i < n; ++i)
#define repr(i, k, n) for (in i = k; i >= n; --i)
#define sz(x) (in) x.size()
#define all(x) begin(x), end(x)
const in MOD = 1e9 + 7;
const in N = 2e5 + 1;

in parent[N];
in bag[N];

void make_set(int v)
{
    parent[v] = v;
    bag[v] = 1;
}

int find_set(int v)
{
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b)
{
    a = find_set(a);
    b = find_set(b);
    if (a != b)
    {
        if (bag[a] < bag[b])
            swap(a, b);
        parent[b] = a;
        bag[a] += bag[b];
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    in n, m;
    cin >> n >> m;

    rep(i, 0, n) make_set(i);

    rep(i, 0, m)
    {
        in x, y;
        cin >> x >> y;
        x--;
        y--;
        union_sets(x, y);
    }

    in ans = 0;
    rep(i, 0, n) ans = max(ans, bag[i]);
    cout << ans;

    return 0;
}

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


#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

void pre(){


}
vi g[200009];
void solve(){


}
int k,dist;
void dfs(int u,int p,int d){
	if(d>=dist) k = u,dist=d;
	trav(i,g[u]) if(i!=p) dfs(i,u,d+1);
}
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin.exceptions(cin.failbit);
	pre();
	int n;cin>>n;
	rep(i,n-1){
		int u,v;cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	dfs(1,0,0);
	dist=0;
	dfs(k,0,0);
	if((dist+1)%3==2){
		cout<<"Second";
	}
	else cout<<"First";
	return 0;
}



Measured memory_bytes: 20608
s = input("")
days = 0
if s == "SUN":
    days = 7
elif s == "MON":
    days = 6
elif s == "TUE":
    days = 5
elif s == "WED":
    days = 4
elif s == "THU":
    days = 3
elif s == "FRI":
    days = 2
elif s == "SAT":
    days = 1
print(days)

Measured memory_bytes: 8892
def main():
    N = int(input())

    ret = 0
    for x in range(1, N + 1):
        if x % 3 == 0: continue
        if x % 5 == 0: continue
        ret += x
    print(ret)


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())


Measured memory_bytes: 9164
N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]
for i in range(N-2):
    if arr[i][0] == arr[i][1] and arr[i+1][0] == arr[i+1][1] and arr[i+2][0] == arr[i+2][1]:
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 62460
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define vlli vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vplli vector< pair< ll,ll> >
#define plli pair< ll,ll >
#define vps vector< pair< string, string> >
#define vpi vector< pair< int, int> >
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n) for(ll i=a;i<n;i++)
#define forr(i,n,a) for(ll i=n-1;i>=a;i--)
#define scan(arr,a,n) for(int i=(a);i<(n);i++)cin>>(arr)[i];
#define print(arr,a,n) for(int i=(a);i<(n);i++)cout<<(arr)[i]<<' ';

const ll inf = 1e18;

ll add(ll x, ll y) {ll res = x + y; return (res >= mod ? res - mod : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= mod ? res % mod : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + mod : res);}
ll power(ll x, ll y) {ll res = 1; x %= mod; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll mod_inv(ll x) {return power(x, mod - 2);}

int main(){
    fast;
    ll n;
    cin>>n;
    ll a;
    map<ll, ll> m;
    ll ans = 0;
    forn(i, 0, n){
        cin>>a;
        m[a]++;
    }
    map<ll, ll>::iterator it;
    for(it=m.begin();it!=m.end();it++){
        ans+=(it->S%2);
    }
    cout<<ans<<endl;
}

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

int main()
{
	int n,k;

	int suu[100000 + 100] = { 0 };
	int a;
	int i;
	int mx;

	cin >> n >> k;

	while (n != 0 && k != 0)
	{
		for (i = 1; i <= n; i++)
		{

			cin >> a;

			suu[i] = a + suu[i - 1];

			if (i >= k)
			{
				if (mx < suu[i] - suu[i - k])
				{
					mx = suu[i] - suu[i - k];
				}

			}

		}

		/*
		for (i = k; i <= n; i++)
		{
			if (mx < suu[i] - suu[i - k])
			{
				mx = suu[i] - suu[i - k];
			}

		}
		*/

		cout << mx << endl;


		cin >> n >> k;
		mx = 0;
	}
	return 0;
}

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

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

fn main() {
    let s:String = read();
    let c = s.chars().step_by(2);
    for i in c {
        print!("{}", i);
    }
    println!("");
}


Measured memory_bytes: 2160
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <queue>
#define inf 0x3F3F3F3F
using namespace std;
struct Node
{
	mutable int x,c,cost;
	operator int&()const{return cost;}
};
priority_queue<Node,vector<Node>,greater<Node> >q;
unordered_map<int,vector<int> >e[100005];
unordered_map<int,int>d[100005];
vector<int>g[100005];
int main(void)
{
	int i,x,y,c,cost,n,m,ans=inf;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i)
	{
		scanf("%d%d%d",&x,&y,&c);
		e[x][c].push_back(y);
		e[y][c].push_back(x);
		g[x].push_back(c);
		g[y].push_back(c);
	}
	d[0][0]=0;q.push((Node){1,0,0});
	while(!q.empty())
	{
		x=q.top().x;c=q.top().c;cost=q.top().cost;q.pop();
		if(d[x].find(0)==d[x].end()||d[x][0]>cost)
		{
			d[x][0]=cost;q.push((Node){x,0,cost});
		}
		if(c==0)
		{
			for(i=0;i<g[x].size();++i)
			{
				y=g[x][i];
				if(d[x].find(y)==d[x].end()||d[x][y]>cost+1)
				{
					d[x][y]=cost+1;q.push((Node){x,y,cost+1});
				}
			}
			continue;
		}
 		for(i=0;i<e[x][c].size();++i)
		{
			y=e[x][c][i];
			if(d[y].find(c)==d[y].end()||d[y][c]>cost)
			{
				d[y][c]=cost;q.push((Node){y,c,cost});
			}
		}
	}
	unordered_map<int,int>::iterator j;
	for(j=d[n].begin();j!=d[n].end();++j)ans=min(ans,j->second);
	if(ans!=inf)printf("%d\n",ans);
	else printf("-1\n");
	return 0;
}


Measured memory_bytes: 80176
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c,d,e,n,f;
    while(scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&n)!=EOF)
    {  f=e-a;
      if(f<=n)
        printf("Yay!\n");
      else
        printf(":(\n");

    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
#define PI 3.141592653589793
#define MOD 1000000007
//#define MOD 998244353
#define ALL(obj) (obj).begin(),(obj).end()
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;}
const ll INF = 1LL << 60;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll n;
    cin >> n;
    vector<P> ki[n];
    for (ll i=0;i<n-1;i++){
        ll a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        ki[a].push_back(P(b,c));
        ki[b].push_back(P(a,c));
    }
    ll color[n];
    bool visited[n];
    fill(visited,visited+n,false);

    queue<P> que;
    que.push(P(0,0));
    while(!que.empty()){
        P p=que.front();
        que.pop();
        ll x=p.first;
        visited[x]=true;
        color[x]=p.second%2;
        for (ll i=0;i<ki[x].size();i++){
            if (visited[ki[x][i].first])continue;
            que.push(P(ki[x][i].first,p.second+ki[x][i].second));
        }
    }
    for (ll i=0;i<n;i++){
        cout << color[i] << endl;
    }
    return 0;
}


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


#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int,int>
#define tiii tuple<int,int,int> >
#define tiiii tuple<int,int,int,int>
#define pl pair<ll> pl
#define vpi vector< pair<int,int> >

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast_io std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)


#define trace(x) cout << '>' << #x << ':' << x << endl;
#define trace2(x,y) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y << endl;
#define trace3(x,y,z) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y <<" | " << #z << ':' << z << endl;
#define trace4(x,y,z,w) cout<< '>' << #x << ':' << x << " | " << #y << ':' << y <<" | " << #z << ':' << z << " | " << #w << ':' << w << endl;

#define REP(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(),(v).end()
#define print(x) cout<<(x)<<endl;

int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};
int toInt(string s){int r=0;istringstream sin(s);sin>>r; return r;}
///////////////////////////////////////////////////////

const int N = 1e5+3;

int n;
int a[N],cost = 0;

int main()
{
	fast_io;
	cout<<fixed;

	cin>>n;

	FOR(i,1,n) cin>>a[i];

	a[0] = 0;
	a[n+1] = 0;

	FOR(i,1,n+1){
		cost += abs(a[i]-a[i-1]);
	}

	FOR(i,1,n){
		int tempcost = cost - abs(a[i]-a[i-1]) - abs(a[i+1]-a[i]) + abs(a[i+1]-a[i-1]);
		cout<<tempcost<<endl;
	}

	return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <set>
using namespace std;
typedef long long int ll;

int main(){
	int n,m; cin >> n >> m;
	vector<int> v[m];
	vector<int> x(n);
	for(int i=0;i<n;i++){
		cin >> x[i];
	}
	sort(x.begin(),x.end());
	for(int i=0;i<n;i++){
		v[x[i]%m].push_back(x[i]);
	}
	ll ans=0;
	ans+=v[0].size()/2;
	if(m%2==0){
		ans+=v[m/2].size()/2;
	}
	for(int i=1;i<=(m-1)/2;i++){
		if(v[i].size()>v[m-i].size()){
			swap(v[i],v[m-i]);
		}
		int cnt=0;
		for(int j=0;j<v[m-i].size();j++){
			int cp=v[m-i][j];
			int res=0;
			while(cp==v[m-i][j]){
				res++;
				j++;
			}
			j--;
			cnt+=res/2;
		}
		ans+=min(cnt,(int)(v[m-i].size()-v[i].size())/2);
		ans+=v[i].size();
	}
	cout << ans << endl;
}

Measured memory_bytes: 6144
#include <stdio.h>
 
int main () {
	int point,a,b, distance1, distance2;
	scanf("%d %d %d", &point, &a, &b);
	
	distance1 = point - a;
	distance2 = point - b;
	if (distance1 < 0) {
		distance1 *= -1;
	} 
	if (distance2 < 0) {
		distance2 *= -1;
	}	 
	if (distance1 < distance2) {
		printf("A\n");
	} else {
		printf("B\n");
	}
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    double a,b,x; cin>>a>>b>>x;
    double ans,theta;
    x/=a;
    if(x>a*b/2) theta=atan2(2*(a*b-x),a*a);
    else theta=atan2(b*b,2*x);
    ans=theta*180/pi;
    printf("%.10lf\n",ans);
	return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

#define	MOD 1000000007

int	main() {
	int N;
	cin >>N;
	vector<int> T(N, 0);
	vector<int> A(N, 0);
	for (int i=0; i<N; i++)
		cin >>T.at(i);
	for (int i=0; i<N; i++)
		cin >>A.at(i);
	vector<int> MX(N, 0);
	vector<int> MI(N, 0);
	MX.at(0)=MI.at(0)=T.at(0);
	for (int i=1; i<N; i++) {
		MX.at(i)=T.at(i);
		if (T.at(i)==T.at(i-1))
			MI.at(i)=1;
		else
			MI.at(i)=T.at(i);
	}
	if (MX.back()<A.back()) {
		cout <<0 <<endl;
		return 0;
	}
	if (MI.back()>A.back()) {
		cout <<0 <<endl;
		return 0;
	}
	MX.back()=MI.back()=A.back();
	for (int i=N-2; i>=0; i--) {
		int mx=A.at(i);
		int mi;
		if (A.at(i)==A.at(i+1))
			mi=1;
		else
			mi=A.at(i);
		MX.at(i)=min(MX.at(i), mx);
		MI.at(i)=max(MI.at(i), mi);
		if (MX.at(i)<MI.at(i)) {
			cout <<0 <<endl;
			return 0;
		}
	}
	long S=1;
	for (int i=1; i<N; i++) {
		S *= MX.at(i)-MI.at(i)+1;
		S %=MOD;
	}
	cout <<S <<endl;
	return 0;
}



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

using namespace std;

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

  return 0;
}
/* vim:set fdm=marker: */


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

int main() {
string s;
cin >> s;
ll n = s.size();
for (ll i = 0; i < n; i++) {
    s.pop_back();
    string a = s.substr(0, (s.size() / 2));
    a += a;
    if (s == a) {
        cout << a.size() << endl;
        return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <unordered_set>
//#define local
#ifdef local
#include "dbg-macro/dbg.h"
#endif
#define ll long long
#define pi (acos(-1))
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
#define vec std::vector
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
int main()
{
    int n;
    cin >> n;
   vec<char> s(n);
    int r = 0, w = 0;
    rep(i, n)
    {
        cin >> s[i];
        if (s[i] == 'R') { ++r; }
        else
        {
            ++w;
        }
    }
    int lw = 0, rr = r;
    int ans;

    ans=r;
#ifdef local
dbg(r,w,lw,rr,ans);

#endif
    rep(i, n)
    {
        if (s[i] == 'R') { --rr; }
        else
        {
            ++lw;
        }
#ifdef local 
	dbg(i,lw,rr);
#endif
        ans = min(ans, max(lw, rr));
    }

    ans=min(ans,w);cout<<ans<<endl;

    return 0;
}

ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}


Measured memory_bytes: 3604
// http://blog.myungwoo.kr/category/ICPC
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <set>
#include <string>

#include <cmath>
#include <vector>
#include <iostream>
#include <iomanip>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VP;


int main() {
	ios::sync_with_stdio(false);
	int n;
	ll x;
	cin >> n >> x;
	VI A(n);
	for (auto& a : A) cin >> a;
	VVI back(n, VI(n));
	for (int i = 0; i < n; ++i) {
		back[i][0] = A[i];
		for (int j = 1; j < n; ++j) {
			back[i][j] = min(back[i][j-1], A[(i-j+n)%n]);
		}
	}
	ll sol = 1LL << 62;
	for (int i = 0; i < n; ++i) {
		ll cur = 0;
		for (int j = 0; j < n; ++j)
			cur += back[j][i];
		sol = min(sol, x*i + cur);
	}
	cout << sol;
}

Measured memory_bytes: 16000
#include <stdio.h>

int main()
{
    int n,m,l[100000],r[100000],liml,limr;

    scanf("%d %d",&n,&m);
    for (int i = 0; i < m; i++)
    {
        scanf("%d %d",&l[i],&r[i]);
    }
    
    liml = l[0];
    limr = r[0];

    for (int i = 1; i < m; i++)
    {
        if(liml < l[i])liml = l[i];
        if(limr > r[i])limr = r[i];
    }
    
    if(limr - liml < 0)
    {
        printf("0");
    }
    else
    {
        printf("%d",limr - liml + 1);
    }
    
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
long long rn, n, d[N], s[N];
vector<int> gr[N];
map<long long, int> mp;
void dfs(int v, int h = 0) {
	for (auto u : gr[v])
		dfs(u, h + 1);
	rn += h;
}
int32_t main() {
	ios_base::sync_with_stdio (false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> d[i], mp[d[i]] = i;
	sort(d, d + n, greater<int> ());
	fill(s, s + n + 1, 1);
	for (int i = 0; i < n - 1; i++) {
		int v = mp[d[i]], valpar = d[i] - n + 2 * s[v];
		if (!mp.count(valpar)) {
			cout << -1;
			return 0;
		}
		int par = mp[valpar];
		if (par == v) {
			cout << -1;
			return 0;
		}
		s[par] += s[v], gr[par].push_back(v);
	}
	dfs(mp[d[n - 1]]);
	if (rn != d[n - 1]) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		for (auto u : gr[i])
			cout << i + 1 << " " << u + 1 << "\n";
	}
	return 0;
}


Measured memory_bytes: 19200
#include "bits/stdc++.h"
using namespace std;
#define fst first
#define scd second
int main()
{
	int h, n;
	pair<int, int> ab[1001];	
	scanf("%d%d", &h, &n);
	for(int i = 0; i < n; ++i)
	{
		scanf("%d%d", &ab[i].fst, &ab[i].scd);
	}
	int dp[10001];
	dp[h] = 0;
	for(int i = 0; i < h; dp[i++] = 1e9);
	for(int i = h; i > 0; --i)
	{
		for(int j = 0; j < n; ++j)
		{
			dp[max(0, i - ab[j].fst)] = min(dp[max(0, i - ab[j].fst)], dp[i] + ab[j].scd);
		}
	}
	printf("%d\n", dp[0]);
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){
  int n,i,j,c,x,y;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    int m[16][16]={0};
    x=(n+1)/2;
    y=(n+1)/2+1;
    for(i=1;i<=n*n;i++){
      if(m[y][x]==0){
	m[y][x]=i;
	x++;
      }
      else{
	x--;
	i--;
      }
      y++;
      if(x<1)	x+=n;
      if(x>n)   x-=n;
      if(y>n)   y-=n;
    }
    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
	printf("%4d",m[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 616
import java.util.*;
import static java.lang.System.out;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int tmp = b;
        b = a;
        a = tmp;
        tmp = c;
        c = a;
        a = tmp;
        out.println(a + " " + b +" " + c);
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<limits.h>
#define ll long long
using namespace std;
int main()
{
	int n;
	cin>>n;
	
	
	int i,j,k;
	int a[n],b[n],c[n];
	
	int dp[n][3];
	for(i=0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	
	for(i=1;i<n;i++)
	{
		dp[i][0] = a[i] + max(dp[i-1][1] , dp[i-1][2]);
		dp[i][1] = b[i] + max(dp[i-1][0] , dp[i-1][2]);
		dp[i][2] = c[i] + max(dp[i-1][0] , dp[i-1][1]);
	}
	
	cout<<max( dp[n-1][0]  ,  max(  dp[n-1][1] , dp[n-1][2] )  );
	
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>

using namespace std;

void solve()
{
	string a, b, c;
	cin >> a >> b >> c;
	cout << a[0] << b[0] << c[0] << endl;
}

int main()
{
	solve();
	return(0);
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const intll INF = 100000000000000000;
const int MOD = 1e9 + 7;

int main() {
  int n , t ;
  cin >> n >> t ;
  vector<intll> v(n+1) ;
  rep(i,n) cin >> v.at(i) ;
  v.at(n) = INF ;
  
  intll ans = 0;
  rep(i,n){
    if(v.at(i)+t <= v.at(i+1) )  ans += t ;
    else                         ans += (v.at(i+1) - v.at(i)) ;
  }
  
  cout << ans <<endl ;
}


Measured memory_bytes: 4776
def func():
    N,K = map(int,input().split())
    S = input()
    L = []
    L.append(0) if S[0] == '0' else 0
    num = '2'
    for i in range(N):
        if num != S[i]:
            L.append(i)
            num = S[i]
    L.append(N)
    L.append(N)
    ans = 0
    for i in range(0,len(L)-K*2-1,2):
        ans = max(ans,L[i+K*2+1]-L[i])
    return N if N < 3 or K >= len(L)//2 else ans
print(func())

Measured memory_bytes: 7156
#include <stdio.h>

int main(){
  int i,j,N,z,miji,count=0,A[100];
  
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
 }
  for(i=0;i<N-1;i++){
    miji=i;
    for(j=i;j<N;j++){
      if(A[j]<A[miji]){
	miji=j;
      }
	
    }
    if(miji!=i){
        z=A[miji];
	A[miji]=A[i];
	A[i]=z;
	count++;
    }
  }
  for(i=0;i<N-1;i++)printf("%d ",A[i]);
  printf("%d",A[N-1]);
  printf("\n%d\n",count);


  return 0;
}



Measured memory_bytes: 2072
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# import numpy as np
# from itertools import permutations
# from itertools import combinations
# from itertools import combinations_with_replacement
# import queue
# import heapq

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    n = int(input())

    book = n - (n // 10) * 10

    if book in [2,4,5,7,9]:
        return 'hon'
    elif book in [0, 1, 6, 8]:
        return 'pon'
    else:
        return 'bon'


def main():
    print(solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
/*
	*#*#*#* Author GaryMr *#*#*#*
	二分？左闭右开？
	long long？
	逆向思维？
	dp？
	贪心？
	匹配括号 左减右>=0
	多组数据清空？
	dp优化用g？
	线段树：左闭右开！
	线段树：find： if(l>=b||r<=a) return 0x3f3f3f3f; if(r<=b&&l>=a) return tree[k];
	线段树：满二叉树 
	vector : insert(v.begin()+位置,val) 
	循环跳出条件 
	代数设出每个值寻找关系？
	优先队列：priority_queue<类型> q;   
	priority_queue<类,vector<类>, less<类> > pq1; 　　　 // 使用递减	
	priority_queue<类，vector<类>, greater<类> > pq2; 　　// 使用递增
	判断括号，判断是否长度为偶数
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;a++)
#define rl(a,b,c) for(int a=b;a>=c;a--)
#define niv vector<int>
#define IT iterator
using namespace std;
const int MAX=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n,/*<=100*/bi;
niv v;
int main(){
	scanf("%d",&n);
	int i=n;
	while(i--){
		scanf("%d",&bi);
		bi--;
		if(v.size()<bi){
			printf("-1\n");
			return 0;
		}
		v.insert(v.begin()+bi,bi+1);
	}
	rb(j,0,n-1) printf("%d\n",v[j]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S.size() 配列名.length()
using namespace std;
typedef unsigned long long ll;

int main(void){
	int n, q;
	cin >> n >> q;
	string s;
	cin >> s;
	int l[n], r[n];
	rep(i, q) cin >> l[i] >> r[i];

	int memo[n];
	memo[0] = 0;
	int cnt = 0;
	for(int i = 1; i < n; i++){
		if(s[i] == 'C' && s[i - 1] == 'A'){
			cnt++;
		}
		memo[i] = cnt;
	}
	rep(i, q){
		cout << memo[r[i] - 1] - memo[l[i] - 1] << endl;
	}

	return 0;
}


Measured memory_bytes: 2176
import java.io.IOException;
import java.util.Scanner;

public class Main {
	static int time = 0;

	public static void main(String[] args) throws IOException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\ALDS1_6_A-in9.txt"));

		int n = scan.nextInt();
		MSTree mst = new MSTree(n);

		for (int y = 0; y < n; y++)
			for (int x = 0; x < n; x++)
				mst.setLeng(x, y, scan.nextInt());

		System.out.println(mst.getMinTree());

		scan.close();
		System.exit(0);
	}
}

class MSTree {
	int[][] leng;
	int[] reach;

	public MSTree(int n) {
		leng = new int[n][n];
		reach = new int[n];
		for (int i = 0; i < n; i++)
			reach[i] = -1;
	}

	public int getMinTree() {
		int min = Integer.MAX_VALUE;
		int xx = 0, yy = 0;
		for (int x = 0; x < leng.length; x++)
			for (int y = x + 1; y < leng[x].length; y++)
				if (leng[x][y] !=-1 && leng[x][y] < min) {
					xx = x;
					yy = y;
					min = leng[x][y];
				}
		reach[xx] = 0;
		reach[yy] = min;
		for (int i = 2; i < reach.length; i++)
			nextMin();

		int total = 0;
		for (int i = 0; i < reach.length; i++)
			total += reach[i];
		return total;
	}

	private void nextMin() {
		int min = Integer.MAX_VALUE;
		int xx = 0, yy = 0;
		for (int x = 0; x < leng.length; x++) {
			if (reach[x] == -1)
				continue;
			for (int y = 0; y < leng[x].length; y++) {
				if (reach[y] != -1||leng[x][y]==-1)
					continue;
				if (leng[x][y] < min) {
					xx = x;
					yy = y;
					min = leng[x][y];
				}
			}
		}
		reach[yy] = min;
	}

	public void setLeng(int x, int y, int length) {
		leng[x][y] = length;
	}

}

Measured memory_bytes: 41440
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

ll calc(ll n, ll m)
{
    ll l = n > m ? n : m;
    ll s = n <= m ? n : m;
    ll mod = l % s;

    if (mod == 0)
    {
        return s;
    }
    else if (mod == 1)
    {
        return 1;
    }
    else
    {
        return calc(s, mod);
    }
}

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

    ll min = a[0];
    for (int i = 1; i < n; i++)
    {
        min = calc(min, a[i]);
        if (min == 1)
        {
            break;
        }
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<assert.h>

#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)>(b))?(b):(a))
#define abs(a)   (((a)<(0))?(-(a)):(a))

typedef long long ll;
typedef unsigned long long ull;

int main(void)
{
	int n, sum = 0, sum2 = 0;
	int* w;
	scanf("%d", &n);
	w = malloc(n * sizeof(int));
	for (size_t i = 0; i < n; i++)
	{
		scanf("%d", w + i);
		sum += w[i];
	}

	for (size_t i = 0; i < n; i++)
	{
		sum2 += w[i];
		if (sum <= sum2 * 2)
		{
			printf("%d", min(-(sum - sum2 - sum2), (sum - (sum2 - w[i]) - (sum2 - w[i]))));
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 128
x,y,a,b,c = map(int,input().split()) 

R=list(map(int,input().split()) )
G=list(map(int,input().split()) )
W=list(map(int,input().split()) )

R.sort(reverse=True)
G.sort(reverse=True)

Z = W+R[0:x] + G[0:y]

Z.sort(reverse=True)

print(sum(Z[0:x+y]))



Measured memory_bytes: 106160
#include<iostream>
#include<math.h>
#include<vector>
#include<stdio.h>
#include<string>
using namespace std;
int main(void){

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


    if(a==1){
        if(b==1){
            cout<<"Draw"<<endl;
            return 0;
        }
    }
    if(a==1){
        cout<<"Alice"<<endl;
        return 0;
    }
    if(b==1){
        cout<<"Bob"<<endl;
        return 0;
    }
    if(a==b){
        cout<<"Draw"<<endl;
        return 0;
    }

    if(a<b){
        cout<<"Bob"<<endl;
        return 0;
    }
    if(b<a){
        cout<<"Alice"<<endl;
        return 0;
    }


    
    
    return 0;

}

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

E = sorted(E,key=lambda x:x[0])

A=[v[0] for v in E]
B=[v[1] for v in E]

A = sorted(A)
B = sorted(B)


if N%2==0:
    A_mid = (A[N//2]+A[N//2-1])
    B_mid = (B[N//2]+B[N//2-1])
    print(B_mid-A_mid+1)
else:
    A_mid = A[N//2]
    B_mid=B[N//2]
    print(B_mid-A_mid+1)


Measured memory_bytes: 144556
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))

    ans = 0
    for i, num in enumerate(a):
        ans += b[num-1]
        if i < len(a)-1:
            if num+1 == a[i+1]:
                ans += c[num-1]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064