akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
  int N;
  cin >> N;
  cout.precision(10);
  
  double x;
  if(N == 1) {
    x = 1.0;
  }
  else if(N%2 == 0) {
    x = 0.5;
  }
  else if(N%2 == 1) {
    int A = N - (N / 2);
    x = (double)A / (double)N;
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
int am[100][100];
int color[100],d[100],f[100],time;

void dfs();
void dfs_visit(int);

int main(){
  int i,j,m,l,o;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      am[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&m,&l);
    m--;
    for(j=0;j<l;j++){
      scanf("%d",&o);
      o--;
      am[m][o]=1;
    }
  }
  
  dfs();

  return 0;
}

void dfs(){
  int i;
  for(i=0;i<n;i++){
    color[i]=WHITE;
  }

  time=0;

  for(i=0;i<n;i++){
    if(color[i]==WHITE) dfs_visit(i);
  }

  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1, d[i],f[i]);
  }
}

void dfs_visit(int x){
  int i;
  
  color[x]=GRAY;
  d[x]=++time;
  for(i=0;i<n;i++){
    if(am[x][i]==0) continue;
    if(color[i]==WHITE){
      dfs_visit(i);
    }
  }
  color[x]=BLACK;
  f[x]=++time;
}




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

using namespace std;

typedef long long ll;

ll f(ll A, ll B, ll C, ll K) {
    if (K == 0) return A - B;
    return f(A + B + C - A, A + B + C - B, A + B + C - C, K - 1);
}

int main() {
    long long A, B, C, K;
    cin >> A >> B >> C >> K;
    cout << f(A, B, C, K % 2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int n;
    cin >> n;
    int x = 2;
    while (x <= n) {
        x *= 2;
    }
    x/=2;
    cout << x << endl;
}


Measured memory_bytes: 3092
#include <iostream>
#include <cmath>

#define N_MAX 200

using namespace std;

bool is_combosite[N_MAX + 1];
bool is_prime (long n) {
  if (n == 1) return false;
  if (n == 2) return true;
  if (is_combosite[n]) return false;

  long sqrtn = ceil(sqrt(n));

  for (long i = 2; i <= sqrtn; i++) {
    if (n % i == 0) {
      is_combosite[n] = true;
      return false;
    }
  }

  return true;
}

int count_factors (int n, int p) {
  int x = n;
  int count = 0;
  while (x % p == 0) {
    x /= p;
    count++;
  }
  return count;
}

int factorize_and_count (int m) {
  int divisors = 1;
  for (int i = 1; i <= m; i++) {
    if (m % i == 0 && is_prime(i)) {
      divisors *= (count_factors(m, i) + 1);
    }
  }
  return divisors;
}

int main () {
  int N, count = 0;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    if (i % 2 == 0) continue;
    if (factorize_and_count(i) == 8) count++;
  }
  cout << count << "\n";
}


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

