akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007
#define ll long long int 
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
    off;

    int n,k;cin>>n>>k;

    ll arr[n];
    for (int i = 0; i < n; ++i)
    {
        cin>>arr[i];
    }

    ll dp[n][k+1];
    dp[0][0] = 1;
    for (int i = 1; i <= k; ++i)
    {
        dp[0][i] = dp[0][i-1];
        if(i<=arr[0]) dp[0][i]++;
    }

    for (int i = 1; i < n; ++i)
    {
        for (int j = 0; j <= k; ++j)
        {
            ll temp = max(j-arr[i],0LL);
            if(temp<1)
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = dp[i-1][j] - dp[i-1][temp-1];
        }

        for (int j = 1; j <= k; ++j)
        {
            dp[i][j] = (dp[i][j] + dp[i][j-1])%MOD;
        }
    }

    if(k)
    cout<<(dp[n-1][k]-dp[n-1][k-1] + MOD)%MOD;
    else
    cout<<dp[n-1][k];
    return 0;
}


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

using namespace std;

int main() {
    long long N;
    long long K;
    long long Q;
    cin >> N >> K >> Q;
    long long A[Q];
    for (int i = 0; i < Q; i++) {
        cin >> A[i];
    }

    long long Nc[N + 1];
    for (int i = 0; i < N + 1; i++) {
        Nc[i] = 0;
    }
    long long index;
    for (int i = 0; i < Q; i++) {
        index = A[i];
        Nc[index]++;
    }

    for (int j = 1; j < N + 1; j++) {
        if ((K - Q + Nc[j]) > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 2176
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
MOD = 10**9+7

s = input()
t = input()
for i in range(len(s)):
    if s[i] != t[i]:
        print("No")
        sys.exit()
print("Yes")


Measured memory_bytes: 9276
program triangles
  implicit none
  integer :: n, l(2000) = 0, m = 0, i, j, k
  integer(8) :: ans = 0_8
  read(*,*) n
  read(*,*) l(1:n)
  call quick_sort(l(1:n))
  do i = 1, n-2
    do j = i+1, n-1
      k = limit(l(1:n),j,l(i)+l(j))
      ans = ans+int(k-j,8)
    end do
  end do
  write(*,'(i0)') ans
contains
  function limit(a,i,v) result(l)
    integer, intent(in) :: a(:), v
    integer, intent(in) :: i
    integer :: l, r, m
    l = i
    r = size(a,1)+1
    do while (r-l > 1)
      m = (r+l)/2
      if (a(m) < v) then
        l = m
      else
        r = m
      end if
    end do
  end
  recursive subroutine quick_sort(a)
    integer, intent(inout) :: a(:)
    integer :: n, l, r, m
    integer :: p
    n = size(a)
    l = 1
    r = n
    m = (n+1)/2
    p = a(l)+a(m)+a(r)-max(a(l),a(m),a(r))-min(a(l),a(m),a(r))
    do
      do while (a(l) < p)
        l = l+1
      end do
      do while (a(r) > p)
        r = r-1
      end do
      if (l >= r) exit
      a(l) = xor(a(l),a(r))
      a(r) = xor(a(l),a(r))
      a(l) = xor(a(l),a(r))
      l = l+1
      r = r-1
    end do
    if (l-1 > 1) call quick_sort(a(1:l-1))
    if (n > r+1) call quick_sort(a(r+1:n))
  end
end program triangles

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

typedef pair<int, int> P;
int INF = 1 << 10;

struct edge{
  int to;
  int cost;
};

vector<vector<edge> > G(10);
vector<int> d(10, INF);
vector<P> ans;

void init(){
  for(int i = 0; i < 10; i++){
	d[i] = INF;
  }
}

void display_d(){
  for(int i = 0; i < 10; i++){
	if(d[i] == INF) cout << "INF ";
	else cout << d[i] << " ";
  }
  cout << endl;
}

void initG(){
  for(int i = 0; i < 10; i++){
	G[i].clear();
  }
}

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> > que;
  init();
  d[s] = 0;
  que.push(P(0, s));
  while(!que.empty()){
	P p = que.top(); que.pop();
	int v = p.second;
	if(d[v] < p.first) continue;
	for(int i = 0; i < G[v].size(); i++){
	  edge e = G[v][i];
	  if(d[e.to] > d[v] + e.cost){
		d[e.to] = d[v] + e.cost;
		que.push(P(d[e.to], e.to));
	  }
	}
  }
  //cout << "d = ";
  //display_d();
  
}

int main(){
  int n = 0;
  while(1){
	cin >> n;
	if(n == 0) break;
	int a = 0, b = 0, c = 0;
	for(int i = 0; i < n; i++){
	  cin >> a >> b >> c;
	  edge e1, e2;
	  e1.to = b; e1.cost = c;
	  e2.to = a; e2.cost = c;
	  G[a].push_back(e1);
	  G[b].push_back(e2);
	}

	for(int i = 0; i < 10; i++){
	  dijkstra(i);
	  int sum = 0;
	  for(int j = 0; j < 10; j++){
		if(d[j] == INF) continue;
		sum += d[j];
	  }
	  if(sum != 0) ans.push_back(P(sum, i));
	}

	sort(ans.begin(), ans.end());
	cout << ans[0].second << " " << ans[0].first << endl;
	ans.clear();
	initG();
  }
  return 0;
}

Measured memory_bytes: 3148
def main():
    import sys
    sys.setrecursionlimit(10 ** 7)

    K, S = map(int, input().split())

    memo = [[-1] * (S + 1) for _ in range(4)]

    def dfs(cur, s=0):
        if ~memo[cur][s]:
            return memo[cur][s]

        if cur == 3:
            ret = int(s == S)
            memo[cur][s] = ret
            return ret

        ret = 0
        for r in range(min(K, S - s) + 1):
            ret += dfs(cur + 1, s + r)
        memo[cur][s] = ret
        return ret

    ans = dfs(0)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 44012
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<30;
const ll LLINF = 1LL<<62;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int S[1<<18];
    int n;
    int s;
    cin >> n;
    REP(i,1<<n){
        cin >> s;
        S[i] = s;
    }
    multiset<int> st;
    REP(i,1<<n)st.insert(-S[i]);
    vector<int> cur, nxt;
    cur.push_back(*st.begin());
    st.erase(st.begin());
    REP(i,n){
        nxt = cur;
        for(int x : cur){
            // cout << x << " ";
            auto it = st.upper_bound(x);
            if(it == st.end()){
                cout << "No" << endl;
                return 0;
            }
            nxt.push_back(*it);
            st.erase(it);
        }
        cur = nxt;
        cout << endl;
    }
    cout << "Yes" << endl;
    }


Measured memory_bytes: 15348
import java.util.Scanner;

class Main{
    public static void main(String[] args){
    	
    	Scanner sc = new Scanner(System.in);
    	
    	int Answer = 0;
    	String strnum = sc.nextLine();//サイコロの目
    	int q = sc.nextInt();//質問数
    	
    	for(int i = 0 ; i < q ; i++ ){//qの回数分繰り返す
    		
    		int ue = sc.nextInt();//質問　上
        	int mae = sc.nextInt();//質問　前
        	
        	Dice dice = new Dice( strnum );
        	
        	Answer = dice.judge( ue , mae );
        	
        	System.out.println(Answer);
        	
    	}
    }
}

//-----------------------------------------------------------------

class Dice{
	
	int[] dice = new int[6];
	String[] me ;
	
	int ue = 0;
	int mae = 0;
	int kari = 0;
	int Answer = 0;
	
	//mainクラスで入力されたものを格納
	public Dice( String strnum ){
				
		me = strnum.split(" ");
		
		for(int i = 0 ; i < me.length ; i++ ){
			dice[i] = Integer.parseInt(me[i]);
		}
	}
	
	//dice[0]=ue dice[1]=mae に合わせた時のdice[2]を返す
	public int judge( int ue , int mae){
		
		for( int i = 0 ; i < 4 ; i++ ){
			if( dice[0] == ue ){
				break;
			}
			N();
		}
		
		for( int i = 0 ; i < 4 ; i++ ){
			if( dice[0] == ue ){
				break;
			}
			E();
		}
		
		for( int i = 0 ; i < 4 ; i++ ){
			if( dice[1] == mae ){
				break;
			}
			N();
			E();
			S();
		}
		
		return dice[2];
		
	}
	
	
	public void E(){
		kari = dice[0];
        dice[0] = dice[3] ;
        dice[3] = dice[5] ;
        dice[5] = dice[2];
        dice[2] = kari;
        //return dice[0];
	}
	
	public void N(){
		kari = dice[0];
        dice[0] = dice[1] ;
        dice[1] = dice[5] ;
        dice[5] = dice[4];
        dice[4] = kari;
        //return dice[0];
	}
	public void S(){
		kari = dice[0];
	    dice[0] = dice[4] ;
	    dice[4] = dice[5] ;
	    dice[5] = dice[1];
	    dice[1] = kari;
	    //return dice[0];
	}
	public void W(){
		kari = dice[0];
	    dice[0] = dice[2] ;
	    dice[2] = dice[5] ;
	    dice[5] = dice[3];
	    dice[3] = kari;
	    //return dice[0];
	}
	
}

Measured memory_bytes: 26252
s = int(input())
s_list = []
if s != 1 or s != 2:
    while s != 1:
        if s % 2 == 0:
            s = s / 2
        else:
            s = 3 * s + 1
        s_list.append(s)
    print(max(len(s_list)+2, 4))
else:
    print(4)

Measured memory_bytes: 3060
#pragma G++ optimize (2)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <queue>
#define INF 0x3f3f3f3f
#define NO 200005
#define MO 100005
typedef long long ll;
typedef double db;
using namespace std;
inline ll read()
{
	char ch = ' ', last;
	ll ans = 0;
	while (ch < '0' || ch > '9')
		last = ch, ch = getchar();
	while (ch >= '0' && ch <= '9')
		ans = ans * 10 + int(ch - '0'), ch = getchar();
	if (last == '-')
		return -ans;
	return ans;
}
void write(ll x)
{
	if (x >= 10)
		write(x / 10);
	putchar(x % 10 + '0');
}
//head

int n, m, father[NO];
bool book[NO];
//variable

int getf(int o)
{
	if (father[o] == o)
		return o;
	return father[o] = getf(father[o]);
}
void init()
{
	n = read(), m = read();
}
//functions

int main()
{
	init();
	for (int i = 1; i <= n; i++)
		father[i] = i;
	while (m--)
	{
		int x = read(), y = read(), z = read();
		int fx = getf(x), fy = getf(y);
		father[fx] = fy;
	}
	for (int i = 1; i <= n; i++)
		book[getf(i)] = true;
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans += book[i];
	cout << ans << endl;
	return 0;
}
//main

Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>
#include<bitset>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const double EPS = 0.000000000001;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================


	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
	}

	vector<bool> ans(N);
	for (int i = 0; i < N; i++) {
		ans[i] = false;
	}

	for (int i = 0; i < M; i++) {

		if (A[i] == 1) {
			ans[B[i]] = true;;
		}
		if (B[i] == 1) {
			ans[A[i]] = true;
		}		
	}

	for (int i = 0; i < M; i++) {
		if (A[i] == N && ans[B[i]]) {
			cout << "POSSIBLE";
			return 0;
		}
		if (B[i] == N && ans[A[i]]) {
			cout << "POSSIBLE";
			return 0;
		}
	}

	cout << "IMPOSSIBLE";
	

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
    
    int i;
    string s;
    getline(cin, s);
    for (i = 0; i < s.size(); i++) {
        if (s[i] >= 'a' and s[i] <= 'z') s[i] = ((s[i] - 'a') + 'A');
        else if (s[i] >= 'A' and s[i] <= 'Z') s[i] = ((s[i] - 'A') + 'a');
    }
    cout << s << "\n";
    
    return 0;
}


