akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000
const int mod = INF+7;

void merge_sort(long *t1, int left, int right){    //アドレスが渡される
    if(left==right){
        ;
    }
    else{
        int n2=(right-left+1)/2;
        int n3=right-left+1-n2;
        int i=0,j=0,k=0;

        merge_sort(t1,left,left+n2-1);
        merge_sort(t1,left+n2,right);

        long t2[n2];
        long t3[n3];
        for(i=0;i<n2;i++){
          t2[i]=t1[left+i];
        }
        for(i=0;i<n3;i++){
          t3[i]=t1[left+n2+i];
        }

        for(i=0;i<n2+n3;i++){
            if(k==n3 || (j<n2 && t2[j]<t3[k])){
                t1[left+i]=t2[j];
                j++;
            }
            else{
                t1[left+i]=t3[k];
                k++;
            }
        }
    }
}

int main(){
  char buf[1024];
  int N;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d", &N);

  char **S=(char **)malloc(sizeof(char *)*N);
  rep(i,N){
    S[i]=(char *)malloc(sizeof(char)*10);
    rep(j,10){
      scanf("%c", &S[i][j]);
    }
    getchar();
  }

  long **number=(long **)malloc(sizeof(long *)*N);
  rep(i,N){
    number[i]=(long *)malloc(sizeof(long)*10);
  }
  rep(i,N){
    rep(j,10){
      number[i][j]=S[i][j]-'a';
    }
  }

  rep(i,N){
    merge_sort(number[i], 0, 9);
  }

  long *count=(long *)calloc(N, sizeof(long));
  rep(i,N){
    rep(j,10){
      count[i]+=pow(26,j)*number[i][j];
    }
  }

  merge_sort(count, 0, N-1);

  int num=0;
  int index=1;
  long ans=0;
  while(index<N){
    if(count[index]==count[index-1]){
      num++;
      ans+=num;
    }
    else{
      num=0;
    }
    index++;
  }

  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 15744
import statistics  
N = int(input())
A=list(map(int, input().split()))
B=[]
for number, i in enumerate(A, 1):
    B.append(i-number)
median = int(statistics.median(B))
ans2 = 0
for i in B:
    ans2 += abs(i-median)
print(ans2)

Measured memory_bytes: 27256
#include <stdio.h>

int main(void)
{
    int n, m ,l, i, j, k;
    long long int sum;
    int a[101][101];
    int b[101][101];
    long long int c[101][101];

    scanf("%d %d %d", &n, &m, &l);

    for (i = 0; i < n; i++){
        for (j = 0; j < m; j++){
            scanf("%d", &a[i][j]);
        }
    }

    for (i = 0; i < m; i++){
        for (j = 0; j < l; j++){
            scanf("%d", &b[i][j]);
        }
    }

    for (i = 0; i < n; i++){
        for (j = 0; j < l; j++){
            sum = 0;
            for (k = 0; k < m; k++){
                sum += a[i][k] * b[k][j];
            }
            c[i][j] = sum;
        }
    }

    for (i = 0; i < n; i++){
        printf("%ld", c[i][0]);
        for (j = 1; j < l; j++){
            printf(" %ld", c[i][j]);
        }
        printf("\n");
    }

    return (0);
}



Measured memory_bytes: 2788
import java.util.Scanner;
 
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    switch (a){
      case "SAT": System.out.println("1"); break;
      case "FRI": System.out.println("2"); break; 
      case "THU": System.out.println("3"); break;
      case "WED": System.out.println("4"); break;
      case "TUE": System.out.println("5"); break;        
      case "MON": System.out.println("6"); break;    
      case "SUN": System.out.println("7"); break;   
    }
  }
}

Measured memory_bytes: 21716
n, m = map(int, input().split())
k = []
s = []
for _ in range(m):
    ks = list(map(int, input().split()))
    _k = ks[0]
    _s = [ks[i] for i in range(1, len(ks))]
    k.append(_k)
    s.append(_s)
p = list(map(int, input().split()))

def get_bits_pattern(n):
    bits_pattern = []
    for i in range(2**n):
        bits = [False]*n

        for j in range(n):
            if i >> j & 1:
                bits[j] = True
        bits_pattern.append(bits)
    return bits_pattern

bits_pattern = get_bits_pattern(n)

pattern_counter = 0
for bits in bits_pattern:
    is_on = True
    for _s, _p in zip(s, p):
        counter = 0
        for __s in _s:
            if bits[__s-1]:
                counter += 1
        if _p != counter % 2:
            is_on = False
    if is_on:
        pattern_counter += 1

print(pattern_counter)

Measured memory_bytes: 9228
// "header" {{{
#pragma GCC optimize("Ofast")

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define int int64_t
#define double long double
#define Fixed fixed << setprecision(10)
#define moke_pair make_pair

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int64_t mod1 = 1000000007;
constexpr int64_t mod2 = 998244353;

constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class T,class U> using umap = unordered_map<T,U>;

inline int64_t updiv(int64_t n,int64_t d){ return ((n + d -1) / d); }
inline int square(int a){ return a * a; }

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

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

    int n,d;
    cin >> n >> d;
    int res = 0;
    vector<vector<int> > x(n,vector<int>(d));
    rep(i,n){
        rep(j,d){
            cin >> x[i][j];
        }
    }

    for(int i = 0;i < n-1;++i){
        for(int j = i+1;j < n;++j){
            double sum = 0;
            rep(k,d){
                int tmp = x[i][k] - x[j][k];
                sum += tmp * tmp;
            }
            for(int k = 1;k * k <= sum;++k){
                if(k * k == sum){
                    ++res;
                    break;
                }
            }
        }
    }

    cout << res << '\n';

    return 0;
}

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

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

