akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 200010
char s[MAXN];
int n,cnt[30];
int main()
{
	scanf("%s",s);
	int n=strlen(s);
	int l=0,r=0;
	while(r<n)
	{
		cnt[s[r]-'a']++;
		r++;
		while(r-l>=2&&cnt[s[l]-'a']<(r-l+1)/2)
		{
			cnt[s[l]-'a']--;
			l++;
		}
		while(r<n&&r-l<2)
		{
			cnt[s[r]-'a']++;
			r++;
		}
		if(r==n&&r-l<2) break;
		for(int i=0;i<26;i++)
			if(cnt[i]>(r-l)/2)
			{
				printf("%d %d\n",l+1,r);
				return 0;
			}
	}
	printf("-1 -1\n");
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int N;
	double V[100010];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> V[i];
	}
	sort(V, V + N);
	for (int i = 1; i < N; i++) {
		V[i] = (V[i - 1] + V[i]) / 2;
	}
	printf("%lf", V[N - 1]);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
int n;
int t[2000],a[2000];
int sum[2000],mini=2;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>t[i]>>a[i];
        if(i>0){
            int l=t[i-1]/t[i];
            int r=a[i-1]/a[i];
            if(t[i-1]%t[i])l++;
            if(a[i-1]%a[i])r++;
            int mul=max(l,r);
            t[i]*=mul;
            a[i]*=mul;
        }
        sum[i]=t[i]+a[i];
        mini=((mini-1)/sum[i]+1)*sum[i];
    }
    cout<<mini<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

const int DEBUG = 0;

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;

const int N = 2000;
bitset<N> a[N];
bitset<N> dp[N];

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  REP(i, 1, n) {
    string s;
    cin >> s;
    REP(j, 0, i) {
      a[i][j] = s[j] == '1';
      a[j][i] = s[j] == '0';
    }
  }
  if (DEBUG) {
    REP(i, 0, n) {
      cerr << "a[" << i << "]";
      REP(j, 0, n) {
        cerr << a[i][j];
      }
      cerr << endl;
    }
  }
  REP(i, 0, n) {
    dp[i][i] = true;
  }
  REP(s, 1, n) {
    REP(i, 0, n - s) {
      int j = i + s;
      bool res = ((dp[i] & dp[j - 1]) & a[j]).any();
      dp[i][j] =res;
      res = ((dp[i + 1] & dp[j]) & a[i]).any();
      dp[j][i] = res;
    }
  }
  int ans = 0;
  if (DEBUG) {
    REP(i, 0, n) {
      cerr << "dp[" << i << "]";
      REP(j, 0, n) {
        cerr << dp[i][j];
      }
      cerr << endl;
    }
  }
  REP(i, 0, n) {
    ans += dp[0][i] && dp[n - 1][i] ? 1 : 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1280
/*  
     author : masaow    
     g++ : 17.3.20  
*/        
#include <bits/stdc++.h>  
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(i,a,b)        for( i = a ; i < b  ; i++ )
#define debug(x)           cout << #x << " " << x << " -- "
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll                 long long  
#define p(x)               cout << x << "\n" ; 
#define MOD                100000007
#define pi                 pair<int,int>
#define vi                 vector <int>
#define pb                 push_back
#define vp                 vector <pair<ll,ll>>
#define endl               cout << "\n"
#define mi                 map <int,int> 
#define f1                 first 
#define s1                 second    
#define in                 insert
#define all(x)             x.begin(),x.end() 
using namespace std ; 
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set ; 
const int N = 2e5+7;  
/*  
    time : 10 : 14    
    date : 22.01.2020
*/    
// int L,R,mid,target,idx ;
int tests() 
{   int n,k;
     cin >> n >> k ; 
     cout << 100*max(0,(10-n))+k  ; 
    
    return 0 ; 
}
int main(){
    I__O ;  
    int cases = 1 ; 
    //cin >> cases;  
    while(cases--)
      tests(); 
  return 0 ; 
}

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

int main() {
	int h, w; cin >> h >> w;
	vector<vector<int>>magic(10, vector<int>(10));
	for (int i = 0; i <= 9; i++) {
		for (int j = 0; j <= 9; j++) {
			cin >> magic[i][j];
		}
	}
	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				magic[i][j] = min(magic[i][j], magic[i][k] + magic[k][j]);
			}
		}
	}

	long long ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int tmp; cin >> tmp;
			if (tmp == 1||tmp==-1)continue;
			ans += magic[tmp][1];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
import java.awt.*;
import java.awt.geom.*;
import java.io.*;

import java.util.*;
class Main {
	
	static int a;
	static int b;
	static int c;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int[] list = new int[n];
		for(int i = 0; i < n; i++) {
			list[i] = sc.nextInt();
		}
		Arrays.sort(list);
		int sumA = c;
		int sumB = a;
		double max = (double)sumA/sumB;
		
		for(int i = n-1; i >= 0; i--) {
			if((double)(sumA + list[i]) / (sumB + b) > max) {
				max = (double)(sumA + list[i]) / (sumB + b);
				sumA += list[i];
				sumB += b;
			}
			else {
				break;
			}
		}
		
		System.out.println((int)max);
		
	}
}

