akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
#import queue
from copy import copy, deepcopy
from operator import itemgetter

import bisect#2分探索
#bisect_left(l,x), bisect(l,x)
from collections import deque 
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
#dequeを使うときはpython3を使う、pypyはダメ
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#q=heapq.heapify(l),heappush(q,a),heappop(q)

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s): return sorted(range(len(s)), key=lambda k: s[k])

#mod = 10**9+7

#N = int(input())
N, P = map(int, input().split())
S=input()
#L = [int(input()) for i in range(N)]
#A = list(map(int, input().split()))
#S = [inputl() for i in range(H)]
#q = queue.Queue() #q.put(i) #q.get() 
#q = queue.LifoQueue() #q.put(i) #q.get() 

#a= [[0]*3 for i in range(5)] #2次元配列はこう準備、[[0]*3]*5だとだめ
#b=copy.deepcopy(a)  #2次元配列はこうコピーする
#w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

#素数リスト
# n = 100
# primes = set(range(2, n+1))
# for i in range(2, int(n**0.5+1)):
#     primes.difference_update(range(i*2, n+1, i))
# primes=list(primes)

#bisect.bisect_left(a, 4)#aはソート済みである必要あり。aの中から4未満の位置を返す。rightだと以下
#bisect.insort_left(a, 4)#挿入
if P!=2 and P!=5:
    l=[0]*(N+1)
    count=0
    for i in range(1,N+1):
        count+=int(S[N-i])*pow(10,(i-1),P)
        l[i]=count%P

    pc=[0]*P
    ans=0
    for p in l:  
        ans+=pc[p]
        pc[p]+=1
    print(ans)
elif P==2:
    ans=0
    for i in range(1,N+1):
        if int(S[N-i])%2==0:
            ans+=N-i+1
    print(ans)
elif P==5:
    ans=0
    for i in range(1,N+1):
        if int(S[N-i])%5==0:
            ans+=N-i+1
    print(ans)



Measured memory_bytes: 42716
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,int>
const ll MOD=1e9+7;
const int INF=1e9;
const double PI=acos(-1);


int main() {
    ios_base::sync_with_stdio(false); 

    int n;
    cin >> n;
    vector<vector<ll>> a(3,vector<ll>(n));
    rep(i,3) {
        rep(j,n) cin >> a[i][j];
        sort(a[i].begin(),a[i].end()); 
    } 
    vector<vector<ll>> dp(3,vector<ll>(n+1));
    rep(i,n) dp[2][i+1]=i+1;
    invrep(i,2) {
        rep(j,n) {
            int k=upper_bound(a[i+1].begin(),a[i+1].end(),a[i][j])-a[i+1].begin();
            dp[i][j+1]=dp[i+1][n]-dp[i+1][k];
        }
        rep(j,n) dp[i][j+1]+=dp[i][j];
    }
    cout << dp[0][n] << endl;

    return 0;
}


Measured memory_bytes: 8680
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n;
    cin>>n;
    vector<P> v[20];
    for(int i=0; i<n; i++){
        int a;
        cin>>a;
        for(int j=0; j<a; j++){
            int x, y;
            cin>>x>>y;
            x--;
            v[i].push_back({x, y});
        }
    }
    int ans=0;
    for(int i=0; i<(1<<n); i++){
        int c=popcount(i);
        bool dame=0;
        for(int j=0; j<n; j++){
            for(auto p:v[j]){
                int x=p.first, y=p.second;
                if(i&(1<<j)){
                    if(y){
                        if(!(i&(1<<x))) dame=1;
                    }else{
                        if(i&(1<<x)) dame=1;
                    }
                }
            }
        }
        if(!dame) ans=max(ans, c);
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int>hight(N);
  
  for(int i=0; i<N; i++)cin >> hight.at(i);
  
  sort(hight.begin(), hight.end());
  
  int ans = 2000000000;
  
  for(int i=0; i<N-K+1; i++){
    ans = min(ans, hight.at(i+K-1)-hight.at(i));
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3712
import java.util.*;
class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int x = stdIn.nextInt();
			int h = stdIn.nextInt();
			if(x == 0 && h == 0) break;
			System.out.println((x * Math.sqrt(4 * h * h + x * x) + x * x));
		}
	}
}

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