class Sol{
	public void Solve(){
		
		int[][] sum = new int[2][];
		for(int i=0;i<2;i++) sum[i] = new int[N+1];
		for(int i=0;i<N;i++){
			sum[0][i+1] = sum[0][i] + A[0][i];
			sum[1][i+1] = sum[1][i] + A[1][i];
		}
		
		
		int max = 0;
		for(int i=1;i<=N;i++){
			int tot = sum[0][i] + (sum[1][N] - sum[1][i-1]);
			max = Math.Max(max,tot);
		}
		
		Console.WriteLine(max);

		
	}
	int N;
	int[][] A;
	public Sol(){
		N = ri();
		A = new int[2][];
		for(int i=0;i<2;i++) A[i] = ria();
	}

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


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[1000001];
  map<int, int> dic;

  for (int i = 1; i < n + 1; i++) {
    cin >> a[i];
    dic[a[i]] = i;
  }

  for (int i = 1; i < n + 1; i++) {
    cout << dic[i];
    if (i != n) {
      cout << " ";
    }
  }
  cout << endl;
}

Measured memory_bytes: 7936
#include<iostream>
#include<cstdio>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 1000010
#define mod 998244353
#define inv2 499122177
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m;
int fac[maxn*2],inv[maxn*2];
int quick_pow(int x,int p)
{
    int an=1;
    int po=x;
    while(p)
    {
        if(p&1)  an=1ll*an*po%mod;
        po=1ll*po*po%mod;
        p>>=1;
    }
    return an;
}
int C(int x,int y)
{
    if(x<y)  return 0;
    return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}
int main()
{
    n=read();m=read();
    fac[0]=1;
    for(int i=1;i<=2*max(n,m);i++)  fac[i]=1ll*fac[i-1]*i%mod;
    inv[2*max(n,m)]=quick_pow(fac[2*max(n,m)],mod-2);
    for(int i=2*max(n,m)-1;i>=0;i--)  inv[i]=1ll*inv[i+1]*(i+1)%mod;
    int res=0;
    for(int i=1;i<=min(n,m);i++)  res=(res+1ll*C(2*i,i)*C(n+m-2*i,n-i)%mod)%mod;
    res=1ll*res*quick_pow(C(n+m,m),mod-2)%mod*inv2%mod;
    printf("%d\n",(res+max(n,m))%mod);
    return 0;
}

Measured memory_bytes: 10496
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    s = S()
    r = 0
    for i in range(n):
        a = set(collections.Counter(s[:i]).keys())
        b = set(collections.Counter(s[i:]).keys())
        r = max(r, len(a&b))

    return r




print(main())



Measured memory_bytes: 5568
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;

int main() {
	
	cin.tie(0); cout.tie(0);
	ll a, b, c; cin >> a >> b >> c;
	cout << min(b / a, c);
 	return 0;                        
}

Measured memory_bytes: 256
from collections import namedtuple

if __name__ == '__main__':
    Item = namedtuple('Item', 'v w')
    N, W = map(int, input().split())
    lisItem = [Item(*map(int, input().split())) for _ in range(N)]
    #print(lisItem)
    dp = [[0 for _ in range(W + 1)] for __ in range(N + 1)]
    for i in range(0, N):
        for w in range(W + 1):
            if lisItem[i].w <= w:
                dp[i+1][w] = max(dp[i][w-lisItem[i].w] + lisItem[i].v, dp[i][w])
            else:
                dp[i+1][w] = dp[i][w]
    print(dp[N][W])