Measured memory_bytes: 18292
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, a, b) for(auto (i)=a;i<b;i++)
#define list(i, N) for(auto (i)=0;i<N;i++)

typedef long long ll;
typedef vector <ll> vi;
typedef pair <ll, ll> pi;
#define mp make_pair
#define pb push_back
#define eb emplace_back

#define int ll
#define INF 1e18+5
#define mod 1000000007

template<class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int highestPowerOf2(int n){
    return (n & (~(n - 1)));
}

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n; cin >> n;
    int ans = 0;
    while(n--){
        int a; cin >> a;
        while(a % 2 == 0) { a /= 2; ans++; }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<long long> a(n);
    for (int i = 0; i < n; i++) std::cin >> a[i];
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a[i] / 2;
        if (i < n - 1 && a[i] & 1 && a[i + 1] > 0) {
            ans++;
            a[i + 1]--;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}



Measured memory_bytes: 1024
#!/usr/bin/env python
# coding: utf-8

# In[16]:


N,K = map(int, input().split())
A = list(map(int, input().split()))


# In[49]:


low = 0
high = max(A)
def ok(x):
    cnt = 0
    for a in A:
        cnt += (a//x)
        if a%x == 0:
            cnt -= 1
    return cnt <= K
 
while high-low > 1:
    mid = (high+low)//2
    if ok(mid):
        high = mid
    else:
        low = mid
print(high)


# In[ ]:






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

#define M 1046527/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M/* your task */; }
int h2(int key){ return 1+(key%(M-1))/* your task */; }

int h(int key,int i){ return (h1(key)+i*h2(key))%M;}

int find(char str[]){
    /* your task */
    long long key,i=0,j;
    key=getKey(str);
    while(1){
        j=h(key,i);
        if(strcmp(H[j],str)==0){
            return 1;
        }else if(strlen(H[j])==0){
            return 0;
        }
        i++;
    }
}

int insert(char str[]){
    /* your task */
    long long key,i=0,j;
    key=getKey(str);
    while(1){
        j=h(key,i);
        if(strcmp(H[j],str)==0)
            return 1;
        else if(strlen(H[j])==0){
            strcpy(H[j],str);
            return 0;
        }
        i++;
    }
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 16100
#include <iostream>
using namespace std;
int main(void){
   int n,i;
   long long a[10001]={0}; //10001個
   cin >> n;
   for(i=0; i<n; i++){
      cin >> a[i];
   }
   long long min=1000000,max=-1000000,sum=0;
   for(i=0; i<n; i++){
      if(a[i]<min){
          min=a[i];
      }
      if(a[i]>max){
          max=a[i];
      }
      sum=sum+a[i];
   }
   cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3160
#include<cstdio>
#include<cstdlib>
#include<algorithm>

using namespace std;

int n,x,y,b,p;

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d%d%d",&x,&y,&b,&p);
		int res=11451419;
		for(int j=0;j<=1;j++){
			int cost=0;
			cost+=(x*5+y*2)*j*0.8;
			if(5*j<b && j==0)cost+=x*(b-5*j);
			if(2*j<p && j==0)cost+=y*(p-2*j);
			if(5*j<b && j==1)cost+=x*(b-5*j)*0.8;
			if(2*j<p && j==1)cost+=y*(p-2*j)*0.8;
			res=min(res,cost);
		}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 1032
# import itertools
# import math


def solve(S):
    alp = [chr(i) for i in range(97, 97+26)]
    index = alp.index(S) + 1
    if index == len(alp):
        index = 0
    return alp[index]


# N = int(input())
S = input()
# A, B = map(int, input().split())
# A = list(map(int, input().split()))

print(solve(S))


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

#define ll long long
const int inf = 1e9+7;
const ll INF = 1e18+7;

using namespace std;

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

  string s;
  cin>>s;
  int i = 0;
  for(int x :s){
    if(x == '+')
      ++i;
    else
      --i;
  }
  cout<<i<<"\n";
}


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

int main() {
  int n;
  cin >> n;
  vector<int> w(n);
  int sum=0;
  for(int i=0; i<n; i++){
    cin >> w.at(i);
    sum += w.at(i);
  }
  int ans=100000;
  int com=0;
  for(int i=0; i<n; i++){
    com += w.at(i);
    ans = min(ans, abs((sum - com) - com));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        N: usize,
      mut tmpAs: [i64; N],
    }

    // 隣接しているのは問題文の通りに処理できる
    // 隣接していなくてもいける??
    // A B C D
    // A B -C -D
    // A - B C -D
    // -A B C -D

    // つまり、適切に2個選んで符号を反転していくということか
    // 負の数を小さい順に処理していく
    // 負の数が0個になったら終わり
    // 負の数が1個だけ余ったら、最小の正の数と入れ替えて大きくなるなら実施して終了

    let mut As: Vec<i64> = Vec::new();
    for a in tmpAs.iter() {
        As.push(*a)
    }

    As.sort();

    let mut ans: i64 = As.iter().sum();
    for i in (0..N).step_by(2) {
        // 2個ずつでやっていると1個余るけど、この1個は使い途が無いのでは?
        if i == N - 1 {
            break;
        }

        let smaller = As[i];
        let bigger = As[i + 1];

        if smaller < 0 && bigger < 0 {
            ans += smaller.abs() * 2;
            ans += bigger.abs() * 2;
        } else if smaller < 0 && bigger >= 0 && smaller + bigger < 0 {
            ans += smaller.abs() * 2;
            ans -= bigger.abs() * 2;
        }
    }



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


Measured memory_bytes: 5104
def generate_range_combinations(n):
    C = [1] * n
    for i in range(2, n):
        C[i] = (C[i - 1] + C[i - 2]) % DIV
    return C


def solve(n, m, A):
    from collections import defaultdict

    if m == 0:
        C = generate_range_combinations(n + 1)
        return C[-1]

    D = defaultdict(lambda: 0)
    for i in range(m - 1):
        d = A[i + 1] - A[i] - 1
        if d == 0:
            return 0
        D[d] += 1
    D[A[0]] += 1
    D[n - A[-1]] += 1

    ans = 1
    C = generate_range_combinations(max(D.keys()))
    for k, v in D.items():
        ans *= C[k - 1] ** v
        ans %= DIV
    return ans


DIV = 1000000007
n, m = map(int, input().split())
A = [int(input()) for _ in range(m)]
print(solve(n, m, A))


Measured memory_bytes: 7284
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int x=stdIn.nextInt(),a=stdIn.nextInt(),b=stdIn.nextInt();
		if(b-a<1) System.out.print("delicious");
		else if(b-a<=x) System.out.print("safe");
		else System.out.print("dangerous");
	}
}

Measured memory_bytes: 20692
#include <cstdio>
#include <iostream>

using namespace std;

int INFTY_ALDS15B = 1000000001;
int cnt_ALDS15B = 0;

void merge(int A[], int left, int mid, int right) {

	int n1 = mid - left;
	int n2 = right - mid;

	int L[n1];
	int R[n2];

	for (int i = 0; i < n1; ++i) {
		L[i] = A[left + i];
	}
	for (int i = 0; i < n2; ++i) {
		R[i] = A[mid + i];
	}

	L[n1] = INFTY_ALDS15B;
	R[n2] = INFTY_ALDS15B;

	int i = 0;
	int j = 0;

	for (int k = left; k < right; ++k) {
		cnt_ALDS15B++;
		if (L[i] <= R[j]) {
			A[k] = L[i++];
		} else {
			A[k] = R[j++];
		}
	}

}

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

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

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

	mergeSort(A, 0, n);

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

		if (i != 0) {
			cout << " ";
		}
		cout << A[i];
	}
	cout << endl;
	cout << cnt_ALDS15B << endl;
	return 0;
}

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