int dp[105][4][2]; // i桁目まで決めて，j個の非0を用いて，k=0:i桁目までNと一致,k=1:Nより小さい
int main(){
    string s; cin >> s;
    int n = s.size();
    int K; cin >> K;
    dp[0][0][0] = 1;
    rep(i,n)rep(j,4)rep(k,2){
        int nd = s[i] - '0';
        rep(d,10){
            int ni = i + 1, nj = j, nk = k;
            if(d != 0) nj++;
            if(nj > K) continue;
            if(k == 0){
                if(nd > d) nk = 1;
                if(nd < d) continue;
            }
            dp[ni][nj][nk] += dp[i][j][k];
        }
    }
    int ans = dp[n][K][0] + dp[n][K][1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(x) for(auto it=(x).begin();it!=(x).end();it++) 
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
 
using namespace std;
int n,m;
vector<vector<bool>> v(8,vector<bool>(8,false));

int dfs(int x,vector<bool> visited){
    bool all_visit=true;
    rep(i,0,n){
        if(!visited[i])all_visit=false;
    }
    if(all_visit)return 1;
    
    int ret=0;
    
    rep(i,0,n){
        if(!v[x][i])continue;
        if(visited[i])continue;
        
        visited[i]=true;
        ret+=dfs(i,visited);
        visited[i]=false;
    }
    
    return ret;
}

int main(){
    cin>>n>>m;
    rep(i,0,m){
        int x,y;
        cin>>x>>y;
        x--; y--;
        v[x][y]=true;
        v[y][x]=true;
    }
    
    vector<bool> visited(8,false);
    visited[0]=true;
    
    cout<<dfs(0,visited)<<endl;
    
    
    return 0;
}

Measured memory_bytes: 256
import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase


"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""



def inpt():
    return [int(k) for k in input().split()]


def main():
    n,k=map(int,input().split())
    ar=inpt()
    j=0
    for i in range(k,n):
        if(ar[j]<ar[i]):
            print('Yes')
        else:
            print('No')
        j+=1


BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


Measured memory_bytes: 104816
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    // Rust version 1.15.1, which is used by AtCoder,
    // does not support std::str::FromStr for char
    ($iter:expr, char) => {
        $iter.next().unwrap().chars().next().expect("Parse error")
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
fn main() {
    use std::cmp::max;
    use std::cmp::min;
    use std::collections::HashMap;

    input!{
        x: usize,
        y: usize,
        z: usize,
    }

    println!("{}", (x-z)/(y+z));
}


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

#define MAXTEXT 81

int main(){
	int i,j,length,tok_len,space,next;
	int Caesar,src;
	char *text,buf[MAXTEXT+1],check[5];
	char **tok, THE[]={"the"},THIS[]={"this"},THAT[]={"that"};
	char str[]=" -";

	while(fgets(buf,sizeof(buf),stdin)!=NULL){
		length=strlen(buf)-1;
		space=Caesar=0;
		text=(char*)malloc(sizeof(char)*(length+1));
		for(i=0;i<=length;i++){
			text[i]=buf[i];
			if(buf[i]==' ') space++;
			if(buf[i]=='\n') break;
		}
		text[i]='\0';
		tok=(char**)malloc(sizeof(char*)*(space+1));
		for(i=0;i<space+1;i++){
			tok[i]=(char*)malloc(sizeof(char)*81);
		}
		next=0;
		for(i=0;i<space+1;i++){
			if(next>length) break;
			for(j=0;j<80;j++){
				if(text[j+next]==' '){
					tok[i][j]='\0';
					next=next+j+1;
					break;
				}else if(text[j+next]=='.'){
					tok[i][j]='.';
					tok[i][j+1]='\0';
					if(text[j+next+1]==' ') next=next+j+2;
					else next=next+j+1;
					break;
				}else{
					if(j+next>length){
						next=next+j;
						break;
					}
					tok[i][j]=text[j+next];
				}
			}
		}
		for(i=0;i<space+1;i++){
			tok_len=strlen(tok[i]);
			if(tok_len>4) continue;
			src='t'-tok[i][0];
			for(j=0;j<tok_len;j++){
				if(tok[i][j]+src>'z') check[j]=tok[i][j]+src-('z'-'a')-1;
				else if(tok[i][j]+src<'a') check[j]=tok[i][j]+src+('z'-'a')+1;
				else check[j]=tok[i][j]+src;
			}
			check[j]='\0';
			if(strcmp(check, THE)==0 || strcmp(check,THIS)==0 || strcmp(check,THAT)==0){
				Caesar='t'-tok[i][0];
				break;
			}
		}
		for(i=0;i<length;i++){
			if(text[i]==' ' || text[i]=='.') continue;
			else if(text[i]+Caesar>'z') text[i]='a'+(text[i]+Caesar-'z')-1;
			else if(text[i]+Caesar<'a') text[i]='z'+(text[i]+Caesar-'a')+1;
			else if(text[i]+Caesar>='a' && text[i]+Caesar<='z') text[i]=text[i]+Caesar;
		}
		printf("%s\n",text);
		text=NULL;
		free(text);
	}
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/04/03  Problem: ABC 046 C / Link: http://abc046.contest.atcoder.jp/tasks/abc046_c  ----- */




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

	int N;
	int T[1000], A[1000];

	cin >> N;
	cin >> T[0] >> A[0];
	LL r = 1, nt = T[0], na = A[0];

	FOR(i, 1, N) {
		cin >> T[i] >> A[i];
		r = max((nt + T[i] - 1) / T[i], (na + A[i] - 1) / A[i]);
		nt = T[i] * r;
		na = A[i] * r;
	}
	LL ans = nt + na;
	cout << ans << endl;

	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++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long int ll;
typedef unsigned long long int ull;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;
  string s="Yes";
  cin >>n>>k;  
  vector<int> a(n);
  rep(i,n){
    cin >>a[i];
    if(i>=k){
      if(a[i]>a[i-k]) cout <<"Yes";
      else cout <<"No";
      if(i!=n-1) cout <<endl;
    }
  }
  
}

Measured memory_bytes: 3988
#include <stdio.h>
#include <string.h>

int main()
{
    char s[101];
    long long int k,i,ans = 0;

    scanf("%s %lld",s,&k);

    int len = strlen(s);

    for (i = 0; i < len; i++)
    {
        if (s[i] != '1')
        {
            ans = s[i] - '0';
            break;
        }
    }
  
    if (i == len)
    {
        ans = 1;
    }
    else if(i + 1 > k)
    {
        ans = 1;
    }
    
    printf("%lld",ans);
}


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

using namespace std;

#define int long long

string s;
int n;
const int md = 998244353;

inline int mod(int x){
    return (x % md + md) % md;
}
map<string, int> cnt;
int an = 0;

void go(string s){
    if(cnt.count(s)) return;
    cnt[s] = 1;
    string t = s;
    if(t[0] != t[1]){
        int su = 3 - t[0] - t[1];
        t[0] = t[1] = su;
        go(t);
    }
    t = s;
    if(t[1] != t[2]){
        int su = 3 - t[1] - t[2];
        t[1] = t[2] = su;
        go(t);
    }
}

int d[2][3][3][200010];

main()
{
    ios_base::sync_with_stdio(false);
    cin >> s;
    bool ok = false;
    for(auto &u: s){
        u -= 'a';
        if(u != s[0]) ok = true;
    }
    if(!ok){
        cout << 1 << endl;
        exit(0);
    }
    if(s.size() == 3){
        go(s);
        cout << cnt.size() << endl;
        exit(0);
    }
    s = "#" + s;
    d[0][0][0][1] = 1;
    d[0][1][1][1] = 1;
    d[0][2][2][1] = 1;
    for(int i = 2; i < (int)s.size(); i++){
        for(int su = 0; su < 3; su++){
            for(int prev = 0; prev < 3; prev++){
                for(int ok = 0; ok < 2; ok++){
                    for(int want = 0; want < 3; want++){
                        bool newok = ok | (want == prev);
                        d[newok][(su + want) % 3][want][i] = mod(d[newok][(su + want) % 3][want][i] + d[ok][su][prev][i-1]);
                    }
                }
            }
        }
    }
    bool oki = false;
    for(int i = 1; i < (int)s.size() - 1; i++){
        if(s[i] == s[i + 1]) oki = true;
    }
    int an = 0;
    if(!oki) an++;
    int su = 0;
    for(int i = 1; i < s.size(); i++) su = (su + s[i]) % 3;
    for(int i = 0; i < 3; i++){
        an = mod(an + d[1][su][i][s.size()-1]);
    }
    cout << an << endl;
}


Measured memory_bytes: 28752
d = int(input())
c = list(map(int, input().split()))
score = []
for i in range(d):
    score.append(list(map(int, input().split())))
last_day = [0 for i in range(26)]
k = 0
for i in range(d):
    ans = 0
    max_score = -10**9
    for j in range(1, 27):
        s = score[i][j-1]
        for k in range(1,27):
            if j == k:
                continue
            else:
                s -= c[k-1] * (i+1 - last_day[k-1])
        if s > max_score:
            ans = j
            max_score = s
    last_day[ans-1] = i+1
    print(ans)

Measured memory_bytes: 69044
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;
int main() {
	int N;
	cin >> N;
	vector<pair<string, pair<int, int>>> v(N);
	for (int i = 0; i < N; i++) {
		cin >> v[i].first >> v[i].second.first;
		v[i].second.second = i+1;
	}
	sort(v.begin(), v.end(), [](pair<string, pair<int, int>> l, pair<string, pair<int, int>> r) {
		return l.first != r.first ? l.first < r.first : l.second.first > r.second.first;
		});
	for (int i = 0; i < N; i++) {
		cout << v[i].second.second << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const* argv[])
{
    std::string in_str;
    std::cin >> in_str;

    char prev_c = 'x';
    auto count = 0;
    auto is_good = false;
    for(auto c: in_str)
    {
        if(prev_c == c)
        {
            count++;
        }
        else
        {
            count = 0;
        }

        prev_c = c;
        if(count == 2)
        {
            is_good = true;
        }
        //std::cout << count << std::endl;
    }

    if(is_good)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)

/*
*/

string s;
bool r=true;
ll n,ans[100010]={},l=0;
vector<pair<char,int>> v;

void RLE(string &s, vector<pair<char,int> > &v){
	v.push_back({s[0],0});
	for(int i=0;i<s.size();i++){
		if(s[i]==v[v.size()-1].first){
			v[v.size()-1].second++;
		}else{
			v.push_back({s[i],1});
		}
	}
}

void init(){
	cin>>s;
	n=s.size();
	RLE(s,v);
}

int main(void){
	init();
	// 右から見る
	ll l=0;
	rep(i,v.size()/2){
		ll mid1=l+v[i*2].second-1;
		ans[mid1]+=(v[i*2].second+1)/2 + (v[i*2+1].second)/2;
		ans[mid1+1]+=(v[i*2].second)/2 + (v[i*2+1].second+1)/2;
		l+=v[i*2].second+v[i*2+1].second;
	}
	rep(i,n)cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

int n, m;
vector<int> ans, g[100010];
bool used[100010];

void dfs(int v) {
    if (used[v]) return;
    used[v] = true;
    for (int u : g[v]) dfs(u);
    ans.pb(v);
}

void tsort() {
    rep(i, n) dfs(i);
    reverse(all(ans));
}

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

    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].pb(b);
    }

    tsort();

    bool f = true;
    rep(i, n-1) {
        bool f2 = false;
        rep(j, g[ans[i]].size()) {
            f2 |= g[ans[i]][j] == ans[i+1];
        }
        f &= f2;
    }
    for (int x : ans) {
        cout << x+1 << endl;
    }
    cout << !f << endl;
    return 0;
}


Measured memory_bytes: 6048
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		var d = ria();
		Array.Sort(d);
		Console.WriteLine(d[0] == 5 && d[1] == 5 && d[2] == 7 ? "YES" : "NO");
	}

	public Sol(){
		
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
using ll = long long;
int main()
{
	int n, x, t;
    cin >> n >> x >> t;
    
    cout << (n / x + (n % x == 0 ? 0 : 1)) * t << endl;
	return 0;
}

Measured memory_bytes: 3584
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9

def main():
    n = int(input())
    P = list(map(int, input().split()))

    minimum = INF
    ans = 0
    for i in range(n):
        if minimum >= P[i]:
            minimum = P[i]
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 92156
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(string, s);

  map<char, int> mp;
  for (auto e : s) mp[e]++;

  for (auto e : mp) {
    if (e.second % 2) {
      puts("No");
      return 0;
    }
  }

  puts("Yes");

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SE second
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define mp make_pair
#define ll long long
#define LLI long long int
#define REP(i,a,b) for(long long i=a;i<b;i++)
#define PER(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define Arrays(a, size) sort((a), (a)+(size))
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
using namespace std;

int _dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
int _dy[] = { 0, 1, 0, -1, 1, -1, 1, -1 };

//vector<int> a;
ll n,d,x;
int r;
int main(){
    cin>>r>>d>>x;
    for(int i=1;i<=10;i++){
        x=r*x-d;
        cout<<x<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<functional>
#include<stack>
#include<utility>
#include<stack>

using namespace std;

int main() {
	long long n, MAX, MIN, SUM = 0, a;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (i == 0) {
			MAX = a;
			MIN = a;
			SUM += a;
			continue;
		}
		MAX = max(MAX, a);
		MIN = min(MIN, a);
		SUM += a;
	}
	cout << MIN <<" "<< MAX <<" "<< SUM << endl;
	return 0;
}

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

using namespace std;

int main(){
	
	long long n, a, b, ans = 0;
	string s;
	
	cin >> n >> a >> b;
	
	
	
	cout << (n/(a+b)) * a + min(n%(a+b), a);
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main() {
    ll A[4];
    rep(i,1){
        cin >> A[i];
    }
    //sort(A,A+3);
    cout << "ABC" << A[0] << endl;
}

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

using namespace std;

#define MAX 100
#define INF (1<<29)
typedef pair<int, int> pii;

int main()
{
    int n, d, m;
    while (cin >> n >> d, n) {
        int N = 0;
        vector<int> cap[MAX];        
        for (int i = 0; i < n; i++) {
            cin >> m;
            cap[i].resize(m);
            for (int j = 0; j < m; j++, N++) {
                cin >> cap[i][j];                
            }
        }
        bool possible = 1;
        vector<int> cur(n, 0), sum(n, 0);        
        while (N--) {
            int p = -1, maxi = -INF;
            vector<pii> v(n);
            for (int i = 0; i < n; i++) {
                v[i] = pii(sum[i], i);
            }
            sort(v.begin(), v.end());
            for (int i = 0; i < n; i++) {
                if (cur[i] == (int)cap[i].size()) {
                    continue;
                }
                int j = 0;
                for (; j < n; j++) {
                    if (v[j].second != i) {
                        break;
                    }
                }
                if (sum[i] + cap[i][cur[i]] > maxi &&
                    sum[i] + cap[i][cur[i]] - v[j].first <= d) {
                    maxi = sum[i] + cap[i][cur[i]];
                    p = i;
                }
            }
            if (p == -1) {
                possible = 0;
                break;
            }
            
            sum[p] += cap[p][cur[p]++];
            int min_p = INF, max_p = -INF;
            for (int i = 0; i < n; i++) {
                min_p = min(min_p, sum[i]);
                max_p = max(max_p, sum[i]);
            }
            if (max_p - min_p > d) {
                possible = 0;
                break;
            }
        }
        cout << (possible ? "Yes" : "No") << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <cmath>
#include <functional>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <set>
#ifdef XLor
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 600000 + 5;

int n, k, b[maxn];
ll ans, a[maxn];

int main() {
  scanf("%d%d", &n, &k);
  map<int,int> mp; mp[0] = 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    a[i] += a[i - 1];
    b[i] = ((a[i] - i) % k + k) % k;
    if (i >= k) mp[b[i - k]]--;
    ans += mp[b[i]];
    mp[b[i]]++;
  }
  // (pre(r) - pre(l)) % k == r - l
  // pre(r) - pre(l) = x * k + r - l
  // pre(r) - r = pre(l) - l + x * k
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 13184
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,D,X = map(int,read().split())

answer = 0
for n in range(N,0,-1):
    mean = D + X * (n+n-1) / 2
    answer += mean
    D = ((n+n+2) * D + 5 * X) / (2*n)
    X = (n + 2) * X / n

print(answer)

Measured memory_bytes: 3064
/* ex2_3
   masaaki52	*/
#include <stdio.h>
int main(void){
  int N;
  scanf("%d",&N);//入力受け取り
  int A;
  scanf("%d",&A);//入力受け取り
  int a = N*N - A;//計算結果をaに代入
  printf("%d\n",a);//aを出力
  return 0;
}

Measured memory_bytes: 128
// #pragma GCC optimize(2)
// #pragma G++ optimize(2)
// #pragma comment(linker,"/STACK:102400000,102400000")

#include <bits/stdc++.h>
using namespace std;

typedef long long int64;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef float fl;
typedef double dl;
typedef pair<int,int> pii;
#if (WIN32) || (WIN64) || (__WIN32) || (__WIN64) || (_WIN32) || (_WIN64) || (WINDOWS)
#define lld "%I64d"
#define llu "%I64u"
#else
#define lld "%lld"
#define llu "%llu"
#endif
#define uint(n) ((unsigned int)(n))
#define int64(n) ((long long)(n))
#define ull(n) ((unsigned long long)(n))
#define fl(n) ((float)(n))
#define dl(n) ((double)(n))
#define char(n) ((char)(n))
#define Bool(n) ((bool)(n))
#define fixpoint(n) fixed<<setprecision(n)

const int INF=1061109567;
const int NINF=-1044266559;
const int64 LINF=4557430888798830399;
const dl eps=1e-15;
#define MOD (1000000007)
#define PI (3.1415926535897932384626433832795028841971)

#define MP make_pair
#define MT make_tuple
#define All(a) (a).begin(),(a).end()
#define pall(a) (a).rbegin(),(a).rend()
#define Log(x,y) log(x)/log(y)
#define SZ(a) ((int)(a).size())
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define rep1(i,n) for(int i=1;i<=((int)(n));i++)
#define repd(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define repd1(i,n) for(int i=((int)(n));i>=1;i--)
#define repv(itr,v) for(__typeof((v).begin()) itr=(v).begin();itr!=(v).end();itr++)
#define repV(i,v) for(auto i:v)
#define repE(i,v) for(auto &i:v)
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x) MS(x,0)
#define MINF(x) MS(x,63)
#define MCP(x,y) memcpy(x,y,sizeof(y))
#define UN(v) sort(All(v)),v.erase(unique(All(v)),v.end())
#define filein(x) freopen(x,"r",stdin)
#define fileout(x) freopen(x,"w",stdout)
#define fileio(x)\
	freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout)
#define filein2(filename,name) ifstream name(filename,ios::in)
#define fileout2(filename,name) ofstream name(filename,ios::out)
#define fileio2(filename,name) fstream name(filename,ios::in|ios::out)
#define sqr(x) ((x)*(x))
#define Pause system("pause")
#define Cls system("cls")
#define fs first
#define sc second
#define SF scanf
#define PF printf

const int maxn=INF;

inline int64 powmod(int64 a,int64 b){int64 res=1;a%=MOD;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res%MOD;}

inline int64 fact(int n)
{
	int64 f=1;
	for(int i=2;i<=n;i++) f=(f*i)%MOD;
	return f;
}

inline int64 binom(int n,int m)
{
	if(n<m) return 0;
	return fact(n)*powmod(fact(m)*fact(n-m),MOD-2);
}

int n;
int64 ans;

int main()
{
	cin>>n;

	for(int i=0;i<=(n-3)/3;i++) ans=(ans+binom(n-3-2*i,i))%MOD;

	cout<<ans;

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  int a[10000];
  int sum=0;
  for(int i=0;i<M;i++){
    cin>>a[i];
    sum=sum+a[i];
  }
  if(sum>N){
    cout<<"-1"<<endl;
  }
  else{
    cout<<N-sum<<endl;
  }
  
  return 0;
}

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

using namespace std;
 
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
 
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) (c.begin(),c.end())
#define in(x, a, b) (a <= x && x < b)
const int inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
//const ll mod = 1000000009;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p <<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);


int main() {
  int n;
  cin >> n;
  vi a(n);
  rep (i, n) {
    cin >> a[i];
  }
  vii sum(n + 1, vi(20));
  rep (i, n) {
    int mask = 1;
    rep (j, 20) {
      if ((a[i] & mask)) {
        sum[i + 1][j] = sum[i][j] + 1;
      }
      else {
        sum[i + 1][j] = sum[i][j];
      }
      mask <<= 1;
    }
  }
  /*
  rep (i, n + 1) {
    rep (j, 20) {
      cout << sum[i][j] << " ";
    }
    cout << endl;
  }
  cout << flush;
  //*/
  ll ans = 0;
  rep (i, n) {
    int ok = i, ng = n + 1;
    while (ok + 1 < ng) {
      int mid = (ng + ok) / 2;
      bool flag = true;
      rep (j, 20) {
        if (sum[mid][j] - sum[i][j] >= 2) {
          flag = false;
          break;
        }
      }
      if (flag) {
        ok = mid;
      }
      else {
        ng = mid;
      }
    }
    //DEBUG(ok);
    ans += (ll)(ok - i);
  }
  cout << ans << endl;
}


Measured memory_bytes: 24448
#include <cstdio>
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <functional>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <utility>
#include <memory>
#include <valarray>
#include <climits>

using namespace std;

using ll = long long int;

#define loop(i, N) for (int i = 0; i < N; ++i)
#define scanInt(x) int x; scanf("%d", &x); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &x); getchar();
#define scanVecInt(A, N) vector<int> A(N); loop(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); loop(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    scanInt(W);
    // vector<int> w(N);
    // vector<int> v(N);
    array<vector<int>, 4> V;
    scanInt(w0);
    {
        scanInt(vj);
        V[w0 - w0].emplace_back(vj);
    }
    loop(j, N - 1){
        scanInt(wj);
        scanInt(vj);
        // w[j] = wj;
        // v[j] = vj;
        V[wj - w0].emplace_back(vj);
    }
    loop(i, 4){
        auto& Vi = V[i];
        sort(Vi.begin(), Vi.end(), greater<int>());
        // for (auto& vj : Vi){
        //     printf("%d ", vj);
        // } puts("");
        for (int j = 1; j < Vi.size(); ++j){
            Vi[j] += Vi[j - 1];
        }
        // for (auto& vj : Vi){
        //     printf("%d ", vj);
        // } puts("");
    }
    function<int(int, int)> f = [&](int i, int Wtemp){
        if (Wtemp > W) return 0;
        if (i >= 4) return 0;
        auto& Vi = V[i];
        int ret = 0;
        ret = max(ret, 0 + f(i + 1, Wtemp));
        loop(j, Vi.size()){
            const int nextWtemp = Wtemp + (w0 + i) * (j + 1);
            if (nextWtemp > W) break;
            ret = max(ret, Vi[j] + f(i + 1, nextWtemp));
        }
        return ret;
    };
    printf("%d\n", f(0, 0));
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    int x = sc.nextInt();
	    ArrayList<Integer>ans  = new ArrayList<>();
	    
	    if(x==1) {
	    	System.out.println("1");
	    }else {
	    for(int i=1; i<=x; i++) {
	    	for(int j=2; j<=x; j++) {
	    		if((int)Math.pow(i, j)<=x) {
	    			ans.add((int)Math.pow(i, j));
	    		}
	    	}
	    }
	    Collections.sort(ans,Collections.reverseOrder());
	    	System.out.println(ans.get(0));
	      }
	}
}

Measured memory_bytes: 35648
#include<iostream>
#include<vector>
#include<string>
using namespace std;
vector<pair<int, int>>x[10][10]; string S;
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 }; char V[5] = "RDLU";
int main() {
	int cnt = 0;
	for (int i = 0; i < 9;i++){
		cin >> S;
		if (i % 2 == 0) {
			for (int j = 0; j < S.size(); j++) {
				if (S[j] == '0')continue;
				x[cnt][j].push_back(make_pair(cnt, j + 1));
				x[cnt][j + 1].push_back(make_pair(cnt, j));
			}
		}
		else {
			for (int j = 0; j < S.size(); j++) {
				if (S[j] == '0')continue;
				x[cnt][j].push_back(make_pair(cnt + 1, j));
				x[cnt + 1][j].push_back(make_pair(cnt, j));
			}
			cnt++;
		}
	}
	int cx = 0, cy = 0, dir = 0;
	while (true) {
		cx += dx[dir]; cy += dy[dir]; cout << V[dir];
		if (cx == 0 && cy == 0)break;
		for (int i = 3; i <= 6; i++) {
			int F = (i + dir) % 4;
			for (int j = 0; j < x[cx][cy].size(); j++) {
				if (x[cx][cy][j] == make_pair(cx + dx[F], cy + dy[F])) {
					dir = F; goto E;
				}
			}
		}
	E:;
	}
	cout << endl;
	return 0;
}

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

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/detail/standard_policies.hpp>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)