Measured memory_bytes: 3240
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

    S=[0]*N
    for i in range(N):
        if i==0:
            S[0]=A[0]
        else:
            S[i]=S[i-1]+A[i]
    S.append(0)
    S.sort()

    now=0
    count=1
    res=0
    for i in range(N+1):
        if i==0:
            now=S[i]
        else:
            if S[i]==now:
                count+=1
                if i==N:
                    res+=count*(count-1)//2
            else:
                res+=count*(count-1)//2
                count=1
                now=S[i]
    print(res)

if __name__=="__main__":
    main()

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

using namespace std;

int main()
{
int a,b,c;
cin>>a>>b>>c;
int ar[10];
ar[0]=(a*c)-b;
int j;
for(int i=1,j=0;i<10,j<10;j++,i++)
{
    
    ar[i]=a*ar[j]-b;
}
for(int i=0;i<10;i++)
    {
        cout<<ar[i]<<endl;
    }
return 0;
}

Measured memory_bytes: 256
N=int(input())
ans=[0]*(N+1)
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            num=x*y+y*z+z*x+x*x+y*y+z*z
            if num>N:
                break
            ans[num]+=1
for i in range(N):
    print(ans[i+1])

Measured memory_bytes: 9136
H,W = map(int, input().split())
Ans = 0