int main(){
string a,b;
  cin>>a>>b;
  int X=stoi(a+b);// stoiはstring型をint型に変更できる関数
  
  bool ans=false;
  for(int i=0; i<=1000; i++){ //最大値100100を平方数でカバーするには、i<=1000にする必要がある
   if(X==i*i){ans=true;}
  }
  if(ans){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}

Measured memory_bytes: 256
# EduDPB - Frog 2
import sys
input = sys.stdin.readline

n, k = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
ans = [0] + [float("inf")] * (n - 1)
for i in range(n):
    for j in range(1, k + 1):
        if i + j >= n:
            break
        ans[i + j] = min(ans[i + j], ans[i] + abs(lst[i] - lst[i + j]))
print(ans[-1])


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

ll dp[10][100];

int main() {
    ll K;
    cin >> K;


    ll tmp;
    queue<ll> que;

    for (ll i = 1; i < 10; ++i) {
        que.emplace(i);
    }
    for (int i = 0; i < K; ++i) {
        tmp = que.front();
        que.pop();

        if (tmp % 10 != 0)
        {
            que.emplace(10 * tmp + tmp % 10 - 1);
        }

        que.emplace(10 * tmp + tmp % 10);

        if (tmp % 10 != 9) {
            que.emplace(10 * tmp + tmp % 10 + 1);
        }
    }

    cout << tmp << endl;
}

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

int main(){
    ll n;
    cin>>n;
    vector<ll> num(100000);
    rep(i,n){
        ll a;
        cin>>a;
        num[a]++;
    }
    ll ans=0;
    rep(i,num.size()-1){
        ll tmp=num[i]+num[i+1]+num[i+2];
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORD(i, m, n) for (int i = m; i >= n; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 0; i <= n; ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using ll = long long;
using ull = unsigned long long;
using ld = long double;

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

	double d, t, s;
	cin >> d >> t >> s;
	if (d / s <= t)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define INF 1e18
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    string S;
    cin >> S;
    int N = S.length();
    vector<int> ans(N);
    char now = 'R';
    int tmp = 0;
    int l_index = 0;
    REP(i, N) {
        if (now == S[i]) {
            tmp += 1;
        } else {
            if (now == 'R') {
                int odd = tmp / 2;
                ans.at(i-1) += tmp - odd; // R
                ans.at(i)+= odd; // L
                now = 'L';
                tmp = 1;
                l_index = i;
            } else {
                int even = tmp / 2;
                ans.at(l_index) += tmp - even; // L
                ans.at(l_index-1) += even; // R
                now = 'R';
                tmp = 1;
            }
        }
        // finally
        if (i==N-1) {
            int even = tmp / 2;
            ans.at(l_index) += tmp - even;
            ans.at(l_index-1) += even;
        }

    }
    REP(i, N) {
        cout << ans.at(i);
        if (i==N-1) {
            cout << endl;
        } else {
            cout << " ";
        }
    }


}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 1024
import scala.io.StdIn._
object Main extends App {
  val Array(a, b, c, x, y) = readLine.split(" ").map(_.toInt)
  println((0 to math.max(x, y)).map { i =>
    math.max(0, x - i) * a + math.max(0, y - i) * b + 2 * c * i
  }.min)
}


Measured memory_bytes: 30400
#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);

	ll n;
	cin >> n;

	ll ans=LLONG_MAX;
	ll flag=0;
	for (ll i=1;i<=sqrt(n)+1;i++)
	{
		if (n%i==0)
		{
			flag++;
			ll local=i+(n/i);
			ans=min(ans,local);
		}
	}

	if (flag==1)
	{
		cout << n-1 << endl;
	}
	else
	{
		cout << ans-2 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
///-----Bismillahir Rahmanir Rahim-----///

#include<bits/stdc++.h>
using namespace std;

///---FAST I/O---///
#define Boost() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

///---DATA TYPE---///
typedef long long ll;
typedef long long int lli;
///vector
typedef vector<int> vi;
typedef vector<ll> vl;
///pair
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;

///---LOOP---///
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)

///---I/O---///
#define sf scanf
#define pf printf

///---OTHERS---///
#define pb push_back
#define all(c)		c.begin(),c.end()
#define MK make_pair
#define F first
#define S second
#define endl '\n'


///---INITIALIZATION---//
#define mem(a,b) memset(a, b, sizeof(a) )

///---CALCULATE---///
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

///---BIT OPERATION---///
inline bool checkBit(ll n, int i) { return n&(1LL<<i); }
inline ll setBit(ll n, int i) { return n|(1LL<<i);; }
inline ll resetBit(ll n, int i) { return n&(~(1LL<<i)); }

///---CONSTANT---///
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

int main()
{
    Boost();

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        int x,n;
        cin>>x>>n;
        int p[n+5];
        int left=x,right=x;
        map<int,int>cnt;
        for(int i=0;i<n;i++)
        {
           cin>>p[i];
           cnt[p[i]]=1;
        }
        for(int i=0;i<n;i++)
        {
            if(cnt[left]==1)
            {
                while(cnt[left]==1)
                {
                    left--;
                }
            }
            if(cnt[right]==1)
            {
                while(cnt[right]==1)
                {
                    right++;
                }
            }
        }
        if(abs(x-left)>abs(right-x)) cout<<right<<endl;
        else cout<<left<<endl;

    }
    return 0;
}



Measured memory_bytes: 3660
#include <stdio.h>
int t[55],y[55],n,x,z,i;
int main(void){
	for(;n-2||!z++;){
		for(i=1;i<2||getchar()==',';scanf("%d",y+i++));
		if(i>n)
			for(n=i;--i;t[i]=y[i]+t[t[i]>t[i-1]?i:i-1]);
		else
			for(n=i,i=0;i++<n;t[i]=y[i]+t[t[i]>t[i+1]?i:i+1]);
	}
	printf("%d\n",t[1]);
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>  
#include<cstring>  
#include<algorithm>  
#include<iostream>  
#include<string>  
#include<vector>  
#include<stack>  
#include<bitset>  
#include<cstdlib>  
#include<cmath>  
#include<set>  
#include<list>  
#include<deque>  
#include<map>  
#include<queue>
using namespace std;
typedef long long ll;
const ll inf=1<<29;
const ll Maxn=1e6;

ll a[Maxn],b[Maxn],c[Maxn];

int main(){
	ll n,x,y;
	ll mid=0;
	cin>>n;
	a[0]=b[n+1]=0;
	for(int i=1;i<=n;i++){
		cin>>x;
		a[i]=a[i-1]+x;
	}
	for(int i=1;i<=n;i++){
		scanf("%lld",&c[i]);
	}
	for(int i=n;i>=1;i--){
		b[i]=b[i+1]+c[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			mid=max(mid,a[i]+b[j]);
		}
	}
	printf("%lld\n",mid);
}

Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
int main() {
	char s[11];
	int sum = 0;
	while(~scanf("%s", s)) {
		sum = 0;
	for(int i = 0; s[i] != '\0'; i++) {
		if(s[i] == '2') sum++;
	}
	printf("%d\n", sum);
	}
	return 0;
}


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

int main() {
  //数の入力
  int N;
  cin >> N;
  vector<int> levels(3 * N);
  for (int i = 0; i < 3 * N; i++) {
    cin >> levels.at(i);
  }
  
  //大きい順に並べ替える
  sort(levels.begin(), levels.end());
  reverse(levels.begin(), levels.end());
  
  //2番目に来て最大値を取るやつを選ぶ
  long long int maxsum = 0;
  for (int i = 0; i < 2 * N; i++) {
    if (i % 2 == 1) {
      maxsum += levels.at(i);
    }
  }
  
  cout << maxsum << endl;
  
}

Measured memory_bytes: 1408
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
xy = [[] for i in range(n)]
for i in range(n):
    for j in range(inp()):
        a,b = inpl()
        xy[i].append([a,b])
# print(xy)
res = 0
for flag in itertools.product([0,1],repeat=n):
    cnt = 0
    theory = [-1]*n #-1:決まってない 0:不明 1:正直
    f = True
    for i,j in enumerate(flag):
        if theory[i] == -1:
            theory[i] = j
        elif theory[i] != j:
            f = False
            break
        if not j:
            continue
        cnt += 1
        for k in xy[i]:
            if theory[k[0]-1] == -1:
                theory[k[0]-1] = k[1]
            elif theory[k[0]-1] != k[1]:
                f = False
                break
        if not f:
            break
    if not f:
        continue
    res = max(res,cnt)
print(res)

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


    


int main(){

    ll n;
    cin >> n;

    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= n; ++a) {
        if (n % a != 0) continue;
        long long ex = 0; 

        while (n % a == 0) {
            ++ex;
            n /= a;
        }

        res.push_back({a, ex});
    }
    if (n != 1) res.push_back({n, 1});

    ll ans = 0;
    for(auto p : res){
        int i = 1;
        while(1){
            p.second -= i;
            if(p.second >0){
                ans ++;
            }else if(p.second == 0){
                ans++;
                break;
            }else{
                break;
            }
            i++;
        }

    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

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

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int N;
    std::cin >> N;

    for(int i=0;i<N;++i){
        string order;
        std::cin >> order;

        reverse(order.begin(), order.end());
    
        string message;
        std::cin >> message;

        for(const char& c : order){
            if(c == 'J'){
                string newMessage = *message.rbegin() + message.substr(0, message.size() - 1);
                message = newMessage;
            }else if(c == 'C'){
                string newMessage = message.substr(1, message.size() - 1) + message[0];
                message = newMessage;            
            }else if(c == 'E'){
                int half = message.size() / 2;
                string left = message.substr(0, half),
                    right = message.substr(message.size() - half, half);
                if(message.size() % 2 == 0){
                    message = right + left;
                }else{
                    message = right + message[half] + left;
                }
            }else if(c == 'A'){
                reverse(message.begin(), message.end());
            }else if(c == 'P'){
                for(auto &c : message){
                    if(isdigit(c)){
                        c = '0' + (c - '0' + 10 - 1) % 10;
                    }
                }
            }else if(c == 'M'){
                for(auto &c : message){
                    if(isdigit(c)){
                        c = '0' + (c - '0' + 1) % 10;
                    }
                }
            }else{
                assert(false);
            }
        }

        std::cout << message << std::endl;
    }
}



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

int n;
int is_allowed = 1;
string message;
int main() {
  cin >> n;
  std::vector<int> A(n);
  for (size_t i = 0; i < n; i++) {
    cin >> A.at(i);
  }
  for (size_t i = 0; i < n; i++) {
    if (A.at(i) % 2 == 0) {
      if (not (A.at(i) % 3 == 0 or A.at(i) % 5 == 0)) {
        is_allowed = 0;
        break;
      }
    }
  }
  if (is_allowed == 0) {
    message = "DENIED";
  }else{
    message = "APPROVED";
  }
  cout << message << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int num = 30;
  
  int A;
  for (int i = 0; i < N; i++) {
    int log = 0;
    cin >> A;
	while (A % 2 == 0) {
      A /= 2;
      log++;
    }
    
    if (log < num) {
      num = log;
    }
  }
  
  cout << num;
}

Measured memory_bytes: 256
n = int(input())
X = list(map(int, input().split()))

mod = 10 ** 9 + 7

ans = 1
now = 0
for cnt in range(n):
    while now < n and X[now] >= 2 * (now - cnt) + 1: now += 1
    ans *= (min(now+1, n) - cnt)
    if ans >= mod:ans %= mod
print(ans)


Measured memory_bytes: 20728
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemB
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var N = read[0];
            var L = read[1];
            var tastes = new int[N];
            for (int i = 0; i < N; i++)
            {
                tastes[i] = L + i;
            }
            var minAbs = tastes.Max() < 0 ? -tastes.Select(x => Math.Abs(x)).Min() : tastes.Select(x => Math.Abs(x)).Min();
            Console.WriteLine(tastes.Sum() - minAbs);
        }
    }
}