#define dbg(x) cerr << (#x) << " --> " << (x) << nl;
#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

#define Toktama ""

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//typedef tree < pair <int, int>, null_type, less < pair <int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 2e5 + 7, inf = 1e9 + 7, mod = 1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

int get_int() {
  char x = getchar();
  bool mns = 0;
  while (!isdigit(x)) mns |= x == '-', x = getchar();
  int res = 0;
  while (isdigit(x)) res = res * 10 + x - '0', x = getchar();
  if (mns) res = -res;
  return res;
}
void add(int &x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  if (x < 0) x += mod;
}
int mult(int x, int y) {
  return x * 1ll * y % mod;
}
int sum(int x, int y) {
  add(x, y);
  return x;
}

int n, m;
int dp[N << 2][2];
int calc(int v, int t) {
  if (v > n + m) return 1;
  if (~dp[v][t]) return dp[v][t];
  int tot = !t ? n : m, can = tot - ((v - 1) >> 1), res = 0;
  add(res, mult(calc(v + 1, t ^ 1), can));
  return dp[v][t] = res;
}
void solve() {
  cin >> n >> m;
  dp[1][0] = n;
  dp[1][1] = m;
  rep(i, 2, n + m) {
    rep(j, 0, 1) {
      int tot = !j ? n : m, can = tot - ((i - 1) >> 1);
      dp[i][j] = mult(dp[i - 1][j ^ 1], can);
    }
  }
  cout << sum(dp[n + m][1], dp[n + m][0]);
  //memset(dp, -1, sizeof(dp));
  //cout << sum(calc(1, 0), calc(1, 1));
}
int main() {
  #ifndef Toktama
    freopen (Toktama".in", "r", stdin);
    freopen (Toktama".out", "w", stdout);
  #endif
  int t = 1;
  while (t--)
    solve();
  ioi
}


