akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main(void)
{
  float a, b, area, perimeter;
  cin >> a >> b;
  area = a * b;
  perimeter = a* 2 + b * 2;
  cout << area << " " << perimeter << endl;
}


Measured memory_bytes: 3204
#include<stdio.h>
#define N 100000
int A[N+1];
void print(int,int);
int main(){
  int i,a;
  scanf("%d", &a);
  for(i = 1; i <= a; i++)
    scanf("%d", &A[i]);
  for(i = 1; i <= a; i++)
    print(i,a);

  return 0;
}

void print(int i, int a){
  printf("node %d: key = %d, ", i, A[i]);
  if(i / 2 >= 1)
    printf("parent key = %d, ", A[i/2]);
  if(i * 2 <= a)
    printf("left key = %d, ", A[i*2]);
  if(i * 2 + 1 <= a)
    printf("right key = %d, ", A[i*2+1]);

  printf("\n");
}




Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b;
    vector<int>m(a+1,0);
    m[0]=1;
    for(int i=0; i<b; i++)
    {
        cin>>c;
        vector<int>n(c);
        for(int j=0; j<c; j++)
        {
            cin>>n[j];
            m[n[j]]++;
        }
    }
    int p=0;
    for(int k=0; k<a+1; k++)
    {
        if(m[k]==0)
            p++;
    }
    cout<<p<<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
lli gcd(lli m, lli n)
{
    return (m % n == 0) ? n : gcd(n, m % n);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    lli T, A, B, C, D;
    cin >> T;
    REP(i, T)
    {
        cin >> A >> B >> C >> D;
        if (A < B || D < B)
        {
            cout << "No"
                 << "\n";
        }
        else
        {
            //            D>=B,A>=B
            if (C >= B - 1)
            {
                cout << "Yes"
                     << "\n";
            }
            else
            {
                lli d = gcd(B, D);
                //C+1とB-1にA%dのやつが存在しないようにする。
                lli Ar = A % d;
                lli v0 = (C) / d + ((C) % d >= Ar ? 1 : 0);
                lli v1 = (B - 1) / d + ((B - 1) % d >= Ar ? 1 : 0);
                if (v1 - v0 >= 1)
                {
                    cout << "No"
                         << "\n";
                }
                else
                {
                    cout << "Yes"
                         << "\n";
                }
            }
        }
    }
}


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

using namespace std ;

int a[100][100];
int b[100];
int n , m , c ;
int ans  ;

int main ()
{
	int i , j ;
	scanf("%d%d%d",&n,&m,&c);
	for ( i=1 ; i<=m ; i++ ) scanf("%d",b+i);
	for ( i=1 ; i<=n ; i++ )
		for ( j=1 ; j<=m ; j++ ) scanf("%d",a[i]+j);
	for ( i=1 ; i<=n ; i++ ) 
	{
		int t=c ;
		for ( j=1 ; j<=m ; j++ ) t+=b[j]*a[i][j];
		if ( t>0 ) ans++;
	}
	printf("%d\n",ans);
	return 0 ;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <ctime>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int INF = 100000000;
const int MAX_M = 100000;

int dp[5005][5005];

ll solve(string s) {
	int counter = 0;
	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		counter++;
		if (i == (int)s.size() - 1 || s[i] != s[i + 1]) {
			ans += counter / 2;
			counter = 0;
		}
	}
	return ans;
}


int main(int argc, char *args[]) {
	string s;
	cin >> s;
	ll k;
	cin >> k;

	int flag = true;
	for (int i = 0; i < (int)s.size() - 1; i++) {
		if (s[i] != s[i + 1])flag = false;
	}
	if (flag == true) {
		cout << s.size() * k / 2 << endl;
	}
	else {
		int l1 = solve(s);
		int l2 = solve(s + s);
		int a = l1;
		int d = l2 - l1;
		cout << a + d * (k - 1) << endl;
	}
	
}

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

int main() {
  int N;
  cin >> N;
  int N2min = 50;
  for(int i=0; i < N; i++){
    int A;
    int count = 0;
    cin >> A;
    while(A%2 == 0){
      A /= 2;
      count ++;
    }
    if ( count < N2min)
      N2min = count;
  }
  cout << N2min <<endl;
 }
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <class T>
using ordered_set =
       tree <T,null_type,less <T>,rb_tree_tag,tree_order_statistics_node_update> ;
///find_by_order()
///order_of_key()