Measured memory_bytes: 42900
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

    int a, b;

    // 9a + 4b = (y / 1000) - n となる a, b を求める
    int right = (y / 1000) - n;

    for (a = 0; (9 * a) <= right; a++) {
        for (b = 0; (9 * a + 4 * b) <= right; b++) {
            if (a + b > n) {
                break;
            }

            if ((9 * a + 4 * b) == right) {
                cout << a << " " << b << " " << (n - a - b) << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;

    return 0;
}

Measured memory_bytes: 256
#!python3.8
# -*- coding: utf-8 -*-
# abc167/abc167_b
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    A, B, C, K = i2nn()
    if K < A:
        print(K)
    elif K <= A + B:
        print(A)
    else:
        print(A - (K - (A + B)))
    return

main()


Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  string a;
  cin >> a;
  if ('a' <= a[0] && a[0] <= 'z')
    cout << "a" << endl;
  else
    cout << "A" << endl;
  return 0;
}


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

int main(){
int a,b,c,d,e;
scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
int s=a*e;
int p=b;
if(c<e)p+=d*(e-c);
printf("%d\n",min(p,s));
}

Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main(void){
    int n,a[100]={0};
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    cout << a[n-1];
    for(int i=1;i<n;i++){
        int j=(n-1)-i;
        cout << " " << a[j];
    }
    cout << endl;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define forn(a,b,c) for(int a=b;a<=c;a++)
#define ford(a,b,c) for(int a=b;a>=c;a--)
#define f first
#define s second
typedef pair<int,int> pii;
const int N=1e5+5;
const int mod=1e9+7;
vector<int>g[N];
int w[N],b[N],n;bool vis[N];
int add(int x, int y){ x+=y;if(x>=mod) x-=mod;return x;}
int mul(int x, int y){ x=(ll)x*y%mod; return x;}
void dfs(int x){
    vis[x]=true;
    for(auto& y:g[x]){
        if(!vis[y]){
            dfs(y);
            //printf("x:%d y:%d w[x]:%d add(w[y],b[y]):%d\n",x,y,w[x],add(w[y],b[y]));
            w[x]=mul(w[x],add(w[y],b[y]));
            b[x]=mul(b[x],w[y]);
        }
    }
}
int main()
{
    scanf("%d",&n);
    fill(&w[0],&w[0]+N,1);
    fill(&b[0],&b[0]+N,1);
    forn(i,1,n-1){
        int u,v;
        scanf("%d%d",&u,&v);
        g[v].pb(u);
        g[u].pb(v);
    }
    dfs(1);
    printf("%d\n",add(w[1],b[1]));
    return 0;
}

Measured memory_bytes: 10752
a,b = map(int, input().split())
s = input()
N = set(['1','2','3','4','5','6','7','8','9','0'])
i = 0
ans = 'Yes'
while i < a:
  if not s[i] in N:
    ans = 'No'
  i += 1

if not s[i] == '-':
  ans = 'No'
i += 1

while i < a+b+1:
  if not s[i] in N:
    ans = 'No'
  i += 1
print(ans)

Measured memory_bytes: 3064
import copy

N = int(input())
a = [0]+list(map(int, input().split()))
b = copy.copy(a)
for j in range(N//2, 0, -1):
    b[j] = sum(b[j::j]) & 1
print(sum(b[1:]))
if sum(b[1:]) != 0:
    print(*[i for i, j in enumerate(b) if j == 1])


Measured memory_bytes: 13868
def answer(input0, input1, input2):
    values = [int(n) for n in input0.split(" ")]
    x = values[2]
    y = values[3]
    # print(x, y)

    if x >= y:
        return False

    xa = sorted([int(n) for n in input1.split(" ")], reverse=True)
    # print(xa)

    ya = sorted([int(n) for n in input2.split(" ")], reverse=True)
    # print(ya)

    x0 = xa[0]
    yN = ya[len(ya)-1]

    if yN <= x0:
        return False

    candidate = yN - x0

    for i in range(candidate):
        z = yN - i
        if x0 < z and z <= yN and x < z and z < y:
            return True

    return False

res = answer(input(), input(), input())
if res:
    print("No War")
else:
    print("War")


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

int main() {
  string s;

  cin >> s;

  vector<int> ans((int)s.size()), childR((int)s.size()), childL((int)s.size());

  for (int i = 0; i < (int)s.size(); i++) {
    if (s[i] == 'L') continue;
    char moto = s[i];
    int j = i, cnt = 0;
    while (moto == s[j]) {
      j++;
      cnt++;
      if (j > (int)s.size() - 1) break;
    }
    int tmp = cnt;
    for (int j = i; j < i + tmp; j++) {
      childR[j] = cnt;
      cnt--;
    }
    if (tmp > 2) i += tmp - 2;
  }

  for (int i = (int)s.size() - 1; i >= 0; i--) {
    if (s[i] == 'R') continue;
    char moto = s[i];
    int j = i, cnt = 0;
    while (moto == s[j]) {
      j--;
      cnt++;
      if (j < 0) break;
    }
    int tmp = cnt;
    for (int j = i; j > i - tmp; j--) {
      childL[j] = cnt;
      cnt--;
    }
    if (tmp > 2) i -= tmp - 2;
  }

  for (int i = 0; i < (int)s.size(); i++) {
    if (childR[i] == 0) continue;
    if (childR[i] % 2 == 0)
      ans[childR[i] + i]++;
    else
      ans[childR[i] + i - 1]++;
  }

  for (int i = (int)s.size(); i >= 0; i--) {
    if (childL[i] == 0) continue;
    if (childL[i] % 2 == 0)
      ans[i - childL[i]]++;
    else
      ans[i - childL[i] + 1]++;
  }

  for (int i = 0; i < (int)s.size(); i++) cout << ans[i] << " ";

  return 0;
}

Measured memory_bytes: 1792
# coding: utf-8
# Your code here!
while True:
    H, W = map(int, input().rstrip().split())
    if H == W == 0:
        break
    for i in range(H):
        for j in range(W):
            if j == W - 1:
                print("#")
            elif j == 0 or i == 0 or i == H - 1: 
                print("#", end="")
            else:
                print(".", end="")
    print()
    


Measured memory_bytes: 7008
#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 rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

ll solve(ll a, ll b){
    if(a < b) swap(a, b);
    if(b == 0) return 0;
    ll ret = b*(a/b);
    ret += solve(b, a%b);
    return ret;
}

int main(){
    ll N, X;
    cin >> N >> X;
    cout << solve(N-X, X)*3 << endl;
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main(){
	int N;
	long i, p, s = 0;
	cin >> N;
	for(int j=0;j<N;j++){
		cin >> i;
		if(i!=0) p+=i;
		else{ s+=p/2; p=0; }
	}
	s+=p/2;
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
if N <= 9:
    print(N)
    exit()

tot_count = 0
for af in map(str, range(1, 10)):
    for bf in map(str, range(1, 10)):
        a_count = 0
        b_count = 0
        for a in map(str, range(1, N + 1)):
            if a[0] == af and a[-1] == bf:
                a_count += 1
        for b in map(str, range(1, N + 1)):
            if b[0] == bf and b[-1] == af:
                b_count += 1

        tot_count += a_count * b_count

print(tot_count)


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

int main(){
	ll n, p;
	scanf("%lld%lld", &n, &p);
	ll an = 1;
	for (ll i = 2; i * i <= p; ++i)if (p % i == 0){
		int fr = 1;
		p /= i;
		while (p % i == 0)p /= i, ++fr;
		while (fr >= n)an *= i, fr -= n;
	}
	if (p > 1 && n == 1)an *= p;
	printf("%lld\n", an);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include <iomanip> 
#include <cmath>  
#include<iostream>
#include <fstream>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl

int x, y, z;

int main() {
	cin >> x >> y >> z;
	x -= z;
	int a = y + z;
	wrln(x / a);

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 1000

int n, L, P[MAX+1], v[(MAX+1)*(MAX+1)];

void compute(){
    int size = 0;
    for ( int i = 0; i < n+1; i++ ){
	for ( int j = i; j < n+1; j++ ){
	    v[size++] = P[i] + P[j];
	}
    }
    sort(v, v + size);
    int maxv = 0;

    for ( int i = 0; i < size; i++ ){
	if ( v[i] > L ) break;
	int first = v[i];
	int target = L - v[i];
	
	int t = distance(v, upper_bound(v, v + size, target));

	if ( v[t] + first <= L && maxv < v[t]+first ) maxv = v[t]+first;
	if ( t+1 <size && v[t+1] + first <= L && maxv < v[t+1]+first ) maxv = v[t+1]+first;
	if ( t-1 >= 0 && v[t-1] + first <= L && maxv < v[t-1]+first ) maxv = v[t-1]+first;
    }
    cout << maxv << endl;
}

main(){
    while( cin >> n >> L && n ){
	P[0] = 0;
	for ( int i = 1; i <= n; i++ ) cin >> P[i];
	compute();
    }
}

Measured memory_bytes: 2828
#include<bits/stdc++.h>
using namespace std;
int main(){
	while(1){
		int H,W;
		cin >> H >> W;
		if(H==0){
			if(W==0) break;
		}
		for(int j=0;j<W;j++) cout << '#';
		cout << endl;
		for(int i=0;i<H-2;i++){
			for(int j=0;j<W;j++){
				if(j==0){
					cout << '#';
				}else if(j==W-1){
					cout << '#';
				}else{
					cout << '.';
				}
			}
			cout << endl;;
		}
		for(int j=0;j<W;j++) cout << '#';
		cout << endl << endl;
	}
}
		


Measured memory_bytes: 3104
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long c = sc.nextLong();
    long d = sc.nextLong();
    long a1 = a*c;
    long a2 = a*d;
    a1 = Math.max(a1,a2);
    long b1 = b*c;
    long b2 = b*d;
    b1 = Math.max(b1,b2);
    long ans = Math.max(a1,b1);
    System.out.println(ans);
  }
}


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

int main()
{
  int a,b;
  cin >> a >> b;
  
  int ans = 0;
  int con = 1;
  while(con < b){
    con--;
    con += a;
    ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3612
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long

bool sosu(int x){
    if(x < 2) return 0;
    if(x == 2) return 1;
    if(x % 2 == 0) return 0;
    for(int i = 3;i * i < x;i += 2) if(x % i == 0) return 0;
    return 1;
}

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

    int x; cin >> x;
    for(int i = x;;i ++){
        if(sosu(i) == true){
            cout << i << endl;
            return 0;
        }
    }
}







Measured memory_bytes: 256
#include <stdio.h>

#define DIGITS_LIMIT 80
#define NUM_UNIT 100000000
#define OVERFLOW -1

typedef struct {
    int digits;
    int length;
    int v[10];
} largenumber;


void clear_large_number(largenumber *num) {
    int i;
    for (i = 0; i < 10; i++) {
        num->v[i] = 0;
    }
}

void read_large_number(largenumber *num) {
    static char buf[DIGITS_LIMIT];
    char c;
    int i, j, m, x;

    while ((c = getc(stdin)) < '0');

    for (i = 0; c >= '0' && i < DIGITS_LIMIT; c = getc(stdin), i++) {
        buf[i] = c - '0';
    }
    if (i == DIGITS_LIMIT && c >= '0') {
        while ((c = getc(stdin)) >= '0');
        num->length = OVERFLOW;
        return;
    }
    num->digits = i;
    num->length = i / 8 + (i % 8 != 0);
    for (i=0, m=1, x=0; i < num->digits; i++) {
        x += buf[num->digits-i-1] * m;
        if (i % 8 == 7 || i == num->digits - 1) {
            num->v[i/8] = x;
            x = 0;
            m = 1;
        }
        else {
            m *= 10;
        }
    }
    return;
}

largenumber *sum_large_number(largenumber *x1, largenumber *x2) {
    int i, l, carry, v;
    l = x1->length > x2->length ? x1->length: x2->length;
    for (i = 0, carry = 0; i < l; i++) {
        v = x1->v[i] + x2->v[i] + carry;
        x1->v[i] = v % NUM_UNIT;
        carry = v / NUM_UNIT;
    }
    if (carry) {
        if (l == 10) {
            l = OVERFLOW;
        }
        else {
            x1->v[i] = carry;
            l += 1;
        }
    }

    x1->length = l;
    return x1;
}

void print_large_number(largenumber *num) {
    int i;
    for (i = num->length - 1; i >= 0; i--) {
        if (i == num->length - 1) {
            printf("%d", num->v[i]);
        }
        else {
            printf("%08d", num->v[i]);
        }
    }
    printf("\n");
}

int main() {
    char c, buf[DIGITS_LIMIT], overflow;
    int n, i, cnt, r1, r2;
    largenumber x1, x2;

    scanf("%d", &n);

    while (n--) {
        clear_large_number(&x1);
        clear_large_number(&x2);
        read_large_number(&x1);
        read_large_number(&x2);
        if (x1.length == OVERFLOW || x2.length == OVERFLOW) {
            printf("overflow\n");
            continue;
        }
        sum_large_number(&x1, &x2);
        if (x1.length == OVERFLOW) {
            printf("overflow\n");
            continue;
        }
        print_large_number(&x1);
    }

    return 0;
}

Measured memory_bytes: 620
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    double[] a = new double[n];
    double d = 0.0;
    for(int i = 0;i<n;i++){
      a[i] = sc.nextDouble();
      d += 1/a[i];
    }
    System.out.println(1/d);      
  } 
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
#include<math.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
using namespace std;

//const double pi = boost::math::constants::pi<double>();
ll mod=1000000007;

ll expo(ll base, ll exponent, ll mod) { //return base^exponent modulo modulus
    ll ans = 1;
    while(exponent !=0 ) {
        if((exponent&1) == 1) {
            ans = ans*base ;
            ans = ans%mod;
        }
        base = base*base;
        base %= mod;
        exponent>>= 1;
    }
    return ans%mod;
}

void dfs(ll color,vector<vector<ll>>&g,vector<ll>&ans, ll k,map<pair<ll,ll>,ll>&vis,ll vertex,map<pair<ll,ll>,ll>&mp)
{
    //ll color=1;
    for(auto x:g[vertex])
    {
        if(vis.find({x,vertex})==vis.end() && vis.find({vertex,x})==vis.end())
        {
            ll index;
            if(mp.find({x,vertex})!=mp.end()) index=mp[{x,vertex}];
            else index=mp[{vertex,x}];
            ans[index]=color%k +1;
            color++;
            vis[{x,vertex}]=1;
            dfs(color,g,ans,k,vis,x,mp);
            
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll tests=1;
   // cin>>tests;
    while(tests--)
    {
       ll n,i,a,b;
       cin>>n;
       vector<vector<ll>>g(n+1);
       map<pair<ll,ll>,ll>mp;
       map<pair<ll,ll>,ll>vis;
       for(i=0;i<n-1;i++)
       {
           cin>>a>>b;
           g[a].pb(b);
           g[b].pb(a);
           mp[{a,b}]=i;
       }
       ll k=0;
       for(i=1;i<=n;i++) k=max(k,(ll)g[i].size());
       vector<ll>ans(n-1);
       dfs(1,g,ans,k,vis,1,mp);
       cout<<k<<"\n";
       for(auto x:ans) cout<<x<<"\n";
       
       
    }
    
    return 0;
}


Measured memory_bytes: 21376
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define rep(i,n)for(urs(n)i=0;i<(n);++i

int main(){
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	if(a >= k) cout << k << endl;
	else if(a + b >= k) cout << a << endl;
	else cout << a - (k - a - b) << endl;
    return 0;
}

Measured memory_bytes: 3508
N,Y = map(int,input().split())

for i in range(N+1):
    for j in range(N-i+1):
        if Y-10000*i-5000*j == 1000*(N-i-j):
            print(i,j,N-i-j)
            break
    else:
        continue
    break
else:
    print(-1,-1,-1)

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

class Program {
  static void Main() {
    string[] input = Console.ReadLine().Trim().Split(' ');
    int A = int.Parse(input[0]);
    int B = int.Parse(input[1]);
    
    int resultAdd = A + B;
    int resultSub = A - B;
    int resultTimes = A * B;
    int answer;
    if(resultAdd >= resultSub && resultAdd >= resultTimes) {
      answer = resultAdd;
    } else if(resultSub >= resultAdd && resultSub >= resultTimes) {
      answer = resultSub;
    } else {
      answer = resultTimes;
    }
    Console.WriteLine(answer);     
  }
}

Measured memory_bytes: 13140
#include<stdio.h>
int main(void)
{
	int a, b, c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<b){
		if(b<c)
			printf("%d %d %d\n",a,b,c);
		
		else if(a<c)
			printf("%d %d %d\n",a,c,b);
		
		else
			printf("%d %d %d\n",c,a,b);
	}
	else{
		if(a<c)
			printf("%d %d %d\n",b,a,c);
		
		else if(b<c)
			printf("%d %d %d\n",b,c,a);
		
		else
			printf("%d %d %d\n",c,b,a);
	}		
	return 0;
}

Measured memory_bytes: 596
/*
 * RD
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#ifndef rd
#define endl '\n'
#endif
#define deb cout<<"Line: "<<__LINE__<<" plz "
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
#define pii pair<int,int>
#define sz(x) ((int)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(con) con.begin(),con.end()
const ll inf=1e18;
const int mod=1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll powm(ll a, ll b, ll m);

int n,q;
int a[100005];
int pref[100005],prefo[100005];
void solve()
{
	cin>>n>>q;
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		pref[i]=pref[i-1]+a[i];
		if((i&1))
			prefo[i]=prefo[i-1]+a[i];
		else
			prefo[i]=prefo[i-1];
	}
	for(int i=0; i<q; i++)
	{
		int te;
		cin>>te;
		if(abs(a[n/2+1]-te)>=abs(a[1]-te))
		{
			cout<<pref[n]-pref[n/2]<<endl;
			continue;
		}
		int lo=1,hi=n/2,mid=(1+lo+hi)/2;
		while(lo<hi)
		{
			if(abs(te-a[n-mid+1])>=abs(te-a[n-2*mid+2]))
				lo=mid;
			else
				hi=mid-1;
			mid=(lo+hi+1)/2;
		}
		ll sum=pref[n]-pref[n-mid];
		if(n&1)
			sum+=prefo[n-2*mid];
		else
			sum+=pref[n-2*mid]-prefo[n-2*mid];
		cout<<sum<<endl;
	}
}
signed main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	auto clk=clock();
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}
ll powm(ll a,ll b, ll m) {
	ll te=1;
	while(b) {
		if(b&1) te=(te*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return te;
}


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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> x(n, 0);
    for(int i = 0; i < k; i++){
        int d;
        cin >> d;
        for(int j = 0; j < d; j++){
            int a;
            cin >> a;
            x[a-1]++;
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        if(x[i] == 0) ans++;
    }

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

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

struct dp {
  int ary[100010];
  constexpr dp() : ary() {
    rep(i, 100010) ary[i] = i;
    for (int i = 6; i < 100010; i *= 6) {
      for (int j = 0; j+i < 100010; ++j) ary[j+i] = min(ary[j+i], ary[j]+1);
    }
    for (int i = 9; i < 100010; i *= 9) {
      for (int j = 0; j+i < 100010; ++j) ary[j+i] = min(ary[j+i], ary[j]+1);
    }
  }
};

int main() {
  int n; cin>>n;
  constexpr auto a = dp();
  print(a.ary[n]);
  return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
void ABC80(void);
void ABC81(void);
void ABC82(void);
void ABC83(void);
void ABC84(void);
void ABC85(void);
void ABC86(void);
void ABC87(void);
void ABC88(void);
void ABC89(void);

int main(void){
    ABC80();
}

void ABC80(){
    int n,sum=0,i,d=1,a=0;
    cin>>n;
    for(i=0;i<9;i++){
        a+=(n/d)%10;
        d*=10;
    }
    if(n%a==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;
int main(){
    string S;
    cin >> S;
    int i = 1;
    long ans = 0;
    long hasA = 0;

    if(S[0] == 'A')hasA++;
    while(S[i] != '\0'){
        long hasBC = 0;
        bool flag = false;
        while(S[i] == 'A'){
            i++;
            hasA++;
        }
        if(S[i - 1] == 'A' && S[i] == 'B' && S[i+1] == 'C'){
            flag = true;
            hasBC++;
            i +=2;
        }
        while(flag && S[i] == 'B' && S[i+1] == 'C'){
            hasBC++;
            i += 2;
        }
        if(flag){
            //cout << hasA << " " << hasBC <<endl;
            ans += hasA * hasBC;
            continue;
        }
        hasA = 0;
        i++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y,ans,r,xd,yd;
  cin >> x >> y;
  ans=1;
  int a = x;
  int b = y;
  if(a<b) swap(a,b);
  while(b>0){
        r = a % b;
        a=b;
        b=r;
  }
  //最大公約数はa
  int s=x/a,t=y/a;
  ans += (s+t-1)*a;
  cout << ans << endl;

  return 0;
}


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

int n,a[100005];

string work(int n)
{
	for(int i = 2;i <= n;i++)
	{
		if(a[i] > a[i - 1])
			a[i]--;
		if(a[i] < a[i - 1])
			return "No";
	}
	return "Yes";
}

int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n;i++)
		scanf("%d",&a[i]);
	cout << work(n);
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
typedef vector<int> ivec;
typedef vector<string> svec;

int a[100010];
int main(){
	int n;
	int ans=0;
	string s;
	cin>>s;	
	for(int i=0;i<(s.size()-8);i++)cout<<s[i];
	cout<<""<<endl;
	return 0;
}

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



ll a , b , k;


void solve(int testCase){
    cin >> a >> b >> k;

    if(a >= k){
            cout << a - k << " " << b << endl;
    }
    else {
            k -= a;
            if(b <= k)b = 0;
            else b -= k;
            cout << 0 << " " << b << endl;
    }


}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 256
use std::io::stdin;

macro_rules! read {
    ($t: ty) => {{
        let mut line = String::new();
        stdin().read_line(&mut line);
        line.trim().parse::<$t>().unwrap()
    }};
    ($($t: ty), *) => {{
        let mut line = String::new();
        stdin().read_line(&mut line);
        let mut iter = line.split_whitespace();
        (
            $(iter.next().unwrap().parse::<$t>().unwrap(), )*
        )
    }}
}
macro_rules! reads {
    ($e:expr, $t:ty) => {{
        let mut v = vec![];
        for _ in 0..$e {
            let mut line = String::new();
            stdin().read_line(&mut line);
            v.push(line.trim().parse::<$t>().unwrap());
        }
        v
    }};
}

fn main() {
    let (mut a, mut b) = read!(u64, u64);

    let mut s = 0;

    if a > b {
        s = s + a;
        a = a - 1;
    } else {
        s = s + b;
        b = b - 1;
    }

    if a > b {
        s = s + a;
        a = a - 1;
    } else {
        s = s + b;
        b = b - 1;
    }

    println!("{}", s);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <stdlib.h>
 
using namespace std;
 
 
const long long int MAX = 2000000007;
long long int dist[1001][1001]={};
long long int visit[8] = {};
int r;
long long int ans = 9223372036854775807;
 
 
int main()
{
  int i,j,k;
  int n,m;
  cin >> n >> m >> r;
 
  //行列を初期化
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(i!=j)
        dist[i][j] = MAX;
      else
        dist[i][j] = 0;
    }
  }
 
  //点を読み込む
  for(i=0;i<r;i++){
    int tmp;  cin >> tmp;
    visit[i] = --tmp;
  }
 
  //辺と重み(距離)を読み込む
  for(i=0;i<m;i++){
    int x,y;
    long long int d;
    cin >> x >> y >> d;  x--;  y--;
    dist[x][y] = d;
    dist[y][x] = d;
  }
 
  //各点に対して、その点を最短経路に含むパスの両端点間の距離を更新
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      for(k=0;k<n;k++){
        if( dist[j][k] > dist[j][i] + dist[i][k] ){
          dist[j][k] = dist[j][i] + dist[i][k];
        }
      }
    }
  }
 
 
  sort(visit,visit + r);
 
 do {
    long long int tmp = 0;
    for(i=0;i<r-1;i++)
      tmp += dist[visit[i]][visit[i+1]];
 
    if(tmp < ans)
      ans = tmp;
  } while ( std::next_permutation(visit,visit+r) );
 
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <deque>

using namespace std;

int main() {

	int n, m;
	char a, b;
	deque<char> s, x, y;

	while(cin >>n) {
		if(!n) {
			break;
		}
		for(int i=0; i<n; i++) {
			cin >> a >> b;
			x.push_back(a);
			y.push_back(b);
		}
		cin >> m;
		for(int i=0; i<m; i++) {
			cin >> a;
			s.push_back(a);
		}
		for(int i=0; i<m; i++) {
			for(int j=0; j<n; j++) {
				if(s[i]==x[j]) {
					s[i]=y[j];
					break;
				}
			}
			cout << s[i];
		}
		cout << endl;
		x.clear();
		y.clear();
		s.clear();
	}

	return 0;

}

Measured memory_bytes: 996
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - Divisible Substring
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;
const int MAX_P = 10000;

/* typedef */

typedef long long ll;

/* global variables */

char s[MAX_N + 4];
int cs[MAX_P];

/* subroutines */

/* main */

int main() {
  int n, p;
  scanf("%d%d%s", &n, &p, s);

  ll sum = 0;
  if (p == 2 || p == 5) {
    for (int i = 0; i < n; i++)
      if ((s[i] - '0') % p == 0) sum += i + 1;
  }
  else {
    int r = 0, e = 1;
    cs[0] = 1;
    for (int i = n - 1; i >= 0; i--) {
      int d = s[i] - '0';
      r = (r + e * (s[i] - '0') % p) % p;
      sum += cs[r];
      cs[r]++;
      e = e * 10 % p;
    }
  }

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 512
#!python3

def resolve():
    N = tuple(map(int,input()))

    if len(N) == 1:
        print(N[0])
        return

    n = len(N)
    dp = [[[0]*10 for j in range(2)] for i in range(2)]

    k0  = N[0]
    dp[0][0][k0] = 1

    dp0, dp1 = dp
    for i in range(n-1):
        xx = 1 if i else 0

        for k in range(1, 10):
            dp1[1][k] = 10 * dp0[1][k] + xx

        x, y = N[i], dp0[0][k0]
        if i == 0:
            dp1[0][k0] = y
            for k in range(1, k0):
                dp1[1][k] = y
        else:
            dp1[1][k0] += x * y
            dp1[0][k0] = y

        #print(dp1)
        dp0, dp1 = dp1, dp0

    dp2 = [[0]*10 for i in range(10)]
    for i in range(1, 10):
        for j in range(1, 10):
            dp2[i][j] = dp0[1][i]

        for j in range(1, N[-1]+1):
            dp2[i][j] += dp0[0][i]

        dp2[i][i] += 1

    #for x in dp2:
    #    print(x)

    ans = 0
    for i in range(1, 10):
        for j in range(1, 10):
            ans += dp2[i][j]*dp2[j][i]
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3064
const input = require('fs').readFileSync('/dev/stdin', 'utf8').trim()
const lines = input.trim().split("\n")

const nextDay = (y,m,d) => {
    d = d + 1
    if(y%3 === 0) {
        if(d > 20) {
            d = 1
            m += 1
            if(m === 11) {
                m = 1
                y++
            }
        }
    } else {
        if(d > 20) {
            d = 1
            m += 1
            if(m === 11) {
                m = 1
                y++
            }
        } else if(d > 19 && m %2 === 0) {
            d = 1
            m += 1
            if(m === 11) {
                m = 1
                y++
            }
        }
    }
    return [y,m,d]
}
lines.shift()
lines.forEach(line => {
    let [y,m,d] = line.trim().split(' ').map(Number)
    let count = 1
    while (y !== 1000 || m !== 1 || d !== 1) {
         [y,m,d] = nextDay(y,m,d)
        count++
    }
    console.log(count - 1)
})


Measured memory_bytes: 19516
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
from math import *
from itertools import *
INF = 10**10

N, K, Q = map(int, input().split())
P = [K-Q] * N
for i in range(Q):
    P[int(input())-1] += 1
for x in P:
    if x > 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 47964
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	while (cin>>n,n) {
		int l=0, d=1, r=1, u=0;
		map<int, pii> rec;
		rec[0] = pii(0, 0);
		REP(i,n-1) {
			int num, dir;
			cin >> num >> dir;
			rec[i + 1] = pii(rec[num].first + dx[dir], rec[num].second + dy[dir]);
			l = min(l, rec[num].first + dx[dir]);
			d = max(d, rec[num].second + dy[dir]+1);
			r = max(r, rec[num].first + dx[dir]+1);
			u = min(u, rec[num].second + dy[dir]);
		}
		cout << (r - l) << ' ' << (d - u) << endl;
	}
}

Measured memory_bytes: 2976
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 1e5 + 5;
const double pi = acos(-1);
int  main(){
 //   ios::sync_with_stdio(false);
    double r ; cin >> r;
    printf("%.7f\n" , r * 2 * pi);
    return 0;
}


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

const int N = 200005, INF = int(1e9);

int n, a[N], d[N][5];

int c(int x, int y){
    if(y == 2) return (a[x] % 2 == 0);
    if(y == 1 || y == 3) return 2 * !a[x] + (a[x] % 2);
    return a[x];
}

int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", a + i);
    for(int i = 1; i <= n; i++){
        int t = INF;
        for(int j = 0; j < 5; j++){
            t = min(t, d[i - 1][j]);
            d[i][j] = t + c(i, j);
        }
    }
    printf("%d\n", *min_element(d[n], d[n] + 5));
}

Measured memory_bytes: 4992
def isCLKWISE(ph):
    a = [ph[-1][0]-ph[-3][0],ph[-1][1]-ph[-3][1]]
    b = [ph[-2][0]-ph[-3][0],ph[-2][1]-ph[-3][1]]
    crs = a[0]*b[1] - a[1]*b[0]
    if crs < 0 : return False
    else : return True
     
def ConvexHullScan(P):
    P = sorted(P)
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        while(True):
            if isCLKWISE(phU) : break
            else :
                del phU[-2]
                if len(phU) == 2 : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        while(True):
            if isCLKWISE(phL) : break
            else :
                del phL[-2]
                if len(phL) == 2 : break
    ph = phU + phL[1:-1]
    return ph
 
n = int(input())
P = []
for i in range(n):
    P.append([int(x) for x in input().split()])
     
Q = ConvexHullScan(P)
Q.reverse()
print(len(Q))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(Q)])[2]
R = Q[idx:] + Q[:idx]
for r in R:
    print(r[0],r[1])

Measured memory_bytes: 33820
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
struct Program {
  int s, t, c;
  Program(int s, int t, int c): s(s), t(t), c(c) {};
  bool operator<(const Program& rhs) const { return s == rhs.s ? t < rhs.t : s < rhs.s; }
  bool operator>(const Program& rhs) const { return s == rhs.s ? t > rhs.t : s > rhs.s; }
};

template<class T>using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;

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

  vector<priority_queue_rev<Program>> q(30);
  rep(i, N) {
    int s, t, c; cin >> s >> t >> c;
    --c;
    q[c].emplace(s, t, c);
  }

  rep(i, 30) {
    queue<Program> tmp_q;
    while (!q[i].empty()) {
      if (q[i].size() == 1) {
        tmp_q.push(q[i].top());
        q[i].pop();
        break;
      }
      Program p1 = q[i].top(); q[i].pop();
      Program p2 = q[i].top(); q[i].pop();
      if (p1.t == p2.s)
        q[i].emplace(p1.s, p2.t, p1.c);
      else {
        tmp_q.push(p1); tmp_q.push(p2);
      }
    }
    while (!tmp_q.empty()) {
      q[i].push(tmp_q.front()); tmp_q.pop();
    }
  }

  priority_queue_rev<pair<int, int>> tv; // [終了時刻, チャンネル]
  int ans = 0;
  rep(t, 1e5+1) {
    int min_idx = -1;
    rep(i, 30) {
      if (q[i].empty())
        continue;
      if (min_idx == -1 || q[i].top() < q[min_idx].top())
        min_idx = i;
    }
    if (min_idx == -1)
      break;
    Program p = q[min_idx].top(); q[min_idx].pop();
    if (tv.empty())
      tv.emplace(p.t, p.c);
    else {
      if (tv.top().first < p.s || tv.top().first <= p.s && tv.top().second == p.c) {
        tv.pop();
        tv.emplace(p.t, p.c);
      } else
        tv.emplace(p.t, p.c);
    }
    ans = max(ans, (int)tv.size());
  }

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


Measured memory_bytes: 2176
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int main()
{
    int n,k,q,x;
    int a[100002]={0};
    cin>>n>>k>>q;
    for(int i=0;i<q;i++)
    {
        scanf("%d",&x);
        a[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i]+k-q>0)
            printf("Yes\n");
        else
            printf("No\n");
    }
}


Measured memory_bytes: 1024