Measured memory_bytes: 1792
from bisect import bisect_left
import random
import time
import math


#入力
D = int(input())
C = [int(c) for c in input().split()]
S = []
for _ in range(D):
    s = [int(x) for x in input().split()]
    S.append(s)
#初期解
T = []
for _ in range(D):
    t = random.randrange(26)
    T.append(t)


last_day = [[-1] for _ in range(26)]
for d in range(D):
    test = T[d]
    last_day[test].append(d)
for i in range(26):
    last_day[i].append(D)


T0 = 5000
time_start = time.perf_counter()
while True:
    time_now = time.perf_counter()
    if time_now - time_start > 1.80:
        break
    #時間を正規化して温度を設定
    time_n = (time_now - time_start) / 1.80
    T1 = T0 ** (1 - time_n)
    for _ in range(100):
        #ランダムな日のテストをランダムに入れ替え
        d = random.randrange(365)
        q = random.randrange(26)
        old = T[d]
        T[d] = q
        #日程dでの元のテストold
        l = last_day[old]
        ind_old = l.index(d)
        dd_left = l[ind_old] - l[ind_old-1] - 1
        dd_right = l[ind_old+1] - l[ind_old] - 1
        dd = l[ind_old+1] - l[ind_old-1] - 1
        dif_old = C[old] * (((dd_left * (dd_left + 1)) // 2) + ((dd_right * (dd_right + 1)) // 2) - ((dd * (dd + 1)) // 2))
        #日程dでのテストq
        l = last_day[q]
        ind_q = bisect_left(last_day[q],d)
        dd_left = d - l[ind_q-1] - 1
        dd_right = l[ind_q] - d - 1
        dd = l[ind_q] - l[ind_q-1] - 1
        dif_q = C[q] * (((dd * (dd + 1)) // 2) - ((dd_left * (dd_left + 1)) // 2) - ((dd_right * (dd_right + 1)) // 2))
        #変更による差
        dif_s = dif_old + dif_q - S[d][old] + S[d][q]
        if (dif_s > 0) or (math.exp(dif_s / T1) > random.random()):
            del last_day[old][ind_old]
            last_day[q].insert(ind_q,d)
        else:
            T[d] = old
for d in range(365):
    print(T[d] + 1)



Measured memory_bytes: 88480
a=[int(input()) for _ in range(int(input()))]
ans=1
c=a[0]
if(c==2):
    print(ans)
else:
    while(c!=2):
        ans+=1
        c=a[c-1]
        if(ans>len(a)):
            print(-1)
            exit()
    print(ans)

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

int main() {
    int N, M;
    cin >> N >> M;

    vector<int> road(N, 0);

    int a, b;

    rep2(i, 0, M){
        cin >> a >> b;
        road.at(a-1)++;
        road.at(b-1)++;
    }

    rep2(i, 0, N){
        cout << road.at(i) << endl;
    }
}


Measured memory_bytes: 3604
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(H, W, N, A):

    ans = []
    A = [(a, i+1) for i, a in enumerate(A)]
    A.sort()
    for a, i in A:
        for _ in range(a):
            ans.append(i)

    for y in range(H):
        tmp = []
        for x in range(W):
            if y % 2 == 0:
                tmp.append(str(ans[y*W + x % W]))
            else:
                tmp.append(str(ans[y*W + W - x % W - 1]))
        print(' '.join(tmp))


def main():
    H, W = read_int_n()
    N = read_int()
    A = read_int_n()

    # H = 4
    # W = 5
    # N = random.randint(1, 20)
    # s = 0
    # A = [1] * N
    # for _ in range(H*W-N):
    #     A[random.randint(0, N)] += 1

    # print(H, W, N, A)
    slv(H, W, N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61932
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <bitset>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
 
typedef long long ll;
typedef long double ld;
 
const ll MOD = 1e9 + 7, INF = 1e18 + 1;
 
using namespace std;

ll k, n, g_min = INF, ptr = 0, a[100];

map < pair <ll, ll>, ll> dp[20][20];

ll Rec (int l, int r, ll xl, ll xr)
{
	if (l == r - 1) return 0;

	if (dp[l][r].find ({xl, xr}) != dp[l][r].end ()) return dp[l][r][make_pair (xl, xr)];

	ll mn = INF;

	for (int i = l + 1; i < r; i++)
		mn = min (mn, Rec (l, i, xl, xl + xr) + Rec (i, r, xl + xr, xr) + a[i] * (xl + xr));

	return dp[l][r][make_pair (xl, xr)] = mn;
}

int main ()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		scanf ("%lld", &a[i]);

	cout << Rec (0, n - 1, 1, 1) + a[0] + a[n-1];
}


Measured memory_bytes: 16640
#include <stdio.h>

int a;
int b;
int num;

num=1;
a=1;
b=0;

int main(void){
	
	for (num=1;num<82;num++){
		b=b+1;
		if (b==10){
			b=1;
			a=a+1;
					}

		printf("%dx%d=%d\n",a,b,a*b);
								}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
queue<int> q1,q2;
int main(){
	while(!q1.empty()) q1.pop();
	while(!q2.empty()) q2.pop();
	int n;
	int a;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a);
		if(a%2){
			if(!q1.empty()){
				int foo=q1.front();
				int sum=a+foo;
				q1.pop();
				if(sum%2){
					q1.push(sum);
				}
				else{
					q2.push(sum);
				}
			}
			else{
				q1.push(a);
			}
		}
		else{
			if(!q2.empty()){
				int foo=q2.front();
				int sum=foo+a;
				q2.pop();
				if(sum%2){
					q1.push(sum);
				}
				else{
					q2.push(sum);
				}
			}
			else{
				q2.push(a);
			}
		}
	}
	if(q1.empty()||q2.empty()){
		puts("YES");
	}
	else{
		puts("NO");
	}
	return 0;
}

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

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

    if (S[2] == S[3] && S[4] == S[5])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
	string s;
	while(getline(cin, s)){
		int n = s.size();
		rep(i, n){
			cout << (char)('A' + (s[i] - 'A' + 23) % 26); 
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
signed main(){
	int n,h[20];
	cin>>n;
	rep(i,n)cin>>h[i];
	int pan=0;
	int ans=0;
	rep(i,n){
		if(h[i]>=pan){
			ans++;
			pan=h[i];
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

unsigned long long int N = 1000000;

int main(void){

  int i, j, n;
  int pn[N];

  for(i=3; i<N; i+=2){
    pn[i]=-1;
  }
  pn[0]=pn[1]=0;
  pn[2]=1;
  

  for(i=3; i<N; i+=2){
    if(pn[i]==-1){
      pn[i]=1;
      for(j=i*2; j<N; j+=i){
	pn[j]=0;
      }
    }
  }

  for(i=3; i<N; ++i){
    pn[i]+=pn[i-1];
  }

  while(scanf("%d", &n)!=EOF){
    printf("%d\n", pn[n]);
  }
  return(0);
}



Measured memory_bytes: 5620