akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  long long n, K;
  cin >> n >> K;
  vector<long long> cnt(K);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    cnt[i % K]++;
  }
  for (int i = 1; i <= n; i++) {
    if (2 * i % K == 0) {
      ans += cnt[(K - i % K) % K] * cnt[(K - i % K) % K];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
import sys
from collections import deque
sys.setrecursionlimit(10**6)

n,m = map(int, input().split())
nextroom = [[] for _ in range(n)]
for i in range(m):
	a,b = map(int, input().split())
	nextroom[a-1].append(b-1)
	nextroom[b-1].append(a-1)

sign = [-1]*n # 道しるべ
sign[0] = -2 
visited = [False]*n # visited or not
visited[0] = True

q = deque([0])
while len(q)>0:
	room = q.popleft()
	for nroom in nextroom[room]:
		if visited[nroom] == 0:
			visited[nroom] = 1
			sign[nroom] = room
			q.append(nroom)

print('Yes')
for i in range(1,n):
	print(sign[i]+1)

Measured memory_bytes: 35136
import java.time.Instant;
import java.util.*;
import java.util.function.ToLongFunction;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<Pair<String, Integer>> SP = new ArrayList<>();
		for(int i=0; i<N; i++){
			SP.add(new Pair<String, Integer>(i+1, sc.next(),sc.nextInt()));
		}

		Comparator<Pair> comparator = Comparator.<Pair, String> comparing(pair -> (String)pair.a)
		        .<Integer>thenComparing(pair -> -1 * (int)pair.b);

		SP = SP.stream().sorted(comparator).collect(Collectors.toList());

		for(Pair pair : SP){
			System.out.println(pair.n);
		}






	}

	static class Pair<T1, T2>   {
		int n;
	    T1 a;
	    T2 b;
	    public Pair(int n, T1 a,T2 b) {
	        this.n = n;
	    	this.a = a;
	        this.b = b;
	    }

	    T1 getA(){
	    	return a;
	    }

	    T2 getB(){
	    	return b;
	    }

	}
}




Measured memory_bytes: 26964
import sys
input = sys.stdin.readline

H, N = map(int, input().split())
l = [tuple(map(int, input().split())) for _ in range(N)]
M = max([A for A, B in l])

dp = [0]*(H+M)
for i in range(1, H+M):
  dp[i] = min([B + dp[i-A] for A, B in l if i>=A]+[10**8])
ans = min([dp[i] for i in range(H, H+M)])
print(ans)

Measured memory_bytes: 3620
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
// const long long MOD = (ll)1e6+3;
const long long MAX = (ll)1e5+10;