template <class T,class U>
void maximize(T &x,U y){
    if(x < y)x=y;
}
template <class T,class U>
void minimize(T &x,U y){
    if(x > y)x=y;
}
template <class T>
T Abs(T x){
    return (x < (T)0 ? -x : x);
}
template <class T>
T safe_sqrt(T x){
    return sqrt(max(x,(T)0));
}
template <class T,class U,class V>
T addmod(T x,U k,V MOD){
    return ((x+k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T submod(T x,U k,V MOD){
    return ((x-k)%MOD + MOD)%MOD;
}
template <class T,class U,class V>
T mul(T x,U y,V MOD){
    return ( (x % MOD) * (y % MOD) ) % MOD;
}

#define ll long long
#define pll pair <ll,ll>
#define pii pair <int,int>
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define emp emplace_back
#define MASK(i) ((1LL)<<(i))
#define BIT(x,i) (((x)>>(i))&1)
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)((c).size())
#define fn "test"    ///FILE_NAME_HERE

/*------------------------------------------END_OF_TEMPLATE------------------------------------------*/

namespace task{

    void solve(){
    	int n;
    	cin>>n;
    	int sum = 0;
    	for(int i = 1;i <= n;++i){
    		int x;
    		cin>>x;
    		sum^=x;
    	}
    	cout<<(sum ? "No" : "Yes");
    }
}

int main(void){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    task::solve();
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int n,ans;

int main(){
  cin >> n;
  REP(i,n){
    int k;
    cin >> k;
    ans += k-1;
  }
  cout <<ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;

int main(){

  int a, b;
  string str;
  
  for(int i=0; i<9; i++){
    cin >> str >> a >> b;
    cout << str << " " << a + b << " " << a * 200 + b * 300 << endl;
  }

  return 0;

}

Measured memory_bytes: 1196
import math
N = int(input())
P = [0] + [int(_) for _ in input().split()]
Q = [0] + [int(_) for _ in input().split()]


def d(R):
    c = [i+1 for i in range(N)]
    cnt = 0
    for i in range(1, N+1):
        idx = c.index(R[i])
        cnt += math.factorial(N - i) * idx
        del c[idx]
    return cnt


print(abs(d(P) - d(Q)))


Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
using namespace std;

int main(){

  string s;
  cin >> s;

  int d[55];
  memset(d,false,sizeof(d));

  char k = 'a';
  int p = 0;
  for(int i=0;i<s.size();i++){
    if(k == s[i]) continue;
    if(s[i] == 'o') d[p] = true;
    if(s[i] == 'x') d[p] = false;
    p++;
    k = s[i];
  }

  int head = 0, tail = p-1;
  bool cnt = true;

  while(head != tail){
    if(cnt){
      if(!d[head]) head++;
      else if(!d[tail]) tail--;
      cnt = false;
    }
    else if(!cnt){
      if(d[head]) head++;
      else if(d[tail]) tail--;
      cnt = true;
    }
  }

  if(!d[head]) cout << "x" << endl;
  if(d[head]) cout << "o" << endl;

}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    long double a, b;
    cin >> a >> b;
    ll c = a * b;
    cout << c << '\n';
}


Measured memory_bytes: 3732
<?php

list($n, $sum) = preg_split('/ /', trim(fgets(STDIN)));
for ($x = 0; $x <= $n ; $x++) {
    for ($y = 0; $y <= $n - $x; $y++) {
        $z = $n - $x - $y;
        if ($sum == $x * 10000 + $y * 5000 + $z * 1000) {
            printf('%d %d %d', $x, $y, $z);
            return;
        }
    } 
}

printf('%d %d %d', -1, -1, -1);


Measured memory_bytes: 3828
import java.util.*;

public class Main {

    public static void main(String[] args){
 
        Scanner sc = null;
        sc = new Scanner(System.in);
        int N = sc.nextInt();
        long num = 0;
        int answer = 0;
        for (int i = 1; i <= N; i++) {
            num = sc.nextLong();
            if (i % 2 != 0 && num % 2 != 0) {
                answer += 1;
            }         
          }
        sc.close();

        System.out.println(answer);
      
      }
    
}

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


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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		int Max=0, Min=Integer.MAX_VALUE;
		for(int i = 0; i<N; i++) {
			A[i] = sc.nextInt();
			if(A[i]>Max)Max=A[i];
			if(A[i]<Min)Min=A[i];
		}
		System.out.println(Max-Min);
		sc.close();
	}

}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;
typedef pair<pair<int,int>,pair<int,int>> P;

P f(int a,int b,int c,int d){
    P aa={{a,b},{c,d}};
    P bb={{b,c},{d,a}};
    P cc={{c,d},{a,b}};
    P dd={{d,a},{b,c}};
    chmin(aa,bb);
    chmin(aa,cc);
    chmin(aa,dd);
    return aa;
}

P f(P &aa){
    int a=aa.fi.fi,b=aa.fi.se,c=aa.se.fi,d=aa.se.se;
    P bb={{b,c},{d,a}};
    P cc={{c,d},{a,b}};
    P dd={{d,a},{b,c}};
    chmin(aa,bb);
    chmin(aa,cc);
    chmin(aa,dd);
    return aa;
}

int g(P aa){
    int a=aa.fi.fi,b=aa.fi.se,c=aa.se.fi,d=aa.se.se;
    if(a==b&&b==c&&c==d) return 4;
    else if(a==c&&b==d) return 2;
    else return 1;
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    map<P,int> MA;
    vector<vector<P>> S(N,vector<P>(4));
    for(int i=0;i<N;i++){
        int a,b,c,d;cin>>a>>b>>c>>d;
        S[i][0]=f(a,b,c,d);
        a=S[i][0].fi.fi;
        b=S[i][0].fi.se;
        c=S[i][0].se.fi;
        d=S[i][0].se.se;
        S[i][1]={{b,c},{d,a}};
        S[i][2]={{c,d},{a,b}};
        S[i][3]={{d,a},{b,c}};
        
        MA[S[i][0]]++;
    }
    ll ans=0;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i==j) continue;
            
            for(int k=0;k<4;k++){
                P a={{S[j][k].fi.se,S[j][k].fi.fi},{S[i][0].fi.se,S[i][0].fi.fi}};
                P b={{S[j][k].fi.fi,S[j][k].se.se},{S[i][0].se.fi,S[i][0].fi.se}};
                P c={{S[j][k].se.se,S[j][k].se.fi},{S[i][0].se.se,S[i][0].se.fi}};
                P d={{S[j][k].se.fi,S[j][k].fi.se},{S[i][0].fi.fi,S[i][0].se.se}};
                
                f(a);
                f(b);
                f(c);
                f(d);
                
                int aa=g(a),bb=g(b),cc=g(c),dd=g(d);
                
                map<P,int> M;
                M[S[i][0]]++;
                M[S[j][0]]++;
                
                ll pat=1;
                pat*=(MA[a]-M[a])*aa;
                M[a]++;
                
                pat*=(MA[b]-M[b])*bb;
                M[b]++;
                
                pat*=(MA[c]-M[c])*cc;
                M[c]++;
                
                pat*=(MA[d]-M[d])*dd;
                M[d]++;
                
                ans+=pat;
            }
        }
    }
    
    cout<<ans/6<<endl;
}