Measured memory_bytes: 13396
import java.util.Scanner;

public class Main {
	private static Scanner sc;
	public static void main(String[] args){
		sc=new Scanner(System.in);
		int n=sc.nextInt();
		int lcm=sc.nextInt();
		for(int i=2;i<=n;i++){
			int a_i=sc.nextInt();
			lcm=getLCM(lcm,a_i);
		}
		System.out.println(lcm);
	}
	static int getGCD(int a,int b){
		if(b>a){
			int tmp=a;
			a=b;
			b=tmp;
		}
		while(b!=0){
			int tmp=b;
			b=a%b;
			a=tmp;
		}
		return a;
	}
	static int getLCM(int a,int b){
		return a/getGCD(a,b)*b;
	}
}

Measured memory_bytes: 26368
#include <cstdio>

using namespace std;

int main()
{
	int c[3];
	int cnt;
	int i;
	
	while (scanf("%d %d %d", &c[0], &c[1], &c[2]) != EOF){
		cnt = 0;
		for (i = 1; i <= 10; i++){
			if (i != c[0] && i != c[1] && i != c[2]){
				if (c[0] + c[1] + i <= 20){
					cnt++;
				}
			}
		}
		
		if (cnt > 3){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
	
	return (0);
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int a[110],b[110];
int br[110];
bool used[110];
vint G[110];

int dfs(int x,int cc){
  used[x]=true;
  int cb=0,ret=cc;
  for(int i=0;i<G[x].size();i++){
    if(used[G[x][i]])continue;
    cb++;
    ret=max(ret,dfs(G[x][i],cc+1));
  }
  br[cc]=max(br[cc],cb);
  return ret;
}

signed main() {
  cin >> N;
  for(int i=0;i<N-1;i++){
    cin>>a[i]>>b[i];
    a[i]--,b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }
  int color=LLONG_MAX,leaf=LLONG_MAX;
  for(int i=0;i<N;i++){
    fill(br,br+N,1);
    fill(used,used+N,false);
    int cc=dfs(i,1),cl=1;
    for(int k=1;k<N;k++)cl*=br[k];
    if(cc<color||cc==color&&cl<leaf)color=cc,leaf=cl;
  }
  for(int i=0;i<N-1;i++){
    fill(br,br+N,1);
    fill(used,used+N,false);
    used[a[i]]=true;
    int cc=dfs(b[i],1),cl=2;
    used[a[i]]=false;
    cc=max(cc,dfs(a[i],1));
    for(int k=1;k<N;k++)cl*=br[k];
    if(cc<color||cc==color&&cl<leaf)color=cc,leaf=cl;
  }
  cout<<color<<" "<<leaf<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    string s;
    while(getline(cin,s)){
        s += " ";
        stack<double> st;
        int num = 0;
        bool c = false;
        rep(i,s.size()){
            if(s[i] == '-' && isdigit(s[i+1])){
                c = true;
            }else if(isdigit(s[i])){
                num *= 10;
                num += s[i]-'0';
            }else if(s[i] == ' '){
                i--;
                if(isdigit(s[i])){
                    if(c)num = -num;
                    //cout << " " << num << endl;
                    st.push(num);
                    num = 0;
                    c = false;
                }else{
                    double a = st.top();
                    st.pop();
                    double b = st.top();
                    st.pop();
                    if(s[i] == '+')st.push(b+a);
                    if(s[i] == '-')st.push(b-a);
                    if(s[i] == '*')st.push(b*a);
                    if(s[i] == '/')st.push(b/a);
                }
                i++;
                //cout << st.top() << endl;
            }
        }
        cout << shosu(10) << st.top() << endl;
    }

}



Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define int long long
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
using namespace std;
static const int INF = 1ll<<60;
typedef pair<int,int> pii;

int W,H;
int N;
int dis[100010];
vector<int> posx;
vector<int> posy;
vector<pii> pos;

int dist(int x,int y){
    memset(dis,0,sizeof(dis));
    int res=0;
    for(int i=0;i<N;++i){
        int disx=abs(x-pos[i].FI);
        int disy=abs(y-pos[i].SE);
        dis[i]=disx+disy;
    }
    sort(dis,dis+N);
    for(int i=0;i<N-1;++i)res+=dis[i]*2;
    res+=dis[N-1];
    return res;
}

signed main(){
    cin>>W>>H;
    cin>>N;
    for(int i=0;i<N;++i){
        int x,y;
        cin>>x>>y;
        posx.PB(x);
        posy.PB(y);
        pos.PB(pii(x,y));
    }
    if(N%2!=0){
        sort(posx.begin(),posx.end());
        sort(posy.begin(),posy.end());
        int x=posx[N/2];
        int y=posy[N/2];
        int ans=dist(x,y);
        cout<<ans<<endl;
        cout<<x<<" "<<y<<endl;
    }
    else{
        sort(posx.begin(),posx.end());
        sort(posy.begin(),posy.end());
        int ans=INF;
        int x,y;
        int d1=dist(posx[N/2-1],posy[N/2-1]);
        int d2=dist(posx[N/2-1],posy[N/2]);
        int d3=dist(posx[N/2],posy[N/2-1]);
        int d4=dist(posx[N/2],posy[N/2]);
        if(ans>d1){
            ans=d1;
            x=posx[N/2-1];
            y=posy[N/2-1];
        }
        if(ans>d2){
            ans=d2;
            x=posx[N/2-1];
            y=posy[N/2];
        }
        if(ans>d3){
            ans=d3;
            x=posx[N/2];
            y=posy[N/2-1];
        }
        if(ans>d4){
            ans=d4;
            x=posx[N/2];
            y=posy[N/2];
        }
        cout<<ans<<endl;
        cout<<x<<" "<<y<<endl;
    }
}

Measured memory_bytes: 5324
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  int n, k;
  cin >> n >> k;
  vector<ll> x(n);
  int Mid = -1;
  rep(i, n)
  {
    cin >> x[i];
    if (x[i] >= 0 && Mid == -1)
    {
      Mid = i;
    }
  }
  if (Mid == -1)
    Mid = n;

  ll Min = LINF;
  dbg(Mid);
  rep(t, k)
  {
    int i = Mid + t;
    int j = Mid - (k - t - 1);
    dbg(i);
    dbg(j);
    if (i >= n || j < 0)
      continue;
    Min = min(Min, x[i] * 2 + abs(x[j]));
    Min = min(Min, abs(x[j]) * 2 + x[i]);
  }
  if (Mid + k - 1 < n)
    Min = min(Min, x[Mid + k - 1]);
  if (Mid - k >= 0)
    Min = min(Min, -x[Mid - k]);
  cout << Min << endl;
  return 0;
}


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

const int mod=1e9+7;

int main()
{
	//#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	//#endif
	int k;
	cin>>k;
	string s;
	cin>>s;
	if((int)s.length()<=k)
		cout<<s<<'\n';
	else
	{
		cout<<s.substr(0,k)<<"...\n";
		
	}	
	return 0;
}


Measured memory_bytes: 3620
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        N: i64,
        A: i64,
        B: i64,
    }

    let n = N / (A + B);
    let rest = N % (A + B);
    let ans = A * n + std::cmp::min(rest, A);
    println!("{}", ans);
}