int main(void) {
    ll K,N;
    cin>>N>>K;
    vector<ll> H(N);
    rep(i,0,N) cin>>H[i];
    sort(H.begin(),H.end());
    ll ans = 0;
    rep(i,0,N-K) {
        ans += H[i];
    }
    cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 1920
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 16 21:44:28 2020

@author: H_Hoshigi
"""

N = input()

n_list = []
for i in range(len(N)):
    n_list.append(int(N[-(i+1)]))
n_list.append(0)

counter = 0
for i in range(len(N)+1):
    if (n_list[i]<=4) or ((n_list[i]==5)and(n_list[i+1]<=4)):
        counter += n_list[i]
        n_list[i] = 0
    else:
        counter += 10-n_list[i]
        n_list[i] = 0
        n_list[i+1] += 1
    #print(counter)
    #print(n_list)

print(counter)


Measured memory_bytes: 15672
def main
    n = gets.to_i
    c = gets.chomp.split(" ").map(&:to_i)
    u_min = [c.last] * (n+1)
    u_max = [c.last] * (n+1)

    (0..n-1).reverse_each do |i|
        u_min[i] = (u_min[i+1]+1)/2 + c[i]
        u_max[i] = u_max[i+1] + c[i]
    end
    if u_min[0] > 1 || u_max[0] < 1
        puts -1
        return
    end
    u_min[0] = 1
    u_max[0] = 1
    ans = 1
    (1..n).each do |i|
        u_max[i] = [u_min[i-1] * 2, u_max[i]].min
        u_min[i] = u_max[i] - c[i]
        ans += u_max[i]
    end
    puts ans
end

main


Measured memory_bytes: 24060
n,x,y=map(int, input().split())

ans=[0]*(n-1)

for i in range(1,n):
    for j in range(i+1,n+1):
        if j<=x:
            tmp=j-i
            
        elif x<i and j<y:
            tmp=min(j-i,(i-x)+1+(y-j))
            
        elif y<=i:
            tmp=j-i

        elif i<=x and y<=j:
            tmp=j-i -(y-x-1)

        elif i<=x and x<j and j<y:
            tmp=min(j-i,(x-i)+1+(y-j))
        elif x<i and i<y and y<=j:
            tmp=min(j-i,(i-x)+1+(j-y))

        ans[tmp-1] += 1

for i in ans:
    print(i)

Measured memory_bytes: 47196
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int d = sc.nextInt();
		int count = 0;
		for (int i = 22; i <= d; i++) {
			if (i % 10 < 2) {
				continue;
			}
			if ((i % 10) * (i / 10) <= m) {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 23252
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
#include <iomanip>
#include <limits>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
typedef priority_queue<ll> PQ_HIGH;
typedef priority_queue<ll,VL,greater<ll>> PQ_LOW;//昇順

void test(priority_queue<pair<ll,ll>> que){
  while(!que.empty()){
    cout<<que.top().first<<" "<<que.top().second<<endl;
    que.pop();
  }
}

int main(){
  ll n,k;cin>>n>>k;
  VL a(n);REP(i,n){cin>>a[i];}

  ll zero=0;
  vector<ll> mi;
  vector<ll> ma;
  for(int i=0;i<k;i++){
    ll count=0;
    REP(i,n){
      ll fi=max(zero,i-a[i]);
      ll se=min(n-1,i+a[i]);
      mi.push_back(fi);
      ma.push_back(se);
    }
    sort(mi.begin(),mi.end());
    sort(ma.begin(),ma.end());
    for(int j=0;j<n;j++){
      auto itr1=lower_bound(ALL(mi),j+1);
      auto itr2=lower_bound(ALL(ma),j);
      ll in1=itr1-mi.begin();
      ll in2=itr2-ma.begin();
      in1--;
      ll tmp=in1-in2+1;
      a[j]=tmp;
      if(tmp==n){
        count++;
      }
    }
    if(count==n){break;}
    mi.clear();
    ma.clear();
  }
  REP(i,n){
    cout<<a[i]<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 7888
N = int(input())
F = [list(map(int,input().split())) for k in range(N)]
P = [list(map(int,input().split())) for k in range(N)]
ans = -float("inf")
for k in range(2**10):
    temp = 0
    S = [0 for l in range(N)]
    for s in range(N):
        for d in range(10):
            if (k>>d)&1 == 1:
                if F[s][d] == 1:
                    S[s] += 1
    if sum(S) > 0:
        for l in range(N):
            temp += P[l][S[l]]
        ans = max(ans,temp)

print(ans)


Measured memory_bytes: 42972
fun main(args: Array<String>) {
    val number = readLine()!!.split(" ").map { it.toInt() }
    val dice = Dice(number[0], number[1], number[2], number[3], number[4], number[5])
    val order = readLine()!!
    order.forEach {
        when (it) {
            'N' -> dice.toN()
            'E' -> dice.toE()
            'S' -> dice.toS()
            'W' -> dice.toW()
        }
    }
    println(dice.getTop())
}

class Dice(var one: Int, var two: Int, var three: Int, var four: Int, var five: Int, var six: Int) {
    fun toN() {
        val temp = one
        one = two
        two = six
        six = five
        five = temp
    }

    fun toS() {
        val temp = one
        one = five
        five = six
        six = two
        two = temp
    }

    fun toE() {
        val temp = one
        one = four
        four = six
        six = three
        three = temp
    }

    fun toW() {
        val temp = one
        one = three
        three = six
        six = four
        four = temp
    }

    fun getTop(): Int {
        return one
    }
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		int x, y;
		cin >> x >> y;
		
		bool ok=0;
		for(int i=0 ; i<=x ; ++i){
			if(i*4 + (x-i)*2 == y){
				ok=1;break;
			}
		}
		
		cout << (ok ? "Yes" : "No");
	}
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(ll i=m;i<n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const int INF=INT_MAX;
const double PI=3.1415926;
int main()
{
    ll n,k,sum=0;
    cin>>n>>k;
    for(ll i=k;i<=n+1;i++)
    {
        sum=(sum+n*(n+1)/2-(n-i)*(n+1-i)/2-i*(i-1)/2+1)%MOD1;
    }
    cout<<sum;
}


Measured memory_bytes: 3636
#include<iostream>

using namespace std;

const int MAX_N = 150;

int diag(int h, int w){
    return h*h + w*w;
}

int main(){
    while (1){
        int h, w;

        cin >> h >> w;
        if (h == 0){
            break;
        }

        int d = diag(h, w);
        int ans_h = MAX_N;
        int ans_w = MAX_N;

        bool flag = false;
        for (int i = 1; i < MAX_N; i++){
            for (int j = i + 1; j < MAX_N; j++){
                if ((diag(i, j) == d && i > h) || diag(i, j) > d){
                    if (diag(i, j) < diag(ans_h, ans_w)){
                        ans_h = i;
                        ans_w = j;
                    }
                }
            }
        }

        cout << ans_h << " " << ans_w << endl;
    }


    return 0;
}

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

#define ll long long
const int inf = 1e9+7;
const ll INF = 1e18+7;

using namespace std;

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

  int n, k;
  cin >> n>>k;
  cout<<((n-2)/(k-1))+1<<"\n";
   
}


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

int n ;
  vector<int> c(500);
  vector<int> s(500);
  vector<int> f(500);

int add(int i,int sum){
  if(i == n-1){
    return sum;
  }
  int add1=0 ;
  if( sum<s.at(i)){
    add1 = s.at(i)+c.at(i)-sum;
  }
  else{
    add1 = s.at(i)+c.at(i)+(sum -s.at(i)+f.at(i)-1)/f.at(i)*f.at(i)-sum;
  }
  sum +=add1;
  sum = add(i+1,sum);
  return sum;
}

int time(int i){
  int sum=0;
  sum = add(i,sum);
  return sum;
}


int main() {
  cin >>n;
  for( int i=0;i<n;i++){
    cin >> c.at(i)>>s.at(i)>>f.at(i);
  }
  for(int i = 0;i<n;i++){
    cout << time(i);
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S, T;
  cin >> S >> T;
  int count = 0;
  string A = S;
  for (int i = S.size() - T.size(); i >= 0; i--) {
    count = 0;
    for (int j = T.size() - 1; j >= 0; j--) {
      if (S.at(i + j) == T.at(j) || S.at(i + j) == '?') {
        S.at(i + j) = T.at(j);
        count++;
        if (count == T.size()) break;
      } else {
        S = A;
        break;
      }
    }
    if (count == T.size()) break;
  }
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == '?') S.at(i) = 'a'; 
  }
  if (count == T.size()) cout << S << endl;
  else cout << "UNRESTORABLE" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);
    ArrayList<Data> data;
    boolean debug = false;
    

    boolean[] p; 
    void set_prime(){
	p = new boolean[123457*2];
	for(int i=2; i<123457*2; i++)
	    for(int j=2; j*i<=123456*2; j++) p[j*i] = true;
    }

    void run() {
	set_prime();
	input();
	for(int i=0; i<data.size();i++){
	    if(debug){
		System.out.println("-----------");
		data.get(i).print_n();
	    }
	    solve(i);
	    data.get(i).print_ans();
	}
    }
    
    void solve(int i){
	int n = data.get(i).get_n();
	int ans = 0;
	for(int j=n+1; j<=n*2; j++)
	    if(!p[j]) ans++;
	data.get(i).set_ans(String.valueOf(ans));
    }
    
    void input(){
	data = new ArrayList<Data>();
	while(true){
	    int n=sc.nextInt();
	    if(n==0) break;
	    data.add(new Data(n));
	}
    }

}

class Data{
    int n;
    String ans;

    Data(int n) {
	this.n=n;
    }

    int get_n(){return n;}

    void set_ans(String a){ans = a;}
    void print_n(){System.out.println("n= "+n);}
    void print_ans(){System.out.println(ans);}
}

Measured memory_bytes: 20708
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 200010
using namespace std;

struct edge{int x, y, next;}a[N*2], b[N*2];
int n, p1, p2, l, p[N], q[N], x, y, dis1[N], dis2[N], fa[N], flag[N], ff[N], ans;

inline char gc(){
	static char now[1<<16], *S, *T;
	if(S==T){T=(S=now)+fread(now, 1, 1<<16, stdin); if(S==T)return EOF;}
	return *S++;
}
inline int read(){
	int x=0, f=1; char ch=gc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=gc();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=gc();}
	return x*f;
}

inline void add1(int x, int y){a[++l].x=x; a[l].y=y; a[l].next=p[x]; p[x]=l;}
inline void add2(int x, int y){b[++l].x=x; b[l].y=y; b[l].next=q[x]; q[x]=l;}

inline int check(int x, int y){
	if(fa[x]==y||fa[y]==x)return 0;
	if(fa[fa[x]]==y||fa[fa[y]]==x||fa[x]==fa[y])return 0;
	return 1;
}
inline void dfs1(int x, int fa){
	if(dis1[x]<dis2[x]&&flag[fa])flag[x]=1;
	for(int i=p[x]; i; i=a[i].next)if(fa!=a[i].y){
		if(check(x, a[i].y))ff[x]=ff[a[i].y]=1;
		dis1[a[i].y]=dis1[x]+1; dfs1(a[i].y, x);
	}
}
inline void dfs2(int x){
	for(int i=q[x]; i; i=b[i].next)if(fa[x]!=b[i].y){
		fa[b[i].y]=x; dis2[b[i].y]=dis2[x]+1; dfs2(b[i].y);
	}
}

int main(){
	n=read(); p1=read(); p2=read();
	l=0; memset(p, 0, sizeof(p));
	for(int i=1; i<=n-1; i++){x=read(); y=read(); add1(x, y); add1(y, x);}
	l=0; memset(q, 0, sizeof(q));
	for(int i=1; i<=n-1; i++){x=read(); y=read(); add2(x, y); add2(y, x);}
	fa[p2]=dis2[p2]=0; dfs2(p2);
	memset(ff, 0, sizeof(ff)); memset(flag, 0, sizeof(flag)); flag[0]=1;
	dis1[p1]=0; dfs1(p1, 0);
	for(int i=1; i<=n; i++)if(flag[i]&&ff[i]){printf("-1"); return 0;}
	ans=0; for(int i=1; i<=n; i++)if(flag[i])ans=max(ans, dis2[i]);
	printf("%d", ans*2);
	return 0;
}

Measured memory_bytes: 19072
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll ans=0LL;
	cin >>n;
	V l(n);
	rep(i, n) { cin >> l[i]; 
	}
	sort(all(l));
	for (int i = 0; i < n - 2; i++) {
		for (int j = i+1; j < n - 1; j++) {
			for (int k = j+1; k < n; k++) {
				if (l[i] == l[j] or l[j] == l[k]) continue;
				if (l[i] + l[j] > l[k]) {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<pair<int, int>> A(M);
  REP(i, M){
    cin >> A[i].first >> A[i].second;
  }

  sort(ALL(A),   // dai -> syou
      [](pair<int, int> const & l, pair<int, int> const &  r){
      return l.second < r.second;
      });

  int ans = 0;
  int now = -INF;
  REP(i, M){
    if(now <= A[i].first){
      ans++;
      now = A[i].second;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  
  vector<int> a(N);
  vector<int> b(N);
  vector<int> c(N);
  
  for (int i=0;i<N;i++){
    cin >> a[i];}
  for (int i=0;i<N;i++){
    cin >> b[i];}
  for (int i=0;i<N;i++){
    cin >> c[i];}
  
  sort(a.begin(),a.end());
  sort(c.begin(),c.end());
  
  long long int answer=0;
  
  for(int i=0;i<N;i++){
      long long int front,back;
      front=distance(a.begin(),lower_bound(a.begin(),a.end(),b[i]));
      
      back =distance(upper_bound(c.begin(),c.end(),b[i]),c.end());
      
       answer += front * back;
  }
   
  cout << answer;
    
  }

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

int main(){
    int n; cin >> n;
    vector <int> A(n);
    for (int i=0; i<n; i++) cin >> A[i];
    
    int ans=0;
    for (int i=1; i<n-1; i++){
        if ((A[i]!=max({A[i-1],A[i],A[i+1]})) && A[i]!=min({A[i-1],A[i],A[i+1]})) ans++;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  FOR(i, k, n - 1) {
    if (a[i] > a[i - k]) cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 4772
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
#include <list>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;

static const ll max_r = 3001;
static const ll max_c = 3001;

vector<vector<ll>> field(max_r, vector<ll>(max_c, 0));
vector<vector<vector<ll>>> dp(max_r, vector<vector<ll>>(max_c, vector<ll>(4, 0)));

void Main(){
    ll R, C, K, r, c, v;
    cin >> R >> C >> K;
    rep(i, K){
        cin >> r >> c >> v;
        --r;
        --c;
        field[r][c] = v;
        // items[r].emplace_back(c, v);

    }

    rep(i, R){
        rep(j, C){
            // if(field[i][j] > 0)
            if(i>0){
                rep(n, 4){
                    dp[i][j][0] = max(dp[i-1][j][n], dp[i][j][0]);
                }
            }
            if(field[i][j]>0){
                dp[i][j][1] = dp[i][j][0] + field[i][j];
            }


            if(j>0){
                rep(n, 3){
                    if(field[i][j]>0){
                        ll v = max(dp[i][j-1][n] + field[i][j], dp[i][j-1][n+1]);
                        dp[i][j][n+1] = max(v, dp[i][j][n+1]);
                    }else{
                        dp[i][j][n] = max(dp[i][j][n], dp[i][j-1][n]);
                        dp[i][j][n+1] = max(dp[i][j][n], dp[i][j-1][n+1]);
                    }
                }
            }
            // rep(n, 4){
                // printf("dp[%lld][%lld][%lld]=%lld \n", i, j, n, dp[i][j][n]);
            // }
        }
    }

    ll score = 0;
    rep(n, 4){
        score = max(score, dp[R-1][C-1][n]);
    }
    cout << score <<endl;

}

int main(){
    Main();
}

Measured memory_bytes: 706920
//#pragma GCC optimize "trapv"
//-D_GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pm(m) for(auto itr=(m).begin();itr!=(m).end();itr++){itr->first<<" "<<itr->second<<"\n";}
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ii pair<int,int>
#define Max 100000+5
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f first
#define s second
#define pb push_back
#define bug(x) cout<<(x)<<" ";exit(0);
int mod = 1000000007;
int mod1 = 998244353;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
vector<int> g[Max];
bool vis[Max];
int d, x, y;
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
void ex(int A, int B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        ex(B, A%B);
        int temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}


void dfs(int u){

	vis[u]=1;
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(vis[v]!=1)
			dfs(v);
	}
}



int power(int a,int b){
    if(b==1)return a;
    if(a>mod)a%=mod;
    int r=1;
    while(b){
        if(b&1)r=r%mod*a%mod;
        a=a%mod*a%mod;
        b/=2;
    }
    return r;
}
class uf{
    vector<int> v;
    vector<int> sz;
    
    
    public :
    uf(int n){
        v.resize(n+1);
        iota(v.begin()+1,v.end(),1);
        sz.resize(n+1,1);
        //1 to sz
    }
    int root(int b){
        while(v[b]!=b){
            b = v[b];
        }   
        return b;
    }
    void u(int a, int b){
        //combine a and b
        
        int ra=root(a);
        int rb=root(b);
        if(ra==rb)return ;
        if(sz[ra]<sz[rb]){
            v[ra] = v[rb];
            sz[rb]+=sz[ra];
        }else{
            v[rb]=v[ra];
            sz[ra]+=sz[rb];
        }
    }
    bool f(int a,int b){
        //same set
        return (root(a)==root(b));
    }
   
    
};
vector<int> matmul(vector<int> a,vector<int> b){
    vector<int> c(4,0);
    c[0] = (a[0]%mod*b[0]%mod + a[1]%mod*b[2]%mod)%mod;
    c[1] = (a[0]%mod*b[1]%mod + a[1]%mod*b[3]%mod)%mod;
    c[2] = (a[2]%mod*b[0]%mod + a[3]%mod*b[2]%mod)%mod;
    c[3] = (a[2]%mod*b[1]%mod + a[3]%mod*b[3]%mod)%mod;
    return c;
}
vector<int> id={1,0,0,1};

int32_t main(){
	IO
	//freopen("input.txt","r",stdin);
    	//freopen("output.txt","w",stdout);
	string s;
	cin>>s;
	int ans=0;
	int cnt=0;
	for(int i=0;i<3;i++){
	    if(s[i]=='R')cnt++;
	    else cnt=0;
	    ans=max(ans,cnt);
	}
	cout<<ans;
}

Measured memory_bytes: 5932
import kotlin.math.max

fun main(){
    val (a, b, c, d) = readLine()!!.split(" ").map { it.toLong() }
    val ac = a * c
    val ad = a * d
    val bc = b * c
    val bd = b * d
    val x = max(ac, ad)
    val y = max(bc, bd)
    println(max(x, y))
}


Measured memory_bytes: 36504
#include "bits/stdc++.h"
using    namespace std;
typedef  long double ld;
#define  int long long
typedef  pair<int,int> pii;
#define  RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  rep(i,n) for(i=0; i <n; i++)
#define  repv(i,k,n) for(int i=k; i<=n; i++)
#define  pb push_back
#define  mp make_pair
#define  F  first
#define  S  second
#define  sz(x)  (int)x.size()
#define  all(v) v.begin(),v.end()
#define  endl '\n'
#define  deb(x) c out<<#x<<" = "<<x<<endl
#define  gcd   __gcd
#define  inf   LLONG_MAX
#define  minf  LLONG_MIN 
#define  sp(n) fixed<<setprecision(n)
const int mod = (int)(1e9+7);
int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
int pct(int x)
{   return __builtin_popcountll(x);}
int  lcm(int a,int b){return a*b/gcd(a,b);}
bool is_power_2(int n){ return log2(n)==floor(log2(n));}
bool is_prime(int n){for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}
void db()
{   
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
void timeit()
{  
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " <<sp(5)<< 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}
int     dx []    =  {-1 , 0 , 1 , 0 ,-1,-1, 1,  1};
int     dy []    =  { 0 , 1 , 0 ,-1 ,-1, 1, 1, -1};
char    dir[]    =  {'U','R','D','L'};
/* ---------------------- ar.cpp --------------------------------- */
const int maxn = 1e6+5;
void solve(int tc)
{
    //  cout<<"Case #"<<tc<<":\n";
    int n,i,j,k,m,q,l,r;
    cin>>n;
    int ar[n];
    rep(i,n)
        cin>>ar[i];
    int now = 1000;
    rep(i,n-1)
    {
        if(ar[i]<ar[i+1])
        {
            k = now/ar[i];
            now += k*(ar[i+1]-ar[i]);
        }
    }
    cout<<now;
}  
signed main()
{
    // ar.cpp 
    RAGE;
//    db();    
    int t=1;
    //cin>>t;
    for(int i=1; i<=t; i++)
    {
        solve(i);
    }
//    timeit();
    return 0;
}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
char tolower(char ch){
if('A'<=ch && ch && ch<= 'Z'){
return ch-'A'+'a';
}else{
return ch;
}
}
int main(){
int count=0;
string W;
cin>>W;
string str;
while(1){
cin>>str;
if(str=="END_OF_TEXT")break;
for(int i=0;i<(int)str.size();i++){
str[i]=tolower(str[i]);
}
if(str==W){
count++;
}
}
cout<<count<<endl;
return 0;
}


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

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

    list<int> b;
    for (int i=0; i < n; ++i)
    {
        int a;
        cin >> a;
        if (i%2 == 0)
        {
            b.push_front(a);
        }
        else
        {
            b.push_back(a);
        }
    }
    if (n%2 == 0)
    {
        b.reverse();
    }

    for (const auto& i : b)
    {
        cout << i << " ";
    }
    cout << std::endl;

    return 0;
}

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

int main( ) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t,n,i,a,b;
    t = 1;
    while(t--) {
     a = 0;
	 cin >> n;
	 int arr[n],brr[n - 1];
	 for(i = 0; i < n - 1; i++)
	  cin >> brr[i];
	 arr[0] = brr[0];
	 arr[n - 1] = brr[n - 2];
	 for(i = 1; i < n - 1; i++) {
	   arr[i] = min(brr[i - 1], brr[i]);
	 }
	 for(i = 0; i < n; i++)
	   a = a + arr[i];
	 cout << a << endl;
    }
    return 0;
}



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

  int a=0,b=0,c=0,d=0,i,j;
  scanf("%d%d",&a,&b);
  if(a<b){
    c=a;
    a=b;
    b=c;
  }
  d=a%b;
  while(d!=0){
    a=b;
    b=d;
    d=a%b;
    
    
  }
  printf("%d\n",b);
  return 0;
  


}



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

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }

        static void SolveA(string[] args)
        {
            int[] nk = ReadAndParseIntArr();
            int n = nk[0];
            int k = nk[1];
            long cnt = 0;
            if( k % 2 == 0)
            {
                long tmp = k / 2;
                long cntA = 0;
                long cntB = 0;
                for(int i=1;i<=n;++i)
                {
                    if( i % k == 0 )
                    {
                        cntA++;
                    }
                    if( i%k == tmp)
                    { cntB++; }
                }
                cnt = cntA * cntA * cntA + cntB * cntB * cntB;
            }
            else
            {
                for(int i=1;i<=n;++i)
                {
                    if( i % k == 0)
                    {
                        cnt ++;
                    }
                }
                // cntの数の組み合わせ
                cnt = cnt * cnt * cnt;
            }

            Console.WriteLine(cnt);
        }
    }
}

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

#define int_inf 1000000000 //1e9
#define ll_inf  100000000000000000 //1e17

using namespace std;

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	
	cout << min(n*a,b) << endl;
	
	return 0;
}


Measured memory_bytes: 256
//
// Created by tac on 2016/10/12.
//

#include <cstdlib>
#include <string>
#include <iostream>

const int B_SIZE = 4;
const int F_SIZE = 3;
const int R_SIZE = 10;

static int residents[B_SIZE + 1][F_SIZE + 1][R_SIZE + 1];

int main() {
    for (int b = 1; b <= B_SIZE; ++b) {
        for (int f = 1; f <= F_SIZE; ++f) {
            for (int r = 1; r <= R_SIZE; ++r) {
                residents[b][f][r] = 0;
            }
        }
    }

    int n;
    int b, f, r, v;
    std::cin >> n;
    for (int i = 0; i < n; ++ i) {
        std::cin >> b >> f >> r >> v;
        residents[b][f][r] += v;
    }

    bool is_sep_b {false};
    for (int b = 1; b <= B_SIZE; ++b) {
        if (is_sep_b) {
            std::cout << "####################" << std::endl;
        }
        is_sep_b = true;
        for (int f = 1; f <= F_SIZE; ++f) {
            for (int r = 1; r <= R_SIZE; ++r) {
                std::cout << " ";
                std::cout << residents[b][f][r];
            }
            std::cout << std::endl;
        }

    }

    return EXIT_SUCCESS;
}

Measured memory_bytes: 3076
use std::cmp::Reverse;
use std::cmp::max;
use std::collections::VecDeque;
use std::cmp::min;
use std::collections::BTreeSet;
use std::cmp::Ordering;
use std::fmt::Debug;

fn read_line() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("No Line");
    buffer
}
fn read_lines<T: std::str::FromStr>(count: usize) -> Vec<T> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for _ in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(buffer.trim().parse().ok().expect("Can't Parse"));
        buffer.clear();
    }
    vec
}
fn read_tabulate<R, T: Fn(&str)->R> (count: usize, transformer: T) -> Vec<R> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for _ in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(transformer(buffer.trim()));
        buffer.clear();
    }
    vec
}
fn read_value<T: std::str::FromStr>() -> T {
    read_line().trim().parse().ok().unwrap()
}
fn read_values<T: std::str::FromStr>() -> Vec<T> {
    read_line().trim().split(' ').map(|x| x.parse().ok().expect("Can't Parse")).collect::<Vec<T>>()
}
macro_rules! freeze {
    ($($id:ident), *) => {
        $(let $id = $id;)*
    };
}
macro_rules! read {
    (mut $ident: ident: [$ty:ty]) => {
        let mut $ident = read_values::<$ty>();
    };
    ($ident: ident: [$ty:ty]) => {
        let $ident = read_values::<$ty>();
    };
    ($($token: tt)*) => {
        let mut iter = read_values::<String>().into_iter();
        read_from_iter!(iter; $($token)*);
    };
}
macro_rules! read_from_iter {
    ($iter:expr; mut $ident:ident:$ty:ty, $($rest:tt)*) => {
        let mut $ident = $iter.next().unwrap().parse::<$ty>().expect("Can't Parse");
        read_from_iter!($iter; $($rest)*);
    };
    ($iter:expr; $ident:ident:$ty:ty, $($rest:tt)*) => {
        let $ident = $iter.next().unwrap().parse::<$ty>().expect("Can't Parse");
        read_from_iter!($iter; $($rest)*);
    };
    ($iter:expr; mut $ident:ident:$ty:ty) => {
        let mut $ident = $iter.next().unwrap().parse::<$ty>().expect("Can't Parse");
    };
    ($iter:expr; $ident:ident:$ty:ty) => {
        let $ident = $iter.next().unwrap().parse::<$ty>().expect("Can't Parse");
    };
    ($iter: expr; ) => {};
}
struct KeyValue<K, V> {
    key: K,
    value: V
}
impl <K: PartialOrd, V> PartialEq for KeyValue<K, V> {
    fn eq(&self, other: &Self) -> bool {
        self.key.eq(&other.key)
    }
}
impl <K: PartialOrd, V> Eq for KeyValue<K, V> {}
impl <K: PartialOrd, V> PartialOrd for KeyValue<K, V> {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        self.key.partial_cmp(&other.key)
    }
}
impl <K: PartialOrd, V> Ord for KeyValue<K, V> {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        self.key.partial_cmp(&other.key).ok_or("Can't Compare").unwrap()
    }
}

fn main() {
    read!(s: String);
    for _ in s.chars() {
        print!("x");
    }
    println!("");
}


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

long long int N, K, i = 1;

int main(){
    scanf("%lld%lld", &N, &K);
    while(K > i && N){
        i *= 2;
        --N;
    }
    for(; N; --N)i += K;
    cout << i << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int q,a,b,c,d,w,lt,rt,mid,i;
int work(int a,int b)
{
	return (a-1)/(b+1)+1;
}
int main()
{
	scanf("%d",&q);
	while(q--)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		w=max(work(a,b),work(b,a));
		lt=0,rt=a+b;
		while(lt<rt)
		{
			mid=(lt+rt+1)/2;
			if(a-mid/(w+1)*w-mid%(w+1)>=0&&b-mid/(w+1)>=0&&work(b-mid/(w+1)+(mid%(w+1)==0),a-mid/(w+1)*w-mid%(w+1))<=w)
				lt=mid;
			else
				rt=mid-1;
		}
		for(i=c;i<=d;++i)
			if(i<=lt)
			{
				if(i%(w+1)==0)
					printf("B");
				else
					printf("A");
			}
			else
			{
				if((a+b-i+1)%(w+1)==0)
					printf("A");
				else
					printf("B");
			}
		puts("");
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()
ans = S.count('R') * S.count('G') * S.count('B')
for i in range(N):
  for j in range(i, N):
    k = 2*j - i
    if k >= N:
      break
    if len(set([S[i], S[j],S[k]])) ==3:
      ans -= 1
print(ans)

Measured memory_bytes: 68260
n = int(raw_input())
sieve = [True] * (n + 1)
for i in range(2, n+1):
    if sieve[i]:
        for j in range(i+i, n+1, i):
            sieve[j] = False

primes = [0] * (n+1)
for i in range(2, n+1):
    if sieve[i]:
        for j in range(i, n+1):
            j2 = j
            num = 0
            while j2 % i == 0:
                j2 /= i
                num += 1
            primes[i] += num
gt2 = 0
gt4 = 0
gt14 = 0
gt24 = 0
gt74 = 0
for i in range(2, n+1):
    if primes[i] >= 2:
        gt2 += 1
    if primes[i] >= 4:
        gt4 += 1
    if primes[i] >= 14:
        gt14 += 1
    if primes[i] >= 24:
        gt24 += 1
    if primes[i] >= 74:
        gt74 += 1
def nCk(n, k):
    numera = 1
    for i in range(n, n-k, -1):
        numera *= i
    denomi = 1
    for i in range(k, 0, -1):
        denomi *= i
    return numera / denomi
res = 0
res += gt14 * (gt4-1)
res += gt24 * (gt2-1)
res += gt74
res += nCk(gt4, 2)*(gt2-2)
print res

Measured memory_bytes: 2696
#include <cstdio>
#include <cctype>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
#define repd(i,x,y) for (int i=x; i>=y; --i) 
using namespace std;

typedef long long LL;
int n,min1,max2,minx[200100],maxy[200100],maxx,miny;
struct data
{
    int x,y;
    bool operator<(const data &t) const
    {
        return y<t.y;
    }
} a[200100];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

int main()
{
    n=getint();
    repu(i,1,n)
    {
        a[i].x=getint(),a[i].y=getint();
        if (a[i].x>a[i].y)
            swap(a[i].x,a[i].y);
    }
    sort(a+1,a+1+n),min1=miny=minx[n+1]=1<<30;
    repd(i,n,1)
    {
        minx[i]=min(minx[i+1],a[i].x);
        maxy[i]=max(maxy[i+1],a[i].y);
        min1=min(min1,a[i].x),max2=max(max2,a[i].x);
    }
    LL ans=1LL<<60;
    repu(i,1,n+1)
    {
        ans=min(ans,LL(max(maxy[i],maxx)-min1)*(max2-min(minx[i],miny)));
        max2=max(max2,a[i].y);
        maxx=max(maxx,a[i].x);
        miny=min(miny,a[i].y);
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define as first
#define va second
class Eratosthenes{
  public:
    int n;
    vector<bool> prime;
    Eratosthenes(int N):n(N+1){
        prime=vector<bool>(n,1); prime[0]=prime[1]=0;
        for(int i=2;i*i<=n;i++) if(prime[i]) for(int j=i*i;j<=n;j+=i) prime[j]=0;}
    vector<int> primeArray(int s=0, int l=10000){vi ret; for(int i=s;ret.size()!=l;i++) if(prime[i]) ret.push_back(i); return ret;}
};
// 13,947 9,821
int main(){
    Eratosthenes e(1000000);
    vvi v(1000,vi(1000,0));
    {
        int y=500,x=499,sight=0;
        vvi vec={{0,1},{-1,0},{0,-1},{1,0}};
        for(int dist=2, num=1; num<=1000000 ; dist++){
            for(int i=0;i<dist/2;i++){
                v[y][x]=num++;
                y+=vec[sight][0];
                x+=vec[sight][1];
            }
            sight=(sight+1)%4;
        }
    }
    int m,n;
    while(cin>>m>>n,m){
        vector<vector<pii>> ana(1000,vector<pii>(1000,make_pair(0,0)));
        for(int y=999;1;y--){
            for(int x=0;x<1000;x++){
                if(e.prime[v[y][x]]){
                    ana[y][x].as++;
                    if(ana[y][x].va==0){
                        ana[y][x].va=v[y][x];
                    }
                }
                if(v[y][x]==n){
                    cout<<ana[y][x].as<<" "<<ana[y][x].va<<endl;
                    goto fin;
                }
            }
            //int is=false;
            for(int x=0;x<1000;x++){
                if(v[y][x]-1>m) continue;
                //cout<<setw(3)<<v[y][x]<<" ";is=true;
                int mind=-2,val=-1, pval=-1;
                for(auto i : {-1,0,1}){ //[y-1][x]????????????????????????[y][x+i]?????????
                    if(x+i>=0 && x+i<1000 && v[y][x+i]<=m &&  (val<ana[y][x+i].as || (val==ana[y][x+i].as && pval<ana[y][x+i].va) )){
                        mind=i;
                        val=ana[y][x+i].as;
                        pval=ana[y][x+i].va;
                    }
                }
                ana[y-1][x]=make_pair(val,pval);
            }
            //if(is)cout<<endl;
        }
        fin:
        ;
    }
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long ll;


int main(){
  int n; cin >> n;
  vector<int> a(n);
  vector<vector<int>> x(n, vector<int>()), y(n, vector<int>());
  rep(i,n){
    cin >> a[i];
    rep(j,a[i]){
      int X, Y;
      cin >> X >> Y;
      x[i].push_back(X-1);
      y[i].push_back(Y);
    }
  }

  int ans = 0;
  rep(i,1<<n){
    vector<int> truth(n, 0);
    int truth_sum = 0;
    rep(j,n){
      if((i >> j)&1){
        truth[j] = 1;
        truth_sum++;
      }
    }
    rep(j,n){
      if(truth[j] == 1){
        rep(k,a[j]){
          if(truth[x[j][k]] != y[j][k]){
            truth_sum = 0;
            break;
          }
        }
      }
      if(truth_sum == 0) break;
    }

    ans = max(ans, truth_sum);
    
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数


int main()
{
  int n ;
  cin >> n ;
  string s, t ;
  cin >> s >> t ;
  
  string u ;
  
  int ans ;
  int m ;
  
  REP(i,n+1){
    u = s + t.substr(i,n-i) ;
    m = u.size() ;
    if(u.substr(0,n)==s && u.substr(m-n,n)==t){
      ans = m ;
    }
  }
  
  cout << ans <<endl ;
  
  


  return 0 ;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n;
  cin>>n;
  int ans = 1;
  int first;
  cin>>first;
  int max_of = first;
  for(int i=0;i<n-1;i++){
    int x;
    cin>>x;
    max_of=max(max_of,x);
    if(x>=max_of){
        ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-7
#define inf 0x3f3f3f3f
#define mod 1000000007ll
using namespace std;

int main() {
	speed;
	string s;
	cin >> s;
	int ans = 0, tmp = 0;
	map<char, bool>a = { {'A', 1},{'C', 1},{'G', 1},{'T', 1} };
	for (int i = 0; i < s.size(); ++i) {
		if (a[s[i]])
			tmp++;
		else
			tmp = 0;
		ans = max(ans, tmp);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    string s;
    cin >> s;
    string t;
    cin >> t;
    int cnt = 0;
    rep(i, sz(s)) {
        if (s[i] != t[i]) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3880
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let (n, m): (isize, isize) = parse!(it, 2);
    println!("{}", n * (n - 1) / 2 + m * (m - 1) / 2);
}

fn test() {
    let mut f = fs::File::open("foo.txt").unwrap();
    let mut s = String::new();
    f.read_to_string(&mut s).unwrap();
    solve(&s);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_main() {
        test();
    }
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
double n , b ;
int main() {
  cin >> n ;
  for (int i = 1 ; i <= n ; i++)
    if ( i % 2 != 0 )
      b++ ;
  cout << fixed ;
  cout << setprecision (9) << b / n ;
}

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

using namespace std;

const int Nmax = 1e5 + 5;
int X, n, a[Nmax], mode, tmp, t, A, B, C, init, i, q;

void advance(int x)
{
    if(mode == -1)
    {
        int t = A + C;
        C -= x;
        if(t <= x) A += x-t;
    }
    else
    {
        int t = X - (B + C);
        C += x;
        if(t <= x) B -= x-t;
    }

    if(A > B)
    {
        if(mode == 1) A = B = X, C = 0;
            else A = B = 0, C = 0;
    }
}

int f(int x)
{
    if(x <= A) return A + C;
    if(x >= B) return B + C;
    return x + C;
}

int main()
{
   // freopen("input", "r", stdin);

    cin >> X >> n;
    for(i=1; i<=n; ++i) cin >> a[i];

    cin >> q; i = 1; A = 0, B = X, C = 0;
    tmp = 0; mode = -1;

    while(q--)
    {
        cin >> t >> init;
        while(i<=n && a[i] <= t)
        {
            advance(a[i] - tmp);
            mode = -mode; tmp = a[i++];
        }

        advance(t - tmp); tmp = t;
        cout << f(init) << '\n';
    }

    return 0;
}


Measured memory_bytes: 1536