int main() {
  int N , i, digitsSum = 0;
  cin >> N;
  
  i = N;
  while (i) {
    int digit;

    digit = i % 10;
    digitsSum += digit;
    i /= 10;
  }
  
  if (N % digitsSum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

template<class T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*(._.)*/
int main(){
	ll ans = 0;
	int N; cin >> N;
	vector<string> Ss;
	REP(i,N){
		string s;
	    cin >> s;
	    sort(ALL(s));
	    //cout << s << endl;
	    Ss.PB(s);
	}
	sort(ALL(Ss));

	vector<int> U;
	int count = 1;
	REP(i,Ss.size()-1){
		if (Ss[i] == Ss[i+1]){
			count++;
		}else{
			U.PB(count);
			count = 1;
		}
	}
	U.PB(count);

	REP(i,U.size()){
	    ll ncount = U[i];
	    ans += ncount * (ncount-1) / 2;
	}

	cout << ans << "\n";

}


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

int main(){
  int a, b;
  char op;
  while(1){
    cin >> a >> op >> b;
    if(op == '?'){break;}
    else if(op == '+'){cout << a+b << endl;}
    else if(op == '*'){cout << a*b << endl;}
    else if(op == '-'){cout << a-b << endl;}
    else if(op == '/'){cout << a/b << endl;}
  }
  return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
ld dp[6100][3010];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ld p;
    cin>>p;
    dp[3001][1]=p;
    dp[2999][1]=1-p;
//    cout<<dp[3001][1]<<" "<<dp[2999][1]<<endl;
    for(ll i=2;i<=n;i++)
    {
        cin>>p;
        //cout<<p<<endl;
        for(ll j=1;j<=6000;j++)
        {
            dp[j][i]+=dp[j-1][i-1]*p;
        }
        for(ll j=1;j<=6000;j++)
        {
            dp[j][i]+=dp[j+1][i-1]*(1-p);
        }
        //for(ll j=2990;j<=3010;j++)
        //{
        //    cout<<dp[j][i]<<" ";
        //}
        //cout<<endl;
    }
    ld sum=0;
    for(ll i=3001;i<=6000;i++)
    {
        sum+=dp[i][n];
    }
    printf("%0.15Lf",sum);
}

Measured memory_bytes: 282880
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n;long double d,x;
int main()
{
    cin>>n>>d>>x;
    long double ans=0;
    for(int i=n;i>=1;i--)ans+=d+(2*i-1)*x/2,d+=d/i+(5*x)/(2*i),x+=2*x/i;
    printf("%.10lf\n",(double)ans);
}

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

int main() {

  string S, T;
  
  cin >> S >> T;
  
  int size = S.size();
  int diff = 0;
  for(int i = 0; i < size; i++){
    if( S.at(i) != T.at(i)){
      diff++;
    }
  }
  
  cout << diff << endl;
}


Measured memory_bytes: 3920
N = int(input())

cities = {}
for i in range(1, N + 1):
    s, p = input().split()
    p = int(p)
    if s in cities:
        cities[s].append((p, i))
    else:
        cities[s] = [(p, i)]
for k in cities.keys():
    cities[k] = list(sorted(cities[k], key=lambda x: x[0], reverse=True))

names = sorted(cities)
for name in names:
    for p, i in cities[name]:
        print(i)


Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
signed main()
{
  int x=0,y=0,z=0,w=0,n=2,m=1;
string s;
std::cin >> x;
if(x==0)std::cout << n << '\n';
else if(x==1)std::cout << m << '\n';
else{
  rep(i,x-1){
    z=m;
    m=n+m;
    n=z;
  }
  std::cout << m << '\n';
}
}


Measured memory_bytes: 256
import itertools

n, k = map(int, input().split())
a = []
sunuke = list(range(1, n + 1))

# 標準入力わからん
for i in range(k):
    d = int(input())
    a.append(map(int, input().split()))

a2 = list(itertools.chain.from_iterable(a))
result = set(sunuke) - set(a2)
print(len(result))

Measured memory_bytes: 9336
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<int> a,z;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    rep(i,s.size()){
        if(s[i]=='A')a.push_back(i);
        if(s[i]=='Z')z.push_back(i);
    }
    cout << z.back() - a[0] + 1 << "\n";
}


Measured memory_bytes: 1428
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int d[k];
    for (int i=0; i<k; i++) cin >> d[i];

    int ans;
    while(1)
    {
        bool f = false;
        int tmp = n;
        while(tmp>0)
        {
            for (int i=0; i<k; i++) {
                if (tmp%10 == d[i]) {
                    f = true;
                    break;
                }
            }
            if (f) break;
            tmp /= 10;
        }
        if (f == false) {
            ans = n;
            break;
        }
        n ++;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
/// In The Name Of God

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)5e5 + 7, inf = (int)1e9 + 7, mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

using namespace std;

int n;
ll ans;
int a[N], b[N], c[N];
int main() {
	#ifdef IOI2018
		freopen ("in.txt", "r", stdin);
	#endif
	Kazakhstan
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> c[i];
	}
	sort (a + 1, a + 1 + n);
	sort (b + 1, b + 1 + n);
	sort (c + 1, c + 1 + n);

	{
		
	}
	for (int i = 1; i <= n; i++) {
		int l = lower_bound(a + 1, a + 1 + n, b[i]) - a - 1;
		int r = (n + 1) - (upper_bound(c + 1, c + 1 + n, b[i]) - c);
		ans += l * 1ll * r;
	}
	cout << ans;
	ioi
}


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

const int N = 100005;
int vet[N];

