akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<queue>
#define ll long long
using namespace std;
const int N = 1e6 + 50;
int n, k, a[N], cnt = 0, flag = 0; 
int ans = 0, maxx, minn;
int vis[N], g[N];
priority_queue < int, vector<int>, greater<int> > q;
priority_queue < int, vector<int>, less<int> > p;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=k;i++) p.push(a[i]), q.push(a[i]);
    for(int i=2;i<=n;i++){
        if(a[i] > a[i-1]){
            int sum = 0;
            while(a[i] > a[i-1] && i <= n) i++, sum++;
            if(sum >= k-1) cnt ++;
        }
    }
    ans = n-k+1;
    int l = 1, r = k;
    while(r <= n){
        r++;
        if(r > n) break;
        while(vis[q.top()]) q.pop(); 
        while(g[p.top()]) p.pop();
        if(a[l] == q.top() && a[r] > p.top()){
            q.pop(); p.push(a[r]);
            q.push(a[r]);
            g[a[l]] = 1;
            ans --;
        }
        else if(a[l] == q.top() && a[r] < p.top()){
            q.pop(); p.push(a[r]);
            q.push(a[r]);
            g[a[l]] = 1;
        }
        else if(a[l] == p.top()){
            p.pop(); p.push(a[r]);
            q.push(a[r]);
            vis[a[l]] = 1;
        }
        else if(a[l] != q.top() && a[l] != p.top()){
            p.push(a[r]); q.push(a[r]);
            g[a[l]] = 1, vis[a[l]] = 1;
        }
        l++;
    }
    if(!cnt) printf("%d\n", ans);
    else printf("%d\n", ans - cnt+1);
    return 0;
}

Measured memory_bytes: 10996
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 922337203685477580
#define mini 9223372036854775807
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};
ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	ll c=power(a,b/2);
	if(b%2==0)
		return ((c%mod)*(c%mod))%mod;
	else
		return ((((c%mod)*(c%mod))%mod)*a)%mod;
}
ll maxi=0;
ll dp[100005];
ll indegree[100005];
vector<ll>v[100005];
ll dfs(ll i)
{
	if(dp[i]!=0)
		return dp[i];
	ll j;
	for(j=0; j<v[i].size(); j++)
		dp[i]=max(dp[i],1+dfs(v[i][j]));
	maxi=max(maxi,dp[i]);
	return dp[i];
}
int main()
{
	boost
	ll n,m;
	cin>>n>>m;
	ll i;
	for(i=0; i<m; i++)
	{
		ll a,b;
		cin>>a>>b;
		indegree[b]++;
		v[a].push_back(b);
	}
	for(i=1; i<=n; i++)
	{
		if(indegree[i]==0)
			dfs(i);
	}
	cout<<maxi<<endl;
	return 0;
}

Measured memory_bytes: 12032
import sys

input = sys.stdin.readline

def is_prime(N):
    prime = set()
    
    if not N % 2: prime.add(2)
    while not N % 2: N //= 2
    
    x = 3
    
    while x ** 2 <= N:
        if not N % x: prime.add(x)
        while not N % x: N //= x
        x += 2
        
    if N > 1: prime.add(N)
    
    return prime