if H == 1 or W == 1:
  Ans = 1
else:
  if (H * W) % 2 == 0:
    Ans = (H * W) // 2
  else:
    Ans = (H * W) // 2 + 1

print(Ans)

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

void print_a_b(char *str, int a, int b)
{
    char tmp[1001] = {0};
    strncpy(tmp, str + a, b - a + 1);
    printf("%s\n", tmp);
}
void reverse_a_b(char *str, int a, int b)
{
    char tmp[1001] = {0};
    strcpy(tmp, str);
    for (int i = 0; i <= b - a; i++) //tmpの[a] ~ [b]にstrの[b] ~ [a]を代入
    {
        tmp[a + i] = str[b - i];
    }
    strcpy(str, tmp);
}
void replace_a_b_p(char *str, int a, int b, char *p)
{
    for (int i = 0; i <= b - a; i++)
    {
        str[a + i] = p[i];
    }
}
void switch_instruction(const char *inst, char *str, int a, int b)
{
    char pr[] = {"print"};
    char rev[] = {"reverse"};
    if (strcmp(inst, pr) == 0)
    {
        print_a_b(str, a, b);
    }
    else if (strcmp(inst, rev) == 0)
    {
        reverse_a_b(str, a, b);
    }
}

int main(void)
{
    char str[1001];
    int q;
    scanf("%s", str);
    scanf("%d", &q);
    for (int i = 0; i < q; i++)
    {
        char inst[8];
        int a, b;
        scanf("%s", inst);
        scanf("%d %d", &a, &b);
        if (strcmp(inst, "replace") == 0)
        {
            char p[1001];
            scanf("%s", p);
            replace_a_b_p(str, a, b, p);
        }
        else
        {
            switch_instruction(inst, str, a, b);
        }
    }
    return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define uint unsigned int
#define pb push_back
#define pi 2*acos(0.0)
#define db double
#define mk make_pair

int main()
{
    ll i,j,k,n,tc,q,x,y,z,t,v,d,c,p,m;
    ///////////////////////////////////////////
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ////////////////////////////////////////////

    cin>>n>>k;
    {
        if(k==0)
        {
            cout<<n*n<<endl;
            return 0;
        }
        x=n-k;
        y=(x+1)*x/2;
        for(i=k; i<n; i++)
        {
            q=n-i;
            x=q;
            p=1;
            while(q>=i+1)
            {
                d=q/(p+1);
                if(d>=i)
                {
                    y+=(x-d)*p;
                }
                else
                {
                    y+=(x-i)*p;
                    break;
                }
                p++;
                x=d;
            }
        }
        cout<<y<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
   
   
public class Main {
	static int INF = 2 << 29;
	static int[][] ok = {{1,3},{0,2,4},{1,5},{0,4,6},{1,3,5,7},{2,4,8},{3,7},{4,6,8},{5,7}};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(int i = 0; i < 1000; i++) {
			char[] in = sc.next().toCharArray();
			boolean ans = true;
			for(int j = 1; j < in.length; j++) {
				if(Arrays.binarySearch(ok[in[j-1] - 'A'],in[j] - 'A') < 0) {
					ans = false;
					break;
				}
			}
			if(ans) {
				System.out.println(String.valueOf(in));
			}
		}
		
	}
	
}

Measured memory_bytes: 32588
//https://atcoder.jp/contests/abc110/tasks/abc110_c
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();

bool check(string S, string T)
{
    vector< set<char> > to(26), from(26);
    for( int i = 0; i < (int)S.size(); ++i )
    {
        to[S[i]-'a'].insert(T[i]);
        from[T[i]-'a'].insert(S[i]);
    }
    for( set<char> &x : to )
    {
        if( x.size() >= 2 ){
            return false;
        }
    }
    for( set<char> &x : from )
    {
        if( x.size() >= 2 ){
            return false;
        }
    }
    return true;
}

int main()
{
    string S, T;
    cin >> S >> T;
    cout << ( check( S, T ) ? "Yes" : "No" ) << endl;
    return 0;
}

Measured memory_bytes: 1112
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		
		int a = in.nextInt();
		int b = in.nextInt();
		
		out.println(Math.max(a + b, Math.max(a - b, a * b)));
		
		out.close();
	}
	
	static class InputReader
	{
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		
		public InputReader(InputStream stream)
		{
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		
		public String next()
		{
			while(tokenizer == null || !tokenizer.hasMoreTokens())
			{
				try
				{
					tokenizer = new StringTokenizer(reader.readLine());
				}
				catch(IOException e)
				{
					throw new RuntimeException(e);
				}
			}
			
			return tokenizer.nextToken();
		}
		
		public int nextInt()
		{
			return Integer.parseInt(next());
		}
	}
}

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

using namespace std;

int main() {
  string s;
  while (getline(cin, s)) {
    for (int i = 0; i < s.size() - 4; ++i) {
      string sub = s.substr(i, 5);
      if (sub == "apple") {
	s.replace(i, 5, "peach");
      } else if (sub == "peach") {
	s.replace(i, 5, "apple");
      }
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <map>
#include <numeric>

using namespace std;
using ll = long long;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

int main() {
  int N, M;
  ins(N, M);
  map<int, int> m;
  vector<int>count(M, 0), odd(M, 0);

  rep(i, N) {
    int X; cin >> X;
    ++m[X];
  }
  for (const auto& [x, c] : m) {
    count[x % M] += c - (c % 2);
    odd[x % M] += c % 2;
  }

  ll ans = 0;
  rep(i, M / 2 + 1) {
    int x = i, y = M-x;
    if (x == 0 || 2 * x == M) {
      ans += (count[x] + odd[x]) / 2;
      continue;
    }
    if (count[x] + odd[x] > count[y] + odd[y]) {
      swap(x, y);
    }
    count[x] += odd[x];
    if (count[x] <= odd[y]) {
      ans += count[x] + count[y] / 2;
      continue;
    }
    count[y] -= count[x] - odd[y];
    ans += count[x] + count[y] / 2;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 8628
#include<iostream>
#include<cmath>
using namespace std;
typedef long long LL;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	LL a,b,n;
	cin>>a>>b>>n;
	cout<<floor(a*min(b-1,n)/b)<<endl;
	return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
int ans[10101];

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    
    // 2. (x, y, z) の 組 を カウント.
    repx(x, 1, 101){
        repx(y, 1, 101){
            repx(z, 1, 101){
                int c = x * x + y * y + z * z + x * y + y * z + z * x;
                if(c <= 10000) ans[c]++;
            }
        }
    }
    
    // 3. 出力.
    repx(i, 1, N + 1) printf("%d\n", ans[i]);
    return 0;
    
}

Measured memory_bytes: 3636
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Map<Integer, Integer> AB = new TreeMap<>();
        String answer = "";
        int lastB = 0;

        for (int i = 0; i < N; i++) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            if (AB.containsKey(B)) {
                AB.put(B, AB.get(B) + A);
            } else {
                AB.put(B, A);
            }
            if (i == N - 1) {
                lastB = B;
            }
        }

        long sum = 0;
        for (Map.Entry<Integer, Integer> ab : AB.entrySet()) {
            sum = sum + ab.getValue();
            if (ab.getKey() < sum) {
                answer = "No";
                break;
            }
            if (lastB == ab.getKey()) {
                answer = "Yes";
            }
        }

        System.out.println(answer);
        sc.close();
    }
}

Measured memory_bytes: 74388
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			int[] p = new int[n + 1];
			for (int i = 1; i <= n; i++)
				p[i] = scanner.nextInt();
			List<Integer> list = new ArrayList<Integer>();
			for (int i = 0; i <= n; i++)
				for (int j = i; j <= n; j++)
					if (p[i] + p[j] <= m)
						list.add(p[i] + p[j]);
			Collections.sort(list);
			int ans = 0;
			int suml = list.size() - 1;
			for (int i = 0; i <= suml; i++) {
				while (list.get(i) + list.get(suml) > m)
					suml--;
				ans = Math.max(ans, list.get(i) + list.get(suml));

			}
			System.out.println(ans);

		}
	}
}

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

