akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int cnt1[100010], cnt2[100010], a[100010], mnL1[100010], mnR1[100010], mnL2[100010], mnR2[100010];
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i <= 100001; ++i) {
		mnL1[i] = 2e9;
		mnL2[i] = 2e9;
		mnR1[i] = 2e9;
		mnR2[i] = 2e9;
	}
	vector<int> vec1, vec2;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		if (i % 2 == 1) {
			++cnt1[a[i]];
		} else {
			++cnt2[a[i]];
		}
	}
	for (int i = 1; i <= 100000; ++i) {
		mnL1[i] = n / 2 - cnt1[i];
		mnR1[i] = n / 2 - cnt1[i];
		mnL2[i] = n / 2 - cnt2[i];
		mnR2[i] = n / 2 - cnt2[i];
	}
	for (int i = 1; i <= 100000; ++i) {
		mnL1[i] = min(mnL1[i - 1], mnL1[i]);
		mnL2[i] = min(mnL2[i - 1], mnL2[i]);
	}
	for (int i = 100000; i >= 1; --i) {
		mnR1[i] = min(mnR1[i + 1], mnR1[i]);
		mnR2[i] = min(mnR2[i + 1], mnR2[i]);
	}
	int answer = 2e9;
	for (int i = 2; i <= 100000 - 1; ++i) {
		answer = min(answer, n / 2 - cnt1[i] + min(mnL2[i - 1], mnR2[i + 1]));
		answer = min(answer, n / 2 - cnt2[i] + min(mnL1[i - 1], mnR1[i + 1]));
	}
	cout << answer;
}

Measured memory_bytes: 2944
n = int(input())
ad_list =[[0, 0, 0]]
flag = 0
for i in range(n):
    ad_list.append(list(map(int, input().split())))
for j in range(1, n + 1):
    t = ad_list[j][0] - ad_list[j - 1][0]
    l = abs(ad_list[j][1] - ad_list[j - 1][1]) + abs(ad_list[j][2] - ad_list[j - 1][2])
    if t >= l and t % 2 == l % 2:
        continue
    else:
        flag = 1
if flag == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 27300
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}
///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