Measured memory_bytes: 2140
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
string s;
bool vis[26];
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		vis[s[i]-'a']=1;
	}
	for(int i=0;i<26;i++){
		if(vis[i]==0){
			cout<<(char)(i+'a');
			return 0;
		}
	}
	cout<<"None";
	return 0;
}

Measured memory_bytes: 512
from collections import defaultdict

h, w = map(int, input().split())
dd = defaultdict(int)
for _ in range(h):
    string = input()
    for s in string:
        dd[s] += 1
        
one = 0
two = 0
for _, value in dd.items():
    if value % 2 == 1:
        one += 1
        value -= 1
    if value % 4 == 2:
        two += 1
        
if h % 2 == 0 and w % 2 == 0:
    if one == two == 0:
        print("Yes")
    else:
        print("No")
elif h % 2 == 1 and w % 2 == 1:
    if one > 1:
        print("No")
    elif two > h // 2 + w // 2:
        print("No")
    else:
        print("Yes")
else:
    if h % 2 == 0:
        tmp = h // 2
    else:
        tmp = w // 2
    if one > 0:
        print("No")
    elif two > tmp:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 67848
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

bool isPrime(int a)
{
  if (a % 2 == 0 && a != 2)
    return false;
  for (int i = 3; i * i <= a; i += 2)
    if (a % i == 0)
      return false;

  return true;
}

