akhauriyash/Code-Regression huggingface dataset:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, M = getNM()
W = []
V = []
for i in range(M):
    a, b = getNM()
    W.append(b)
    V.append(a)

# magicを重複ありで適当に組み合わせて合計Nを目指す
def knapsack_4(N, limit, weight, value):
    dp = [float('inf')] * (limit + 1)
    dp[0] = 0

    for i in range(1, limit + 1):
        for j in range(N):
            if i < value[j]:
                dp[i] = min(dp[i], weight[j])
            else:
                dp[i] = min(dp[i], dp[i - value[j]] + weight[j])
    return dp[-1]
print(knapsack_4(M, N, W, V))


Measured memory_bytes: 83976
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
#define mREP(a,b) for (int i = a; i == (b); --i)
#define mod 1e9 + 7
typedef long long ll;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	　　　　　 　 _... ..._
	　　　　　 , ´⌒ ⌒ヽ
	　　　 　 ﾉｨ（ノﾉ）ﾉ）ﾉ）
	　　　 　 （（q|.ﾟ ヮﾟﾉ|ﾊ
	　　　　　　△ﾑ,8ﾑﾌつ
	　　　　　/(ﾝ_/＿ヽ＼
	　　　　 ～～i_ﾌ_ﾌ～´
	*/
	int n, t;
	cin >> n >> t;
	int ans = 1e9;
	vector<int>time(n);
	vector<int>cost(n);
	rep0(i, n - 1) {
		cin >> cost[i] >> time[i];
	}
	rep0(j, n - 1) {
		if (t >= time[j]) {
			ans = min(ans, cost[j]);
		}
	}
	if (ans == 1e9) {
		cout << "TLE" << endl;;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
MOD = 10 ** 9 + 7

memo = [{} for _ in range(N)]

def ok(last4):
    if last4.find('AGC') != -1:
        return False
    for i in range(3):
        t = list(last4)
        t[i], t[i+1] = t[i+1], t[i]
        if ''.join(t).find('AGC') != -1:
            return False
    return True

def dfs(i, last3):
    if i == N:
        return 1
    if last3 in memo[i]:
        return memo[i][last3]
    ret = 0
    for s in 'ACGT':
        if ok(last3+s):
            ret = (ret + dfs(i+1, last3[1:]+s)) % MOD
    memo[i][last3] = ret
    return ret

answer = dfs(0, 'TTT')
print(answer)


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

using namespace std;

int N;
int main(){
    cin >> N;
    int cnt = 0;
    for(int i=0; i<N; i++){
        int x;
        cin >> x;
        if( x % 2 ) cnt++;
    }
    cout << ( cnt % 2 ? "NO" : "YES") << endl;
    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
//int freq[10];
int main()
{


    int row,col;
    cin>>row>>col;
    char mat[row*2+1][col+1];
    for(int i=1;i<=2*row;i++)
    {

        for(int j=1;j<=col;j++)
        {
            cin>>mat[i][j];
        }
        i++;
        for(int j=1;j<=col;j++)
        {
            mat[i][j]=mat[(i-1)][j];
        }
    }
    for(int i=1;i<=row*2;i++)

        {for(int j=1;j<=col;j++)
    {
        cout<<mat[i][j];
    }
    cout<<endl;
        }

}



Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    a1 = int(input())
    a.append(a1)
z = -1
s = 0
for h in range(n):
    if a[s] == 2:
        z = 'Yes'
        z = h+1
        break
    else:
        s = a[s]-1
print(z)

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

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	map<ll,ll> mp;
	rep(i,n){
		cin >> a[i];
		mp[a[i]]++;
	}
	
	ll ans = 0;
	
	for(auto p : mp){
		ans += p.second*(p.second-1)/2;
	}
	
	ll temp = ans;
	
	rep(i,n){
		ll c = mp[a[i]];
		ans = ans - c*(c-1)/2 + (c-1)*(c-2)/2;
		cout << ans << endl;
		ans = temp;
	}
	
    return 0;
}



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

    int n;
    cin >> n;

    string s;
    cin >> s;

    for(int i=0;i<s.length();i++){
        s[i] = (s[i] - 'A' + n) % 26 + 'A';
    }

    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(){
    string ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int n;
    string s;
    scanf("%d ",&n);
    cin >> s;
    for (int i = 0; i < s.size(); i++){
        char c = s[i];

        cout << ch[(c-'A'+n)%26];
    }

}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class CAttackSurvival {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,k,q,a;
        in>>n>>k>>q;
        vector<int> p(n,k-q);
        fr(i,q) in>>a,++p[--a];
        fr(i,n) out<<(p[i]>0?"Yes":"No")<<endl;
    }
};

int main() {
    CAttackSurvival solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	char a[300000];
	int ans[300000] = {};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i < n; i++) {
		if (a[i] == 'E') {
			ans[0]++;
		}
	}
	for (int i = 1; i < n; i++) {
		if (a[i - 1] == 'E'&&a[i] == 'E') {
			ans[i] = ans[i - 1] - 1;
		}
		else if (a[i - 1] == 'E'&&a[i] == 'W') {
			ans[i] = ans[i - 1];
		}
		else if (a[i - 1] == 'W'&&a[i] == 'W') {
			ans[i] = ans[i - 1] + 1;
		}
		else if (a[i - 1] == 'W'&&a[i] == 'E') {
			ans[i] = ans[i - 1];
		}
	}
	sort(ans, ans + n);
	cout << ans[0] << endl;
}

