akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();

        final int[] h = new int[N];

        for (int i = 0; i < N; i++) {
            h[i] = sc.nextInt();
        }

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            while (h[i] != 0) {
                for (int j = i; j < N; j++) {
                    if (h[j] == 0) break;
                    h[j]--;
                }
                cnt++;
            }
        }

        System.out.println(cnt);
    }
}


Measured memory_bytes: 23124
# 空白区切の入力値を数値の配列で返す
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N, M, C = gets_i_list
b = gets_i_list
a_list = []
N.times do
  a_list.push(gets_i_list)
end

count = 0
a_list.each do |a|
  total = C
  (0...M).each do |i|
    total += a[i] * b[i]
  end
  count += 1 if total > 0
end

puts count


Measured memory_bytes: 3836
/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>

/* include c-lang libraries */
#include <climits>
#include <cmath>

/* include my libraries */
//#include <show_vec.hh>

using namespace std;

#define LINE DEBUG{ printf("LINE : %d\n", __LINE__); }
#define DEBUG if(false)

using ll = long long;
template<class T> using vec = vector<T>;

const int MOD = 1000000007;

int main(){
  int S;
  cin >> S;
  if(S < 3){ cout << 0 << endl; return 0; }
  ll Ans = 0;
  vec<vec<ll>> nCk(S-2);
  vec<ll> templ(S-2, 0);
  templ[0] = 1;
  for(int n = 0; n < S-2; n++){
    nCk[n] = templ;
    for(int k = 1; k < n+1; k++){
      nCk[n][k] = (nCk[n-1][k-1] + nCk[n-1][k]) % MOD;
    }
  }

  for(int k = 1; k <= S/3; k++){
    Ans = (Ans + nCk[S-2*k-1][ ((S-3*k<k-1)?S-3*k:k-1) ]) % MOD;
  }

  cout << Ans << endl;


  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  while (n) {
    ans++;
    n /= k;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, R, C, K, r, c, v, item[3001][3001] = {};
	scanf("%d %d %d", &R, &C, &K);
	for (i = 1; i <= K; i++) {
		scanf("%d %d %d", &r, &c, &v);
		item[r][c] = v;
	}
	
	int j, k;
	long long dp[4][3001] = {};
	for (i = 1; i <= R; i++) {
		for (j = 1; j <= C; j++) {
			for (k = 1; k <= 3; k++) {
				if (dp[k][j] > dp[0][j-1]) dp[0][j-1] = dp[k][j];
				dp[k][j] = 0;
			}
			for (k = 0; k <= 3; k++) if (dp[k][j-1] > dp[k][j]) dp[k][j] = dp[k][j-1];
			for (k = 1; k <= 3; k++) if (dp[k-1][j-1] + item[i][j] > dp[k][j]) dp[k][j] = dp[k-1][j-1] + item[i][j];
		}
	}

	for (k = 1; k <= 3; k++) if (dp[k][C] > dp[0][C]) dp[0][C] = dp[k][C];
	printf("%lld\n", dp[0][C]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 37008
#include <stdio.h>
#include <stdlib.h>
int main()
{
    int n, k;
    char *s, p, *t;
    scanf("%d", &n);
    s = malloc(n+1);
    scanf("%s", s);
    scanf("%d", &k);
    p = s[k-1];
    t = s;
    while(*t != '\0'){
        if(*t != p) *t = '*';
        t++;
    }
    printf("%s\n", s);
    return 0;
}

Measured memory_bytes: 128
from itertools import product
n,m,x = map(int,input().split())
books = [list(map(int,input().split())) for i in range(n)]
costs = []
skills = []
for book in books:
    costs.append(book[0])
    skills.append(book[1:])

ans = float('inf')

for bit in product((0,1),repeat=n):
    #print('bit',bit)
    current_cost = 0
    current_skill = [0] * m
    for i in range(n):
        if bit[i] == 1:
            for j in range(m):
                current_skill[j] += skills[i][j]
                #print('current_s',current_skill[j])
            current_cost += costs[i]


    if x <= min(current_skill):
        ans = min(ans,current_cost)


if ans == float('inf'):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 74140
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	int d = sc.nextInt();
	int dist = Math.min(b,d)-Math.max(a,c);
	System.out.println((dist<0)?0:dist);
    }
}

Measured memory_bytes: 22612
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int main(void)
{
int x;
cin>>x;
if(x==0) cout<<1<<endl;
else cout<<0<<endl;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  long long n,ans=0;
  cin >> n;
  long long a[n+1],b[n];
  for(int i=0;i<n+1;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    cin >> b[i];
  }
  for(int i=n;i>0;i--){
    long long tmp=min(a[i], b[i-1]);
    ans+=tmp;
    a[i]-=tmp;
    b[i-1]-=tmp;
    tmp=min(a[i-1], b[i-1]);
    ans+=tmp;
    a[i-1]-=tmp;
    b[i-1]-=tmp;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<ctime>
#define ll long long
#define pr(x) cerr<<#x<<"="<<x<<endl
using namespace std;
ll a,b,c,d,e,f,ans,i,dp[100000];
double maxx;
int main()
{
	scanf("%lld %lld %lld %lld %lld %lld",&a,&b,&c,&d,&e,&f);
	for (i=1;i<=f;i++) dp[i]=-10000000;
	dp[0]=0;
	for (i=1;i<=f;i++)
	{
		if (i-100*a>=0) dp[i]=max(dp[i],dp[i-100*a]);
		if (i-100*b>=0) dp[i]=max(dp[i],dp[i-100*b]);
		if (i-c>=1)
		{
			if (((double)(dp[i-c]+c)*100.0/(i-dp[i-c]-c))<=e)
			dp[i]=max(dp[i],dp[i-c]+c);
		}
		if (i-d>=1)
		{
			if (((double)(dp[i-d]+d)*100.0/(i-dp[i-d]-d))<=e)
			dp[i]=max(dp[i],dp[i-d]+d);
		}
	}
	for (i=0;i<=f;i++)
	{
		if ((double)(dp[i])*100.0/(i-dp[i])>=maxx) 
		maxx=(double)(dp[i])*100.0/(i-dp[i]),ans=i;
	}
	if (dp[ans]==0) 
	{
		printf("%lld 0\n",100*a);
	}
	else printf("%lld %lld\n",ans,dp[ans]);

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int ans = 0;
  for(int i=1; i<=N; i++){
    if(i >= 10 & i <= 99){
      continue;
    }
    if(i >= 1000 & i <= 9999){
      continue;
    }
    if(i == 100000){
      continue;
    }
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

ll gcd(ll a, ll b){
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int main(){
  int n; cin >> n;
  priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> q;
  
  rep(i,n){
    int a, b; cin >> a >> b;
    q.push(make_pair(b,a));
  }
  ll time = 0;
  while(!q.empty()){
    int a,b;
    tie(b,a) = q.top();q.pop();
    time += a;
    if(time > b){
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
  
  return 0;
}

Measured memory_bytes: 2420
using System;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int N = int.Parse(input[0]);
    int T = int.Parse(input[1]);
    
    int min = int.MaxValue;
    for (int i = 0; i < N; i++) {
      input = Console.ReadLine().Split(' ');
      if (int.Parse(input[1]) <= T) {
        min = Math.Min(min, int.Parse(input[0]));
      }
    }
    Console.WriteLine((min == int.MaxValue) ? "TLE" : min.ToString());
  }
}

Measured memory_bytes: 13140
n = int(input())
a = [int(x) for x in input().split()]

ball = [0] * (n//2) + a[n//2:]

for i in reversed(range(n//2)):
    sum_ball = 0
    for j in range(1, n//(i+1)):
        sum_ball += ball[(i+1)*(j+1)-1]
    if sum_ball % 2 != a[i]:
        ball[i] = 1

index = [i+1 for i, x in enumerate(ball) if x == 1]
l = len(index)
print(l)
if l > 0:
    print(" ".join(map(str, index)))



Measured memory_bytes: 20280
#include<cstdio>
#define MOD 1000000007
int n,f[1000010];
int main()
{
	scanf("%d",&n);f[n]=n;f[n-1]=1ll*n*n%MOD;
	for(int i=n-2,s=0;i>0;--i)s=(s+f[i+3])%MOD,f[i]=(f[i+1]+1ll*(n-1)*(n-1)+s+i+1)%MOD;
	printf("%d\n",f[1]);return 0;
}


Measured memory_bytes: 4096
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = readline().strip()

    ans = [0] * len(S)
    for i, c in enumerate(S):
        ans[i] = chr((ord(c) - 65 + N) % 26 + 65)

    print(''.join(ans))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9228
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const int mod = 998244353;

inline void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

inline int mul(int a, int b) {
  return (int)((long long)a * b % mod);
}

const int N = 2'009;

int fa[N][N];
int fb[N][N];

int main() {
  memset(fa, 0, sizeof fa);
  memset(fb, 0, sizeof fb);
  fa[0][0] = 1;
  fb[0][0] = 1;
  for (int i = 1; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      fa[i][j] = fa[i - 1][j];
      fb[i][j] = fb[i - 1][j];
    }
    int sa = fa[i - 1][0];
    int sb = fb[i - 1][0];
    for (int j = 1; j < N; ++j) {
      add(fa[i][j], sa);
      add(fb[i][j], mul(sb, 2));
      add(sa, fa[i - 1][j]);
      add(sb, fb[i - 1][j]);
    }
  }
  int m, n;
  scanf("%d %d", &m, &n);
  for (int i = 2; i <= 2 * m; ++i) {
    int cnta = 0, cntb = 0, cntc = 0;
    for (int j = 1; j <= m; ++j) {
      if (j >= i || i - j > m) {
        ++cnta;
      } else
      if (i - j != j) {
        ++cntb;
      } else {
        cntc = 1;
      }
    }
    cntb /= 2;
    int ans = 0;
    for (int s = 0; s <= cntc; ++s) {
      for (int j = 0; j <= n - s; ++j) {
        add(ans, mul(fa[cnta][j], fb[cntb][n - s - j]));
      }
    }
    printf("%d\n", ans);
  }
}


Measured memory_bytes: 31872
#include<cstdio>


int main(){
    int X,N;
    scanf("%d %d", &X, &N);
    int p[N];
    for(int i=0;i<N;i++){
        scanf("%d", &p[i]);
    }
    for (int i=0; i<N;i++) {
        for (int j=i+1;j<N;j++) {
            if (p[i] > p[j]) {
            int tmp =  p[i];
            p[i] = p[j];
            p[j] = tmp;
            }
        }
    }
    int index = N;
    for(int i=0;i<N;i++){
        if(p[i] == X) index = i;
    }
    int ans;
    if(index == N) ans = X;
    else{
        int X_m = X;
        int X_p = X;
        int ind_m = index;
        int ind_p = index;
        while(true){
            X_m--;
            X_p++;
            ind_m--;
            ind_p++;
            if(X_m  != p[ind_m]){
                ans = X_m;
                break;
            } 
            if(X_p != p[ind_p]){
                ans = X_p;
                break;
            }
            if(ind_m == 0){
                ans = X_m - 1;
                break;
            }
            if(ind_p == N-1){
                ans = X_p + 1;
                break;
            }

        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 1684
#include <iostream>
using namespace std;
int N;
 
int solve(){
    int ans = 0;
    for(int i = 0; i <= 9; ++i){
        for(int j = 0; j <= 9; ++j){
            for(int k = 0; k <= 9; ++k){
                for(int l = 0; l <= 9; ++l){
                    int tmp = i + j + k + l;
                    if(tmp == N) ans++;
                }
            }
        }
    }
    return ans;
}
 
int main(){
    while(cin >> N){
        int ans = solve();
        cout << ans << endl;
    }
}


Measured memory_bytes: 3100
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    // マージソートとクイックソートの結果を比べる
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

  ll N,K;
  cin>>N>>K;

  vector<ll> A(N),B(N),C(N);
  if(N%2==0){
    rep(i,N){
      if(i<N/2) A[i]=i*2+1;
      else A[i]=(i-N/2)*2;
    }
    rep(i,N){
      if(i<N/2) B[i]=(N/2)-1-i+N;
      else B[i]=2*N-1-(i-(N/2));
    }
  }else{
    rep(i,N){
      if(i<N/2) A[i]=i*2+1;
      else A[i]=(i-N/2)*2;
    }
    rep(i,N){
      if(i<N/2) B[i]=(N/2)-1-i+N;
      else B[i]=2*N-1-(i-(N/2));
    }
  }
  rep(i,N)C[i]=2*N-K+i;

  bool ok=true;
  rep(i,N)if(A[i]+B[i]>C[i])ok=false;
  if(!ok)cout<<-1<<endl;
  else{
    rep(i,N)cout<<A[i]+K<<" "<<B[i]+K<<" "<<C[i]+2*K<<endl;
  }

  return 0;
}


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

Measured memory_bytes: 256
use proconio::input;

const MAX_A:usize = 1000000;
fn main() {
    input! {
        n:usize,
        a:[usize;n]
    };

    let mut sum_a = {
        let mut sum_a = vec![0;MAX_A+1];
        for &e in &a {
            sum_a[e]+=1;
        }
        sum_a
    };

    let mut ans = 0;
    for i in 1..(MAX_A+1) {
        if sum_a[i]==0 {
            continue
        }
        for j in (i*2..(MAX_A+1)).step_by(i) {
            sum_a[j] = 0;
        }
        if sum_a[i]>1 {
            sum_a[i] = 0;
        }
        ans += sum_a[i];
    }

    println!("{}",ans);

    


    
    
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


struct SegmentTreeSUM{
  ll n;
  vll tree;

  SegmentTreeSUM(ll len){
    n=1;
    while(len>n)
      n*=2;

    tree.assign(2*n-1, 0);
  }

  void update(ll index, ll value){
    index += n-1;
    tree[index] = value;

    while(index>0){
      index=(index-1)/2;
      tree[index] = tree[index*2+1]+tree[index*2+2];
    }
  }


  //[a, b)
  ll query(ll a, ll b){
    return query(a,b,0,0,n);
  }

  ll query(ll a, ll b, ll index, ll l, ll r){
    if(b<=l || r<=a)
      return 0;

    if(a<=l && r<=b)
      return tree[index];

    ll value_l = query(a,b,2*index+1,l,(l+r)/2);
    ll value_r = query(a,b,2*index+2,(l+r)/2,r);
    return value_l+value_r;
  }
};


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

  ll n,q;
  cin>>n>>q;

  vll c(n);
  REP(i,n)cin>>c[i];
  vll l(q), r(q);
  REP(i,q){
    cin>>l[i]>>r[i];
    l[i]--;
    r[i]--;
  }


  vll index(n+1,-1);
  SegmentTreeSUM st(n);

  vpl qu(q);
  REP(i,q){
    qu[i].FI=r[i];
    qu[i].SE=l[i];
  }
  sort(ALL(qu));


  map<pll,ll> ans;
  ll cur=-1;
  REP(i,q){
    for(ll j=cur+1; j<=qu[i].FI; j++){
      if(index[c[j]]!=-1)
        st.update(index[c[j]],0);

      st.update(j,1);
      index[c[j]]=j;
    }
    cur=qu[i].FI;

    ll a=st.query(qu[i].SE,qu[i].FI+1);
    ans[pll(qu[i].SE,qu[i].FI)]=a;
  }

  REP(i,q)cout<<ans[pll(l[i],r[i])]<<endl;


}



Measured memory_bytes: 66716
#include<iostream>
#include<cstdio>
using namespace std;
int cnt_odd,cnt_even;
int main(){
	int n;
	scanf("%d",&n);
	int temp;
	for(int i = 0;i < n;i ++){
		scanf("%d",&temp);
		if((temp & 1) == 0){
			cnt_even++;
		}
		else{
			cnt_odd ++;
		}
	}
	if((cnt_odd & 1) != 0){
		printf("NO");
		return 0;
	}
	printf("YES");
	return 0;
}

Measured memory_bytes: 256
MAX_INT = 10**6
N, M = map(int, input().split())
room = [set() for _ in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    room[a].add(b)
    room[b].add(a)

dis = [MAX_INT] * (N + 1)
sign = [-1] * (N + 1)
dis[1] = 0
def sign_root(n):
    nxt = []
    for i in room[n]:
        if dis[n] + 1 < dis[i]:
            sign[i] = n
            dis[i] = dis[n] + 1
            nxt += [i]
    return nxt

nxt = sign_root(1)
while nxt != []:
    for i in nxt.copy():
        nxt.pop(0)
        nxt += sign_root(i)
if MAX_INT in dis[2:]:
    print("No")
else:
    print("Yes")
    for i in sign[2:]:
        print(i)

Measured memory_bytes: 63548
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define ALL(a) (a).begin(), (a).end()
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}


int main(void){
  int N, A, B, W, H;
  cin >> N;
  string s[N];
  ull count[5] = {0};
  rep(i, N) {
    cin>>s[i];
    if (s[i][0] == 'M') count[0]++;
    if (s[i][0] == 'A') count[1]++;
    if (s[i][0] == 'R') count[2]++;
    if (s[i][0] == 'C') count[3]++;
    if (s[i][0] == 'H') count[4]++;
  }
  ull ans = 0;
  rep(i, 3){
    rep_s(j, i+1, 4){
      rep_s(k, j+1, 5){
        ans += count[i] * count[j] * count[k];
      }
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//約数列挙
//昇順
//#include <vector>
//#include <cmath>
std::vector<long long> div(long long n) {
	std::vector<long long> v(1, 1);
	if (n == 1) return v;
	for (long long i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) v.push_back(i);
	}
	if (sqrt(n) == (long long)sqrt(n)) {
		for (long long i = v.size() - 2; i >= 0; i--) v.push_back(n / v[i]);
	}
	else {
		for (long long i = v.size() - 1; i >= 0; i--) v.push_back(n / v[i]);
	}
	return v;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	vector<ll> v = div(n);
	ll ans = 0;
	for (auto i : v) {
		if (i - 1 > 0 && i - 1 > n / i) ans += i - 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
  int i,max=0,x=0;
  char s[11];
  scanf("%s",&s);
  for(i=0;s[i]!='\0';i++){
    if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T' ){
      x++;
    }else{
      if(max<x){
        max=x;
      }
      x=0;
    }
  }
        if(max<x){
        max=x;
      }
  printf("%d",max);
  return 0;
  
  
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n, m;
double p;
vector<llint> G[20];
llint in[1<<14];
double dp[1<<14];

int main(void)
{
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	
	cin >> n >> m >> p;
	p /= 100;
	
	llint u, v;
	for(int i = 0; i < m; i++){
		cin >> u >> v;
		u--, v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	
	llint N = 1<<n;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < n; j++){
			if((i & (1<<j)) == 0) continue;
			for(int k = 0; k < G[j].size(); k++){
				if(i & (1<<G[j][k])) in[i]++;
			}
		}
		in[i] /= 2;
	}
	
	for(int i = 0; i < N; i++){
		if((i & 1) == 0) continue;
		dp[i] = 1;
		for(int j = (i-1)&i; j > 0; j = (j-1)&i){
			if((j & 1) == 0) continue;
			dp[i] -= dp[j]*pow(p, in[i]-(in[i-j]+in[j]));
		}
	}
	printf("%.11f\n", dp[N-1]);
	
	return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int N;
	int x;
	int sum = 0;

	cin >> N;
	vector<int> v;
	for (int i = 0; i < N; i++)
	{
		cin >> x;
		v.push_back(x);

	}
	sort(v.begin(), v.end());
	for (int i = 0; i < v.size(); i++)
	{
		sum += v[i];
	}
	if (sum % 10 == 0)
	{
		for (int i = 0; i < v.size(); i++)
		{
			if (v[i] % 10 != 0)
			{
				sum -= v[i];
				break;
			}
		}
		if (sum % 10 == 0) cout << 0 << endl;
		else cout << sum << endl;
	}
	else
	{
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using Graph = vector<vector<int>>;
using ll = long long;
 
 
int main() {
    int x,n;
    cin>>x>>n;
    vector<int> p(n);
    if(n==0){
        cout<<x<<endl;
        return 0;
    }
    rep(i,n){
        cin>>p[i];
    }
    rep(i,200){
        bool oka=true;
        bool okb=true;
        rep(j,n){
            if(x-i==p[j]){
                oka=false;
            }
            if(x+i==p[j]){
                okb=false;
            }
        }
        if(oka==true){
            cout<<x-i<<endl;
            return 0;
        }
        if(okb==true){
            cout<<x+i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.caesarCipherDecoder();
		return;
	}
	
	//入力された文字列をシーザー暗号から復号する
	private void caesarCipherDecoder() {
		
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); //標準入力
		
		try {
			String inputStr = bufferedReader.readLine();
			
			StringBuffer outputStr = new StringBuffer();
			for (int i = 0; i < inputStr.length(); i++) {
				char c = this.caesarCipherCharacterDecoder(inputStr.charAt(i));
				outputStr.append(c);
			}
			
			System.out.println(outputStr);
			
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
		
	}
	
	//アルファベット一文字をシーザー暗号から復号する
	private char caesarCipherCharacterDecoder(char c) {
		
		if (c == 'D') {
			c = 'A';
		} else if (c == 'E') {
			c = 'B';
		} else if (c == 'F') {
			c = 'C';
		} else if (c == 'G') {
			c = 'D';
		} else if (c == 'H') {
			c = 'E';
		} else if (c == 'I') {
			c = 'F';
		} else if (c == 'J') {
			c = 'G';
		} else if (c == 'K') {
			c = 'H';
		} else if (c == 'L') {
			c = 'I';
		} else if (c == 'M') {
			c = 'J';
		} else if (c == 'N') {
			c = 'K';
		} else if (c == 'O') {
			c = 'L';
		} else if (c == 'P') {
			c = 'M';
		} else if (c == 'Q') {
			c = 'N';
		} else if (c == 'R') {
			c = 'O';
		} else if (c == 'S') {
			c = 'P';
		} else if (c == 'T') {
			c = 'Q';
		} else if (c == 'U') {
			c = 'R';
		} else if (c == 'V') {
			c = 'S';
		} else if (c == 'W') {
			c = 'T';
		} else if (c == 'X') {
			c = 'U';
		} else if (c == 'Y') {
			c = 'V';
		} else if (c == 'Z') {
			c = 'W';
		} else if (c == 'A') {
			c = 'X';
		} else if (c == 'B') {
			c = 'Y';
		} else if (c == 'C') {
			c = 'Z';
		}
		
		return c;
	}
}

Measured memory_bytes: 17008
#include<stdio.h>
 
int main()
{
    int n,m=1,s,i,j,p[50000]={1,1},d[5200]={2};
    for(i=2;i*2<50000;i++)
        p[2*i]=1;
    for(i=3;i<50000;i+=2)
        if(p[i]==0)
        {
            d[m++]=i;
            for(j=i*2;j<50000;j+=i)
                p[j]=1;
        }
    while(1)
    {
        s=0;
        scanf("%d",&n);
        if(!n)
            break;
        for(i=0;d[i]<=n/2;i++)
            if(n-d[i]>1&&!p[n-d[i]])
                s++;
        printf("%d\n",s);
    }
    return 0;
}

Measured memory_bytes: 824
#include<iostream>
using namespace std;
int main(){
	int N,ans;
	cin >> N;
	if (N >= 65 && N <= 90){
		ans = 1;
	}
	else if (N >= 97 && N <= 122){
		ans = 2;
	}
	else{
		ans = 0;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3104
import sys
#import numpy as np
import copy

fline = input().rstrip().split(' ')
N, Q = int(fline[0]), int(fline[1])

list = []
for i in range(N):
    tlist = []
    line = input().split(' ')
    tlist = [line[0], line[1]]
    #print(tlist)
    list.append(tlist)

#print(list)
current = 0
while len(list) != 0:
    if int(list[0][1]) <= Q:
        current += int(list[0][1])
        print(list[0][0] + " " + str(current))
        del list[0]
    else:
        list[0][1] = str((int)(list[0][1])-Q)
        list.append(list[0])
        del list[0]
        current += Q
    #print(list)



Measured memory_bytes: 13516
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)

const int NR = 2e5 + 100;

vector<int> mex[NR], ring;
int in[NR], n, p[NR], q[NR], sg[NR];

int calc(vector<int> &mex) {
	sort(mex.begin(), mex.end());
	int sg = 0;
	for (int i : mex) {
		if (i == sg) ++sg;
		else if (i > sg) break;
	}
	return sg;
}

int main() {
	scanf("%d", &n);
	iter(i, n) scanf("%d", &p[i]), ++in[p[i]];
	
	int h = 1, t = 0;
	iter(i, n) if (!in[i]) q[++t] = i;

	while (h <= t) {
		int i = q[h++];
		sg[i] = calc(mex[i]);
		mex[p[i]].push_back(sg[i]);
		if (!--in[p[i]]) q[++t] = p[i];
	}

	iter(i, n) if (in[i]) {
		for (int x = i; ; x = p[x]) {
			ring.push_back(x);
			sg[x] = calc(mex[x]);
			if (p[x] == i) break;
		}

		reverse(ring.begin(), ring.end());

		int len = ring.size(), lst = sg[ring[0]];
		for (int i = 1; i < len; ++i) {
			if (lst == sg[ring[i]]) ++lst;
			else lst = sg[ring[i]];
		}

		if (lst != sg[ring[0]]) puts("POSSIBLE");
		else {
			lst = sg[ring[0]] + 1;
			for (int i = 1; i < len; ++i) {
				if (lst == sg[ring[i]]) ++lst;
				else lst = sg[ring[i]];
			}
			if (lst == sg[ring[0]]) puts("POSSIBLE");
			else puts("IMPOSSIBLE");
		}
		break;
	}
	return 0;
}

Measured memory_bytes: 11136
import math

N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

res = 0

for i in range(N - 1):
    for j in range(i + 1, N):
        t = 0
        for d in range(D):
            t += (X[i][d] - X[j][d]) ** 2

        tt = math.sqrt(t)
        if tt.is_integer():
            res += 1

print(res)

Measured memory_bytes: 9144
stringToCheck=input()
j=0;
i=0;
notHitachi=False
length=len(stringToCheck)
if length%2 !=0:
 notHitachi=True
else:
 while i < len(stringToCheck):
  i+=2
  if not stringToCheck[j:i]=='hi': notHitachi=True
  j=i
if notHitachi: print("No")
else: print("Yes")


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int x;cin>>x;
    if(x<1200)cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
 
using namespace std;

class Point {
  public:
  double x, y;

  Point(double x = 0, double y = 0): x(x), y(y) {}

  Point operator + (Point p) { return Point(x + p.x, y + p.y); }
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
  Point operator * (double a) { return Point(a * x, a * y); }
  Point operator / (double a) { return Point(x / a, y / a); }

  double abs() {return sqrt(norm()); }
  double norm() { return x * x + y * y; }

  bool operator < (const Point &p) const{
    return x != p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const{
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }
};
 
typedef Point Vector;

typedef struct Segment{
  Point p1, p2;
};

typedef Segment Line;

class Circle{
public:
  Point c;
  double r;
  Circle(Point c = Point(), double r = 0.0): c(c), r(r) {}
};

typedef vector<Point> Polygon;

double dot(Vector a, Vector b){
  return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b){
  return a.x * b.y - a.y * b.x;
}

bool isOrthogonal(Vector a, Vector b){
  return equals(dot(a, b), 0.0);
}

bool isOrthogonal(Point a1, Point a2, Point b1, Point b2){
  return isOrthogonal(a1 - a2, b1 - b2);
}
bool isOrthogonal(Segment s1, Segment s2){
  return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

bool isParallel(Vector a, Vector b){
  return equals(cross(a, b), 0.0);
}

bool isParallel(Point a1, Point a2, Point b1, Point b2){
  return isParallel(a1 - a2, b1 - b2);
}

bool isParallel(Segment s1, Segment s2){
  return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}

Point project(Segment s, Point p){
  Vector base = s.p2 - s.p1;
  double r = dot(p-s.p1, base) / base.norm();
  return s.p1 + base * r;
}

int main(){
  Point p1, p2;
  cin >> p1.x >> p1.y >> p2.x >> p2.y;

  Segment s;
  s.p1 = p1;
  s.p2 = p2;

  int q;
  scanf(" %d", &q);
  for(int i = 0; i < q; ++i){
    Point p;
    cin >> p.x >> p.y;
    Point ans = project(s, p);
    printf("%.10lf %.10lf\n", ans.x, ans.y);
  }
}


Measured memory_bytes: 3288
#include<iostream>
using namespace std;
const int N=51;
int n,a[N],cnt;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			cnt+=a[i]*a[j];
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int a, b;
	scanf("%d", &a);
	scanf("%d", &b);
	if(a<=8 && b<=8){
		printf("Yay!\n");
	}else{
		printf(":(\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    long long n,i,a[200010],sum=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        a[i]=a[i]-i;
    }
    sort(a+1,a+n+1);
    for(i=1;i<=n;i++)
    {
        sum=sum+fabs(a[i]-a[(n+1)/2]);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <cstring>
#include <set>
#include <map>
using namespace std;
#define ld long double
#define F first
#define S second
#define ll long long
#define int ll
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define p 1000000007
#define p1 998244353
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)
const int N=1e3+10;
const int W=1e3+3;
const int inf=1e17+10;

int dp[N][W];
int grid[N][W];
int n,w;

int rec(int i,int j)
{
   
    if(i<=0||i>n||j<=0||j>w) return 0;
     if(grid[i][j]==0) return 0;
    if(i==1&&j==1) return 1;
    if(dp[i][j]!=-1) return dp[i][j];
    return dp[i][j]=(rec(i,j-1)%p+rec(i-1,j)%p)%p;
}


int32_t main()
{
    cin>>n>>w;
    char c;
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++)
        for(int j=1;j<=w;j++)
        {
            cin>>c;
            if(c=='.') grid[i][j]=1;
            else grid[i][j]=0;
        }
    cout<<rec(n,w)%p;
    
}



Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define deb(x) cerr << #x <<": " << x << '\n';
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long double ld;
typedef long long ll;
 
vector<ll> primes;
void SieveOfEratosthenes(ll n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
  
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
  
    for (ll p=2; p<=n; p++)
       if (prime[p])
           primes.push_back(p);
}
 
bool isPrime(ll n){
  if(n == 1) return false;
  ll i = 2;
  while (i*i <= n){
      if (n % i == 0) return false;
      ++i;
  }
  return true;
}
 
int main(){
    ios;
    ll n; cin >> n;
    if(isPrime(n)){cout << 1; return 0;}
    SieveOfEratosthenes(7e6);
    ll ans = 0, check = 0;
    for(ll i = 0; i < primes.size(); i++ ){
        for(ll j = 1; j <= 40; j++){
            check = pow(primes[i],j);
            if(n % check == 0) {ans++; n/=check;}
        }
    }
    if(isPrime(n) && n > 7e6)ans++;
    cout << ans;
    return 0;
}


Measured memory_bytes: 14260
<?php
function isPoor()
{
    fscanf(STDIN, "%d %d %d", $a, $b, $c);
    if ($a === $b && $b === $c && $a === $c) {
        return true;
    }

    if ($a !== $b && $b !== $c && $a !== $c) {
        return true;
    }

    return false;
}

if (isPoor()) {
    echo('No').PHP_EOL;
} else {
    echo('Yes').PHP_EOL;
}


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

using Graph=vector<vector<int>>;
void solve(int n,vector<int> r){
    Graph g(n);
    int idx=0;
    vector<int> vs;
    vector<int> d(n);
    auto addEdge=[&](int a,int b){
        d[a]--,d[b]--;
        g[a].push_back(b);
        g[b].push_back(a);
    };
    int p=0;
    function<void(int)> dfs=[&](int v){
        d[v]+=r[p++];
        vs.push_back(v);
        while(d[v]){
            if(r[p]<0){
                int to=vs[vs.size()-1+r[p]];
                addEdge(v,to);
                p++;
            }
            else{
                int to=idx++;
                addEdge(v,to);
                dfs(to);
            }

        }
        vs.pop_back();
    };
    dfs(idx++);
    for(int i=0;i<n;i++){
        sort(g[i].begin(),g[i].end());
        cout<<i+1;
        for(auto &v:g[i]){
            cout<<" "<<v+1;
        }
        cout<<endl;
    }

}
int main(){
    int n;
    cin>>n;
    while(n--){
        vector<int> r;
        int x;
        int v=0;
        while(cin>>x,x){
            r.push_back(x);
            if(x>0) v++;
        }
        solve(v,r);
    }
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <set>
#include <algorithm>
#include <string>
#include <cstring>

using namespace std;

set<string> s;
bool used[10];
string card[10];
int n,k,u[4];

int dfs(int c){
    if(c==k){
        do{ 
            string cb;
            for(int i=0;i<k;++i) cb +=card[u[i]];
            s.insert(cb);
        }while(next_permutation(card,card+k));
        return 0;
    }
    for(int i=0;i<n;++i){
        if(!used[i]){
            used[i]=1;u[c]=i;
            dfs(c+1);
            used[i]=0;
        }
    }
}
int main(){
    while(cin>>n>>k,n){
        s.clear();
        for(int i=0;i<n;++i) cin>>card[i];
        memset(used,0,sizeof(used));
        sort(card,card+n);
        dfs(0);
        cout<<s.size()<<endl;
    }
    return 0;
}

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

#define INF 1LL << 60
#define MOD 1000000007;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)

const int nMax = 1005;
int H, W;
string a[nMax];
ll dp[nMax][nMax];

int solve() {
    REP(i, H){
        REP(j, W){
            if (a[i][j] == '#') dp[i][j] = 0;
            else {
                if (i == 0 && j == 0) dp[i][j] = 1;
                else if (i == 0) dp[i][j] = dp[i][j-1];
                else if (j == 0) dp[i][j] = dp[i-1][j];
                else dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
            }
        }
    }
    return dp[H-1][W-1];
}

int main() {
    cin >> H >> W;
    REP(i, H) cin >> a[i];

    cout << solve() << endl;
    return 0;
}

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

using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using ll = long long int;
using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>;
using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using cdouble = complex<double>;

const double eps = 1e-7;
#define Loop(i, n) for(int i = 0; i < int(n); i++)
#define Loopll(i, n) for(ll i = 0; i < ll(n); i++)
#define Loop1(i, n) for(int i = 1; i <= int(n); i++)
#define Loopll1(i, n) for(ll i = 1; i <= ll(n); i++)
#define Loopr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = ll(n) - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = int(n); i >= 1; i--)
#define Looprll1(i, n) for(ll i = ll(n); i >= 1; i--)
#define Foreach(buf, container) for(auto buf : container)
#define Loopdiag(i, j, h, w, sum) for(int i = ((sum) >= (h) ? (h) - 1 : (sum)), j = (sum) - i; i >= 0 && j < (w); i--, j++)
#define Loopdiagr(i, j, h, w, sum) for(int j = ((sum) >= (w) ? (w) - 1 : (sum)), i = (sum) - j; j >= 0 && i < (h); j--, i++)
#define Loopdiagsym(i, j, h, w, gap) for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); i++, j++)
#define Loopdiagsymr(i, j, h, w, gap) for (int i = ((gap) > (h) - (w) - 1 ? (h) - 1 : (w) - 1 + (gap)), j = i - (gap); i >= 0 && j >= 0; i--, j--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(ex_i, vector.size()) { cout << vector[ex_i] << " "; } cout << endl;
#define printmx(matrix) Loop(ex_i, matrix.size()) { Loop(ex_j, matrix[ex_i].size()) { cout << matrix[ex_i][ex_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
#define Comp(type_t) bool operator<(const type_t &another) const
#define fst first
#define snd second
#define INF INFINITY
bool feq(double x, double y) { return abs(x - y) <= eps; }
bool inrange(ll x, ll t) { return x >= 0 && x < t; }
bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; }
int ceillog2(ll x) { int ret = 0;	x--; while (x > 0) { ret++; x >>= 1; } return ret; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); }
ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }

/*******************************************************/

int main() {
	ll n, d; cin >> n >> d;
	cout << ceildiv(n, d * 2 + 1) << endl;
}

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

bool isprime(ll n)
{
  ll i;
  for(i=2;i<=sqrt(n);i++)
    {
      if(n%i==0)
        return false;
    }
    return true;
}
int main()
{
  ll a,b,ans,d,cnt=0;
  set<ll> factorization;
  cin>>a>>b;

  ans=__gcd(a,b);

  for ( d = 2; d * d <= ans; d++) {
          while (ans % d == 0) {
              factorization.insert(d);
              ans /= d;
          }
      }
      if (ans > 1)
          factorization.insert(ans);

  cout<<factorization.size()+1<<endl;
}


Measured memory_bytes: 256
n=int(input())
a=[int(input()) for _ in range(n)]
buf=1
count=0
if 2 not in a:
    print(-1)
else:
    while count<n:
        a_buf=a[buf-1]
        if a_buf==2:
            print(count+1)
            break
        buf=a_buf
        count+=1
    if count==n:
        print(-1)

Measured memory_bytes: 7084
from collections import defaultdict

class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n)]
        self.rank = [0] * n

    def find(self, k):
        if self.parent[k] == k:
            return k
        else:
            self.parent[k] = self.find(self.parent[k])
            return self.parent[k]

    def same(self, a, b):
        return self.find(a) == self.find(b)

    def unite(self, a, b):
        a = self.find(a)
        b = self.find(b)
        if self.rank[a] < self.rank[b]:
            self.parent[a] = b
        else:
            if self.rank[a] == self.rank[b]:
                self.rank[a] += 1
            self.parent[b] = a


N, M = map(int, input().split())
uf = UnionFind(N)
p = list(map(int, input().split()))
for i in range(N):
    p[i] -= 1

for i in range(M):
    x, y = map(int, input().split())
    uf.unite(x - 1, y - 1)

num = 0
for i in range(N):
    if uf.same(i, p[i]):
        num += 1

print(num)

Measured memory_bytes: 18960
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <cstdlib>
using namespace std;




int main() {

    int N,L;

    cin >> N >> L  ;

    int index;

    if(L+N-1<=0){
        index=N;
    }
    else if(L>=0){
        index=1;
    }
    else{
        index=1-L;
    }

    int Sum=N*(L-1)+N*(N+1)/2;

    int ans=Sum-(L+index-1);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> balls(N, 1);
  balls[0] = -1;
  rep(i, M)
  {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if (balls[x] > 0 && balls[y] >= 0)
    {
      balls[x]--;
      balls[y]++;
    }
    else if (balls[x] < 0 && balls[y] >= 0)
    {
      balls[x] = -(-balls[x] - 1);
      balls[y]++;
      balls[y] *= -1;
    }
    else if (balls[x] > 0 && balls[y] <= 0)
    {
      balls[x]--;
      balls[y] = -(-balls[y] + 1);
    }
    else if (balls[x] < 0 && balls[y] <= 0)
    {
      balls[x] = -(-balls[x] - 1);
      balls[y] = -(-balls[y] + 1);
    }
  }
  int ans = 0;
  rep(i, N)
  {
    if (balls[i] < 0)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  if n==1:
    return l[0]

  cen=l[0]
  l.remove(cen)

  la=[]
  lb=[]
  for i in range(len(l)):
    if i%2==0:
      la.append(l[i])
    else:
      lb.append(l[i])

  if n%2==0:
    la.reverse()
    return ' '.join(str(x) for x in la)+' '+str(cen)+' '+' '.join(str(x) for x in lb)
  else:
    lb.reverse()
    return ' '.join(str(x) for x in lb)+' '+str(cen)+' '+' '.join(str(x) for x in la)

print(main())


Measured memory_bytes: 29388
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_abc151_c();
	}
  	public static void solve_abc151_c(){

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		int[] pi = new int[M];
		boolean[] p_ac = new boolean[N];

		int ans_correct = 0;
		int ans_penalty = 0;
		int[] p_penalty = new int[N];


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

			pi[i] = sc.nextInt() - 1;
			String s = sc.next();

			if(!p_ac[pi[i]]){

				if(s.equals("AC")){

					ans_correct++;
					p_ac[pi[i]] = true;
					ans_penalty += p_penalty[pi[i]];
				}
				else{
					p_penalty[pi[i]]++;
				}
			}
		}

		System.out.println(ans_correct + " " + ans_penalty);


		sc.close();
	}
}

Measured memory_bytes: 64196