int main(){
	int n;
	scanf("%d", &n);
	for (int i=0; i<n+1; i++){
		scanf("%d", &vet[i]);
	}
	long long ans = 0LL;
	for (int j=0; j<n; j++){
		int x;
		scanf("%d", &x);
		int mn = min(vet[j], x);
		ans += mn;
		vet[j] -= mn;
		x -= mn;
		if(x > 0){
			mn = min(vet[j+1], x);
			ans += mn;
			vet[j+1] -= mn;
			x -= mn;
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 640
#include<cstdio>
const int N=1e5+10;
const int mod=1000000007;
int n,a[N],m,k;
long long f[N];
int main()
{
	scanf("%d%d",&n,&m);
	while(m--)
	{
		scanf("%d",&k);
		a[k]=1;
	}
	f[0]=1;
	if(!a[1])f[1]=1;
	for(int i=2;i<=n;i++)
		if(!a[i])
		{
			if(!a[i-1])f[i]=(f[i]+f[i-1])%mod;
			if(!a[i-2])f[i]=(f[i]+f[i-2])%mod;
		}
	printf("%lld",f[n]);
	return 0;
}


Measured memory_bytes: 1280
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::cmp::*;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n = sc.read();
    let mut min = 10_000_000_000i64;
    let mut ans = -10_000_000_000;
    for _ in 0..n {
        let x = sc.read();
        if ans < x - min {
            ans = x - min;
        }
        if min > x {
            min = x;
        }
    }
    println!("{}", ans);
}



Measured memory_bytes: 9084
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<string,string>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;

 string l,r;
 map <P , ll> h;
int n;
ll cnt;
void depth(int f, int t, string red, string blue){
    if(f == t){
        P p;
        p.first = red;
        p.second = blue;
        if(h[p] != 0){
            h[p]++;
        }else{
            h[p] = 1;
        }
        //cout << red << "::" << blue << endl;
        return ;
    }
    string s = red+l[f];
    string ss = blue + l[f];
    
    depth(f+1,t, s, blue);
    depth(f+1,t, red, ss);
}

void depthr(int f, int t, string red, string blue){
    //cout << "!" << endl;
    if(f == t){
        P p;
        p.first = red;
        p.second = blue;
        if(h[p] != 0){
            cnt += h[p];
            //cout << "cnt : " << cnt << endl;
        }
        //cout << red << "::::" << blue << endl;
        return ;
    }
    string s = red+r[f];
    string ss = blue + r[f];
    
    depthr(f+1,t, s, blue);
    depthr(f+1,t, red, ss);
}


int main(){
    cin >> n;
    string s;
    cin >> s;
    l = s.substr(0,n);
    //cout << l << endl;
    r = s.substr(n,2*n);

    reverse(r.begin(),r.end());
    //cout << r << endl;
    depth(0,n,"","");
    depthr(0,n,"","");
    /*
    for(int it = h.begin();it != h.end();it++){
        cout << h[it] << endl;
    }*/
    cout << cnt << endl;


  
  return 0;
}


Measured memory_bytes: 87808
#include<stdio.h>
#include<string.h>
int main(){
    int l,i,j;
    char a[201];
    gets(a);
    l=strlen(a)-1;
    if(l%2!=0)
        l--;
    i=0;
    j=l/2;
    for(;i<j,j<l;){
        if(a[i++]!=a[j++]){
            i=0;
            l-=2;
            j=l/2;
        }
    }
    printf("%d",l);
    }


Measured memory_bytes: 1644
import java.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.util.*;
class Main {
	
	static int[][] map;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			if(x == 0 && y == 0) break;
			
			int tx = sc.nextInt()-1;
			int ty = sc.nextInt()-1;
			
			int kx = sc.nextInt()-1;
			int ky = sc.nextInt()-1;
			
			map = new int[y][x];
			for(int i = 0; i < y; i++) {
				for(int j = 0; j < x; j++) {
					map[i][j] = sc.nextInt();
				}
			}
			
			int ans = solv(x,y,tx,ty,kx,ky);
			
			if(ans == -1 || ans == 100) {
				System.out.println("NA");
			}
			else {
				System.out.println(ans);
			}
		}
	}
	static Queue<Data> queue = new ArrayDeque<Data>();
	static HashMap<String,Boolean> h_map = new HashMap<String,Boolean>();
	static int[] vyt = new int[] {1,0,-1,0};
	static int[] vxt = new int[] {0,1,0,-1};
	static int[] vyk = new int[] {-1,0,1,0};
	static int[] vxk = new int[] {0,-1,0,1};
	
	
	static int solv(int x, int y, int tx, int ty, int kx, int ky) {
		queue.clear();
		h_map.clear();
		queue.add(new Data(0,x,y,tx,ty,kx,ky));
		
		while(!queue.isEmpty()) {
			Data data = queue.poll();
			if(data.tx == data.kx && data.ty == data.ky) return data.time;
			bfs(data);
		}
		return -1;
	}
	
	static void bfs(Data a) {
		for(int i = 0; i < 4; i++) {
			
			int movetx = a.tx + vxt[i];
			int movety = a.ty + vyt[i];
			int movekx = a.kx + vxk[i];
			int moveky = a.ky + vyk[i];
			Data next = new Data(a.time+1 ,a.x ,a.y ,movetx ,movety ,movekx ,moveky );
			if(next.time >= 100) {
				queue.clear();
				return;
			}
			if(movetx >= a.x || movety >= a.y || movetx < 0 || movety < 0 || map[movety][movetx] == 1) {
				next.tx = a.tx;
				next.ty = a.ty;
			}
			if(movekx >= a.x || moveky >= a.y || movekx < 0 || moveky < 0 || map[moveky][movekx] == 1) {
				next.kx = a.kx;
				next.ky = a.ky;
			}
			String tmp = next.tx+""+next.ty+""+next.kx+""+next.ky;
			if(h_map.containsKey(tmp)) continue;
			
			h_map.put(tmp, true);
			
			queue.add(next);
			
		}
	}
	
	
	
	
	
	static class Data {
		int time;
		int x;
		int y;
		int tx;
		int ty;
		int kx;
		int ky;
		
		Data() {
			time = 0;
			x = 0;
			y = 0;
			tx = 0;
			ty = 0;
			kx = 0;
			ky = 0;
		}
		
		Data(int a, int b, int c, int d, int e, int f, int g) {
			time = a;
			x = b;
			y = c;
			tx = d;
			ty = e;
			kx = f;
			ky = g;
		}
		
		
	}
 	
}