Measured memory_bytes: 1664
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()

	diccnt, divlist := getDivlistSlow(n)

	minf := 100000 * 100000
	for i := 0; i < diccnt; i++ {
		a := divlist[i]
		now := f(a, n/a)
		minf = min(minf, now)
	}

	fmt.Println(minf)

}

func f(a int, b int) int {
	return max(keta(a), keta(b))
}

// 約数列挙リストを作成(愚直)
func getDivlistSlow(a int) (cnt int, divlist []int) {
	for i := 1; i*i <= a; i++ {
		if a%i == 0 {
			cnt++
			divlist = append(divlist, i)
			if i*i != a {
				cnt++
				divlist = append(divlist, a/i)
			}
		}
	}
	sort.Ints(divlist) // 昇順ソート
	return cnt, divlist
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// 正数の桁数を返す
func keta(n int) int {
	keta := 0
	if n == 0 {
		return 1
	}
	for n > 0 {
		keta++
		n /= 10
	}
	return keta
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1884
import java.util.Scanner;

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();

        for (int i = 0, x = a; i < 1000; i += 1, x += a) {
            if (x % b == c) {
                System.out.println("YES");
                return;
            }
        }

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

Measured memory_bytes: 21844
a = gets.chomp
b = gets.chomp
c = gets.chomp
d = gets.chomp
e = gets.chomp
arr = [a, b, c, d, e]

num_of_1 = [a[-1].to_i, b[-1].to_i, c[-1].to_i, d[-1].to_i, e[-1].to_i]
min = num_of_1[0]
4.times do |i|
    if num_of_1[i+1] != 0 && num_of_1[i+1] < min
        min = num_of_1[i+1]
    end
end

sum = 0
5.times do |i|
    if num_of_1.find_index(min) != i
        sum += arr[i].to_i
        if sum.to_s[-1].to_i != 0
            sum += 10 - sum.to_s[-1].to_i
        end
    end
end

puts sum + arr[num_of_1.find_index(min)].to_i

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

#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pr(a, b) pair<a, b>
#define si set<int>
#define sl set<long long>
#define pq prioirty_queue
#define all(v) v.begin(),v.end()
#define left (2*idx)+1
#define right (2*idx)+2
#define frt(i,a,b) for(ll i=a; i<b; i++)
#define rew(i,a,b) for(ll i=a; i>=b; i--)
#define fre(i,a,b) for(ll i=a; i<=b; i++)
#define pb push_back

#define test if(!true)
#define N 100007
#define MOD (ll)(1e9 + 7)

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

    for(int i=0; i<3; i++)
    {
        if(s[i] == s[i+1])
        {
            cout << "Bad\n";
            return 0;
        }
    }
    cout << "Good\n";
    return 0;
}

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

int dp[101010],a[105],b[105];
int n,w,kotae;
int main(){
  cin>>n>>w;
  rep(i,n)cin>>a[i]>>b[i];
  dp[0]=0;
  for(int i=0;i<n;i++){
    for(int j=w;j>=b[i];--j){
      if(dp[j-b[i]]+a[i]>dp[j]){
        dp[j]=dp[j-b[i]]+a[i];
      }
        kotae=max(kotae,dp[j]);
    }
  }
  cout<<kotae<<endl;
  return 0;
}


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

void call(int n)
{
    int i = 1;
    while(i <= n)
    {
        int x = i;
        if((x % 3) == 0){
            cout << " " << i;
            i++;
            continue;
        }
        while(x)
        {
            if((x % 10) == 3)
            {
                cout << " " << i;
                i++;
                break;
            }
            x /= 10;
        }
        if(!x) i++;
        
    }

    cout << endl;
}

int main(void)
{
    int n;
    cin >> n;

    call(n);

    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/ 
using namespace std;

#define endl "\n"
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define re(i,a) for(ll i=0; i<a; ++i)
#define tr(i,v) for(auto &i: v)
#define mem(a,val) memset(a,val,sizeof(a))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define in(v,n) vll v(n);re(i,n) cin>>v[i]
#define printVec(v,s) cout << s; tr(i, v) cout << i << " ";
#define sz(v)	((ll)((v).size()))
#define dbgv(c, v) cout << c << " = " << v << endl;
#define P(x)				cout<<#x<<" = { "<<x<<" }\n"

typedef int ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<ll, ll> pll;
typedef vector< pll > vpll;
typedef vector< ll > vll;
typedef complex<double> point;

const long long MOD = 1000000007;
const long long inf = 1e18;
const double EPS = (1e-7);
inline ll dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}
ll h, v, k;
vector<vector<char>> mat;
vb rows, cols;
ll cnt = 0;

ll countBlacks() {
  ll c = 0;
  re(i, h) {
    if(!rows[i]) continue;
    re(j, v) {
      if(cols[j] and mat[i][j] == '#') c++;
    }
  }
  return c;
}

void solveCols(ll col) {
  if(col == v){
    if(countBlacks() == k) cnt++;
    return;
  }
  solveCols(col+1);
  cols[col] = 0;
  solveCols(col+1);
  cols[col] = 1;
}

void solveRows(ll row) {
  if(row == h){
    cols = vb(v, 1);
    solveCols(0);
    return;
  }
  solveRows(row + 1);
  rows[row] = 0;
  solveRows(row + 1);
  rows[row] = 1;
}

void solve(){
  cin>> h>>v>>k;
  mat = vector<vector<char>>(h, vector<char>(v));
  rows = vb(h, 1);
  cols = vb(v, 1);
  re(i, h) {
    re(j, v) {
      cin >> mat[i][j];
    }
  }
  solveRows(0);
  cout << cnt;
}

int main()
{
 
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    	solve();
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int N;
    string S;
    cin >> N >> S;

    vector<int> cnt1(N),cnt2(N);
    rep(i,0,N){
        if(S[i]=='E') ++cnt1[i];
        else ++cnt2[i];
        if(i){
            cnt1[i]+=cnt1[i-1];
            cnt2[i]+=cnt2[i-1];
        }
    }

    int ans=inf;
    rep(i,0,N){
        int l=i==0?0:cnt2[i-1];
        int r=cnt1[N-1]-cnt1[i];
        ans=min(ans,l+r);
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 2964
A,V=map(int, input().split())
B,W=map(int, input().split())
T=int(input())

if W>=V:
    print("NO")
    quit()

SA=abs(A-B)

IDOU=V-W

IDOUTARN=IDOU*T

ANS=SA-IDOUTARN

if ANS<=0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9092
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <cmath>
#include <math.h>

#define	MOD 1000000007;
#define PI 3.14159265358979323846;
#define rep(i,n) for(ll i = 0;i<(ll)n;i++)
using namespace std;
typedef long long ll;
static const int MAX = 1000;
static const long long INFTYL = 9223372036854775807;
static const int INFTY = 2147483647;
ll mod = 1000000007;
static const long long N = 100000;
long long Combination(long long n, long long r)
{
	long long result = 1;
	if (n < 0 || r < 0 || r > n) {
		return -1;
	}

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	int numerator[N];
	int denominator[N];

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) {
			result *= numerator[k];
			//result %= 1000000007;
		}
	}

	return result;
}

int main()
{
	int N, A, B;
	cin >> N >> A >> B;
	ll v[50];
	rep(i, N) {
		cin >> v[i];
	}

	sort(v, v + N);

	double sum = 0;
	for (int i = N - 1; i > N - 1 - A; i--) {
		sum += v[i];
	}

	printf("%.6f\n", sum / A);

	bool same = true;

	ll V = v[N - 1];
	for (int i = N - 1; i > N - 1 - A; i--) {
		if (v[i] != V) {
			same = false;
			break;
		}
	}

	ll minValue = v[N - A];

	int Ncount = 0;
	int Acount = 0;
	rep(i, N) {
		if (v[i] == minValue) {
			Ncount++;
			if (i > N - 1 - A) {
				Acount++;
			}
		}
	}

	if (Ncount == Acount) {
		cout << 1 << endl;
	}
	else {
		if (same) {
			ll sumcount = 0;
			ll maxCount = min(B, Ncount);
			for (int i = A; i <= maxCount; i++) {
				sumcount += Combination(Ncount, i);
			}
			cout << sumcount << endl;
		}
		else {
			cout << Combination(Ncount, Acount) << endl;
		}
	}

	return 0;
}

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

using namespace std;
#define int long long
const int INF = 200000000007;


  
signed main(){
    int n;
    cin>>n;
    vector<int> h[n];
    int a,b;
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        h[a-1].push_back(b-1);
        h[b-1].push_back(a-1);

    }
    queue<pair<int,int>> que;
    bool used[n]={};
    used[0]=true;
    que.push(make_pair(0,0));
    pair<int,int> t,t2;
    while(!que.empty()){
        t=que.front();
        que.pop();
        for(int i=0;i<h[t.first].size();i++){
            if(!used[h[t.first][i]]){
                used[h[t.first][i]]=true;
                que.push(make_pair(h[t.first][i],t.second+1));
            }
        }
    }
    fill(used,used+n,0);
    used[t.first]=true;
    que.push(make_pair(t.first,0));
   
    while(!que.empty()){
        t2=que.front();
        que.pop();
        for(int i=0;i<h[t2.first].size();i++){
            if(!used[h[t2.first][i]]){
                used[h[t2.first][i]]=true;
                que.push(make_pair(h[t2.first][i],t2.second+1));
            }
        }
    }

    if(t2.second%3==1)cout<<"Second";
    else cout<<"First";
    return 0;
}