int main() {
  int n,k,q;
  cin>>n>>k>>q;
  vector<int>hito(n,k-q);
  for(int i=0;i<q;i++){
    int a;
    cin>>a;
    a--;
    hito[a]++;
  }
  for(int i=0;i<n;i++){
    if(hito[i]<=0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3796
#include<iostream>
#include<stdio.h>
#include<string>
using namespace std;
static const int MAX = 100000;

int main(){
  int num, buff[MAX];
  string s;
  for(int i=0; i<MAX; i++){
    buff[i] = 0;
    getline(cin, s);
    if(s == "0"){
      num = i;
      break;
    }
    for(int j=0; j<s.size(); j++)
      buff[i] += s[j] - '0';
  }

  for(int i=0; i<num; i++)
    cout << buff[i] << endl;
  return 0;
}


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

#define REPI(i, n) for(int i = 0; i < n; i++)
#define REPJ(j, n) for(int j = 0; j < n; j++)

using ll = long long;
using namespace std;

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

    int n; string s; cin >> n >> s;

    REPI(i, s.length()/2){
        if(s[i] != s[i + s.length()/2]){
            cout << "No"; return 0;
        }
    }cout << (n % 2 ? "No" : "Yes");
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
using namespace std;
using ll = long long int;
//typedef pair<int,int> P;


int main(void){
	ll X;
	cin >> X;
	ll m=100;
	int k=0;
	while(1){
		if(m>=X){
			cout << k;	
			return 0;
		}
		m*=1.01;
		k++;
	}
}

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

// #define multitest 1
#define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

ll power(int base, int index)
{
	if (index == 0)
		return 1;
	ll temp = power(base, index / 2);
	temp = (temp * temp) % mod;
	if (index & 1)
		temp *= base;
	return temp % mod;
}

void solve()
{
	int n, m;
	cin >> n >> m;
	vector<int> A(n), B(m);
	for (auto &x : A)
		cin >> x;
	for (auto &x : B)
		cin >> x;
	vector<vector<ll>> CommonSequences(n + 1, vector<ll>(m + 1, 1));
	ll answer = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
		{
			if (A[i - 1] == B[j - 1])
				CommonSequences[i][j] = (mod + CommonSequences[i - 1][j] + CommonSequences[i][j - 1]) % mod;
			else
				CommonSequences[i][j] = (mod + CommonSequences[i - 1][j] + CommonSequences[i][j - 1] - CommonSequences[i - 1][j - 1]) % mod;
		}
	cout << CommonSequences[n][m] % mod << '\n';
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 31616
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

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

Node T[MAX];
int N, D[MAX];

void print(int u) {
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "depth = " << D[u] << ", ";

    if (T[u].parent == NIL)
        cout << "root, ";
    else if (T[u].left == NIL)
        cout << "leaf, ";
    else
        cout << "internal node, ";

    cout << "[";
    for (int i = 0, c = T[u].left; c != NIL; i++, c = T[c].right) {
        if (i > 0) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void set_depth(int u, int p) {
    D[u] = p;
    if (T[u].right != NIL)
        set_depth(T[u].right, p);
    if (T[u].left != NIL)
        set_depth(T[u].left, p + 1);
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++)
        T[i].parent = T[i].left = T[i].right = NIL;

    int left = 0;
    for (int i = 0; i < N; i++) {
        int v, k;
        cin >> v >> k;
        for (int j = 0; j < k; j++) {
            int c;
            cin >> c;
            if (j == 0) T[v].left = c;
            else T[left].right = c;
            left = c;
            T[c].parent = v;
        }
    }

    int root = 0;
    for (int i = 0; i < N; i++) {
        if (T[i].parent == NIL) root = i;
    }

    set_depth(root, 0);

    for (int i = 0; i < N; i++)
        print(i);

    return 0;
}


Measured memory_bytes: 7768
#include <bits/stdc++.h>
std::vector<int>G[605];
double f[605],ans;
int n,m,vis[605],sel,u,v;
double dfs(int u){
	if (u==n)return 0;
	if (f[u]!=-1)return f[u];
	f[u]=0;
	int max=0,cnt=0;
	for(int i=0;i<G[u].size();++i){
		if (!vis[G[u][i]])continue;
		f[u]+=dfs(G[u][i]);if (f[G[u][i]]>f[max])max=G[u][i];cnt++;
	}
	if (sel!=u)f[u]=f[u]/cnt+1;
	else f[u]=(f[u]-f[max])/(cnt-1)+1;
	return f[u];
}

int work(int u){
	if (vis[u]!=-1)return vis[u];
	vis[u]=0;
	for (int i=0;i<G[u].size();++i)
		if (work(G[u][i])){vis[u]=1;break;}
	return vis[u];
}
	

int main(){
	scanf("%d%d",&n,&m);
	std::memset(vis,-1,sizeof(vis));vis[n]=1;
	for(int i=1;i<=m;++i){
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
	}for(int i=1;i<=n;++i)work(i);
	sel=0;for(int i=1;i<=n;++i)f[i]=-1;ans=dfs(1);
//	for(int i=1;i<=n;++i)printf("%.2f ",f[i]); 
	for(sel=1;sel<=n;++sel){
		if (!G[sel].size())continue;
		for(int i=1;i<=n;++i)f[i]=-1;
		ans=std::min(ans,dfs(1));
	}printf("%.8f",ans);
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1) 
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a) emplace_back(a)
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

ll solve(ll n,ll x)
{
  return (n+x-1)/x ;
}

int main()
{
	FAST_IO ;
	ll n,x,t;
  	cin >> n >> x >> t;
  	cout << solve(n,x)*t endl ;
	return 0;
}

/*
If u haven't come up with an approach yet ,skip this one
  Try this when feeling stuck -
  1. Int overflow, array bounds
  2. Special cases (n=1?)
  3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
  4. Calm down and don't look at standings and stop thinking about rating and think about the question
  5. Just do it! 
*/ 

//Benq's advice - 
/* 
	And following advices are must for me -
	* do something instead of nothing and stay organized
	* WRITE STUFF DOWN 
*/

//#define _GLIBCXX_DEBUG 
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv" 
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere

Measured memory_bytes: 3648
#!/usr/bin/env python3
import sys
import heapq

MOD = 1000000007  # type: int

def containPositive(arr):
    for a in arr:
        if a >= 0:
            return True
    return False

def solve(N: int, K: int, A: "List[int]"):
    if N == K:
        m = 1
        for a in A:
            m = m*a%MOD
        print(m)
    elif not containPositive(A) and K%2 == 1:
        A = list(reversed(sorted(A)))
        m = 1
        for i in range(K):
            m = m*A[i]%MOD
        print(m)
    else:
        m = 1
        B = [(abs(a),a) for a in A]
        B = list(reversed(sorted(B)))
        lastNegative = 0
        lastPositive = 1
        hadPositive = False
        for i in range(K):
            a = B[i][1]
            if a < 0:
                if lastNegative == 0:
                    lastNegative = a
                else:
                    m = m*lastNegative*a%MOD
                    lastNegative = 0
            else:
                if a > 0 and lastPositive != 1:
                    m = m*lastPositive%MOD
                if a > 0:
                    lastPositive = a
                    hadPositive = True
                else:
                    m=m*a%MOD
        if lastNegative == 0:
            print(m*lastPositive%MOD)
        else:
            nextNegative = 0
            for i in range(K,N):
                b = B[i][1]
                if b < 0:
                    nextNegative = b
                    break
            if nextNegative == 0:
                m = m*B[K][1]
                print(m*lastPositive%MOD)
            else:
                c1 = lastNegative*nextNegative
                nextPositive = 0
                k = K
                while k < N:
                    a = B[k][1]
                    if a >=0:
                        nextPositive = a
                        break
                    k+=1
                c2 = nextPositive*lastPositive
                if not hadPositive: # This array contain some non-negative value. This means the result value could be positive. But if there were no positive values in the first K values sorted by the absolute value, use just next positive value instead of the last negative values.
                    m = m*nextPositive%MOD
                    print(m)
                    exit()
                if c1 > c2:
                    m = m*lastNegative*nextNegative%MOD
                    print(m)
                else:
                    m =m*nextPositive*lastPositive%MOD
                    print(m)


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()


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

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

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

    map<int, int> mp;
    set<pair<int, int>> cont;
    vector<int> v(2019 + 1);
    for (int i = 1; i <= n; ++i) {
        int tp;
        cin >> tp;

        v[tp] = i;
        cont.insert({i, tp});
        mp[i] = tp;
    }

    int m;
    cin >> m;

    for (int i = 1; i <= m; i++) {
        int a;
        cin >> a;

        int tp = a;
        a = mp[a];
        if (a + 1 > 2019)
            continue;
        if (v[a + 1] != 0) {
            continue;
        } else {
            cont.erase({v[a], a});
            v[a + 1] = v[a];
            v[a] = 0;
            mp[tp] = a + 1;
            cont.insert({v[a + 1], a + 1});
        }
    }
    vector<int> ans;
    for (auto x: cont)
        ans.push_back(x.second);
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i];
        if (i != ans.back())
            cout << endl;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

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


Measured memory_bytes: 3244
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int32_t A;
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	int32_t ans = 0;
	for (size_t i = 0; i < N; i++)
	{

		in >> A;
		while ((A & 1) == 0) {
			A /= 2;
			ans++;
		}
	}
	out << ans << endl;
	return 0;
}
#endif


Measured memory_bytes: 888
#include<iostream>
using namespace std;
long long dp[1001];
int main() {
	dp[0] = 1;
	for (int i = 1; i <= 31; i++) {
		for (int j = 0; j < 1000; j++) {
			if (i*i + j > 1000) { continue; }
			dp[i*i + j] += dp[j];
		}
	}
	int n;
	while (true) {
		cin >> n; if (n == 0) { break; }
		cout << dp[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long LL;

LL a[204014], b[204014], c[204014], d[204014];
int book[204014];

LL get_f(LL f[], int x);

int main(){
  int n, k, l, i, u, v, t1, t2, id;
  while(~scanf("%d %d %d", &n, &k, &l)){
    for(i = 1; i <= n; i++){
      a[i] = b[i] = i;
    }
    for(i = 0; i < k; i++){
      scanf("%d %d", &u, &v);
      t1 = get_f(a, u);
      t2 = get_f(a, v);
      if(t1 != t2) a[t2] = t1;
    }

    for(i = 0; i < l; i++){
      scanf("%d %d", &u, &v);
      t1 = get_f(b, u);
      t2 = get_f(b, v);
      if(t1 != t2) b[t2] = t1;
    }

    LL e = n+1;
    for(i = 1; i <= n; i++){
      ///c[i] = a[i] + e*b[i];
      c[i] = get_f(a, i) + e*get_f(b, i);
      d[i] = c[i];
    }

    sort(d+1, d+1+n);
    memset(book, 0, sizeof(book));
    for(i = 1; i <= n; i++){
      id = lower_bound(d+1, d+1+n, c[i]) - d;
      book[id]++;
    }
    for(i = 1; i <= n; i++){
      id = lower_bound(d+1, d+1+n, c[i]) - d;
      printf("%d%c", book[id], i == n? '\n': ' ');
    }
  }
  return 0;
}
LL get_f(LL f[], int x){
  if(x == f[x]) return f[x];
  return f[x] = get_f(f, f[x]);
}


Measured memory_bytes: 7808
import math
from functools import reduce


k = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k += 1
ans = 0

for i in range(1,k):
    for j in range(i,k):
        #print(i,j)
        if i == j:
            ans += gcd(i,j)
        else:
            ans += gcd(i,j)*6

for i in range(1,k):
    for j in range((i+1),k):
        for h in range((j+1),k):
            #print(i,j,h)
            ans += gcd(i,j,h)*6


print(ans)


Measured memory_bytes: 69672
#include <bits/stdc++.h>
#define ll long long
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);

ll fpow(ll a, ll b, ll mod){
	if(b == 0)
		return 1;
	if(b == 1)
		return a;
	ll prod = fpow(a,b/2,mod)%mod;
	ll ans = (prod*prod)%mod;
	if(b%2)
		return (ans*a)%mod;
	return ans;
}

using namespace std;

ll find(ll a, vector<ll> &parent){
	if(a == parent[a])
		return a;
	return parent[a] = find(parent[a],parent);
}

void union_sets(ll a, ll b, vector<ll> &parent, vector<ll> &size){
	a = find(a,parent);
	b = find(b,parent);

	if(a== b)
		return;

	if(size[b] > size[a])
		swap(a,b);

	parent[b] = a;
	size[a] += size[b];
}

int main(){
	fastIO;
	ll n,m,a,b;
	cin >> n >> m;

	vector<ll> parent(n+1);
	vector<ll> size(n+1,1);
	for(int i = 1;i <= n; i++){
		parent[i] = i;
	}
	for(int i = 0; i < m; i++){
		cin >> a >> b;
		union_sets(a,b,parent,size);
	}

	set<ll> s;

	for(int i = 1; i <= n; i++){
		s.insert(find(i,parent));
	}
	cout << s.size() - 1 << "\n";
}

Measured memory_bytes: 8480
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	long long int a, b, c;
	cin >> a >> b >> c;
	if(a == b && b == c && a % 2 == 0){
		cout << -1 << endl;
		return 0;
	}
	long long int ans = 0;
	long long int tmpa, tmpb, tmpc;
	while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
		tmpa = a / 2;
		tmpb = b / 2;
		tmpc = c / 2;
		a = tmpb + tmpc;
		b = tmpc + tmpa;
		c = tmpa + tmpb;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

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

typedef std::pair<int, int> P;

int main()
{
	int n;
	while( std::cin >> n, n )
	{
		std::vector<P> v;

		while( n-- )
		{
			int c, t = 0;
			
			std::cin >> c;
			for( int i = 0; i != 4; ++i )
			{
				int m, s;
				std::cin >> m >> s;
				t += m * 60 + s;
			}

			v.push_back( P( t, c ) );
		}

		std::sort( v.begin(), v.end() );

		for( int i = 0; i != 2; ++i )
			std::cout << v[i].second << std::endl;

		std::cout << v[v.size()-2].second << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1304
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

string t;

int main()
{
  size_t len;
  size_t i;

  cin >> t;

  len = t.size();
  for (i=0; i<len; i++) {
    switch(t[i]) {
    case 'D': printf("D"); break;
    case 'P': printf("P");
      if (i<len-1 && (t[i+1] == 'D' || t[i+1] == '?')) {
        printf("D");
        i++;
      }
      break;
    case '?': printf("D"); break;
    }
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 3764
import collections

N=int(input())
D=list(map(int,input().split()))
M=int(input())
T=list(map(int,input().split()))

D_dict=collections.Counter(D)
T_dict=collections.Counter(T)

for i in T_dict.keys():
    if not i in D_dict.keys():
        print("NO")
        exit()
    else:
        if T_dict[i]>D_dict[i]:
            print("NO")
            exit()
print("YES")

Measured memory_bytes: 57056
#prep
n = int(input())
m = list(map(int, input().split())) #initial values
asmt = [0]*n
cnt = 0

#assessment 
while True:
    a = list(map(lambda x: x*(1/2)**(cnt+1), m))
    for i in range(n):
        asmt[i] = a[i].is_integer() 
        
    if all(asmt) == False:
        break 
    else: cnt = cnt+1

print(cnt)

Measured memory_bytes: 3060
use std::io::*;

fn main() {
  let mut n = 0;
  let mut m = 0;
  let mut l = 0;

  let stdin = stdin();
  for line in stdin.lock().lines() {
    let line = line.unwrap();
    let mut args = line.split_whitespace().map(|str| str.parse::<i32>().unwrap());

    let mut lens = [
        args.next().unwrap(),
        args.next().unwrap(),
        args.next().unwrap(),
    ];
    lens.sort();

    let a = lens[0];
    let b = lens[1];
    let c = lens[2];

    if a + b <= c { break; }

    let a = a * a;
    let b = b * b;
    let c = c * c;

    if a + b < c {
      l += 1
    }
    else if a + b == c {
      m += 1
    }
    else {
      n += 1
    }
  }

  println!("{} {} {} {}", n + m + l, m, n, l);
}



Measured memory_bytes: 5036
N,K=map(int, input().split())
instr=input()
lft=0
rgt=1
voids=0 if instr[0] == '1' else 1

maxlen=0
while lft < rgt:
    maxlen = max(maxlen, rgt-lft)
    if rgt < N and (instr[rgt] == '1' or (instr[rgt-1] == '0' and instr[rgt] == '0')):
        rgt += 1
    elif rgt < N and instr[rgt] == '0' and voids < K:
        voids += 1
        rgt += 1
    else:
        if lft+1 < N and instr[lft] == '0' and instr[lft+1] == '1':
            voids -= 1
        lft += 1

print(maxlen)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
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()
{
string s,t;
cin >> s >> t;
cout << t << s << endl;

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;


int main(){
    ll k;
    cin >> k;
    ll num = 7;
    rep(i,1000000){
        num = num % k;
        if(num == 0){
            cout << i+1 << endl;
            return 0;
        }
        num = num * 10 + 7;
    }

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

Measured memory_bytes: 3628
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

n = ni()
a = li()

# 正→負→正→...
cur = a[0]
ans_pn = 0
if cur <= 0:
    ans_pn = abs(a[0])+1
    cur = 1

for i in range(1,n):
    cur += a[i]
    if i%2 == 0 and cur <= 0:
        ans_pn += abs(cur)+1
        cur = 1
    elif i%2 == 1 and cur >= 0:
        ans_pn += abs(cur)+1
        cur = -1


# 負→正→負...
cur = a[0]
ans_np = 0
if cur >= 0:
    ans_np = abs(a[0])+1
    cur = -1

for i in range(1,n):
    cur += a[i]
    if i%2 == 0 and cur >= 0:
        ans_np += abs(cur)+1
        cur = -1
    elif i%2 == 1 and cur <= 0:
        ans_np += abs(cur)+1
        cur = 1
        

print(min(ans_np, ans_pn))

Measured memory_bytes: 14332
import scala.collection.mutable.ArrayBuffer

object Main extends App {
	val sc = new java.util.Scanner(System.in)
	val pw = new java.io.PrintWriter(System.out)
	
	val x, y = sc.nextInt
	
	val M = BigInt(1000000007)
	val nm = (x+y) / 3
	
	def cmb(n: Int, k: Int): BigInt =
		(BigInt(1) to BigInt(k)).foldLeft(BigInt(1))((z, i) => (n - k + i) * i.modInverse(M) * z % M)
	
	pw.println(if (((x+y) % 3 != 0) || (2*y < x || 2*x < y)) 0 else cmb(nm, x - nm).toInt)
	pw.flush()
}

Measured memory_bytes: 112984
#include <iostream>
#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
#include <math.h>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vll x(n),y(n) ;
	ld ans = 0 ;
	for(int i=0;i<n;i++) cin >> x.at(i) >> y.at(i) ;
	vll num(n) ;
	for(int i=1;i<=n;i++) num.at(i-1) = i ;
	do{
		for(int i=0;i<n-1;i++){
			ans += sqrt(pow(x.at(num.at(i+1)-1)-x.at(num.at(i)-1),2)+pow(y.at(num.at(i+1)-1)-y.at(num.at(i)-1),2)) ;
		}
	}while(next_permutation(num.begin(),num.end())) ;
	ll f = 1 ;
	for(int i=1;i<=n;i++) f *= i ;
	cout << fixed << setprecision(15) << ans/(ld)f << endl ;
}


Measured memory_bytes: 256
N,W = map(int, input().split())
dp = [0]*(W+1)

for i in range(1,N+1):
    w,v = map(int,input().split())
    dp[w:W+1] = [max(dp[i+w],dp[i]+v) for i in range(W-w+1)]

print(dp[-1])

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

using namespace std;

int n;
const int maxn = 3005;

double p[maxn];

double dp[maxn][maxn];

int main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        scanf("%lf", &p[i]);
    }
    dp[0][0] = 1;
    for(int i = 1;i <= n;i++){
        for(int j = 0;j <= i;j++){
            dp[i][j] += dp[i - 1][j] * (1 - p[i]);
            if(j > 0){
                dp[i][j] += dp[i - 1][j - 1] * p[i];
            }
        }
    }
    double ans = 0;
    for(int i = n / 2 + 1;i <= n;i++){
        ans += dp[n][i];
    }
    printf("%.10lf\n", ans);
    return 0;
}


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

using namespace std;

int main(void)
{
  int A,B;
  
  cin >> A >> B;
  
  if(A>=13)
  {
    cout << B << endl;
  }else if(A>=6)
  {
    cout << B/2 << endl;
  }else{
    cout << 0 << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <queue>
using namespace std;

int main()
{
const int dx[] = {0, -1, 1, 0}, dy[] = {-1, 0, 0, 1};
while(true) {
int h, w;
char fld[128][128];
scanf("%d%d", &h, &w);
if(h == 0)
break;
for(int i = 0; i < h; ++i)
scanf("%s", fld[i]);
int ans = 0;
for(int sx = 0; sx < h; ++sx) {
for(int sy = 0; sy < w; ++sy) {
if(fld[sx][sy] == 'x')
continue;
char c = fld[sx][sy];
queue<pair<int, int> > q;
q.push(make_pair(sx, sy));
while(!q.empty()) {
int x = q.front().first, y = q.front().second;
q.pop();
for(int i = 0; i < 4; ++i) {
int nx = x + dx[i], ny = y + dy[i];
if(nx < 0 || ny < 0 || nx >= h || ny >= w)
continue;
if(fld[nx][ny] != c)
continue;
fld[nx][ny] = 'x';
q.push(make_pair(nx, ny));
}
}
ans += 1;
}
}
printf("%d\n", ans);
}
return 0;
}

Measured memory_bytes: 1072