Measured memory_bytes: 320304
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>
//1000
#include <ctype.h>
using namespace std;long a,z,x,y,b[4001];bool s,p[4001];
int main(){
	while(cin>>a){
		if(a==0){break;}
	for(int aa=1;aa<=4000;aa++){
	b[aa]=0;p[aa]=false;}
	s=false;
	for(int i=0;i<a;i++){cin>>x>>y>>z;
	b[x]+=y*z;if(b[x]>=1000000&&p[x]==false){cout<<x<<endl;s=true;p[x]=true;}}
	if(s==false){cout<<"NA"<<endl;}}
return 0;}


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

#define int long long

signed main()
{
    int i=0, j=0, k=0, ans=0;
    
    string s;
    cin>>s;

    int n=s.length();

    for(i=0;i<n/2;i++){
        if(s[i]!=s[n-1-i]){
            cout<<"No"<<endl;
            return 0;
        }        
    }

    for(i=0;i<(n-1)/4;i++){
        if(s[i]!=s[(n-1)/2-1-i]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    for(i=(n+3)/2-1;i<n-1;i++){
        if(s[i]!=s[n-1-i]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    string s;
    cin >> s;

    int count_a=0;
    int count_b=0;
    for (int i=0;i<=s.length()-1;i++)
    {
        if ((i%2==0)&&(s[i]=='0'))
        {
            count_a++;
        }
        else if ((i%2==1)&&(s[i]=='1'))
        {
            count_a++;
        }
    }    

    for (int i=0;i<=s.length()-1;i++)
    {
        if ((i%2==0)&&(s[i]=='1'))
        {
            count_b++;
        }
        else if ((i%2==1)&&(s[i]=='0'))
        {
            count_b++;
        }
    }

    cout << s.length()-max(count_a,count_b) << endl;
    return 0;
}

Measured memory_bytes: 3760
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<tuple>
#include<set>
#include<map>
#include<cctype>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

int N,M;
int main(void) {
	cin >> N>>M;
	ct((N + M) % 24);
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<set>
typedef unsigned long long ull;
const int MaxN=200010,B=1000000007;
int N,K,P[MaxN];
ull pw[MaxN],H[MaxN];
struct info{
	int s;ull h;
	info operator+(const info&i)const{
		return(info){s+i.s,h+i.h*pw[s]};
	}
}T[1<<19];
#define Def int o,int L,int R
#define Mid (L+R>>1)
#define Ls o<<1,L,Mid
#define Rs o<<1|1,Mid,R
void modify(Def,int i,int x){
	if(R-L==1){
		T[o]=(info){x,i*x};
		return;
	}
	i<Mid?modify(Ls,i,x):modify(Rs,i,x);
	T[o]=T[o<<1]+T[o<<1|1];
}
int main(){
	scanf("%d%d",&N,&K);
	for(int i=0;i<N;i++)scanf("%d",P+i);
	for(int i=*pw=1;i<=N;i++)pw[i]=pw[i-1]*B;
	for(int i=0;i<N;i++)H[i+1]=H[i]+P[i]*pw[i];
	std::set<ull>st;
	for(int l=0,r=K;r<=N;l++,r++){
		if(!l){
			for(int i=0;i<K;i++)modify(1,0,N,P[i],1);
		}
		else{
			modify(1,0,N,P[l-1],0);
			modify(1,0,N,P[r-1],1);
		}
		st.insert(H[l]+H[N]-H[r]+T[1].h*pw[l]);
	}
	printf("%d\n",st.size());
}

Measured memory_bytes: 21760
n = int(input())
x = list(map(int, input().split()))
a = min(x) + (max(x) - min(x)) // 2
s = 1000000000000
for a in range(min(x), max(x)+1):
    s = min(s, sum(map(lambda x: (x - a) ** 2, x)))
print(s)


Measured memory_bytes: 3060
import math

def triangle(a, b, deg):
    result = {}
    rad = math.radians(deg)
    c = math.sqrt(a*a+b*b-(2*a*b*math.cos(rad)))
    s = (a+b+c)/2
    result['area'] = math.sqrt(s*(s-a)*(s-b)*(s-c))
    result['perimeter'] = a+b+c
    result['height'] = result['area'] * 2 / a
    return result

if __name__ == '__main__':
    a, b, deg = map(int, input().split())
    triangle = triangle(a, b, deg)
    print(triangle['area'])
    print(triangle['perimeter'])
    print(triangle['height'])



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

using namespace std;
using ll = long long;
using P = pair<int,int>;
inline int ri() {
	int r; cin >> r; return r;
}
vector<vector<P>> hen;
vector<int> dist;
const ll INF = 2e9;
bool res = true;

void dfs(int v) {
 	for(auto i : hen[v]) {
		if(dist[i.first] != -INF) {
			if(dist[i.first] != dist[v] + i.second) {
				res = false;
				return;
			}

		}else {
			dist[i.first] = dist[v] + i.second;
			dfs(i.first);
		}
	}
}

int main()
{
	int n = ri(), m = ri();
	hen.resize(n);
	dist.resize(n, -INF);
	for(int i = 0; i < m; i++) {
		int l = ri() - 1, r = ri() - 1, d = ri();
		hen[l].emplace_back(r, d);
		hen[r].emplace_back(l, -d);
	}

	for(int i = 0; i < n; i++) {
		if(dist[i] == -INF) {
			dist[i] = 0;
			dfs(i);
		}
	}
	cout << (res ? "Yes" : "No") << endl;
}

Measured memory_bytes: 11008
o,x,b;main(a){for(scanf("%d");~scanf("%s",&a)&&(a%=9);o=o==3?b=x=!printf("%d\n",x):o)for(a-8?b=b*2+1,x+=b>>3&1,b&=7:o++;a<7&&b;b/=2)x+=b&1;}

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

using namespace std;

vector <vector <int>> g;
vector <int> inc;

void dfs(int v, int sum, int p) {
	inc[v] += sum;
	for (auto u : g[v]) {
		if (u == p) {
			continue;
		}
		dfs(u, inc[v], v);
	}
}

int main() {
	ios_base::sync_with_stdio(0); 
	cin.tie(0);
	int n, q;
	cin >> n >> q;
	g.resize(n + 1);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	inc.resize(n + 1);
	for (int i = 0; i < q; i++) {
		int p, x;
		cin >> p >> x;
		inc[p] += x;
	}
	dfs(1, 0, -1);
	for (int i = 1; i <= n; i++) {
		cout << inc[i] << " ";
	}
	return 0;
}


Measured memory_bytes: 23552
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
char f[1005][1005];
int dp[1005][1005];
int main()
{
    int h,w;
    cin >> h >> w;
    for(int i=1;i<=h;i++)
        cin >> f[i]+1;
    dp[0][1] = 1;
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            dp[i][j] = f[i][j] == '.'? (dp[i-1][j]+dp[i][j-1])%mod : 0;
    cout << dp[h][w];
}


Measured memory_bytes: 5120
#include <iostream>
#include <algorithm>

int main() {
  int x;
  int y;

  while(1) {
    std::cin >> x >> y;
    if((x == 0) && (y == 0)) {
      break;
    }
    if(x > y) {
      using std::swap;
      swap(x, y);
    }
    std::cout << x << " " << y << std::endl;
  }

  return 0;
}

Measured memory_bytes: 3024
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
int main() {
    string S,T;
    std::cin >> S;
    std::cin >> T;
    bool flag;
    for (int i = 0; i < S.length(); i++) {
        flag=true;
        for (int j = 0; j < S.length(); j++) {
            if(S[(j+i)%S.length()]!=T[j]){
                flag=false;
                break;
            }
        }
        if(flag){
            std::cout << "Yes" << std::endl;
            break;
        }
    }
    if(!flag){
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int a[maxn],o[maxn],e[maxn];
int main(){
	int n,max1=0,max2=0,t1,t2;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i%2)o[a[i]]++;//2 4 6
		else e[a[i]]++;
	}
	vector<int>v1,v2;
	for(int i=1;i<maxn;i++){
		if(o[i]){
			v1.push_back(o[i]);
			if(max1<o[i]){
				max1=o[i];
				t1=i;
			}
		}
		if(e[i]){
			v2.push_back(e[i]);
			if(max2<e[i]){
				max2=e[i];
				t2=i;
			}
		}
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	int l1=v1.size(),l2=v2.size(),k1=n/2,k2=n/2;
	if(n%2)k1+=1;
	if(t1!=t2)cout<<k1-v1[l1-1]+k2-v2[l2-1];
	else if((k1-v1[l1-2]+k2-v2[l2-1])<(k2-v2[l2-2]+k1-v1[l1-1]))cout<<k1-v1[l1-2]+k2-v2[l2-1];
	else if((k1-v1[l1-2]+k2-v2[l2-1])>(k2-v2[l2-2]+k1-v1[l1-1]))cout<<k2-v2[l2-2]+k1-v1[l1-1];
	else cout<<k1-v1[l1-2]+k2-v2[l2-1];
}

Measured memory_bytes: 2044
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Eric
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CMinimization solver = new CMinimization();
        solver.solve(1, in, out);
        out.close();
    }

    static class CMinimization {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            //out.println();
            out.println(solveWrong(N, K));
        /*for (int i = 2; i < 1000; i++) {
            for (int k = 2; k <= i; k++) {
                if (solve(i, k) != solveWrong(i, k))
                    System.err.println("Wrong for i = " + i + " ; k = " + k);
            }
        }*/
        }

        int solveWrong(int N, int K) {
            int[] arr = new int[N];
            int cur = 0;
            for (int i = 0; i < N; i++) {
                arr[i] = i; //in.nextInt();
                if (arr[i] == 1)
                    cur = i;
            }
            int res = 0;
            if (cur - K + 1 < 0)
                cur += -(cur - K + 1);
            int tmp = cur;
            while (tmp > 0) {
                tmp -= K - 1;
                res++;
            }
            tmp = cur;
            while (tmp < N - 1) {
                tmp += K - 1;
                res++;
            }
            return res;
        }

    }
}



Measured memory_bytes: 23124
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;


//サイコロは1つ
//繰り返すのは6→5→6...

int main() {
	long long x; cin >> x;

	long long ans = (long long)ceil(x / 11.0) * 2;

	if (x % 11 <= 6 && x % 11 != 0) {
		ans--;
	}

	cout << ans << endl;


}


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

#define PI 3.14159265358979323846
#define int long long int
#define ff first
#define ss second
#define pb push_back

#define N 100010
#define MOD 1000000007

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int a, b;
    cin >> a >> b;
    cout << (a * b) /__gcd(a, b); 
   	return 0;	
}

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

int main(){

    while(1) {
    int a,b;
    string op;
    cin>>a>>op>>b;
       if(op == "?") break;

       int ans;
       if(op == "+") ans = a + b;
       if(op == "-") ans = a - b;
       if(op == "*") ans = a * b;
       if(op == "/") ans = a / b;
    cout<<ans<<endl;
    }
    return 0;
}


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


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

    vector<int> vec(N);
    for (int i = 0; i < N;i++) {
        cin >> vec.at(i);
    }
    if (vec.size()%2 != 0) {
        vec.push_back(0);
    }
    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());
    int Alice = 0;
    int Bob = 0;
    for (int i = 0; i < N;i++) {
        Alice = Alice + vec.at(i);
        i = i + 1;
        Bob = Bob + vec.at(i);
    }
    cout << Alice - Bob << endl;

}