Measured memory_bytes: 16368
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <time.h>
#include <bits/stdc++.h>

#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
const ll INF=1e18+5;
int dp[100005];
vector<vector<int>>graph;
int longest(int node){
    if(dp[node]!=-1)return dp[node];
    int ans=0;
    for(int n : graph[node]){
        ans=max(ans,longest(n));
    }
    return dp[node]=ans+1;
}
int main() {
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    IO;
     int n , m ;
     cin>>n>>m;
     graph.resize(n+2);
     int a ,b;
     memset(dp,-1, sizeof(dp));
     for(int i = 0 ; i< m ; i++){
         cin>>a>>b;
         graph[a].push_back(b);
     }
     int ans=0;
     for(int i =1 ;i <= n ; i++){
         ans=max(ans,longest(i));
     }
     cout<<ans-1<<endl;
}


Measured memory_bytes: 8192
/*
     ॐ त्र्यम्बकं यजामहे सुगन्धिं पुष्टिवर्धनम् |
     उर्वारुकमिव बन्धनान्मृत्योर्मुक्षीय माऽमृतात् ||
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int            long long int
#define F              first
#define S              second
#define pb             push_back
#define si             set <int>
#define vi             vector <int>
#define pii            pair <int, int>
#define vpi            vector <pii>
#define vpp            vector <pair<int, pii>>
#define mii            map <int, int>
#define mpi            map <pii, int>
#define spi            set <pii>
#define endl           "\n"
#define sz(x)          ((int) x.size())
#define all(p)         p.begin(), p.end()
#define double         long double
#define que_max        priority_queue <int>
#define que_min        priority_queue <int, vi, greater<int>>
#define bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)       for(auto x : a) cout << x << " "; cout << endl
#define print1(a)      for(auto x : a) cout << x.F << " " << x.S << endl
#define print2(a,x,y)  for(int i = x; i < y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
     int x = 1;
     while (b)
     {
          if (b & 1) x *= a;
          a *= a;
          b >>= 1;
     }
     return x;
}

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

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...);
}

const int N = 200005;
int a[N], n, m, k;

void solve()
{
     cin >> k >> m >> n;

     int x = (m + k - 1) / k;
     x *= k;
     if (x <= n)
          cout << "OK";
     else
          cout << "NG";

}

int32_t main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);



     cout << setprecision(9) << fixed;
     clock_t z = clock();
     solve();
     cerr << "Run Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

     return 0;
}

Measured memory_bytes: 3804
#include <stdio.h>

int	min(int a, int b)
{
	if (a < b)
	{
		return (a);
	}
	return (b);
}

int	main(void)
{
	int			step_num;
	int			broken;
	int			steps[100001] = {};
	long		dp[100001] = {};
	const long	MOD = 1000000007;

	scanf("%d %d", &step_num, &broken);
	for (int i = 0; i < broken; i++)
	{
		int broken_i;
		scanf("%d", &broken_i);
		steps[broken_i] = 1;
	}
	dp[0] = 1;
	dp[1] = 1;
	for (int i = 2; i <= step_num; i++)
	{
		if (!steps[i - 1])
		{
			dp[i] += dp[i - 1];
		}
		if (!steps[i - 2])
		{
			dp[i] += dp[i - 2];
		}
		dp[i] %= MOD;
	}
	printf("%ld\n", dp[step_num]);
	return (0);
}


Measured memory_bytes: 1280
from collections import deque
n = int(input())
path = [[] for _ in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    path[a].append(b)
    path[b].append(a)
C = sorted(list(map(int,input().split())),reverse = True)
M = sum(C[1:])
ans = [-1]*n
que = deque([0])
i = 0
while que:
    p = que.popleft()
    ans[p] = C[i]
    i += 1
    for nxt in path[p]:
        if ans[nxt] >= 0:continue
        que.append(nxt)
print(M)
print(' '.join(str(i) for i in ans))


Measured memory_bytes: 6260
a, b, c, d = map(int, input().split())
 
def gcd(x, y):
    if y > x:
        return gcd(y, x)
    if x % y == 0:
        return y
    return gcd(y, x%y)
 
cd = c * d // gcd(c, d)
 
b_div = b - b//c - b//d + b//cd
a_div = a-1 - (a-1)//c - (a-1)//d + (a-1)//cd
 
print(b_div - a_div)

Measured memory_bytes: 3064
from collections import deque, Counter

n, x, y = map(int, input().split())

neighbor = [[] for _ in range(n)]

for i in range(n-1):
    neighbor[i].append(i+1)
    neighbor[i+1].append(i)

neighbor[x-1].append(y-1)
neighbor[y-1].append(x-1)

dist = [[-1] * n for _ in range(n)]

for i in range(n):
    d = deque([(i, 0)])
    dist[i][i] = 0

    while len(d) > 0:
        node, length = d.pop()

        for ne in neighbor[node]:
            if dist[i][ne] < 0:
                dist[i][ne] = length + 1
                d.appendleft((ne, length+1))

c = []
for i in range(n):
    c.append(Counter(dist[i]))

for i in range(1, n):
    total = 0
    for j in range(n):
        total += c[j][i]
    print(total // 2)

Measured memory_bytes: 382472
#include<stdio.h>
#include<string.h>
typedef long long ll;
const int mod=1000000007;
const int go[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int mul(int a,int b){return(ll)a*b%mod;}
int x[40],y[40],sx[1000010],sy[1000010],ix[1000010],iy[1000010],mx,my;
bool bx[1000010],by[1000010],mp[70][70];
int dis[70][70],vx[70],vy[70];
struct pr{
	int x,y;
	pr(int x=0,int y=0):x(x),y(y){}
}q[4010];
bool ok(int x,int y){
	return 0<x&&x<=mx&&0<y&&y<=my&&!mp[x][y];
}
void bfs(pr t){
	int head,tail,x,y,i;
	memset(dis,63,sizeof(dis));
	head=tail=1;
	q[1]=t;
	dis[t.x][t.y]=0;
	while(head<=tail){
		t=q[head++];
		for(i=0;i<4;i++){
			x=t.x+go[i][0];
			y=t.y+go[i][1];
			if(ok(x,y)&&dis[t.x][t.y]+1<dis[x][y]){
				dis[x][y]=dis[t.x][t.y]+1;
				q[++tail]=pr(x,y);
			}
		}
	}
}
int main(){
	int h,w,n,i,j,k,l,res,tmp;
	scanf("%d%d%d",&h,&w,&n);
	for(i=1;i<=n;i++){
		scanf("%d%d",x+i,y+i);
		bx[++x[i]]=1;
		by[++y[i]]=1;
		sx[x[i]]++;
		sy[y[i]]++;
	}
	res=0;
	for(i=1;i<=h;i++)sx[i]+=sx[i-1];
	for(i=1;i<=w;i++)sy[i]+=sy[i-1];
	ix[1]=++mx;
	for(i=2;i<=h;i++){
		if(!bx[i]&&!bx[i-1]){
			ix[i]=ix[i-1];
			(res+=mul(mul(i-1,w)-sx[i-1],mul(h-i+1,w)-(sx[h]-sx[i-1])))%=mod;
		}else
			ix[i]=++mx;
	}
	iy[1]=++my;
	for(i=2;i<=w;i++){
		if(!by[i]&&!by[i-1]){
			iy[i]=iy[i-1];
			(res+=mul(mul(i-1,h)-sy[i-1],mul(w-i+1,h)-(sy[w]-sy[i-1])))%=mod;
		}else
			iy[i]=++my;
	}
	for(i=1;i<=h;i=j){
		for(j=i;ix[j]==ix[i];j++);
		vx[ix[i]]=j-i;
	}
	for(i=1;i<=w;i=j){
		for(j=i;iy[j]==iy[i];j++);
		vy[iy[i]]=j-i;
	}
	for(i=1;i<=n;i++)mp[ix[x[i]]][iy[y[i]]]=1;
	for(i=1;i<=mx;i++){
		for(j=1;j<=my;j++){
			if(!mp[i][j]){
				bfs(pr(i,j));
				tmp=0;
				for(k=i;k<=mx;k++){
					for(l=1;l<=my;l++){
						if((k>i||l>j)&&!mp[k][l])(tmp+=mul(dis[k][l],mul(vx[k],vy[l])))%=mod;
					}
				}
				(res+=mul(tmp,mul(vx[i],vy[j])))%=mod;
			}
		}
	}
	printf("%d",(res+mod)%mod);
}

Measured memory_bytes: 16128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
bool canPair(pair<int, int> &r, pair<int, int> &b)
{
    return r.first < b.first and r.second < b.second;
}
int main()
{
    int N, ans = 0;
    cin >> N;
    vint a(N), b(N), c(N), d(N);
    vector<pair<int, int>> R(N), B(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i] >> b[i];
        R[i] = {a[i], b[i]};
    }
    for (int i = 0; i < N; i++)
    {
        cin >> c[i] >> d[i];
        B[i] = {c[i], d[i]};
    }
    sort(all(B));
    sort(all(R), [](const pair<int, int> &a, const pair<int, int> &b) { return a.second > b.second; });
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (canPair(R[j], B[i]))
            {
                ans++;
                R[j] = {INT_MAX, INT_MAX};
                break;
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<map>
#include<cstdlib>
#include<cctype>
#include<string>

using namespace std;

typedef long long ll;
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;

const int d[]={0,1,0,-1};

#define SQR(x) ((x)*(x))
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define reps(i,j,n) for(int i = (j) ; i < (n) ; ++i )
#define rep(i,j) reps(i,0,j)
#define INF (1 << 30)
#define dout(x,n) fixed << setprecision(n) << x

int getint(){ int x; cin >> x; return x;}
string itos(int v) {stringstream ss;ss<<v;return ss.str();}
int stoi(string s) {int v; stringstream ss(s);ss>>v;return v;}


int main(){
  int h,w;
  char mas[51][51];
  int cost[51][51];
  fill_n(cost[0],51*51,INF);
  cost[0][0] = 0;

  cin >> h >> w;
  rep(i,h) rep(j,w) cin >> mas[i][j];
  queue<Pii> que;
  que.push(Pii(0,Pi(0,0)));
  while(!que.empty()){
    Pii p = que.front(); que.pop();
    int nx = p.sc.fr + 1 , ny = p.sc.sc;
    if(nx >= 0 && nx < h && ny >= 0 && ny < w){
    int c = p.fr + mas[nx][ny] - '0';
    if(cost[nx][ny] > c){
      que.push(Pii(c,Pi(nx,ny)));
      cost[nx][ny] = c;
    }
    }
    nx = p.sc.fr , ny = p.sc.sc + 1;
    if(nx >= 0 && nx < h && ny >= 0 && ny < w){
    int  c = p.fr + mas[nx][ny] - '0';
    if(cost[nx][ny] > c){
      que.push(Pii(c,Pi(nx,ny)));
      cost[nx][ny] = c;
    }
    }
  }
  cout << cost[h-1][w-1] << endl;
}

Measured memory_bytes: 1292
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {

  int N, a, b, imos[1000005]={1};
  cin>>N;
  REP(i,0,N){
    cin>>a>>b;
    imos[a]++;
    imos[b+1]--;
  }
  REP(i,1,1000005) imos[i] += imos[i-1];

  int ans = 0;
  REP(i,0,1000005){
    if(imos[i] >= i) ans = max(ans, i);
  }

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

Measured memory_bytes: 7020
#include <bits/stdc++.h>
using namespace std;
void debug() {cout<<endl;}
template<typename T,typename... Args>
void debug(T x,Args... args) {cout<<x<<" ";debug(args...);}
#define forn(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;

const int N = 1e5+5;
vector<int> g[N];
int dp[N];

int dfs(int u) {
    if (dp[u] != -1) return dp[u];
    dp[u] = 0;
    for (auto &v : g[u]) {
        dp[u] = max(dp[u], dfs(v)+1);
    }
    return dp[u];
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    
    forn(i, 0, m) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
    }
    
    memset(dp, -1, sizeof dp);
    int ans = 0;
    forn(i, 0, n) {
        if (dp[i] == -1) {
            ans = max(ans, dfs(i));
        }
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

string a,b,c;

int main(){
    cin >> a >> b >> c;
    if(a.back() == b[0] && b.back() == c[0])cout << "YES" << endl;
    else cout << "NO" << endl;

}

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

int main() {
	int en, H;
	int N;
	cin >> N;

	vector<int> x(N), y(N), h(N);
	for (int i = 0; i < N; i++)
	{
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] > 0) en = i;
	}

	for (int cx = 0; cx <= 100; cx++)
	{
		for (int cy = 0; cy <= 100; cy++)
		{
			H = h[en] + abs(x[en] - cx) + abs(y[en] - cy);
			for (int i = 0; i < N; i++)
			{
				if (max(H - (int)abs(x[i] - cx) - (int)abs(y[i] - cy), 0) != h[i]) break;
				if (i == N-1) {
					cout << cx << ' ' << cy << ' ' << H;
					return 0;
				}
			}
		}
	}
}


Measured memory_bytes: 256
object Main extends App {
  val Array(a,b,c) = readLine.split(" ").map{_.toInt}
  
  if ((a+b)%2==0&&(b+c)%2==0&&(c+a)%2==0) {
    val Array(aa,bb,cc) = Array(a,b,c).sorted
    println((2*cc-aa-bb)/2)
  } else {
    val even = Array(a,b,c).filter{_%2==0}
    val odd = Array(a,b,c).filter{_%2==1}
    if (even.size==1) {
      val aa = even(0)
      val bb = odd(0)+1
      val cc = odd(1)+1
      val Array(aaa,bbb,ccc) = Array(aa,bb,cc).sorted
      println(1+(2*ccc-aaa-bbb)/2)
    } else {
      val aa = even(0) + 1
      val bb = even(1) + 1
      val cc = odd(0)
      val Array(aaa,bbb,ccc) = Array(aa,bb,cc).sorted
      println(1+(2*ccc-aaa-bbb)/2)
    }
  }
}

Measured memory_bytes: 25540
import numpy as np
import sys
def solve():
    N=int(sys.stdin.readline())
    dp=np.zeros((3,N)).astype('int64')
    for i in range(N):
        a,b,c=list(map(int,sys.stdin.readline().split()))
        if i:
            dp[0,i]=max(dp[1,i-1]+a,dp[2,i-1]+a)
            dp[1,i]=max(dp[0,i-1]+b,dp[2,i-1]+b)
            dp[2,i]=max(dp[1,i-1]+c,dp[0,i-1]+c)
        else:
            dp[0,i]=a
            dp[1,i]=b
            dp[2,i]=c

    return np.max(dp[:,N-1])
    
if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 16800
a, b, c = map(int, input().split())
maxi = max(a, b, c)
s = (maxi - a) + (maxi - b) + (maxi - c)
if (s % 2) == 0:
  print(int(s / 2))
else:
  sd = s + 1
  print(int(sd / 2) + 1)

Measured memory_bytes: 3060
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"

ll f(ll n){
    if(n==0)return INF;
    ll ret=0;
    while(n%2==0){
        n/=2;
        ret++;
    }
    return ret;
}

char rf(int n){
    if(n<26)return ('A'+n);
    else return ('a'+(n-26));
}

bool solve(){
    ll n;cin>>n;
    vector<ll>A(n);
    vector<ll>B(n);
    rep(i,n)cin>>A[i]>>B[i];
    ll sum=0;
    reverse(all(A));
    reverse(all(B));

    rep(i,n){
        if(((A[i]+sum)%B[i]+B[i])%B[i]==0)continue;
        sum+=B[i]-((A[i]+sum)%B[i]+B[i])%B[i];
        // cout<<sum<<endl;
    }
    cout<<sum<<endl;
    return false;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	return solve();
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
	int a,b;
	char c;
	while(~scanf("%d %c %d",&a,&c,&b)){
		int sum;
		if(c=='+'){
			sum=a+b;
		}else if(c=='-'){
			sum=a-b;
		}
		printf("%d\n",sum);
	}
	
	return 0;
}

Measured memory_bytes: 256
try:
    N = int(input())
    
    if N>=1 and N<=10**5:
        dic = {'AC':0,'WA':0,'TLE':0,'RE':0}
        
        while N>0:
            
            case = input()
            
            if case in dic:
                dic[case] +=1
            
            N-=1
        for key in dic:
            print(key," x ",dic[key])
        
        
except Exception as e:
    print(e)

Measured memory_bytes: 9068
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var aList = Console.ReadLine().Split(' ').Select(int.Parse);

            var output = 0L;
            var list = aList.OrderByDescending(x => x).ToArray();
            for (var i = 1; i < 2 * N; i += 2)
            {
                output += list[i];
            }

            Console.WriteLine(output);
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 47496
def solve_israil(n):
	if 400<=n and n<=599:
		return 8
	elif 600<=n and n<=799:
		return 7
	elif 800<=n and n<=999:
		return 6
	elif 1000<=n and n<=1199:
		return 5
	elif 1200<=n and n<=1399:
		return 4
	elif 1400<=n and n<=1599:
		return 3
	elif 1600<=n and n<=1799:
		return 2
	else:
		return 1
									


n=int(input())
print(solve_israil(n))

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	
	if (s == "keyence" or s.substr(0, 7) == "keyence") {
		cout << "YES" << endl;
		return 0;
	}

//	cout << s.length() << endl;
	string tmp = s;
	rep(i, s.length()) {
//		cout << s.erase(i, s.length() - 7) << endl;
		if (s.erase(i, s.length() - 7) == "keyence") {
			cout << "YES" << endl;
			return 0;
		}
		s = tmp;
	}
	
//	rep(i, s.length()-6)
	
	cout << "NO" << endl;
	
	return 0;
}

Measured memory_bytes: 256
while True:
    h,w = map(int,input().split())
    if w == 0 and h == 0:
        break
    for j in range(h):
        for i in range(w):
            if (i % 2 == 0 and j % 2 == 0) or (i % 2 == 1 and j % 2 == 1):
                print('#', end='')
            else:
                print('.', end='')
        print()
    print()

Measured memory_bytes: 9072
import java.util.Scanner;

//Gather the Maps!
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			boolean[][] f = new boolean[n][31];
			for(int i=0;i<n;i++){
				int k = sc.nextInt();
				while(k--!=0)f[i][sc.nextInt()] = true;
			}
			long[][] dp = new long[n][31];
			for(int i=0;i<n;i++)dp[i][0] = 1L << i;
			int res = -1;
			for(int j=1;j<=30;j++){
				if(res!=-1)break;
				for(int i=0;i<n;i++){
					if(!f[i][j]){
						dp[i][j] = dp[i][j-1]; continue;
					}
					for(int k=0;k<n;k++){
						if(!f[k][j])continue;
						dp[i][j]|=dp[k][j-1];
					}
					if(dp[i][j]==(1L<<n)-1){
						res = j; break;
					}
				}
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
from itertools import accumulate,chain
n,*s=open(0).read().split()
t=[2*i.count("(")-len(i) for i in s]
st=[[min(accumulate(s_,lambda a,b: a+(1 if b=="(" else -1),initial=0)),t_] for s_,t_ in zip(s,t)]
now=0
for c,d in chain(sorted([x for x in st if x[1]>=0])[::-1],sorted([x for x in st if x[1]<0],key=lambda z:z[1]-z[0])[::-1]):
    if now+c<0:
        print("No");break
    now+=d
else:
    print("No" if now else "Yes")

Measured memory_bytes: 128008
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

ll min(ll a, ll b) {return a < b ? a : b;}
ll min(int a, ll b) {return a < b ? a : b;}
ll min(ll a, int b) {return a < b ? a : b;}
ll min(int a, int b) {return a < b ? a : b;}

ll max(ll a, ll b) {return a > b ? a : b;}
ll max(int a, ll b) {return a > b ? a : b;}
ll max(ll a, int b) {return a > b ? a : b;}
ll max(int a, int b) {return a > b ? a : b;}

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

const int N = 6010;

int n, k;
long long ans;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    ans = 0;
    if (k == 0)
    {
        cout << 1LL * n * n;
        return 0;
    }
    for (int b = k + 1; b <= n; b++)
    {
        int cnt = b - k;
        int blocks = n / b;
        ans += 1LL * blocks * cnt;
        int x = n % b;
        if (x >= k)
        {
            ans += x - k + 1;
        }
    }
    cout << ans;
}


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

/* macros */
#define inf 1e9
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define vt vector
#define pb push_back
#define fi first
#define se second
#define pi pair<int,int>
#define tc int t;cin>>t;while (t--){solve();}
#define gtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": " << solve() << "\n";TC++;}
#define gvtc int t;cin>>t;int TC=1;while (t--) {cout << "Case #" << TC << ": "; vsolve(); TC++;}
#define notc solve();
#define newline cout << "\n";
#define mod 1000000007
#define ret return 0;
#define sz(x) (int)x.size();
#define rep(i,a,b) for(int i=a;i<b;i++)
#define srt(x) sort(x.begin(), x.end())
#define rsrt(x) sort(x.rbegin(), x.rend())