int main()
{
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    int a;
    cin >> a;
    if (isPrime(a))
      cnt++;
  }
  cout << cnt << endl;

  return 0;
}



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

int main() {
    int h, w,cnt = 0;
    cin >> h >> w;
    rep(i,h){
        string s;
        cin >> s;
        rep(j,w) if(s[j]=='#') cnt++;
    }
    if(cnt==(h+w-1)) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		queue<int> q;
		rep(i,n){
			q.push(i);
		}
		rep(i,m){
			if(q.size()==1){
				reep(j,i,m){
					string t;
					cin>>t;
				}
				break;
			}
			int fr=q.front();
			q.pop();
			string s;
			cin>>s;
			if((i+1)%15==0){
				if(s!="FizzBuzz"){

				}
				else{
					q.push(fr);
				}
			}
			else if((i+1)%5==0){
				if(s!="Buzz"){

				}
				else{
					q.push(fr);
				}
			}
			else if((i+1)%3==0){
				if(s!="Fizz"){

				}
				else{
					q.push(fr);
				}
			}
			else{
				stringstream ss;
				ss<<s;
				int tt;
				ss>>tt;
				if(i+1==tt){
					q.push(fr);
				}
				else{

				}
			}
		}
		vint v;
		while(!q.empty()){
			v.PB(q.front());
			q.pop();
		}
		sort(ALL(v));
		rep(i,v.size()){
			if(i) cout<<" ";
			cout<<v[i]+1;
		}
		cout<<endl;
	}
}