Measured memory_bytes: 256
#include<stdio.h>


int main(){

  int a, b, c1, c5, c10;

  while(scanf("%d %d", &a, &b), a){
    c10=(b-a)/1000;
    c5=(b-a)%1000/500;
    c1=(b-a)%1000%500/100;
    printf("%d %d %d\n", c1, c5, c10);
  }

  return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Linq;

class Progaram
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var k = int.Parse(Console.ReadLine());
        var x = Console.ReadLine().Split(' ').Select(f => int.Parse(f)).ToArray();
        var res = 0;
        for (var i = 0; n > i; i++)
        { 
            res += (Math.Abs(k - x[i]) < x[i]) ? Math.Abs(k - x[i]) : x[i];
        }
        Console.WriteLine(res * 2);
    }
}


Measured memory_bytes: 11348
from collections import deque

n, q = list(map(int, input().split()))
A = deque()
[A.append([]) for _ in range(n)]

for i in range(q):
    query = list(map(int, input().split()))
    t = query[1]

    # pushBack
    if query[0] == 0:
        x = query[2]
        A[t].append(x)

    # dump
    elif query[0] == 1:
        print(*A[t])

    # clear
    else:
        if len(A[t]) != 0:
            A[t].clear()


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

int main()
{
    string s;
    cin >> s;
    int l = s.length();
    if(s[l - 1] == 's')
    {
        s = s + "es";
        cout << s << endl;
    }
    else
    {
        s = s + "s";
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();

		if (Math.abs(a - x) < Math.abs(b - x)) {
			System.out.println("A");
		} else {
			System.out.println("B");
		}

		sc.close();
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define crep(i) for(char i='a';i<='z';i++)
typedef long long ll;
#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);}
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
#define MOD 1000000007
#define EPS 10e-8

ll d[40],p;

int  depth(ll parent[],ll i){
    if(parent[i]==-1){
        return 0;
    }
    else if(d[i]!=0){
        return d[i];
    }
    else{
        p = depth(parent,parent[i])+1;
        d[i] = p; 
        return p;
    }
}

int height(ll root[40][3],ll i){
    if(root[i][0]==-1 && root[i][1]==-1){
        return 0;
    }
    else{
        return max(height(root,root[i][0]),height(root,root[i][1]))+1;
    }
}

int main(){
    ll N,t,x,parent[40];
    rep(i,40){
        parent[i]=-1;
    }
    cin >> N;
    ll root[40][3];
    rep(i,N){
        cin >> x;
        rep(j,2){
            cin >> t;
            if(t!=-1){
                parent[t] = x;
            }
            root[x][j]=t;
        }
    }
    rep(i,N){
        // 節点番号
        printf("node %d: ",i);

        // 親
        if(parent[i]==-1){
            printf("parent = -1, ");
        }
        else{
            cout << "parent = "  << parent[i] << ", " ;
        }

        // 兄弟
        if(parent[i]==-1){
            cout << "sibling = "  << -1 << ", " ;
        }
        else{
            if(root[parent[i]][0]==i){
                cout << "sibling = "  << root[parent[i]][1] << ", " ;
            }
            else{
                cout << "sibling = "  << root[parent[i]][0] << ", " ;
            }
        }

        // 子の数
        if(root[i][0]==-1 && root[i][1]==-1){
            printf("degree = 0, ");
        }
        else if(root[i][0]>-1 && root[i][1]>-1){
            printf("degree = 2, ");
        }
        else{
            printf("degree = 1, ");
        }

        // 深さ
        printf("depth = %d, ",depth(parent,i));

        // 高さ
        printf("height = %d, ",height(root,i));

        // 種類
        if(parent[i]==-1){
            printf("root");
        }
        else if(root[i][0]==-1 && root[i][1]==-1){
            printf("leaf");
        }
        else{
            printf("internal node");
        }

        cout << endl;
    }
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int n,k;
    cin>>n>>k;
    vi a(n);rep(i,n){
        cin>>a[i];
        if(a[i]==k){
            cout<<"POSSIBLE";return 0;
        }
    }
    sort(all(a));
    if(a[n-1]<k){cout<<"IMPOSSIBLE";return 0;}
    int GCD=a[0];
    rep(i,n){
        GCD=gcd(GCD,a[i]);
    }
    if(k%GCD==0)cout<<"POSSIBLE";
    else cout<<"IMPOSSIBLE";
}

Measured memory_bytes: 640
import numpy as np

N=int(input())
A=np.array([int(x) for x in input().split()])

ans=0
M=pow(10,9)+7
for i in range(100):
  one=np.sum((A>>i)&1)
  zero=N-one
  ans+=(one*zero)%M*pow(2,i,M)%M
  ans%=M
  #print(one,zero)
print(ans)

Measured memory_bytes: 68804
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,0,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define fst first
#define sec second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);	
}
int main()
{
	fastio;
	//fopen();
	int n,m;
	cin>>n>>m;
	if(n/10==0 && m/10==0)
	{
		cout<<n*m;
	}
	else{
		cout<<-1;
	}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
// #include <regex> //正規表現
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// グリッドグラフの移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int64_t X, Y; cin >> X >> Y;

if (X == Y) {
    cout << 1 << endl;
    return 0;
}

int64_t cnt = 0;
int64_t Ai1 = X, A = X;

while(A <= Y){
    int c = 2;
    if ((c * A) % Ai1 == 0){
        ++cnt;
        A *= c;
        Ai1 = A;
    }
    else {
        ++c;
    }
}

cout << cnt << endl;

}

// 境界，出力文字列 チェック



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n; cin >> n;
    int cnt[60][30] = {};
    rep(i,0,n) {
        string s; cin >> s;
        rep(j,0,s.length()) {
            cnt[i][ s[j] - 'a' ]++;
        }
    }

    int rec[30] = {};
    rep(i,0,26) rec[i] = INF;
    rep(i,0,26) {
        rep(j,0,n) {
            rec[i] = min(rec[i], cnt[j][i]);
        }
    }

    string ans = "";
    rep(i,0,26) {
        rep(j,0,rec[i]) ans += ('a' + i);
    }
    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 < (n); i++)