def main():
    A, B = map(int, input().split())
    
    a = is_prime(A)
    b = is_prime(B)
    
    print(len(a & b) + 1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>

#define LL  long long
#define MAXN    200010
#define P   1000000007
using namespace std;
int N;
int A[MAXN];
map<int, LL> dp[MAXN];

int main()
{
    
    cin>>N;

    for(int i=1; i<=N; i++) {
        cin>>A[i];
    }    

	dp[1][0] = 0; dp[1][1] = A[1];
	dp[2][0] = 0; dp[2][1] = max(A[1], A[2]);
	for(int i=3; i<=N; i++) {
		for(int j=i/2-1; j<=(i+1)/2; j++) {
			//if(dp[i-1].count(j) && !dp[i-2].count(j-1)) continue;	// 确定每一轮都要加一个
			if(dp[i-1].count(j)) {
				dp[i][j] = dp[i-1][j];
			}
			if(dp[i-2].count(j-1)) {
				if(!dp[i].count(j))
					dp[i][j] = dp[i-2][j-1]+A[i];
				else dp[i][j] = max(dp[i][j], dp[i-2][j-1]+A[i]);
			}
		}
	}

	cout << dp[N][N/2]<<endl;
    return 0;
}

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

int main () {
	int n;
	cin >> n;
	int cnt[101001] = {0};
	for (int i=0; i<n; i++) {
		int x; cin >> x;
		cnt[x]++;
	}
	int ans = 0;
	for (int i=1; i<100001; i++) {
		ans = max(ans, cnt[i-1]+cnt[i]+cnt[i+1]);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3992
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;
typedef long long lint;

int main() {
    string s;
    cin >> s;
    set<char> S;
    for (const char c : s) {
        S.insert(c);
    }
    int ans = 100;
    for (const char c : S) {
        string t = s;
        int tmp = 0;
        for (size_t _ = 0; _ < s.size(); ++_) {
            //cout << t << endl;
            bool all = true;
            for (const char m : t) {
                all &= (c == m);
            }
            if (all) break;
            ++tmp;
            string nt;
            for (size_t i = 0; i < t.size() - 1; i++) {
                if (t[i] == c || t[i+1] == c) {
                    nt += c;
                } else {
                    nt += '?';
                }
            }
            t = nt;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  if (abs(A-B)%2 == 0)
    cout << "Alice" << endl;
  else
    cout << "Borys" << endl;
  return 0;
}
  


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

int main() {
  int N, max = 50, count;
  
  cin >> N;
  for(int i = 0; i < N; i++) {
    int A;
    cin >> A;
    count = 0;
    while(A % 2 == 0) {
      count = count + 1;
      A = A / 2;
    }
    if(count < max) {
      max = count;
    }
  }
  cout << max;
}



Measured memory_bytes: 256
n, k = map(int, input().split())
mod = 10 ** 9 + 7

a = [0] * (n + 1)
for i in range(n + 1):
    temp = (n * 2 - i) * (i + 1) // 2 - i * (i + 1) // 2 + 1
    a[i] = temp % mod
b = a[k - 1:]
print(sum(b) % mod)

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

#define ll long long

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

    sort(s.begin(), s.end());

    if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
using namespace std;
typedef long long int lli;
const long long int MaxN=300005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	void solve(){
		lli N,tot=0,i,p,maxi=0;
		cin>>N;
		for(i=0;i<N;i++){
			cin>>p;
			tot+=p;
			maxi=max(maxi,p);
		}
		tot-=maxi/2;
		cout<<tot;
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}

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

int main()
{
	int64_t n, mod = 1000000007;
	cin >> n;
	vector<int64_t> as(n);
	for (auto &&a : as)
	{
		cin >> a;
	}

	vector<int64_t> cntt(60, 0), cntf(60, 0);

	int64_t ans = 0;

	for (auto &&a : as)
	{
		for (int i = 0; i < 60; i++)
		{
			if ((a >> i) & 1)
			{
				(ans += (1LL << i) % mod * cntf[i] % mod) %= mod;
				cntt[i]++;
			}
			else
			{
				(ans += (1LL << i) % mod * cntt[i] % mod) %= mod;
				cntf[i]++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
const double EPS=1e-10;
 
typedef int Weight;
//typedef
//------------------------------------------
 
typedef int Weight;
//typedef
//------------------------------------------

int main(){
    vector<int>N(4),N2(4);
    
    REP(i,4)cin>>N[i];
    N2[0]=1;
    N2[1]=4;
    N2[2]=7;
    N2[3]=9;
    SORT(N);
    REP(i,4)if(N[i]!=N2[i]){
        cout<<"NO"<<endl;
        return 0;
    }
    cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
typedef long long ll;
int main() {
	int n; scanf("%d",&n);
	int r, num[n];
	for (int i=0; i<n-1; i++) scanf("%d",&num[i]);
	scanf("%d",&num[n-1]);
	ll dp[n-1][21];
	for (int i=0; i<n-1; i++) for (int j=0; j<21; j++) dp[i][j]=0;
	dp[0][num[0]]=1;
	for (int i=1; i<n-1; i++) {
		for (int j=0; j<21; j++) {
			if (j+num[i]<21) dp[i][j]+=dp[i-1][j+num[i]];
			if (j-num[i]>=0) dp[i][j]+=dp[i-1][j-num[i]];
		}
	}	
	printf("%lld\n",dp[n-2][num[n-1]]);
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>
#include <stdlib.h>


struct Node{
	int key;
	struct Node *right, *left , *parent;
};

struct Node *root , *NIL;

struct Node * find(struct Node *u , int k)
{
	while( u != NIL && k != u->key)
	{
		if( k < u->key)u = u->left;
		else u = u ->right;
	}
	return u;
}

void insert(int k)
{
	struct Node *y = NIL;
	struct Node *x = root;
	struct Node *z;
	
	z = (struct Node *)malloc(sizeof(struct Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while( x != NIL)
	{
		y = x;
		if(z->key < x->key)
		{
			x = x->left;
		}
		else{
			x = x->right;
		}
	}
	z->parent = y;
	if(y == NIL)
	{
		root = z;
	}
	else{
		if(z->key < y->key)
		{
			y->left = z;
		}
		else{
			y->right = z;
		}
	}
}

void inorder(struct Node *u)
{
	if( u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}

void preorder(struct Node *u)
{
	if( u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

int main(void)
{
	int n , i , x;
	char com[100];
	char str1[] = "insert";
	char str2[] = "print";
	scanf("%d",&n);
	
	for( i = 0; i < n; i++)
	{
		while(scanf("%s",com) != EOF)
		
		if( com[0] == 'f')
		{
			scanf("%d",&x);
			struct Node *t = find(root,x);
			if(t != NIL) printf("yes\n");
			else printf("no\n");
		}
		else if(strcmp(com,str1)==0)
		{
			scanf("%d",&x);
			insert(x);
		}
		else if(strcmp(com,str2)==0)
		{
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}



Measured memory_bytes: 20548
import java.util.*;
public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
    		int i, j, k;
    		while(true) {
	    		int count = 0;
	            int n = sc.nextInt();
	            int x = sc.nextInt();
	            
	            if(n == 0 && x == 0) break;
	            for(i = 1; i <= n; i++) {
	            	for(j = 1; j <= n; j++) {
	            		for(k= 1; k <= n; k++) {
	            			if(i + j + k == x && i < j && j < k) count++;
	            		}
	            	}
	            }
	            System.out.println(count);
    		}	
    }
}



Measured memory_bytes: 26684
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, K: int, x: "List[int]"):
    print(sum(min(xi, K - xi) for xi in x) * 2)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, x)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

void eval(int val, int cur, int par, vector<vector<int>> &adj, vector<int> &dp, vector<int> &add) {
	dp[cur]+=val;
	for (int nxt : adj[cur]) {
		if(nxt==par)
			continue;
		eval(val+add[nxt],nxt,cur,adj,dp,add);
	}
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,Q; cin>>N>>Q;
	vector<vector<int>> adj(N);
	for (int i=0; i<N-1; i++) {
		int a,b; cin>>a>>b; a--; b--;
		adj[a].push_back(b); adj[b].push_back(a);
	}
	vector<int> dp(N,0), add(N,0);
	for (int i=0; i<Q; i++) {
		int p,x; cin>>p>>x; p--;
		add[p]+=x;
	}
	eval(add[0],0,-1,adj,dp,add);
	for (auto x : dp)
		cout<<x<<" ";
	cout<<"\n";
	return 0;
}


Measured memory_bytes: 30592
#include <bits/stdc++.h>
#define whatis(x) cout << #x << " is " << x << endl;
#define MOD 1000000007
#define endl "\n"
#define ll long long
#define ii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MAX 100001
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int i, t = 1;
    //cin>>t;
    int arr[MAX][3];
    while (t--)
    {
        int n, i, j,ans=0;
        cin >> n;
        for (i = 0; i < n; i++)
        {
            cin >> arr[i][0];
            cin >> arr[i][1];
            cin >> arr[i][2];
        }
        for(i=n-2;i>=0;i--)
        {
            arr[i][0]=max(arr[i][0]+arr[i+1][1],arr[i][0]+arr[i+1][2]);
            arr[i][1]=max(arr[i][1]+arr[i+1][2],arr[i][1]+arr[i+1][0]);
            arr[i][2]=max(arr[i][2]+arr[i+1][1],arr[i][2]+arr[i+1][0]);
        }
        ans=max(arr[0][0],arr[0][1]);
        ans=max(ans,arr[0][2]);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1408
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	S := sc.nextStr()
	for i := 1; i < len(S)-1; i++ {
		last := len(S) - 1 - i
		if last%2 == 0 {
			continue
		}
		mid := last / 2
		if S[0:mid+1] == S[mid+1:last+1] {
			fmt.Fprintln(wtr, last+1)
			wtr.Flush()
			return
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
  int n,x;
  cin>>n;
  x=n%10;
  if (x==2 || x==4 || x==5 || x==7 || x==9){
    cout<<"hon";
  }
  else if (x==0 || x==1 || x==6 || x==8){
    cout<<"pon";}
  else {
    cout<<"bon";}
}

Measured memory_bytes: 3624
# -*- coding: utf-8 -*-
n = int(input())
g = [[] for _ in range(n)]
for i in range(n - 1):
    u, v, w = map(int, input().split())
    g[u - 1].append((v - 1, w % 2))
    g[v - 1].append((u - 1, w % 2))

# print(g)

ans = [-1 for _ in range(n)]
q = list()

# g[0] の処理
ans[0] = 0
q.append(0)

while(len(q) != 0):
    v = q[0]
    q.pop(0)
    for u, w in g[v]:
        # print(v, u, w)
        if ans[u] != -1:
            continue
        ans[u] = (ans[v] + w) % 2
        q.append(u)
    # print(v, q)

for a in ans:
    print(a)

Measured memory_bytes: 35620
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
    int n;
    vector<int>a(1000000);
    vector<int>b(1000000);
    for(int i=0;i<3;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end(),std::greater<>());
    cout<<10*a[0]+a[1]+a[2]<<endl;
    
    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B;
  C = A*B;
  D = C/2;

  if (C == D*2) {
    cout << "Even" << endl;
  }
  else {
      cout << "Odd" << endl;
    }
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.abs

fun main() {
    val jin = BufferedReader(InputStreamReader(System.`in`))
    val (a, v) = jin.readLine().split(" ").map { it.toLong() }
    val (b, w) = jin.readLine().split(" ").map { it.toLong() }
    val t = jin.readLine().toLong()
    if (a == b) {
        println("YES")
    } else if (v > w && ((v - w) * t) >= abs(a - b)) {
        println("YES")
    } else {
        println("NO")
    }
}

Measured memory_bytes: 36376
#include<bits/stdc++.h>
#include<queue>
#include<cmath>
#include<algorithm>

using namespace std;
using ll=long long;

int main()
{
    int n=0;
    cin >> n;
    vector<vector<ll>> dp(n+10,vector<ll>(3,0));
    vector<vector<ll>> num(n+10,vector<ll>(3,0));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin >> num.at(i).at(j);
        }
    }
    for(ll i=1;i<n+1;i++)
    {
        for(ll j=0;j<3;j++)
        {
            for(ll k=0;k<3;k++)
            {
                if(j!=k)
                {
                    dp.at(i).at(j)=max(dp.at(i).at(j),dp.at(i-1).at(k)+num.at(i-1).at(j));
                }
            }
        }
        
    }
    ll ans=0;
    ans=max(dp.at(n).at(0),max(dp.at(n).at(1),dp.at(n).at(2)));
    cout << ans << endl;
    return(0);

}

Measured memory_bytes: 14040
#include<cstdio>
#include<algorithm>
int N,x[510],ls[510],rs[510],a[510*510],L[510];
bool cmp(int i,int j){return x[i]<x[j];}
bool solve(){
	for(int i=1;i<=N;i++)a[--x[i]]=i,L[i-1]=i;
	std::sort(L,L+N,cmp);
	for(int i=0;i<N;i++){
		ls[L[i]]=x[L[i]]-i;
		rs[L[i]]=N*N-N-x[L[i]]+i;
	}
	int pos=0;
	for(int t=0;t<2;t++){
		for(int*i=L;i<L+N;i++){
			for(int j=t?N-*i:*i-1;j--;){
				while(a[pos])pos++;
				if(t==(pos<x[*i]))return 0;
				a[pos++]=*i;
			}
		}
	}
	return 1;
}
int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++)scanf("%d",x+i);
	if(solve()){
		puts("Yes");
		for(int i=0;i<N*N;i++)printf("%d%c",a[i]," \n"[i==N*N-1]);
	}
	else puts("No");
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define mod 1000000007
#define inf 1e9
#define endl '\n'
#define zeros(x) ((x)&(-x))

using namespace std;

typedef long long ll;
typedef long double ld;

ll put(ll a, ll b)
{
    if (b==0)
        return 1;

    ll c = put(a, b/2);
    c*=c;
    c%=mod;
    if (b%2==1)
        c*=a;
    return c%mod;
}

ll inv(ll x)
{
    return put(x, mod-2);
}

ll comb(ll n, ll k)
{
    ll a = 1;
    for (ll i=1; i<=n; i++)
        a*=i, a%=mod;

    ll b = 1;
    for (ll i=1; i<=n-k; i++)
        b*=i, b%=mod;

    for (ll i=1; i<=k; i++)
        b*=i, b%=mod;

    return a * inv(b) % mod;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll x, y;

    cin>>x>>y;

    if (!((x+y)%3 == 0 && (2 * (x+y)/3 >= x && x >= (x+y)/3)))
    {
        cout<<0;
        return 0;
    }

    ll n = (x+y)/3;
    ll k = x - (x+y)/3;
    cout<<comb(n, k);
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            String S = in.next();
            String T = in.next();
            int A = in.nextInt();
            int B = in.nextInt();
            String U = in.next();

            if (U.equals(S)) {
                A--;
            } else {
                B--;
            }
            out.printf("%d %d\n", A, B);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int n;
vector<int> d(100);
set<int> S;

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> d.at(i);
  }
  for(int i=0;i<n;i++){
    S.insert(d.at(i));
  }
  cout << S.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int k = n / 1000;
	if (k * 1000 == n)
	{
		cout<<0 << endl;
	}else
	{
		cout << (k + 1) * 1000 - n << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 1e3 + 10 ;
const ll INF = 1e18 + 10 ;
int main(){
    fastio
    ll n ;
    cin >> n ; 
    vector<vector<bool>> v(n, vector<bool>(61)) ; 
    for(ll i = 0; i < n; i++){
        ll x ;
        cin >> x ; 
        for(ll j = 0; j < 61; j++){
            if ( x & (1LL << j) ){
                v[i][j] = 1; 
            }
        }
    }
    vector<ll> cnt(61) ;
    for(ll i = 0; i < 61; i++){
        ll ones = 0 ; 
        for(ll j = 0; j < n; j++){
            if ( v[j][i] ) ones++ ; 
        }
        cnt[i] = ones ; 
    }
    ll sum = 0 ;
    for(ll i = 0; i < 61; i++){
        ll ones = cnt[i] ; 
        ll zeroz = n - cnt[i] ; 
        sum += (((ones % MOD) * (zeroz % MOD)) % MOD * ((1LL << i) % MOD)) % MOD ; 
        sum = sum % MOD ; 
    }
    cout << sum << endl;
    return 0; 
}


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

    double a,b,c;
    double ans=0;
    a = L/3.0;
    b = L/3.0;
    c = L/3.0;

    cout << fixed << setprecision(12) <<a*b*c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define chmax(x,y) x = max(x,y)

 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int> > VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<LL> VL;
typedef vector<vector<long long>> VVLL;
const int MOD = 1e9+7;
const int INF = 1e9;
const LL LINF = 1e18;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}

int main() {
    LL x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    VI red(a);
    VI blue(b);
    VI none(c);
    rep(i,a) cin >> red[i];
    rep(i,b) cin >> blue[i];
    rep(i,c) cin >> none[i];
    RSORT(red);
    RSORT(blue);
    int cntx,cnty = 0;
    VI ans_app;
    rep(i,x) ans_app.push_back(red[i]);
    rep(i,y) ans_app.push_back(blue[i]);
    rep(i,c) ans_app.push_back(none[i]);
    RSORT(ans_app);
    LL ans = 0;
    rep(i,x+y) ans += ans_app[i];
    cout << ans << endl;
    
}


Measured memory_bytes: 3572
package main

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

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}

	return x
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() int64 {
		sc.Scan()
		i, _ := strconv.ParseInt(sc.Text(), 10, 64)
		return i
	}

	x, k, d := in(), in(), in()
	x = abs(x)

	v := x / d

	if v >= k {
		x -= k * d
	} else {
		if d*v == x {
			x = 0
			k -= v
		} else {
			if abs(x-v*d) < abs(x-(v+1)*d) {
				x -= v * d
				k -= v
			} else if abs(x-v*d) > abs(x-(v+1)*d) {
				x -= (v + 1) * d
				k -= (v + 1)
			} else {
				if (k-v)%2 == 0 {
					x -= v * d
					k -= v
				} else {
					x -= (v + 1) * d
					k -= (v + 1)
				}
			}
		}

		k %= 2
		x = abs(x)

		if k == 1 {
			x = abs(x - d)
		}
	}

	fmt.Println(x)
}


Measured memory_bytes: 1812
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
 /* #ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/
fast();
//ll  t;cin>>t;while(t--)
{
  char n;
  cin>>n;
  if(n=='a'||n=='e'||n=='i'||n=='o'||n=='u')
  {
    cout<<"vowel"<<endl;
  }
  else
  {
    cout<<"consonant"<<endl;
  }
  
  

}
return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

//#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;

#define FST first
#define SND second

const int MAX_N = 3500;                  // 10^5
// const int MAX_N = 100000;                  // 10^5
// const int MAX_N = 1000000000;              // 10^9
// const ll  MAX_N = 1000000000000000000;     // 10^18
// const int BASE  = 1000000000 + 7;          // 10^9 + 7
// const int INFI  = 1000000000 + 7;          // 10^9 + 7
// const ll INFL  = 1000000000000000000 + 7; // 10^18 + 7

ll MOD(ll x, ll y) { return (x % y + y) % y; }
ll DIV(ll x, ll y) { return (x - MOD(x, y)) / y; }

ll N;

void solve() {
  for (ll n = 1; n <= MAX_N; n++) {
    for (ll h = 1; h <= MAX_N; h++) {
      ll x = N * n * h;
      ll y =  4 * h * n - N * n - N * h;
      if (y > 0 && x % y == 0) {
        #ifdef DEBUG
        cout << x << " " << y << endl;
        #endif
          ll w = x / y;
        cout << n << " " << h << " " << w << " " << endl;
        return;
      }
    }
  }
}

int main() {
  cin >> N;

  solve();

  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var S string
	fmt.Scan(&S)

	if S == "Sunny" {
		fmt.Println("Cloudy")
	}

	if S == "Cloudy" {
		fmt.Println("Rainy")
	}

	if S == "Rainy" {
		fmt.Println("Sunny")
	}
}

Measured memory_bytes: 512
{
  const main = (input: string) => {
    const r = reader(input)
    const S = r.s()

    const sl = Math.floor(S.length / 2)
    // 7 => 0 1 2 [3] 4 5 6 => 3
    // 6 => 0 1 2 [] 3 4 5

    let res = 0

    for (let i = 0; i < sl; i++) {
      // console.log(S[i], S[S.length - i - 1])
      if (S[i] !== S[S.length - i - 1]) {
        res++
      }
    }
    console.log(res)
  }

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    const nls = () => lines.map(Number)

    return { lines, s, n, ss, ns, nls }
  }

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')

  main(getInput())
}


Measured memory_bytes: 11468
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
typedef pair<LL, LL> P;

int main() {
  LL N, D, A; cin >> N >> D >> A;
  vector<P> X(N);
  vector<LL> carry(N + 1, 0);
  for (int i = 0; i < N; ++i) {
    int x; double h; cin >> x >> h;
    int atk = ceil(h/A);
    X[i] = {x, atk};
  }

  LL total_atk = 0;
  LL damage = 0;
  sort(X.begin(), X.end());

  vector<LL> pos(N);
  for (int i = 0; i < N; ++i) pos[i] = X[i].first;

  for (int i = 0; i < N; ++i) {
    damage -= carry[i];
    if (X[i].second <= damage) continue;
    X[i].second -= damage;

    total_atk += X[i].second;
    damage += X[i].second;
    LL last = X[i].first + 2 * D + 1;
    LL j = lower_bound(pos.begin(), pos.end(), last) - pos.begin();
    carry[j] += X[i].second;
  }
  cout << total_atk << endl;
}


Measured memory_bytes: 6528
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int k;
	string s;
	vector<string > bubunretu;
	cin >> s;
	cin >> k;
	for (int i = 0; i < s.size(); i++) {
		int a = s.size() - i;
		if (a > 5) {
			a = 5;
		}
		for (int j = 1; j <= a; j++) {
			bubunretu.push_back(s.substr(i,j));
		}
	}
	sort(bubunretu.begin(), bubunretu.end());
	string c = " ";
	for (int i = 0; i < bubunretu.size(); i++) {
		if (c != bubunretu[i]) {
			k = k - 1;
		}
		c = bubunretu[i];
		if (k == 0) {
			cout << bubunretu[i];
			return 0;
		}
	}
}

Measured memory_bytes: 1660
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
count = c
for i in range(n):
    a = list(map(int, input().split()))
    for j in range(m):
        count += a[j] * b[j]
    if count > 0:
        ans += 1
    count = c
print(ans)

Measured memory_bytes: 3064
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
f=max([a,b,c,d,e])
g=min([a,b,c,d,e])
z= f-g
if (z>k):
    print(':(')
else :
    print('Yay!')

Measured memory_bytes: 3064
while 1:
    n,x=map(int,input().split())
    if (n,x)==(0,0) : exit()
    sm=0
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if i+j+k==x:sm+=1
    print(sm)


Measured memory_bytes: 5596
n = int(input())
A = list(map(int, input().split()))
a, c = 0, 0
b = False
for i in A:
  if i%4 == 0:
    a += 1
  elif i%2 == 0:
    b = True
  else:
    c += 1
if b:
  if a >= c:
    print("Yes")
  else:
    print("No")
else:
  if a >= c-1:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define ii pair<int,int>
#define ll long long

using namespace std;

int main(){
    int n;cin>>n;
    vector<int>b(n-1);
    for(int i = 0;i<n-1;i++){
        cin>>b[i];
    }
    vector<int>a(n);
    a[n-1] = b[n-2];
    a[0] = b[0];
    for(int i=1;i<n-1;i++){
        a[i] = min(b[i-1],b[i]);
    }
    ll ans = 0;
    for(auto x:a){
        ans+=x;
    }
    cout<<ans;
}

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

int main(){
  int n, d, x;
  cin >> n;
  cin >> d >> x;
  int sum = x;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    sum++;
    int day = a+1, cnt = 2;
    while(day <= d){
      sum++;
      day = a * cnt + 1;
      cnt++;
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque
import sys

def bfs(maze, sy, sx):
    h = len(maze)
    w = len(maze[0])
    visited = [[-1 for _ in range(w)] for _ in range(h)]
    d = deque([[sy, sx]])
    visited[sy][sx] = 0
    while d:
        y, x = d.popleft()
        
        for k, l in ([1, 0], [0, 1], [-1, 0], [0, -1]):
            new_y, new_x = y + k, x + l
            if new_y < 0 or h <= new_y or new_x < 0 or w <= new_x:
                continue
            elif visited[new_y][new_x] != -1:
                continue
            elif maze[new_y][new_x] == '#':
                continue
            
            d.append([new_y, new_x])
            visited[new_y][new_x] = visited[y][x] + 1
    
    return visited

if __name__ == "__main__":
    h, w = map(int, input().split())
    
    maze = []
    cnt = 0
    for i in range(h):
        maze.append(input())
        cnt += maze[i].count('.')
        
    visited = bfs(maze, 0, 0)
    goal = visited[h - 1][w - 1]
    
    if goal == -1:
        print(-1)
    else:
        print(cnt - goal - 1)

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

  int N;		cin >> N;
  long long ans = 0;
  vector<string> s(N);
  unordered_map<string , int> mp;

  //文字列を入力後ソート
  for(int i = 0 ; i < N ; i++){
	 cin >> s[i];
	 sort(s[i].begin(), s[i].end());

	 
	 //mpが設定されていなかったら設定、設定されてたら加算
	 if(mp[s[i]]){
     	        mp[s[i]] += 1;
		ans += (mp[s[i]] - 1);
	 }else{
		mp[s[i]] = 1;
	 }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 17700
#include <iostream>
using namespace std;
int main() {
    int r,g,b =0;
    cin >> r >> g >> b;
    int rgb = r*100+g*10+b;
    if(rgb % 4 == 0){
        cout << "YES";
    }else{
        cout << "NO";
    }
    return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn solve(ss: &[usize]) -> usize {
    let acc = ss.iter().fold(0, |acc, s| acc + s);
    if acc % 10 != 0 {
        return acc;
    }

    let mut ss = ss.iter().collect::<Vec<_>>();
    ss.sort();

    for s in ss {
        let ans = acc - s;
        if ans % 10 != 0 {
            return ans;
        }
    }

    0
}

fn main() {
    let n = parse_line!(usize);

    let ss = (0..n).map(|_| parse_line!(usize)).collect::<Vec<_>>();

    println!("{}", solve(&ss));
}

#[test]
fn solve_test() {
    assert_eq!(solve(&[5, 10, 15]), 25);
    assert_eq!(solve(&[10, 10, 15]), 35);
    assert_eq!(solve(&[10, 20, 30]), 0);
}


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int N;
    cin >> N;
    int pt = 0, px = 0, py = 0;
    string S = "Yes";
    REP(i, N)
    {
        int t, x, y;
        cin >> t >> x >> y;
        if (t - pt < abs(x - px) + abs(y - py) || (t - pt - (abs(x - px) + abs(y - py))) % 2 != 0)
        {
            S = "No";
        }
        pt = t;
        px = x;
        py = y;
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
import math


def get_min(num_step):
    res = float("inf")
    for i in range(1, min(num_step, K)+1):
        cost = costs[num_step-i] + abs(steps[num_step] - steps[num_step-i])
        if cost < res:
            res = cost
    return res


N, K = map(int, input().split(" "))
steps = list(map(int, input().split(" ")))
costs = [None] * N
costs[0] = 0

for i in range(1, N):
    costs[i] = get_min(i)

print(costs[N-1])

Measured memory_bytes: 52980
#include<iostream>
#include<cstdio>
using namespace std;
int n,sum;
char previous = 'A';
char a[100001];
int main(){
	cin>>n;
	cin>>a;
	for(int i=0;i<n;i++)
	{
		if(a[i]==previous)continue;
		else{
			sum++;
			previous = a[i];
		}
	}
	cout<<sum;
}

Measured memory_bytes: 384
import Foundation

let HW = readLine()!.components(separatedBy: " ")

let H = Int(HW[0])!
let W = Int(HW[1])!

let (W1, _) = W.quotientAndRemainder(dividingBy: 2)
let (W2, _) = (W+1).quotientAndRemainder(dividingBy: 2)

if (H == 1 || W == 1) {
    print(1)
} else if (H % 2 == 0) {
    let HH = UInt64(H/2)
    print(HH*UInt64(W1+W2))
} else {
    let HH = UInt64((H-1)/2)
    print(HH*UInt64(W1+W2) + UInt64(W2))
}


Measured memory_bytes: 13252
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp1 {
    public class Class1 {
        static void Main(string[] args) {
            var S = Console.ReadLine();
            var ans = new long[S.Length + 1];
            for (var i = 0; i < S.Length; i++) {
                if (S[i] == '<') {
                    ans[i + 1] = ans[i] + 1;
                }
            }
            for (var i = S.Length - 1; i >= 0; i--) {
                if (S[i] == '>' && ans[i] <= ans[i + 1] + 1) {
                    ans[i] = ans[i + 1] + 1;
                }
            }
            Console.Write(ans.Sum());
        }
    }
}

Measured memory_bytes: 16864
#include <iostream>
#include <algorithm>
#include <set>
#include <queue>
#include <utility>
#include <cmath>
using namespace std;

typedef pair<int,int[16]> state;
set<int> cl[65536];
priority_queue<pair<int,state>, vector<pair<int,state> >, greater<pair<int,state> > > ol;
const long long goal=1401602636313LL;
int md[16][16];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

long long hash(const int *board)
{
    const static long long fact[]={1307674368000LL,87178291200LL,6227020800LL,479001600LL,39916800LL,3628800LL,362880LL,40320LL,5040LL,720LL,120LL,24LL,6LL,2LL,1LL};
    long long h=0;
    int work;
    for(int i=0; i<15; i++) {
        work=board[i];
        for(int j=0; j<i; j++) {
            if(board[j]<board[i]) --work;
        }
        h+=work*fact[i];
    }
    return h;
}

int search()
{
    while(!ol.empty()) {
        pair<int,state> temp=ol.top();
        ol.pop();
        int nowcost=temp.first;
        state now=temp.second;
        if(nowcost==now.first) return now.first;
        int h=hash(now.second);
        int hl=h&0xffff;
        int hn=h>>16;
        if(cl[hl].find(hn)!=cl[hl].end()) continue;
        cl[hl].insert(hn);

        int f;
        for(f=0; f<16&&now.second[f]; f++);

        for(int i=0; i<4; i++) {
            int ty=f/4+dy[i];
            int tx=f%4+dx[i];
            if(tx<0||3<tx||ty<0||3<ty) continue;
            int t=ty*4+tx;
            state next=now;
            next.first++;
            swap(next.second[f],next.second[t]);
            int h=hash(next.second);
            int hl=h&0xffff;
            int hn=h>>16;
            if(cl[hl].find(hn)!=cl[hl].end()) continue;
            int nextcost=nowcost+1-md[t][now.second[t]]+md[f][next.second[f]];
            ol.push(pair<int,state>(nextcost,next));
        }

    }
    return -1;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int i=0; i<16; i++) {
        for(int j=1; j<16; j++) {
            md[i][j]=abs(i%4-(j-1)%4)+abs(i/4-(j-1)/4);
        }
    }
    state board;
    board.first=0;
    for(int i=0; i<16; i++) cin>>board.second[i];
    int cost=0;
    for(int i=0; i<16; i++) {
        cost+=md[i][board.second[i]];
    }
    long long h=hash(board.second);
    int hl=h&0xffff;
    int hn=h>>16;
    cl[hl].insert(hn);
    ol.push(pair<int,state>(cost,board));
    cout<<search()<<'\n';
    return 0;
}

Measured memory_bytes: 210024
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <iostream>
#include <math.h>
#include <cmath>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <string.h>
#include <cstring>
#include <queue>
#include <iomanip>
#include <istream>
#include <map>
#include <list>
#include <stack>
#include <numeric>
#include <ostream>
#include <set>
#include <cassert>
#include <sstream>
#include <string>
#include <utility>
#include <stdio.h>
#include <bitset>
#include <vector>
#include <random>

using namespace std;

#define dout if (debug) cout
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int((x.size())))

typedef long double ld;
typedef long long ll;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<PII> VPI;

#define REP(i,a,n) for (int i=a;i<n;i++)
#define PER(i,a,n) for (int i=n-1;i>=a;i--)
#define db(x)		 cerr << #x << " = " << x << endl
#define db2(x, y)	{cerr << #x << " = " << x << "\t";	db(y);		}
#define db3(x, y, z){cerr << #x << " = " << x << "\t";	db2(y,z);	}

template <typename t1, typename t2> inline bool upmax(t1 &a, t2 b) { if (a<(t1)b) { a = (t1)b; return true; } else return false; }
template <typename t1, typename t2> inline bool upmin(t1 &a, t2 b) { if (a>(t1)b) { a = (t1)b; return true; } else return false; }
template <typename T>inline bool pal(T &x){ int n = SZ(x); REP(i, 0, n / 2) { if (x[i] != x[n - i - 1]) return 0; } return 1; }
template <typename T>inline T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }
template <typename T>inline T lcm(T a, T b) { return a*(b / gcd(a, b)); }
template <typename T>inline T sqr(T a) { return a*a; }

int month[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

inline ll mp(ll a, ll b) { return (a << 31) + b; }

class PQ_compare{
public:
	bool operator()(const int a, const int b) const {
		return 1;
	}
};

const int INF = 1000000404;
const ll  MOD = 1000000007ll;
const ld  PI = acos(-1.0);
const ld  EPS = 1e-9;

int SQ = 404;

#define debug 1
#define N 111111


int n;
int ask(int pos) {
	cout << pos << endl;
	string ret;
	cin >> ret;
	if (ret == "Vacant") return 0;
	if (ret == "Male") return 1;
	else return -1;
}
int cnt(int l, int r) {
	if (l < r) return (r - l - 1);
	else return (r + n - 1 - l);
}

void solve()
{
	cin >> n;
	int l = 0;
	int r = n-1;
	int lf = ask(l);
	if (lf == 0) return;
	int rg = ask(r);
	if (rg == 0) return;

	while (l != r) {
		int x = cnt(l, r);
		int m = (l + (x + 1) / 2) % n;
		int md = ask(m);
		if (md == 0) return;
		int a = cnt(l, m);
		int b = cnt(m, r);
		if ((a % 2 == 0) && (lf == md) || (a % 2 == 1) && (lf != md)) {
			r = m;
			rg = md;
		}
		else{
			l = m;
			lf = md;
		}
	}

}

int main()
{


	//freopen("codeforces.in", "r", stdin);
	//freopen("codeforces.out", "w", stdout);
	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	int t = 1;

	//cin >> t;

	while (t--) solve();
	//getchar();
	//getchar();
	return 0;
}

Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp make_pair
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
typedef long long ll;
ll q,n;
ll a[2000005];
ll b[2000005];
int main()
{
    //IOS;
    while(cin>>n)
    {
        rep1(i,n) cin>>a[i];
        vector<ll> ans;
        for(int i=n;i>=1;i--)
        {
            ll cnt=0;
            for(int j=i+i;j<=n;j+=i)
            {
                if(j%i==0) if(b[j]==1) cnt++;
            }
            if(a[i]==1)
            {
                if(cnt%2==0) b[i]=1;
                else b[i]=0;
            }
            else
            {
                if(cnt%2==1) b[i]=1;
                else b[i]=0;
            }
            if(b[i]==1) ans.pb(i);
        }
        reverse(ans.begin(),ans.end());
        cout<<ans.size()<<"\n";
        for(auto i:ans) cout<<i<<" ";
        cout<<"\n";

    }
    return 0;
}



Measured memory_bytes: 7668