Measured memory_bytes: 81024
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
    
    int n;cin>>n;
    string s,t;cin>>s>>t;
    int slen=s.length(),tlen = t.length();
    for(int i=0;i<=slen;i++){
        string tmp=s.substr(0,i);
        tmp+=t;
        //cout<<tmp<<endl;
        int res=i+tlen;
        if(res<slen) continue;
        bool flag=true;
        for(int j=0;j<slen;j++){
            if(tmp[j]!=s[j]) flag=false;
            else continue;
        }
        if(flag){
            cout<<res<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N,M=[int(x) for x in input().strip().split()]
AN=[]
BN=[]
val={}
for i in range(N):
    Ai,Bi=[int(x) for x in input().strip().split()]
    val[Ai]=Bi+val.get(Ai,0)
    AN.append(Ai)

AN=sorted(set(AN))
m=0
ans=0
for Ai in AN:
    ans+=Ai*min(M-m,val[Ai])
    m+=min(M-m,val[Ai])
    if m==M:
        break
print(ans)


Measured memory_bytes: 23040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int sum = 0;
		int count  = 0;
		while(true) {
			if(b == 1)
				break;
			count++;
			sum += a;
			//System.out.println(sum);
			if(sum >= b)
				break;

			if(sum != 0)
				sum--;
			//System.out.println(sum);
		}
        System.out.println(count);

	}


}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int k = sc.nextInt() - 1;
		for (int i = 0; i < n; i++) {
			if (s[i] != s[k]) {
				s[i] = '*';
			}
		}
		System.out.println(s);
	}
}


Measured memory_bytes: 22996
'''
- f(X)のイメージ

x軸: 正整数, y軸: 約数

                    10 ... every 10
                  9    ... every 9
                8      ... every 8
              7        ... every 7
            6          ... every 6
          5          5 ... every 5
        4       4      ... every 4
      3     3     3    ... every 3
    2   2   2   2    2 ... every 2
  1 1 1 1 1 1 1 1 1  1 ... every 1

問題は Σ^N_{K=1} K × f(K) なので
約数の数f(K)にKが掛かっている。

なので上のイメージを少し変更して

                    10 ... Σ^floor(N/10)_{K=1} 10*K
                  9    ...
                8      ...
              7        ...
            6          ...
          5         10 ...
        4       8      ...
      3     6     9    ...
    2   4   6   8   10 ... Σ^floor(N/2)_{K=1} 2*K
  1 2 3 4 5 6 7 8 9 10 ... Σ^floor(N/1)_{K=1} 1*K

これの総和を求めれば良い。

=> Σ^N_{K=1} Σ^{floor(N/K)}_{L=1} K*L
'''
N = int(input())

# ans = 0
# for i in range(1, N+1):
#     for j in range(1, N//i+1):
#         ans += i*j

ans = 0
for i in range(1, N+1):
    ans += (i + N//i*i) * (N//i) // 2

print(ans)


Measured memory_bytes: 63456
import numpy as np

n = int(input())
a = list(map(int, input().split()))

avg = np.average(a)

def delta(tsumugi):
  return tsumugi - avg

a_delta = list(map(delta, a))
a_abs = list(np.abs(a_delta))
num_min = np.min(a_abs)
index = a_abs.index(num_min)

print(index)

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

int main(){
    int N, i, j, t;
    cin >> N;
    int C[N-1], S[N-1], F[N-1];
    for (i=0; i<N-1; i++){
        cin >> C[i] >> S[i] >> F[i];
        }

    for (i=0; i<N-1; i++){
        t = 0;
        for (j=i; j<N-1; j++){
            if (t < S[j]){
                t = S[j];
            }
            else if (t%F[j] == 0){
            }
            else {
                t += F[j] - t%F[j];
            }

            t += C[j];
        }
    cout << t << endl;
    }
    cout << 0 <<endl;
    return 0;
}
    

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int n, k;
	Books[] books;
	int[][] vals;

	void run() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt(); k = sc.nextInt();
		books = new Books[10];
		for (int i=0;i<10;i++) books[i] = new Books();
		for (int i=0;i<n;i++) {
			int c = sc.nextInt(), g = sc.nextInt() - 1;
			books[g].add(c);
		}
		for (int i=0;i<10;i++) sort(books[i], new MyComp());
		vals = new int[10][k+1];
		vals[0][0] = 0;
		for (int i=0;i<10;i++) {
			int p = 1, sum = 0;
			for (int v : books[i]) {
				sum += v;
				vals[i][p] = sum + p * (p-1);
				if (p == k) break;
				p++;
			}
		}
		mem = new int[10][k+1];
		for (int[] a : mem) fill(a, -1);
		System.out.println(solve(0, k));

	}
	int[][] mem;
	int solve(int j, int k) {
		if (j == 10 || k == 0) return 0;
		if (mem[j][k] >= 0) return mem[j][k];

		int ret = 0;
		for (int i=0;i<=k;i++) {
			ret = max(ret, solve(j+1, k-i) + vals[j][i]);
		}

		return mem[j][k] = ret;
	}

	class MyComp implements Comparator<Integer> {

		@Override
		public int compare(Integer o1, Integer o2) {
			// TODO ティツ?ェテ・ツ仰陛ァツ板淌ヲツ按静」ツ?陛」ツつ古」ツ?淌」ツδ。テ」ツつステ」ツδε」ツδ嘉」ツδサテ」ツつケテ」ツつソテ」ツδ?
			return o2 - o1;
		}

	}

	class Books extends LinkedList<Integer> {}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 36516