int main() {
  long long int a,b,c=0,ans=1;
  cin>>a>>b;
  for(int i=a;i<=b;i++){
    if(i==0){
      cout<<"Zero"<<endl;
      return 0;
    }
    if(i<0){
      c++;
    }
  }
  if(c%2==0){
    cout<<"Positive"<<endl;
  }else{
    cout<<"Negative"<<endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int64_t n;
  cin >> n;
  int64_t pre = 0, suf = 0, presuf = 0;
  int64_t result = 0;
  bool is_all_prefix=true,is_all_suffix=true;
  for (int i = 0; i < n; i++) {
    std::string s;
    cin >> s;
    for (int j = 0; j < s.size() - 1; j++) {
      if (s[j] == 'A' && s[j + 1] == 'B') {
        result++;
      }

    }
    if (s.front() == 'B' && s.back() == 'A') {
      presuf++;
    } else if (s.front() == 'B') {
      pre++;
    } else if (s.back() == 'A') {
      suf++;
    }

    if(s.front()!='B'){
      is_all_prefix=false;
    }
    if(s.back()!='A'){
      is_all_suffix=false;
    }
  }

  bool is_suf_zero=suf==0,is_pre_zero=pre==0;

  if(presuf>=1&&is_suf_zero){
    pre+=presuf-1;
  }else{
    pre+=presuf;
  }

  if(presuf>=1&&is_pre_zero){
    suf+=presuf-1;
  }else{
    suf+=presuf;
  }





  result+=std::min(pre,suf);
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 1e5 + 10;
typedef long long ll;
ll n, L, T, a[N];

int main() {
	cin >> n >> L >> T;
	rep(i, 1, n) {
		int w; scanf("%lld%d", &a[i], &w);
		a[i] += (w == 1 ? T : -T);
	}
	int pos = 0;
	rep(i, 1, n) {
		pos += a[i] / L - (a[i] % L < 0);
		a[i] = (a[i] % L + L) % L;
	}
	sort(a + 1, a + n + 1);
	pos = (pos % n + n) % n + 1;
	rep(i, 1, n) {
		printf("%lld\n", a[pos]);
		pos = (pos == n ? 1 : pos + 1);
	}
	return 0;
}

Measured memory_bytes: 4572
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int h = sc.nextInt();
        int count = 0;
        ArrayList<Integer> attack = new ArrayList<>();
        ArrayList<Integer> throwPoint = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            attack.add(sc.nextInt());
            throwPoint.add(sc.nextInt());
        }
        int maxAttack = Collections.max(attack);
        Collections.sort(throwPoint, Collections.reverseOrder());
        for (int point : throwPoint) {
            if (maxAttack < point) {
                h -= point;
                count++;
                if (h <= 0) {
                    System.out.println(count);
                    return;
                }
            }
        }
        while (h > 0) {
            h -= maxAttack;
            count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 67448
#include<bits/stdc++.h>
using namespace std;
#define maxn 100005
#define P pair<int,int>

int n;
vector<int> e[maxn];
map<P,int> mp;
int ans[maxn];
bool used[maxn];
int cnt;

void dfs(int f,int x,int c){
	used[x] = 1;
	if (f != -1){
		ans[mp[P{f,x}]] = c;	
	}
	int cc = 1;
	for (int i = 0;i<e[x].size();i++){
		if (e[x][i] == f) continue;
		if (cc == c) ++cc;
		dfs(x,e[x][i],cc);
		cnt = max(cnt,cc);
		++cc;
	}
}



int main(){
	cin >> n;
	for (int i =0;i<n-1;i++){
		int a,b;
		cin >> a >> b;
		e[a].push_back(b);
		e[b].push_back(a);
		mp[P{a,b}] = i;
		mp[P{b,a}] = i;
	}
	dfs(-1,1,0);
	cout << cnt << endl;
	for (int i = 0;i<n-1;++i){
		cout << ans[i] << endl;
	}

}


Measured memory_bytes: 19456
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

bool issosuu(int x){
	if(x==2) return true;  
	if(x%2==0 || x==1) return false;
  	int i=3;
  	while(i<=sqrt(x)){
    	if(x%i==0) return false;
      	i+=2;
    }
  	return true;
}

int main(){
	int n;cin>>n;
  	vector<int> a(n);
  	for (int i=0;i<n;i++){
    	cin>>a.at(i);
    }
  int count=0;
  for(int i=0;i<n;i++){
    if(issosuu(a.at(i))) count++;    
}
       cout<<count<<endl;
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first

#if MYDEBUG
#define DBG(...) {string dst__=#__VA_ARGS__;dbgsplit(dst__);stringstream dss__; dss__<<dst__; debug(dss__,__VA_ARGS__);}
#else
#define DBG(...)
#endif
void debug(stringstream& ds){cerr<<endl;return;}
template<typename F, typename... R>void debug(stringstream& ds,const F& f, const R&... r){string n; ds>>n; cerr<< n <<'='<<f<<' '; debug(ds,r...);}
void dbgsplit(string &s){int l=s.length(),n=0;for(int i=0; i<l; ++i){if(s[i]=='(')++n;if(s[i]==')')--n;if(s[i]==','&&!n)s[i]=' ';}}
using LL = long long;
constexpr long long LINF=334ll<<53; constexpr int INF=15<<26; constexpr long long MOD=1E9+7;
void ok(){cout << "YES" <<"\n"; exit(0);}
void fail(){cout << "NO" <<"\n"; exit(0);}
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    LL n;
    cin >> n;
    if(n==1) ok();
    vector<LL> a(n),b(n),c(n);
    for(int i=0; i<n; ++i){
        cin >> a[i];
    }
    LL sum=accumulate(a.begin(),a.end(),0ll);
    if(sum%(n*(n+1)/2)!=0)fail();
    LL cnt=sum/(n*(n+1)/2);
    a.push_back(a[0]);
    LL removes=0;
    for(int i=0; i<n; ++i){
        LL dif=a[i+1]-a[i];
        if((cnt-dif)%n!=0)fail();
        else{
            b[i]=(cnt-dif)/n;
            if(b[i]<0)fail();
            removes+=b[i];
        }
    }
    if(removes!=cnt)fail();
    a.pop_back();
    vector<int> visited(n);
    int adddif=0,add=0;
    for(int i=0; i<2*n; ++i){
        int now=i%n;
        if(visited[now]==0){
            adddif+=b[now];
            visited[now]=1;
        }
        else {
            adddif-=b[now];
            add-=b[now]*n;
        }
        add+=adddif;
        c[(now+1)%n]+=add;
    }
    for(int i=0; i<n; ++i){
        if(c[i]!=a[i])fail();
    }

    ok();



    return 0;
}



Measured memory_bytes: 3456