void solve() {
    int x;
    cin>>x;
    cout << 1 - x << "\n";
}

int32_t main(){
    fastio
    notc
    ret
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Dice{
private:
	static const int _roll[4][6], _turn[2][6];
public:
	vector<int> value;
	// 1-6 : top, near, right, left, far, bottom 

	Dice(){
		value.resize(6);
		for (int i = 0; i < 6; ++i) value[i] = i;
	}

	void roll(int dir){ // N, E, W, S
		vector<int> nxt(6);
		for (int i = 0; i < 6; ++i){
			nxt[i] = value[_roll[dir][i]];
		}
		value = nxt;
	}

	void turn(int dir){ // L, R
		vector<int> nxt(6);
		for (int i = 0; i < 6; ++i){
			nxt[i] = value[_turn[dir][i]];
		}
		value = nxt;
	}

	int &operator[](int i){
		return value[i];
	}
};

const int Dice::_roll[4][6] = {
	{ 1, 5, 2, 3, 0, 4 }, // North
	{ 3, 1, 0, 5, 4, 2 }, // East
	{ 2, 1, 5, 0, 4, 3 }, // West
	{ 4, 0, 2, 3, 5, 1 }, // South
};

const int Dice::_turn[2][6] = {
	{ 0, 3, 1, 4, 2, 5 }, // Left
	{ 0, 2, 4, 1, 3, 5 }, // Right
};

typedef pair<int, int> P;

const int N = 30;

int main(){	
	int n;

	int rdir[] = { 0, 3, 1, 2, 0 };
	int dx[] = { 0, 1, -1, 0};
	int dy[] = { 1, 0, 0, -1};
	while (cin >> n, n){
		P field[N][N];

		while (n--){
			int t, f;
			cin >> t >> f;
			Dice d;
			for (int i = 0; i < 6; ++i) d[i] = i + 1;
			if (d[2] == t || d[3] == t) d.turn(0);
			while (d[0] != t) d.roll(0);
			while (d[1] != f) d.turn(0);

			P pos = make_pair(N/2, N/2);
			while (1){
				P dir = make_pair(-1, -1);
				for (int i = 1; i <= 4; ++i){
					int nx = pos.first + dx[rdir[i]], ny = pos.second + dy[rdir[i]];
					if(d[i] >= 4 && field[pos.second][pos.first].first > field[ny][nx].first) dir = max(dir, make_pair(d[i], rdir[i]));
				}
				if (dir.second < 0) break;
				d.roll(dir.second);
				pos.first += dx[dir.second];
				pos.second += dy[dir.second];
			}
			++field[pos.second][pos.first].first;
			field[pos.second][pos.first].second = d[0];
		}
		int cnt[7] = {};
		for (int i = 0; i < N; ++i)for (int j = 0; j < N; ++j){
			++cnt[field[i][j].second];
		}
		for (int i = 0; i < 6; i++) cout << (i ? " " : "") << cnt[i + 1];
		cout << endl;
	}

	return 0;
}

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

using namespace std;

int compare(int a, int b)
{
	if (a == b)
		return 0;
	else if (a > b)
		return -1;
	else
		return 1;
};
int main()
{
	int N;
	vector<int> a;
	cin >> N;
	int temp;
	for (int i = 0; i < N; i++)
	{
		cin >> temp;
		a.push_back(temp);
	}
	int sub_num = 0;
	int head = 0;
	int tend_flag = 0;
	if (N == 1)
		cout << 1;
	else
	{
		for (int i = 0; i < N - 1; i++)
		{
			if (tend_flag*compare(a[i], a[i + 1]) < 0)
			{
				sub_num++;
				tend_flag = 0;
			}
			else
				tend_flag += compare(a[i], a[i + 1]);
		}
		sub_num++;
		cout << sub_num;
	}
	return 0;

}

Measured memory_bytes: 892
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
using namespace std;

#define pb push_back
#define fst first
#define snd second

typedef long long ll;
typedef pair<int,int> pii;
template<typename T> using min_queue=priority_queue<T,vector<T>,greater<T>>;

const ll MOD=1e9+7;

int N,K;

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

    vector<ll> pos, neg;
    int C=0;

    cin>>N>>K;
    for (int i=0;i<N;i++) {
      int x;cin>>x;
      if (x>0)
        pos.pb(x);
      else if (x<0)
        neg.pb(-x);
      else
        C++;
    }
    int A=pos.size(), B=neg.size();
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());

    ll res = 1;
    if (N==K) {
      if (C)
        res = 0;
      else {
        for (ll k : pos) res = res * k%MOD;
        for (ll k : neg) res = res * k%MOD;
        if (B%2==1)
          res = (MOD-res)%MOD;
      }
      cout << res << '\n';
      return 0;
    }

    if (A==0) {
      if (K > B) {
        res = 0;
      } else if (K%2==0) {
        for (int i = B-1;i>=B-K;i--)
          res = res * neg[i] % MOD;
      } else if (C > 0) {
        res = 0;
      } else {
        for (int i = 0;i<K;i++)
          res = res * neg[i] % MOD;
        res = (MOD-res)%MOD;
      }
      cout << res << '\n';
      return 0;
    }

    int mx = A + B/2*2;
    if (mx < K) {
      res = 0;
    } else {
      int i=A-1, j=B-1;
      if (K%2 == 1) {
        res = pos[i];
        i--;
        K--;
      }
      while (K >= 2)  {
        ll a = 0, b = 0;
        if (i > 0) a = pos[i]*pos[i-1];
        if (j > 0) b = neg[j]*neg[j-1];
        if (a >= b) {
          i -= 2;
          res = (res * (a%MOD)) % MOD;
        } else {
          j -= 2;
          res = (res * (b%MOD)) % MOD;
        }
        K -= 2;
      }
    }

    cout << res << '\n';


    return 0;
}


Measured memory_bytes: 5432