#include <iostream>
#include <string>
#include <cstdio>

using namespace std;

int main(){
	int n, taro=0, hana=0;

	cin >> n;
	for(int i=0; i<n; ++i){
		string s1, s2;
		cin >> s1 >> s2;
		
		if(s1>s2) 
			taro+=3;
		else if(s1<s2)
			hana+=3;
		else{
			++taro;
			++hana;
		}
		
	}
	printf("%d %d\n", taro, hana); 	
	
	return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+2;
int a[100];
map<pi,bool>mp;
int main()
{
    ft
    int t,i,j,n,m,l=0,r,z=0;
    cin>>n>>m;
    for(i=0;i<m;i++)
    {
        cin>>l>>r;
        a[l]++;
        if(l!=r)
        {
            a[r]++;
        }
    }
    for(i=1;i<=n;i++)
    {
        cout<<a[i]<<"\n";
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define fi first
#define se second
#define endl '\n'
#define int int64_t
#define double long double
// mt19937 rnd(time(0));
// const double TIME_LIMIT = 1.8;
// Heuristic TL: clock() < TIME_LIMIT * CLOCKS_PER_SEC
const int MAXN = 1000001;
const int INF = numeric_limits<int>::max() >> 3;
const int MOD = (int)998244353;

signed main(){
	ios_base::sync_with_stdio(0); 
	cin.tie(0); 
	cout.tie(0); 
	// freopen("FDT.txt","r",stdin);
	int n;
	cin >> n;
	set<string> s;
	while(n --){
		string x;
		cin >> x;
		s.insert(x);
	}
	cout << s.size();
}

Measured memory_bytes: 19284
#include <iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;
#define PI acos(-1)

int main()
{
	int a, b;
	cin >> a >> b;

	int c = a * b;

	if (c % 2) {
		cout << "Odd";
	}
	else {
		cout << "Even";
	}
	

}



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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) {
        ll d = euclid(b, a % b, y, x);
        return y -= a / b * x, d;
    }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

bool ok(int x) {
    string s = to_string(x);
    rep(i, 0, s.length() - 1) if (s[i] + 1 != s[i + 1]) return false;
    return true;
}

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    int n; cin >> n;
    vector<int> v(n);
    rep(i, 0, n) cin >> v[i];
    int mx = -1;
    rep(i, 0, n) rep(j, i + 1, n) if (ok(v[i] * v[j])) mx = max(mx, v[i] * v[j]);
    cout << mx << endl;
}



Measured memory_bytes: 3324
n=int(input())
ans=0
p=1
chk=[0]*n
l=[]
for i in range(n):
    l.append(int(input()))

while 1:
    if chk[p-1]==1:
        print(-1)
        break
    chk[p-1]=1
    ans+=1
    if l[p-1]==2:
        print(ans)
        break
    p=l[p-1]

Measured memory_bytes: 7852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define all(a) (a).begin(), (a).end()
template<typename T = int> using V = vector<T>;
template<typename T = int> using P = pair<T, T>;
using Vi = V<int>;
using Vl = V<ll>;
using Vd = V<ld>;
using VVi = V<Vi>;
using VVl = V<Vl>;
using VVd = V<Vd>;
using Pi = P<int>;
using Pl = P<ll>;
using Pd = P<ld>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int fLog2(const ll x) { assert(x > 0); return 63-__builtin_clzll(x); } // floor(log2(x))
inline int cLog2(const ll x) { assert(x > 0); return (x == 1) ? 0 : 64-__builtin_clzll(x-1); } // ceil(log2(x))
inline int popcount(const ll x) { return __builtin_popcountll(x); }
inline void fail() { cout << -1 << '\n'; exit(0); }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
// const int INF  = 1<<30;
// const ll INFll = 1ll<<60;
// const ld EPS   = 1e-10;
// const ld PI    = acos(-1.0);
// const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  ll h, w, m; cin >> h >> w >> m;

  V<V<Vi>> v = {V<Vi>(h), V<Vi>(w)};

  rep(i, m) {
    int x, y; cin >> x >> y;
    --x, --y;
    v[0][x].push_back(y);
    v[1][y].push_back(x);
  }

  V<Pi> cnt(w);
  rep(i, w) cnt[i] = Pi(sz(v[1][i]), i);
  auto cnt2 = cnt;
  sort(all(cnt));
  reverse(all(cnt));

  
  ll ans = 0;
  rep(i, h) {
    int k = sz(v[0][i]);
    ll res = 0;

    set<int> S;
    for (auto e: v[0][i]) {
      res = cnt2[e].first + k - 1;
      chmax(ans, res);
      S.insert(e);
    }

    for (auto [m, j] : cnt) {
      if (S.find(j) == S.end()) {
        res = k + m;
        chmax(ans, res);
        break;
      }
      else S.erase(j);
    }
  }

  cout << ans << '\n';
}