Measured memory_bytes: 1264
#include<cstdio>
using namespace std;
const int MAX = 100000 + 10;
int n;
char arr[MAX];
char ans[MAX];
bool check() {
    for(int i = 0 ; i < n ; i++) {
        int l = (i+n-1) % n;
        int r = (i+1) % n;
        if(ans[i] == 'S') {
            if(arr[i] == 'o' && ans[l] != ans[r]) return false;
            else if(arr[i] == 'x' && ans[l] == ans[r]) return false;
        } else {
            if(arr[i] == 'o' && ans[l] == ans[r]) return false;
            else if(arr[i] == 'x' && ans[l] != ans[r]) return false;
        }
    }
    return true;
}
bool test(char a, char b) {
    ans[0] = a;
    ans[1] = b;
    for(int i = 1 ; i < n ; i++) {
        int next = (i+1) % n;
        if(ans[i] == 'S') {
            if(arr[i] == 'o') {
                ans[next] = ans[i-1];
            } else {
                if(ans[i-1] == 'S') ans[next] = 'W';
                else ans[next] = 'S';
            }
        } else {
            if(arr[i] == 'x') {
                ans[next] = ans[i-1];
            } else {
                if(ans[i-1] == 'S') ans[next] = 'W';
                else ans[next] = 'S';
            }
        }
    }
    if(check()) {
        puts(ans);
        return true;
    }
    return false;
}
int main() {
    scanf("%d", &n);    
    scanf("%s", arr);
    if(test('S', 'S')) return 0;
    if(test('S', 'W')) return 0;
    if(test('W', 'S')) return 0;
    if(test('W', 'W')) return 0;
    puts("-1");
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(ll i = 0; i < (ll)(n); ++i)
#define MOD 1000000007

using namespace std;
using ll = long long;

int main() {
	int h, a, eh, ea;
	string ans = "Yes";
	cin >> h >> a >> eh >> ea;
	int x, y;
	x = (h + ea - 1) / ea;
	y = (eh + a - 1) / a;
	if (x < y) ans = "No";
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
#define N 100050
#define M 605
int n,d1,d2,head[N],cnt,col[M][M],col2[M][M],vis[M][M],ct,s1[N][2];
queue<int> tp;
void bfs(int x,int y)
{
	vis[x][y]=1;
	tp.push(x*1000+y);
	while(!tp.empty())
	{
		int s=tp.front()/1000,t=tp.front()%1000;tp.pop();
		for(int i=0;i<=ct;i++)
		for(int j=s-s1[i][0];j<=s+s1[i][0];j+=s1[i][0]*2)
		{
			for(int k=t-s1[i][1];k<=t+s1[i][1];k+=s1[i][1]*2)
			{
				if(j>=1&&j<=n&&k>=1&&k<=n&&!vis[j][k])vis[j][k]=1,col[j][k]=col[s][t]^1,tp.push(j*1000+k);
				if(!s1[i][1])break;
			}
			if(!s1[i][0])break;
		}
	}
}
int main()
{
	scanf("%d%d%d",&n,&d1,&d2);n*=2;
	ct=0;for(int i=0;i<=n;i++)if(d1>=i*i){int tp=sqrt(d1-i*i);if(i*i+tp*tp==d1)s1[++ct][0]=i,s1[ct][1]=tp;}
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(!vis[i][j])bfs(i,j);
	int tp=0;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)tp+=col[i][j]?-1:1;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)col2[i][j]=col[i][j]^(tp>=0),vis[i][j]=0,col[i][j]=0;
	ct=0;for(int i=0;i<=n;i++)if(d2>=i*i){int tp=sqrt(d2-i*i);if(i*i+tp*tp==d2)s1[++ct][0]=i,s1[ct][1]=tp;}
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(!vis[i][j])bfs(i,j);
	tp=0;for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)tp+=col[i][j]?-1:1;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)col[i][j]=col[i][j]^(tp>=0);
	int ct=0;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(ct<n*n/4&&col[i][j]==1&&col2[i][j]==1)printf("%d %d\n",i-1,j-1),ct++;
}