// https://melheaven.hatenadiary.jp/entry/atcoder144
///約数の配列を返す
func makeDivisors(_ n:Int) -> [Int] {
    var divisors = [Int]()
    for i in 1..<Int(pow(Double(n), 0.5)) + 1 {
        if n % i == 0{
            divisors.append(i + n / i)
        }
    }
    
    return divisors
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = index(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(rifgt:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = rifgt
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}

func main() {
    let n = readInt()
    var aryInput = [String]()
    var ans = 0
    
    for _ in 1...n {
        let str = readLine()!
        var aryStr = [String]()
        for s in str {
            aryStr.append(String(s))
        }
        aryStr.sort()
        aryInput.append(aryStr.reduce("") { $0 + $1 })
    }
    
    aryInput.sort()
    var left = 0
    var right = 1
    while right < n {
        while right < n && aryInput[left] == aryInput[right] {
            ans += right - left
            right += 1
        }
        left = right
        right += 1
    }
    print(ans)
}
main()


Measured memory_bytes: 15048
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int read(){
	int w=0,f=1;
	char c=' ';
	while(c<'0'||c>'9')c=getchar(),f=c=='-'?-1:f;
	while(c>='0'&&c<='9')w=w*10+c-48,c=getchar();
	return w*f;
}
int n;
int a[N], b[N];
int ca[N], cb[N];
signed main(){
	n = read();
	for(int i = 1; i <= n; i++) a[i] = read(), ca[a[i]]++;
	for(int i = 1; i <= n; i++) b[i] = read(), cb[b[i]]++;
	for(int i = 1; i <= n; i++) if(ca[i] + cb[i] > n) return printf("No\n"), 0;
	reverse(b + 1, b + n + 1);
	vector<int> t;
	int cnt = 0, val = 0, len = 0;
  	set<int> st;
	for(int i = 1; i <= n; i++)
	{
		if(b[i] == a[i])
		{
			cnt++;
			val = b[i];
			t.push_back(i);
          	st.insert(a[i]);
		}
	}
  	assert(st.size() <= 1);
	len = cnt;
	vector<int> s;
	for(int i = 1; i <= n; i++)
	{
	 if(a[i] == b[i]) continue;
	 if(cnt == 0) break;
	 if(a[i] != val && b[i] != val)
	 {
	 	s.push_back(i);
	 	cnt--;
	 }		
	}
	for(int i = 0; i < len; i++)
	{
		swap(b[s[i]], b[t[i]]);
	}
	printf("Yes\n");
	for(int i = 1; i <= n; i++) printf("%d ", b[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 7304
N = int(input())
a = list(map(int, input().split()))
temp = sum(a)
if temp / N > temp // N + 0.5:
  temp = temp // N + 1
else: temp = temp // N
res = 0
for i in range(N):
  res += (a[i] - temp) ** 2
print(res)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

int main(){
  int N; cin >> N;
  string s; cin >> s;
  
  int cnt_r = 0;
  rep(i,N) if (s[i]=='R') cnt_r++;

  int cnt = 0;
  rep(i,cnt_r) {
    if (s[i]=='W') cnt++;
  }
  cout << cnt << endl;






  //cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3748
#include <iostream>
#include <string>

using namespace std;

typedef long long llong;

#define front (0)
#define back  (1)

int main() {
	string S;
	cin >> S;
	llong K;
	cin >> K;

	for (int i = 0; i < S.size(); i++) {
		if(S[i] != '1' && i < K) {
			cout << S[i] << endl;
			exit(0);
		}
	}
	cout << "1" << endl;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

n, a, b = Is()
k = n // (a+b)
l = n % (a+b)
ans = k*a
if a < l:
    ans += a
else:
    ans += l
print(ans)

Measured memory_bytes: 64108
n = int(input())
a = list(map(int,input().split()))

li = [0] * 9

for i in a:
    if i >= 3200:
        li[-1] += 1
    else:
        li[i//400] += 1

ans = 0

for i in range(8):
    if li[i] > 0:
        ans += 1

if li[-1] == 0:
    print(ans, ans)
else:
    if ans == 0:
        print(1, li[-1])
    else:
        print(ans, ans+li[-1])


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

int main() {
  int a,c=0,d=0;
  cin>>a;
  vector<int> b(a);
  for(int i=0;i<a;i++)
    cin>>b[i];
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  for(int i=0;i<a;i++){
    if(i%2==0)
      c+=b[i];
    else
      d+=b[i];
  }
  cout<<c-d<<endl;
}

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

const int maxn=(int)1e5+10;
int a[maxn];
int b[maxn];
int c[maxn];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d %d %d",&a[i], &b[i], &c[i]);
	for(int i=2;i<=n;i++)
	{
		int aa=a[i]+max(b[i-1],c[i-1]);
		int bb=b[i]+max(a[i-1],c[i-1]);
		int cc=c[i]+max(a[i-1],b[i-1]);
		a[i]=aa; b[i]=bb; c[i]=cc;
	}
	printf("%d",max(a[n],max(b[n],c[n])));
}

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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}
int n,m;
ll *a;


int findpos(ll x,int curr){
	for(int i=n; i > 0; i/=2)
		while(curr+i < n && a[curr+i]< x) curr+=i;
	return min(curr,n-1);
}



int main(){
	startTime=clock();
	cin >> n >> m;
	a=new ll[n];
	ll y;
	int x;
	std::vector<pair<ll,int>> w;
	FOR(i,n) cin >> a[i];
	FOR(i,m) {
		cin >> x >> y;
		w.PB(MP(y,x));
	}
	

	sort(a,a+n);
	sort(w.begin(),w.end());
	int curr=0;
	for(int i=m-1;i >=0;i--){
		int y=min(w[i].S+curr-1,findpos(w[i].F,curr));
		if(y >=n) break;
		while(curr <= y ) {
			a[curr]=max(w[i].F,a[curr]);
			curr++;
			
		}
	}
	
	

	ll sum=0;
	FOR(i,n) sum+=a[i];
	cout  << sum;
	
	//FOR(i,n) cout << "\n" << a[i];

	return 0;
}

Measured memory_bytes: 6136
#-*-coding:utf-8-*-

def main():
    A, B = list(map(int, input().split()))
    cul_list = []
    cul_list.append(A + B)
    cul_list.append(A - B)
    cul_list.append(A * B)

    print(max(cul_list))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
from heapq import heappush,heappop
INF=10**18
n,m,r=map(int,input().split())
e=[[] for _ in range(n)]
d=[INF]*n
for i in range(m):
  a,b,c=map(int,input().split())
  e[a].append((b,c))
q=[]
heappush(q,(0,r))
d[r]=0
while q:
  dist,node=heappop(q)
  for to,cost in e[node]:
    if d[to]>cost+dist:
      d[to]=cost+dist
      heappush(q,(d[to],to))
for i in d:
  if i!=INF:print(i)
  else:print('INF')


Measured memory_bytes: 89280
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a) % mod;  a = (a * a) % mod;  b /= 2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 100009;
ll a,b;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>a>>b;
    cout<<a + b / 2;
    return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::{Chars};
use std::cmp::*;
#[fastout]
fn main() {
    input!{
        s: Chars,
    }
    let mut cnt0 = 0;
    let mut cnt1 = 0;
    for i in 0..s.len() {
        if s[i]=='0' {
            cnt0 += 1;
        } else {
            cnt1 += 1;
        }
    }
    println!("{}", 2*min(cnt0, cnt1));
}


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

using namespace std;

#define FOR(i,l,r) for( int i = l ; i < r; i++ )
#define li long long int
#define lma LLONG_MAX

int main() {
    int n; cin>>n;
    li dp[n][n];
    li a[n];
    li p[n+1];
    p[0] = 0;
    FOR(i,0,n) {
        cin>>a[i];
        p[i+1] = a[i]+p[i];
        dp[i][i] = 0;
        if( i > 0 ) dp[i-1][i] = a[i-1]+a[i];
    }
    FOR(j,3,n+1) {
        FOR(i,0,n) {
            int k = i+j-1;
            if( k >= n ) break;
            dp[i][k] = lma;
            FOR(h,i,k) {
                dp[i][k] = min(dp[i][h]+dp[h+1][k],dp[i][k]);
                // cout<<i<<" "<<h<<" "<<k<<"\n";
                // cout<<dp[i][h]<<" "<<dp[h+1][k]<<"\n";
            }
            // cout<<dp[i][k]<<"\n";
            dp[i][k] += p[k+1]-p[i];
            // cout<<i<<" "<<k<<" "<<dp[i][k]<<"\n";
        }
    }
    cout<<dp[0][n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 1664
package main

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

var (
	BufferSize = 100
)

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

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)

	ans := "Yes"
	if n > 9*9 {
		ans = "No"
	} else if n >= 10 {
		for i := 2; i <= 9; i++ {
			if n%i != 0 || n/i > 9 {
				ans = "No"
			} else {
				ans = "Yes"
				break
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
template <class T1, class T2>
void vadd(vector<T1> &v, T2 x);

#define int long long int

void solve(long long N)
{
  lli ret = 0;
  rep(i, N)
  {

    int j = i + 1;
    if (j % 3 == 0 && j % 5 == 0)
    {
      continue;
    }
    else if (j % 3 == 0)
      continue;
    else if (j % 5 == 0)
      continue;
    else
    {
      ret += j;
    }
  }
  cout << ret << endl;
}

signed main()
{
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2>
void vadd(vector<T1> &v, T2 x)
{
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 3768
N = int(input())
txys = [list(map(int, input().split())) for _ in range(N) ]
txys.insert(0, [0, 0, 0])

for i in range(N):
    t1, x1, y1 = txys[i]
    t2, x2, y2 = txys[i+1]
    dt = t2 - t1
    tIsEven = dt % 2 == 0
    dist = abs(x1 - x2) + abs(y1 - y2)
    xyIsEven = dist % 2 == 0
    if tIsEven != xyIsEven or dist > dt:
        print("No")
        exit()
print("Yes")



Measured memory_bytes: 27324
#include<stdio.h>
int main()

{
    int X, equ, equ1, equ2, equ3;

    scanf("%d", &X);

    equ=X%500;

    equ1=(X-equ)/500;

    equ2=equ%5;

    equ3=(equ-equ2);

    printf("%d\n", (equ1*1000)+ equ3);
}


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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i(0);i<N;i++) cin>>A[i];
  ll ans(pow(3,N));
  ll tmp(1);
  for(int i(0);i<N;i++){
    if(A[i]%2==0) tmp *= 2;
  }
  cout << ans - tmp << endl;
  return 0;
}


Measured memory_bytes: 512
package main

import (
	"fmt"
	"sort"
)

func Sorting3(n []int) {
	sort.Ints(n)
		fmt.Printf("%d %d %d\n", n[0], n[1], n[2]);
}

func main(){
	var dataInt []int
	var inp int
	
		for i := 0; i < 3; i++ {		
			fmt.Scan(&inp)
			dataInt = append(dataInt, inp)
		}

	Sorting3(dataInt)
}


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

using namespace std;

typedef long long ll;

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

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

	if(a == b && b == c){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

}


Measured memory_bytes: 256
from collections import defaultdict
N = int(input())
S = list(map(ord, list(input())))
mod = 10**9+7
base = 1234
power = [1]*(N+1)
for i in range(1, N+1):
    power[i] = power[i-1]*base%mod
def check(m):
    if N-m<m:
        return False
    res = 0
    for i in range(m):
        res+=S[i]*power[m-i-1]
        res%=mod
    dic = defaultdict(lambda : -1)
    dic[res] = 0
    for i in range(N-m):
        res = ((res-S[i]*power[m-1])*base
                             +S[i+m])%mod
        if dic[res]>=0:
            index = dic[res]
            if index +m<=i+1:
                return True
        else:
            dic[res] = i+1
    return False
ok = 0
ng = N+1
while ng-ok>1:
    mid = (ok+ng)//2
    
    if check(mid):
        ok = mid
    else:
        ng = mid
print(ok)
        


Measured memory_bytes: 44496
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

// 素数判定O(√n)
bool is_prime(int n){
for(int i=2;i*i<=n;i++){
    if(n%i==0) return false;
}
return n!=1; //1の場合は除外
}

// 約数の列挙O(√n)
vector<ll> divisor(ll n){
vector<ll> res;
for(ll i=1LL;i*i<=n;i++){
    if(n%i==0){
        res.push_back(i);
        if(i!=n/i) res.push_back(n/i);
    }
}
sort(res.begin(), res.end());
return res;
}

// 素因数分解O(√n)
map<int,int> prime_factor(int n){
    map<int,int> res;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            ++res[i];
            n/=i;
        }
    }
    if(n!=1) res[n]=1;
    return res;
}

int prime[100010];     // i番目の素数
bool isprime[100010];   // isprime[i]がtrueならiは素数

// n以下の素数の数を返す
int eratos(int n){
    int p=0;
    for(int i=0;i<=n;i++) isprime[i]=true;
    isprime[0]=isprime[1]=false;
    for(int i=2;i<=n;i++){
        if(isprime[i]){
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i) isprime[j]=false;
        }
    }
    return p;
}

int main(){
	int a,b;
    cin>>a>>b;
    if(a<=9 && b<=9) cout<<a*b<<endl;
    else cout<<-1<<endl;
}

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i);
  }
  vector<int> check(n, 0);
  if(n % 2 == 1)
  {
    for(i = 0; i < n; i += 2)
    {
      if(i == 0) check.at(i) = 1;
      else check.at(i) = 2;
    }
  }
  else
  {
    for(i = 1; i < n; i += 2) check.at(i) = 2;
  }
  bool ok = true;
  for(i = 0; i < n; i++)
  {
    check.at(a.at(i))--;
  }
  for(i = 0; i < n; i++)
  {
    if(check.at(i) != 0)
    ok = false;
  }
  if(!ok) cout << 0 << endl;
  else
  {
    long long ans = 1;
    for(i = 0; i < n/2; i++)
    {
      ans *= 2;
      ans %= 1000000007;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

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 long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

int main() {
    int d,t,s;
    cin >> d >> t >> s;
    if(s*t < d) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string s){
  long long count = 0;
  for(long long i = 0; i < s.size(); i++){
    if(count == 0 && s[i] == 'C') {
      count++;
    }
    else if(count == 1 && s[i] == 'F') {
      cout << YES << endl;
      return;
    }
  }

  cout << NO << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string s;
  std::cin >> s;
    solve(s);
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	int n, d, ans = 0;
	double dist=0;
	cin >> n >> d;
	int x[11][11];
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= d; j++)
		{
			cin >> x[i][j];
		}
	}

	for (int k = 1; k < n; k++)
	{
		for (int i = k + 1; i <= n; i++)
		{
			for (int j = 1; j <= d; j++)
			{
				dist += (double)pow((x[k][j] - x[i][j]), 2);
			}
			dist = pow(dist, 0.5);
			if ((double)((int)dist) == dist)ans++;
			dist = 0;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <stack>
#include <string>
#include <iomanip>
#include <queue>
#include <deque>
#include<cstring>
#include<limits>
#include <sstream>
#include <stdio.h>
#include<unordered_map>
using namespace std;
#define sz(x) (x).size()
#define all(v) (v).begin(),(v).end()
#define m_p make_pair
void run()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
}
void fast()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int main()
{

	fast();
	int n;
	cin >> n;
	set<int>s;
	int x;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		s.insert(x);
	}
	cout << s.size() << endl;
return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i = l; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
  int n;
  scanf("%d", &n);
  int dp[n+1] = {};
  int h[n+1];
  rep(i,1,n+1) scanf("%d", &h[i]);
  rep(i,2,n+1) {
    if(i-2 == 0) dp[i] = dp[i-1] + abs(h[i-1]-h[i]);
    else dp[i] = min(dp[i-1] + abs(h[i-1]-h[i]), dp[i-2] + abs(h[i-2]-h[i]));
  }
  printf("%d\n", dp[n]);
  return 0;
}

Measured memory_bytes: 1024
import itertools
import math

N = int(input())

towns = []
for _ in range(N):
    towns.append(tuple(map(int, input().split())))

tot = 0
for path in itertools.permutations(towns, N):
    path_length = 0
    for i, (x, y) in enumerate(path[:-1]):
        path_length += math.sqrt(
            (x - path[i + 1][0]) ** 2 + (y - path[i + 1][1]) ** 2
        )
    tot += path_length

print(tot / math.factorial(N))


Measured memory_bytes: 3064
#include<stdio.h>

int main(){
    int arr[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}, K;
    scanf("%d", &K);
    printf("%d\n", arr[K - 1]);
    return 0;
}


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

typedef long long ll;
const ll INF = 1LL<<60, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define all(v) (v).begin(), (v).end()

template<class T> inline void chmax(T &a, T b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, T b) {if(a > b) a = b;}

ll n,dp[100010][4],a[100010][3];

ll rec(ll x,ll y){
  if(x==n) return 0;
  if(dp[x][y] != -1) return dp[x][y];
  ll sum = 0;
  rep(i,3){
    if(y==i) continue;
    chmax(sum, rec(x+1, i)+a[x][i]);
  }
  return dp[x][y] = sum;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin >> n;
  rep(i,n){
    rep(j,3){
      cin >> a[i][j];
      dp[i][j] = -1;
    }
  }
  rep(i,n) dp[i][3] = -1;
  cout << rec(0,3) << endl;
  return 0;
}

Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int dx[] = { -1 , -1 , -1 , 0 , 0 , 0 , 1 , 1 , 1 };
const int dy[] = { -1 , 0 , 1 , -1 , 0 , 1 , -1 , 0 , 1 };
#define N 8010000
#define TC int t;cin>>t;for(int T=1;T<=t;T++)
#define mod 1000000007
#define PI acos(-1)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
void AIA() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isprim(int x){
	for(int j=2;j*j<=x;j++){
		if(x%j==0){
			return 0;
		}
	}
	return (x!=1);
}

//cout<<fixed<<setprecision(20);
// freopen("stand.in","r",stdin);
// freopen("stand.out","w",stdout);

/*
 _____________              __                ___        ___       __________________________     ____        ____
|             |            /\ \              |   |      |   |     |                          |    \   \      /   /
|   __________|           / /\ \             |   |      |   |     |     _____      _____     |     \   \    /   /
|  |                     / /  \ \            |   |      |   |     |    |     |    |     |    |      \   \  /   /
|  |                    / /    \ \           |   |      |   |     |    |     |    |     |    |       \   \/   /
|  |______             / /      \ \          |   |______|   |     |    |     |    |     |    |        \      /
|         |           / /        \ \         |              |     |    |     |    |     |    |         \    /
|   ______|          / /          \ \        |    ______    |     |    |     |    |     |    |          |  |
|  |                / /============\ \       |   |      |   |     |    |     |    |     |    |          |  |
|  |               / /==============\ \      |   |      |   |     |    |     |    |     |    |          |  |
|  |              / /                \ \     |   |      |   |     |    |     |    |     |    |          |  |
|  |             / /                  \ \    |   |      |   |     |    |     |    |     |    |          |  |
|__|            /_/                    \_\   |___|      |___|     |____|     |____|     |____|          |__|

							<<<<<<<<<<< NEVER GIVE UP !! >>>>>>>>>>>
							<<<<<<<< YOU CAN DO IT IF YOU WANT !! >>>>>>>>
							<<<<<<<<< BELIEVE IN YOURSELF !! >>>>>>>>>
*/

int main()
{
	//cout<<fixed<<setprecision(20);
	//freopen("stand.in","r",stdin);
	//freopen("stand.out","w",stdout);
	AIA();
    int n , k;
    cin>>n>>k;
    vector<int>v(n);
    for(int i=00;i<n;i++){
    	cin>>v[i];
	}
	sort(all(v));
	ll sum = 0;
	for(int i =0 ; i < k ; i++){
		sum+=v[i];
	}
	cout<<sum;
	return 0;
}

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

class BNode{
public:
	int value;
	BNode *right,*left;
};

class BTree{
	BNode *root;
	void Inorder(BNode *cur){
		if(cur){
			Inorder(cur->left);
			cout << " " << cur->value;
			Inorder(cur->right);
		}
	}
	void Preorder(BNode *cur){
		if(cur){
			cout << " " << cur->value;
			Preorder(cur->left);
			Preorder(cur->right);
		}
	}
public:
	BTree(){
		root = NULL;
	}
	void Insert(int v){
		BNode *cur = root;
		BNode *prt = NULL;
		BNode *node = new BNode();
		node->value = v;
		
		while(cur){
			prt = cur;
			if(cur->value < v){
				cur = cur->right;
			}else{
				cur = cur->left;
			}
		}
		if(prt){
			if(prt->value > v){
				prt->left = node;
			}else{
				prt->right = node;
			}
		}
		if(!root){
			root = node;
		}
	}
	void PrintInorder(){
		Inorder(root);
		cout<<endl;
	}
	void PrintPreorder(){
		Preorder(root);
		cout<<endl;
	}
	void Find(int v){
		BNode *cur = root;
		
		while(cur){
			if(cur->value == v){
				cout<<"yes"<<endl;
				return;
			}else if(cur->value > v){
				cur = cur->left;
			}else{
				cur = cur->right;
			}
		}
		cout<<"no"<<endl;
		
	}
};

int main() {
	BTree bt;
	int m, v;
	string com;
	
	cin>>m;
	for(int i=0;i<m;++i){
		cin>>com;
		if(com=="insert"){
			cin>>v;
			bt.Insert(v);
		}else if(com=="print"){
			bt.PrintInorder();
			bt.PrintPreorder();
		}else if(com=="find"){
			cin>>v;
			bt.Find(v);
		}
	}
	
	return 0;
}

Measured memory_bytes: 13712
#define DEBUG 0

/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-6-1 21:12:09
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <random>
#include <chrono>
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

/*
void Yes()
{
  cout << "Yes" << endl;
  exit(0);
}

void No()
{
  cout << "No" << endl;
  exit(0);
}
*/

/*
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
*/

// const ll MOD = 1000000007;

typedef tuple<int, int> X;

ll sum = 0;
int N;
ll c[10010];
int ind = 0;
bool visited[10010];
vector<int> V[10010];
ll assign[10010];

void dfs(int v)
{
  if (!visited[v])
  {
    visited[v] = true;
    assign[v] = c[ind++];
    for (auto x : V[v])
    {
      dfs(x);
    }
  }
}

int main()
{
  cin >> N;
  for (auto i = 0; i < N - 1; i++)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    V[b].push_back(a);
    V[a].push_back(b);
  }
  for (auto i = 0; i < N; i++)
  {
    cin >> c[i];
  }
  sort(c, c + N);
  reverse(c, c + N);
  fill(visited, visited + N, false);
  dfs(0);
  for (auto i = 0; i < N; i++)
  {
    for (auto j : V[i])
    {
      sum += min(assign[i], assign[j]);
    }
  }
  cout << sum / 2 << endl;
  for (auto i = 0; i < N; i++)
  {
    cout << assign[i];
    if (i < N - 1)
    {
      cout << " ";
    }
    else
    {
      cout << endl;
    }
  }
}

Measured memory_bytes: 1280
from collections import deque

n, m = map(int, input().split())

n_in = [0] * n
graph = [[] for _ in range(n)]
for i in range(n+m-1):
    A, B = map(int, input().split())
    n_in[B-1] += 1
    graph[A-1].append(B-1)

root = 0
for i in range(n):
    if n_in[i] == 0:
        root = i
        break

parent = [0] * n
q = deque([root])
count = 0
while q:
    node = q.popleft()
    for next_v in graph[node]:
        parent[next_v] = node+1
        n_in[next_v] -= 1
        if n_in[next_v] == 0:
            q.append(next_v)

for i in range(n):
    print(parent[i])




Measured memory_bytes: 69920
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<ll> A(N), B(N), C(N);
  for(int i=0;i<N;++i) cin>>A[i];
  for(int i=0;i<N;++i) cin>>B[i];
  for(int i=0;i<N;++i) cin>>C[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  ll ans = 0;
  ll index1, index2;
  for(int i=0;i<N;++i) {
    index1 = lower_bound(A.begin(), A.end(), B[i])-A.begin();
    index2 = upper_bound(C.begin(), C.end(), B[i])-C.begin();
    ans += index1*(N-index2);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 5632
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;

# define N 10
# define k 3

int main()
{
	int i,A[11];
	for (i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	sort(A, A + N);
	for (i = N - 1; i > N - k - 1; i--) cout << A[i] << endl;		//输出后 k 位
	return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a = vector<int>();
    for (int i = 0; i < n; i++) {
        int aa;
        cin >> aa;
        a.push_back(aa);
    }
    float sra = 0;
    for (int i = 0; i < n; i++) {
        sra += 1.0 / a[i];
    }
    float r = 1 / sra;
    printf("%.5f\n", r);
//    cout << fixed << r << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    private static int[][] dp;
    private static int calculate(int i, int j, String s, String t){
        if(i >= s.length() || j >= t.length()) return 0;
        if(dp[i][j] != -1) return dp[i][j];
        if(s.charAt(i) == t.charAt(j)){
            dp[i][j] = 1 + calculate(i + 1, j + 1, s, t);
            return dp[i][j];
        }else {
            int x = calculate(i + 1, j, s, t);
            int y = calculate(i, j + 1, s, t);
            dp[i][j] = Math.max(x, y);
            return dp[i][j];
        }
    }

    private static String process(int i, int j, String s, String t){
        if(i >= s.length() || j >= t.length()) return "";
        if(s.charAt(i) == t.charAt(j)){
            return s.charAt(i) +""+ process(i + 1, j + 1, s, t);
        }else {
            if(calculate(i + 1, j , s, t) < calculate(i, j + 1, s, t)){
                return process(i, j + 1, s, t);
            }else {
                return process(i + 1, j, s, t);
            }
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        String s = br.readLine();
        String t = br.readLine();
        dp = new int[s.length()][t.length()];
        for(int i = 0; i < dp.length; i++){
            Arrays.fill(dp[i], -1);
        }
        calculate(0, 0, s, t);

        sb.append(process(0, 0, s, t));
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}


Measured memory_bytes: 89264
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, M; cin >> N >> M;
    vl cnt(N, 0);
    REP(i, M){
        ll a, b; cin >> a >> b; a--; b--;
        cnt[a]++; cnt[b]--;
    }
    
    bool ok = true; ll sum = 0;
    REP(i, N){
        sum += cnt[i];
        if(sum%2 == 1){
            ok = false; break;
        }
    }
    cout << (ok ? "YES" : "NO") << endstr;
    return 0;
}


Measured memory_bytes: 1024
#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <utility>

using namespace std;
typedef long long ll;
typedef long double ld;

ll solve(void);

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

ll hoge(ll x, ll y)
{
	if (x % y == 0) {
		return y;
	}
	if (x == 1) return 1;
	return hoge(y, x % y);
}

ll solve(void)
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	ll gcd = hoge(c,d);
	ll lcm = c * d / gcd;

	ll da = a - 1 - ((a-1)/c + (a-1)/d - (a-1)/(lcm));
	ll db = b - (b/c + b/d - b/lcm);

	cout << db - da << endl;


	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <memory.h>
using namespace std;

int n,a[100005];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	sort(a+1,a+n+1);
	long long i1=0,i2=0;
	for(int i=n;i>1;i--){
		if(a[i]==a[i-1]){
			if(i1==0) i1=a[i];
			else i2=a[i];
			i--;
		}
		if(i2) break;
	}
	cout<<i1*i2<<endl;
return 0;
}

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


int main() {
    vector<vector<char>>data(3,vector<char>(3));
    rep(i,3){
        rep(j,3)cin>>data[i][j];
    }
    cout <<data[0][0]<<data[1][1]<<data[2][2]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#define ll long long
#define double long double

using namespace std;

int main() {
    double q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    //sort by value
    double prices[4] = {q, h, s, d};
    double litres[4] = {0.25, 0.5, 1, 2};
    pair<double, pair<double, double>> vpl[4];
    for (int i = 0; i < 4; i++) {
        vpl[i] = {prices[i]/litres[i], {prices[i], litres[i]}};
    }
    //sort
    sort(vpl, vpl + 4);
    ll price_to_pay = 0;
    for (int i = 0; i < 4; i++) {
        price_to_pay += (int)(n/vpl[i].second.second) * vpl[i].second.first;
        n = fmodl(n, vpl[i].second.second);
    }
    cout << price_to_pay;
}

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

const int mod=1000000007,iv2=(mod+1>>1);
int f[3010][3010],a[3010],x,y,n,m,g[3010][3010],nw,ans;

int main()
{
	scanf("%d%d",&n,&m),nw=1;
	for (int i=1; i<=n; i++) scanf("%d",&a[i]);
	for (int i=1; i<=n; i++)
		for (int j=1; j<=n; j++) f[i][j]=(a[i]>a[j]);
	while (m--)
	{
		nw=2ll*nw%mod,scanf("%d%d",&x,&y);
		g[x][x]=g[y][y]=0;
		g[y][x]=g[x][y]=1ll*iv2*(f[x][y]+f[y][x])%mod;
		for (int i=1; i<=n; i++) if (i!=x&&i!=y)
			g[i][y]=g[i][x]=1ll*iv2*(f[i][x]+f[i][y])%mod,
			g[x][i]=g[y][i]=1ll*iv2*(f[x][i]+f[y][i])%mod;
		for (int i=1; i<=n; i++) f[i][x]=g[i][x],f[i][y]=g[i][y],f[x][i]=g[x][i],f[y][i]=g[y][i];
	}
	ans=0;
	for (int i=1; i<=n; i++)
		for (int j=i+1; j<=n; j++) ans=(ans+1ll*nw*f[i][j])%mod;
	return printf("%d\n",ans),0;
}

Measured memory_bytes: 70912
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    x, y = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    flag = False
    for i in range(x+1):
        if 2*i + 4*(x-i) == y:
            print("Yes")
            flag = True

    if flag == False:
        print("No")


resolve()

Measured memory_bytes: 61684
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	k := readInt()
	a, b := readInt(), readInt()

	for i := a; i <= b; i++ {
		if i%k == 0 {
			fmt.Println("OK")
			return
		}
	}
	fmt.Println("NG")
}


Measured memory_bytes: 1756
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <unordered_map>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

int const MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-12;
int INF = INT_MAX / 10;

bool z = false;

bool dfs(int u, int p, vector<vector<int> >& G) {
	int x = 0;
	for (int v: G[u]) if (v != p) x += dfs(v, u, G);
	if (x == 0) return true;
	if (x == 1) return false;
	z = true;
	return false;
}

int main() {
	int N; cin >> N;
	if (N % 2) {
		cout << "First" << endl;
		return 0;
	}
	vector<vector<int> > G(N);
	rep(i, N - 1) {
		int u, v; scanf("%d%d", &u, &v);
		u--; v--;
		G[u].pb(v);
		G[v].pb(u);
	}
	dfs(0, -1, G);
	cout << (z ? "First" : "Second") << endl;
}


Measured memory_bytes: 5888
from collections import deque
def resolve():
    N = int(input())
    G = [[] for _ in range(N)]
    nextV = []

    for _ in range(N - 1):
        a, b = map(lambda x: int(x) - 1, input().split())
        G[a].append(b)
        nextV.append(b)

    q = deque()
    q.append(0)
    color = [0] * N
    while q:
        v = q.popleft()
        parentC = color[v]
        c = 1
        for to in G[v]:
            if c == parentC:  # 親と同じ色だったら次の色を使用
                c += 1
            color[to] = c
            c += 1
            q.append(to)

    print(max(color))
    for b in nextV:
        print(color[b])


if __name__ == "__main__":
    resolve()


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

int main() {
	int x, n, a;
	map<int, int> mps;
	scanf("%d %d", &x, &n);
	for(int i = 0;i < n;i++){
		scanf("%d", &a);
		mps[a]++;
	}int ans = x;
	a = 0;
	while(1){
		if(!mps[ans - a]){
			ans -= a;
			break;
		}
		if(!mps[ans + a]){
			ans += a;
			break;
		}
		a++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 3796
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int S;
    cin >> S;

    int h,m,s;

    h = S / (60*60);
    S -= (60*60)*h;

    m = S / 60;
    S -= 60*m;
    s = S;

    cout << h << ":" << m << ":" << s << endl;

    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n, k, c;
string s;
int main() {
    cin >> n >> k >> c;
    cin >> s;
    vector<int> l(k, 0);
    vector<int> r(k, 0);

    int lnow = 0;
    for(int i = 0; i < n; ) {
        if(s.at(i) == 'o') {
            l.at(lnow) = i;
            lnow++;
            if(lnow == k) break;
            i += c+1;
        }else i++;
    }

    int rnow = k-1;
    for(int i = n-1; i >= 0; ) {
        if(s.at(i) == 'o') {
            r.at(rnow) = i;
            rnow--;
            if(rnow == -1) break;
            i -= c+1;
        }else i--;
    }

    for(int i = 0; i < k; ++i) {
        if(l.at(i) == r.at(i)) {
            cout << l.at(i)+1 << endl;
        }
    }
}

Measured memory_bytes: 3332
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int mod = 1e9+7;
const int inf = 1e9+9;
const ll MOD = 1e9+696969;
const long long INF = 1e18+3;
#define maxn 1000100

ll dp[60];

char s[3][60];
int type[60], slen;

void addmod(int &x, int v) {
	x += v;
	while (x >= mod) x -= mod;
}
int n;
int main()
{
	scanf("%d", &n);
	scanf("%s", s[1] + 1);
	scanf("%s", s[2] + 1);
	for (int i=1; i<=n; ++i)
		if (s[1][i] == s[2][i]) type[i] = 1;
		else type[i] = 2;
	
	if (type[1] == 1) dp[1] = 3;
	else dp[1] = 6;
	if (type[1] == 2) slen = 1;
	for (int i=2; i<=n; ++i)
	{
		if (type[i] == 2)
		{
			++slen;
			if (slen % 2 == 0) dp[i] = dp[i-1];
			else
			{
				if (slen == 1) dp[i] = (dp[i-1] * 2LL)%mod;
				else dp[i] = (dp[i-1] * 3LL)%mod;
			}
		}
		if (type[i] == 1)
		{
			if (slen > 0) dp[i] = dp[i-1];
			else dp[i] = (dp[i-1] * 2LL)%mod;
			slen = 0;
		}
	}
	
	cout << dp[n] % mod;
}


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

using namespace std;

using ll = long long;

ll calc(ll x) {
    if (x <= 0) return 0;

    ll res = 0;
    for (int i = 0; i < 40; i++) {
        ll hoge = (1LL << (i + 1));
        ll foo = x / hoge;
        ll bar = x % hoge;
        ll cnt = foo * hoge / 2;
        cnt += max(bar - hoge / 2 + 1, 0LL);
        if (cnt % 2 == 1) res |= (1LL << i);
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b;
    cin >> a >> b;
    cout << (calc(b) ^ calc(a - 1)) << endl;
    return 0;
}

Measured memory_bytes: 256