Measured memory_bytes: 46580
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main(){
  int n;
  int a,min,max;
  long long sum;
  
  scanf("%d",&n);
  scanf("%d",&a);
  min=max=sum=a;
while (--n > 0) {
		scanf("%d", &a);
		if (a < min) min = a;
		if (a > max) max = a;
		sum += a;
	}
  printf("%d %d %lld\n",min,max,sum);
  return 0;
}



Measured memory_bytes: 2096
import sys
h, w = map(int, sys.stdin.readline().split())
dp = [[0] * w for _ in range(h)]
G = [[int(j) for j in sys.stdin.readline().split()] for _ in range(h)]
for i in range(0, h):
    for j in range(0, w):
        dp[i][j] = (G[i][j] + 1) % 2
for i in range(1, h):
    for j in range(1, w):
        if(G[i][j] == 0):
            dp[i][j] = min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1
print(max([max(item) for item in dp])**2)

Measured memory_bytes: 57944
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int
main()
{
  int N;
  cin >> N;
  int parity = 0;
  for (int n = 0; n < N; n++)
  {
    int A;
    cin >> A;
    parity = (parity + A) % 2;
  }
  cout << (parity ? "NO" : "YES") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define ll long long
#define For(i,a,b) for(register long long i=a;i<=b;i++)
using namespace std;
const int maxn=2e5+10;
char s[maxn];
ll ans,n;
int c[30];
signed main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	ans=n*(n-1)/2;
	For(i,1,n){
		c[s[i]-'a']++;
	}
	For(i,0,26){
		ans-=1ll*c[i]*(c[i]-1)/2;
	}
	ans++;
	printf("%lld\n",ans);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define lson l,mid,p<<1
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
using namespace std;
const int inf=1e9+10;
const int mod=1e9+7;
const int maxn=1e5+10;
int n;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>n;
	cout<<(n+1)/2<<endl;
	return 0;
}

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

using namespace std;

bool mark[55][55];

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

    int n;
    cin >> n;
    vector<int> v;
    while(n--) {
        int x;
        cin >> x;
        if(x != 0) v.push_back(x);
    }
    long long sum = 0;
    for(int i = 0; i < (int) v.size(); i++) {
        for(int j = 0; j < (int) v.size(); j++) {
            if(i == j || mark[i][j] || mark[j][i]) continue;
            sum += (v[i] * v[j]);
            mark[i][j] = 1, mark[j][i] = 1;
        }
    }
    cout << sum << "\n";

    return 0;
}


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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	int n;
	cin >> n;
	double p[n];
	for (int i = 0; i < n; i++) 
		cin >> p[i];
	cout.precision(10);	
	double dp[n + 1][n + 1];
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (i == 0 && j == 0)
				dp[i][j] = 1;
			else if (j > i)
				dp[i][j] = 0;
			else {
				double a = dp[i - 1][j] * (1 - p[i - 1]); 
				double b = (j - 1 >= 0) ?  dp[i - 1][j - 1] * p[i - 1] : 0;
				dp[i][j] = a + b;
			}
		}
	}
	double ans = 0;
	for (int i = n / 2 + 1; i <= n; i++)
		ans += dp[n][i];
	cout << ans << endl;
}


Measured memory_bytes: 70656
//HonestOrUnkind2

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, map<int,int>>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    vector<p>m(n);
    rep(i,0,n){
        int a;cin>>a;
        m[i].first=i;
        rep(j,0,a){
            int t,y;cin>>t>>y;
            m[i].second[t-1]=y;
        }
    }
    int ans=0;
    rep(bit,0,(1<<n)){
        vector<int>c(n,-1);
        int sho=0;
        bool mujun=true;
        rep(i,0,n)if(bit&(1<<i)){
            c[i]=1;
            sho++;
        }else c[i]=0;
        rep(i,0,n)if(bit&(1<<i))for(auto j:m[i].second)if((j.second==0&&c[j.first]==1)||(j.second==1&&c[j.first]==0))mujun=false;
        if(mujun)ans=max(ans,sho);
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 3588
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
ll a,b;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>a>>b;
	if(b<a)
	cout<<a-1;
	else
	cout<<a;
	return 0;
}


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


int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  if ((B - A)%2 == 0) cout << (B - A)/2 << endl;
  else cout << (2*min(A-1, N-B)+1+B-A)/2 << endl;
}


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

const int mod = 998244353;

long long dp[4010][4010];
int cnt[2010];
char s[2010];
int sum[4010];