Measured memory_bytes: 5376
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;

int main()
{
    string s;
    string r;
    string t;
    cin>>s>>r>>t;
    cout<<s[0]<<r[1]<<t[2];
system("pause");
return 0;
}

Measured memory_bytes: 504
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep3(i, l, r) for (ll i = (ll)(l); i < (ll)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

int main() {
    ll n, x, m;
    cin >> n >> x >> m;
    
    vector<ll> vec;
    vec.push_back(x);
    vector<ll> idx(m, -1);
    idx[x] = 0;
    ll ans = x;
    rep(i, 1, n) {
        ll y = vec[i - 1] * vec[i - 1] % m;
        if (ll a = idx[y]; a != -1) {
            ll nokori = n - i;
            ll shuki = i - a;
            ll shuki_sum = 0;
            rep(j, shuki) shuki_sum += vec[a + j];
            ans += nokori / shuki * shuki_sum;
            nokori %= shuki;
            rep(j, nokori) ans += vec[a + j];
            cout << ans << "\n";
            return 0;
        }
        vec.push_back(y);
        idx[y] = i;
        ans += y;
    }
    
    cout << ans << "\n";
}


Measured memory_bytes: 4640
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;
typedef tuple<int, int, int> TI;

int main()
{
    int N;
    cin >> N;
    char siri;
    bool res = true;
    set<string> set;
    rep0(i, N)
    {
        string input;
        cin >> input;
        set.insert(input);
        if (i == 0)
        {
            siri = input[0];
        }
        if (siri != input[0])
        {
            res = false;
            break;
        }
        siri = input[input.length() - 1];
    }
    if (res && set.size() == N)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3568
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int N;
	string c;
	cin >> N >> c;
	vector<int> w;
	vector<int> r;
	for(int i = 0; i < N; i++){
		if(c[i] == 'W'){
			w.push_back(i);
		}
	}
	for(int i = N-1; i >= 0; i--){
		if(c[i] == 'R'){
			r.push_back(i);
		}
	}
	
	int ans = 0;
	for(int i = 0; i < r.size() && i < w.size(); i++){
		if(w[i] <= r[i]){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4540