int main(){
	scanf("%s", s);
	int n = strlen(s);
	for (int i = 1; i <= n; i++){
		cnt[i] = s[i - 1] - '0';
		sum[i] = sum[i - 1] + cnt[i];
	}
	dp[0][0] = 1;
	for (int i = 1; i <= 2 * n; i++){
		for (int j = 0; j <= i; j++){
			if (j <= sum[min(i, n)] && i - j <= 2 * min(i, n) - sum[min(i, n)]){
				if (j) dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % mod;
				else dp[i][j] = dp[i - 1][j];
			} 
		}
	}
	long long ans = 0;
	for (int i = 0; i <= 2 * n; i++){
		ans = (ans + dp[2 * n][i]) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}


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

int N;

int main(){
  
  cin >> N;
  
  int ans = 0;
  for(int n = 105; n <= N; n+=2){
    int kosu = 0;
    for(int i = 1; i <= n; i++){
      if(n%i == 0) kosu++;
    }
    if(kosu == 8) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>

typedef long long ll;

// print(x, y, z);
void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}

int main(int argc, char* argv[])
{
  ll N;
  std::cin >> N;
  std::set< ll > sa;
  for (ll i = 0; i < N; i++) {
    int a;
    std::cin >> a;
    sa.insert(a);
  }

  ll cnt = (ll)sa.size();
  if (cnt % 2 == 0) {
    cnt--;
  }
  print (cnt);
  return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define Rint register int
#define MP make_pair
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int N = 403, mod = 998244353;
template<typename T>
void read(T &x){
	int ch = getchar(); x = 0; bool f = false;
	for(;ch < '0' || ch > '9';ch = getchar()) f |= ch == '-';
	for(;ch >= '0' && ch <= '9';ch = getchar()) x = x * 10 + ch - '0';
	if(f) x = -x;
}
void qmo(int &x){x += (x >> 31) & mod;}
int ksm(int a, int b){
	int res = 1;
	for(;b;b >>= 1, a = (LL) a * a % mod) if(b & 1) res = (LL) res * a % mod;
	return res;
}
template<typename T>
inline bool chmax(T &a, const T &b){if(a < b) return a = b, 1; return 0;}
template<typename T>
inline bool chmin(T &a, const T &b){if(a > b) return a = b, 1; return 0;}
int n, h[N], pw2[N], ans, f[N][N], g[N][N];
int solve(int l, int r, int val){
	if(l > r) return 0;
	int mid = l;
	for(Rint i = l + 1;i <= r;++ i) if(h[mid] > h[i]) mid = i;
	int lc = solve(l, mid-1, h[mid]), rc = solve(mid+1, r, h[mid]);
	for(Rint i = 0;i <= mid-l;++ i)
		for(Rint j = 0;j <= r-mid;++ j){
			int tmp = (LL) f[lc][i] * f[rc][j] % mod;
			qmo(f[mid][i+j] += tmp - mod); qmo(f[mid][i+j+1] -= tmp); qmo(g[mid][i+j+1] += tmp - mod);
			qmo(g[mid][i+j] += (LL) (f[lc][i] + g[lc][i]) * (f[rc][j] + g[rc][j]) % mod - mod); qmo(g[mid][i+j] -= tmp);
		}
	for(Rint i = 0;i <= r-l+1;++ i){
		f[mid][i] = (LL) f[mid][i] * ksm(pw2[r-l+1-i], h[mid] - val) % mod;
		g[mid][i] = (LL) g[mid][i] * ksm(pw2[r-l+1-i]-1, h[mid] - val) % mod;
	} return mid;
}
int main(){
	read(n); pw2[0] = f[0][0] = 1;
	for(Rint i = 1;i <= n;++ i){read(h[i]); qmo(pw2[i] = (pw2[i-1]<<1) - mod);}
	int rt = solve(1, n, 0);
	for(Rint i = 0;i <= n;++ i){qmo(ans += f[rt][i] - mod); qmo(ans += g[rt][i] - mod);}
	printf("%d\n", ans);
} // ntfnmsl

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

int main(){
    ll n;
    ll sum=0;

    cin >> n;

    for (int i =0;i<=n;i++){
        if((i%3)!=0&&(i%5)!=0){
            sum += i;
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define ll long long
#define fr(i,k,N) for(ll i=k; i<N;i++)
#define rep(i,N) for(ll i=0; i<N;i++)
#define alll(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<<endl;}cout<<endl;}


void update(ll i, ll x, vector<ll> &v){
    v[i] = x;
}

ll find(ll s, ll t, vector<ll> &v){
    ll tmp = v[s];
    fr(i, s, t+1) tmp = min(v[i],tmp);
    return tmp;
}

int main() {
    ll n,q;
    cin>>n>>q;
    vector<ll> v(n, 2147483647);
    rep(i, q){
        ll a,b,c;
        cin>>a>>b>>c;
        if (a==0) {
            update(b, c, v);
        } else {
            cout<<find(b, c, v)<<endl;
        }
    }
}




Measured memory_bytes: 3548
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );

	while ( true ) {

	    final int n = stdin.nextInt();
	    if ( n == 0 ) {
		break;
	    }

	    int[] hist = new int[ 7 ];
	    for ( int i = 0; i < n; i++ ) {
		final int index = min( 6, stdin.nextInt() / 10 );
		hist[ index ]++;
	    }
	    for ( final int val : hist ) {
		System.out.println( val );
	    }
	}	
    }    
}

Measured memory_bytes: 209400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (ll i = (a); i < (n); i += (s))
#define rep(...) _overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void print(const T& x) {cout << x << "\n";}
template<typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template<typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
struct Init {Init() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10);}} init;

int main() {
    ll N; cin >> N;
    vi res(N, 0);
    rep(x, 1, 101) {
        rep(y, 1, 101) {
            rep(z, 1, 101) {
                ll n = x*x+y*y+z*z+x*y+y*z+z*x;
                if (n <= N) res[n-1]++;
            }
        }
    }
    rep(i, N) print(res[i]);
}

Measured memory_bytes: 3624
#include <stdio.h>
#define SIZE 8
#define CELL_SKIP -3
#define UNSAFE(cell) (cell > 0)
#define QUEEN(cell) (cell < 0)
#define SKIP(cell) (cell == CELL_SKIP)
#define PUT_FIXED_QUEEN(cb, r, c) \
  do {\
    cb[r][c] = -2;\
    dot_radially(cb, r, c, 1);\
  } while (0)
#define PUT_QUEEN(cb, r, c) \
  do {\
    cb[r][c] = -1;\
    dot_radially(cb, r, c, 1);\
  } while (0)
#define REMOVE_QUEEN(cb, r, c) \
  do {\
    cb[r][c] = 0;\
    dot_radially(cb, r, c, -1);\
  } while (0)

typedef struct { int r, c; } cell_t;

static void initialize(int cb[SIZE][SIZE]) {
  int i, j;

  for (i = 0; i < SIZE; ++i) {
    for (j = 0; j < SIZE; ++j) cb[i][j] = 0;
  }
}

static void print_chess_board(int cb[SIZE][SIZE]) {
  int i, j;

  for (i = 0; i < SIZE; ++i) {
    for (j = 0; j < SIZE; ++j) {
      if (QUEEN(cb[i][j])) {
        printf("%s", "Q");
      } else if (UNSAFE(cb[i][j])) {
        printf("%s", ".");
      } else {
        printf("%s", "X");
      }
    }
    printf("\n");
  }
}

static void dot_radially(int cb[SIZE][SIZE], int r, int c, int d) {
  int i;

  for (i = 1; r-i >= 0 || r+i < SIZE || c-i >= 0 || c+i < SIZE; ++i) {
    if (r-i >= 0)                 cb[r-i][c+0] += d;
    if (r-i >= 0 && c+i < SIZE)   cb[r-i][c+i] += d;
    if (c+i < SIZE)               cb[r+0][c+i] += d;
    if (r+i < SIZE && c+i < SIZE) cb[r+i][c+i] += d;
    if (r+i < SIZE)               cb[r+i][c+0] += d;
    if (r+i < SIZE && c-i >= 0)   cb[r+i][c-i] += d;
    if (c-i >= 0)                 cb[r+0][c-i] += d;
    if (r-i >= 0 && c-i >= 0)     cb[r-i][c-i] += d;
  }
}

static void try_eight_queen(int cb[SIZE][SIZE]) {
  int i, j, k;
  cell_t stk[SIZE];

  for (i = k = 0; i < SIZE; ++i) {
    for (j = 0; j < SIZE; ++j) {
      if (UNSAFE(cb[i][j])) continue;
      if (SKIP(cb[i][j])) {
        cb[i][j] = 0;
        continue;
      }
      if (QUEEN(cb[i][j])) break;
      if (k < SIZE) {
        stk[k].r = i;
        stk[k].c = j;
        PUT_QUEEN(cb, stk[k].r, stk[k].c);
        ++k;
        break;
      }
    }
    if (j < SIZE) continue;
    if (k > 0) {
      --k;
      REMOVE_QUEEN(cb, stk[k].r, stk[k].c);
      cb[stk[k].r][stk[k].c] = CELL_SKIP;
      i = stk[k].r - 1;
    }
  }
}

int main(int argc, char **argv) {
  int i, k, r, c, cb[SIZE][SIZE];

  initialize(cb);
  scanf("%d", &k);
  for (i = 0; i < k; ++i) {
    scanf("%d %d", &r, &c);
    PUT_FIXED_QUEEN(cb, r, c);
  }
  try_eight_queen(cb);
  print_chess_board(cb);
}


Measured memory_bytes: 2112
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const int INF = 1e9;

int main() {
  ll n, total = 0;
  string s;
  cin >> n >> s;
  ll r = 0, g = 0, b = 0;
  rep(i, n) {
    if (s[i] == 'R') r++;
    if (s[i] == 'G') g++;
    if (s[i] == 'B') b++;
  }
  total = r * g * b;
  int k;
  for (int i = 0; i < n - 2; ++i) {
    for (int j = i + 1; j < n - 1; ++j) {
      k = j + j - i;
      if (k < n) {
        if ((s[i] != s[j]) && (s[i] != s[k]) && (s[j] != s[k])) total--;
      }
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

bool isMonth(int a) {
  return 1 <= a && a <= 12;
}

bool isYear(int a) {
  return 0 <= a && a <= 99;
}

bool isYYMM(int fh, int sh) {
  return (isYear(fh) && isMonth(sh));
}

bool isMMYY(int fh, int sh) {
  return (isYear(sh) && isMonth(fh));
}

int main() {
  fastIO;
  string s;
  cin >> s;

  string YY = ""s + s.at(0) + s.at(1);
  string MM = ""s + s.at(2) + s.at(3);

  int former = stoi(YY);
  int latter = stoi(MM);

  if(isYYMM(former, latter) && isMMYY(former, latter)) {
    cout << "AMBIGUOUS";
  } else if(isYYMM(former, latter)) {
    cout << "YYMM";
  } else if(isMMYY(former, latter)) {
    cout << "MMYY";
 } else {
    cout << "NA";
  }
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define pp pair<ll,ll>
#define maxn 100005
#define mod 998244353
using namespace std;
void solve()
{
	ll x,y,a,b,c;
	cin >> x >>y  >> a >> b >> c;
	ll r[a],g[b],co[c];
	for(ll i=0;i<a;i++)
		cin >> r[i];
	for(ll i=0;i<b;i++)
		cin >> g[i];
	for(ll i=0;i<c;i++)
		cin >> co[i];
	sort(r,r+a,greater<ll> ());
	sort(g,g+b,greater<ll> ());
	sort(co,co+c,greater<ll> ());
	ll p,q,ind=0;
	if(a <= x)
	{
		p=a-1;
		ind+=(x-a);
	}
	else p=x-1;
	if(b <= y)
	{
		q=b-1;
		ind+=(y-b);
	}
	else q=y-1;
	while(ind<c and (p>=0 || q >= 0))
	{
		if(co[ind] > min(p>=0?r[p]:1000000007,q>=0?g[q]:1000000007))
		{
			ind++;
			if(p >= 0 and min(p>=0?r[p]:1000000007,q>=0?g[q]:1000000007) == r[p])
				p--;
			else if(q >= 0 and min(p>=0?r[p]:1000000007,q>=0?g[q]:1000000007) == g[q])
				q--;
		}
		else break;
	}
	ll ans=0;
	for(ll i=0;i<=p;i++)
		ans += r[i];
	for(ll i=0;i<=q;i++)
		ans+=g[i];
	for(ll i=0;i<ind;i++)
		ans+=co[i];
	cout << ans ;
}
int main()
{
	ll t=1,i=1;
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
    std::cout.precision(10);
    std::cout.setf( std::ios::fixed, std:: ios::floatfield ); 
	//cin >> t;
	//cin >> n;
	while(i<=t)
	{
		solve();
		i++;
	}
	return 0;
}

Measured memory_bytes: 2688
//32
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int mc=1<<30;
    for(int a=0;a*200<n+200;a++){
      for(int b=0;a*200+b*300<n+300;b++){
	for(int c=0;a*200+b*300+c*500<n+500;c++){
	  if(a*200+b*300+c*500==n){
	    int cst=a*380+b*550+c*850-(a/5)*380*20*5/100-(b/4)*550*15*4/100-(c/3)*850*12*3/100;
	    mc=min(cst,mc);
	  }
	}
      }
    }
    cout<<mc<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;




int main()
{
int a,b,c,d;
cin>>a>>b>>c>>d;

a= max(a,c);
b=min(b,d);

if(a<b)
    cout<<b-a<<endl;
else
    cout<<0<<endl;
 return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
//#define INF 1000000007
#define MOD 1000000007
#define MAX_N 105
#define MAX_V 1005
const ll INF = LLONG_MAX/2;



ll c[51][51];

void combination(int n){
 
    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= i;j++){
            if(j == 0 || i == j){
                /*nC0 = 1、nCn = 1*/
                c[i][j] = 1LL;
            }else{
                c[i][j] = c[i-1][j-1] + c[i-1][j];
            }
        }
    }
}

int main(){

    ll n,a,b;
    cin >> n >> a >> b;
    vector<ll> arr(n);
    vector<ll> vec;
    REP(i,n){
        cin >> arr[i];
    }
    sort(arr.begin(),arr.end(),greater<ll>());
    combination(n);

    ll sum = 0;
    REP(i,a){
        sum += arr[i];
    }

    ll N = 0,R = 0;
    for(int i = 0;i < n;i++){
        if(arr[i] == arr[a-1]){
            N++;
            if(i < a){
                R++;
            }
        }
    }

    double ave = sum/double(a);
    ll ans = 0;
    if(R == a){

        for(ll i = a;i <= b;i++){
            ans += c[N][i];
        }
    }else{
        ans += c[N][R];
    }
    printf("%.8f\n%lld\n",ave,ans);


    return 0;
}

Measured memory_bytes: 256
// acdart
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cstdlib>
#include <list>
#include <limits.h>
#include <utility>
#include <functional>
#include <deque>
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second
#define F first
#define S second
#define MOD9 1000000009ll
#define MOD7 1000000007ll
#define MOD
#define INF  1023456789ll
#define INF16 10000000000000000ll
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define SZ(x) ((int)(x).size())
#define MAXN 10010
#define MAXM
#define ALL(x) ((x).begin()),((x).end())
#define RESET(a,b) memset(a,b, sizeof a)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define LEN(X) strlen(X)
#define FI(a,b,c) for(int a=b; a<c; a++)
#define FD(a,b,c) for(int a=b; a>c; a--)
using namespace std;
typedef long long ll;
typedef long long LL;
typedef double db;
typedef double D;
typedef long double ld;
typedef long double LD;
/*********default*********/
int a[100010];

int main()
{
	int n, c, s = 0;
	int k;
	
	scanf("%d%d%d", &n, &c, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	int t = 0, cnt = c;
	for (int i = 0; i < n; i++) {
		if (a[i] > t || cnt >= c) {
			s++;
			t = a[i] + k;
			cnt = 1;
		} else {
			cnt++;
		}
	}
	printf("%d\n", s);
}

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

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

  for (int i = 0; i < N; i ++){
    string S;
    cin >> S;
    if ( S == "Y"){
      cout << "Four" << endl;
      break;
    }
    if (i +1 ==N)
      cout << "Three" <<endl;
  }
    
}


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

int wa(int x, int n) {
  int s = 0;
  for (int i = 0; i < n; i++) {
    int a = x % 10;
    s += a;
    x /= 10;
  }
  return s;
}

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int s = 0;
  for (int i = 1; i <= n; i++) {
    if (a <= wa(i, 5) && wa(i, 5) <= b) {
      s += i;
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256