akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let k:usize = read();
    let a:usize = read();
    let b:usize = read();
    let mut bis = 1;
    let mut mon = 0;

    if b <= 1 || b <= a + 2 {
        println!("{}", bis + k);
        return
    }

    for i in 0..k {
        if mon > 0 {
            mon -= 1;
            bis += b;
        } else if bis >= a && k - i >= 2 {
            bis -= a;
            mon += 1;
        } else {
            bis += 1;
        }
    }
    println!("{}", bis);
}


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

int gcd(int a, int b) {
	int tmp,r;
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int main() {
	int N,X,tmp;
	cin >> N >> X;
	int x[N];
	for (int i = 0; i < N; i++) {
		cin >> x[i];
	}

	sort(x, x + N);
	int y[N];
	for (int i = 0; i < N; i++) {
		y[i] = abs(X - x[i]);
	}
	tmp = y[0];
	for (int i = 0; i < N; i++) {
		tmp = gcd(y[i], tmp);
	}
	cout << tmp;

	return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    s = [x for x in input()]
    n = int(''.join(s))
    k = len(s)
    a = s[0] + '9' * (k - 1)
    b = int(a)
    a = [int(x) for x in a]
    if b > n:
        a[0] -= 1
    print(sum(a))


t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""


"""


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
const int V=100005;
vl to[2*V];
bool visited[2*V];
vl cnt;
void dfs(ll now,ll last=-1){
    if(visited[now])return;
    visited[now]=true;
    cnt[now/V]++;
    for(auto nxt:to[now]){
        if(last==nxt)continue;
        dfs(nxt,now);
    }
    return;
}
int main(){
    ll n;cin>>n;
    rep(i,n){
        ll x,y;cin>>x>>y;
        y+=V;
        to[x].push_back(y);
        to[y].push_back(x);
    }
    ll ans=0;
    rep(i,2*V){
        if(visited[i])continue;
        cnt=vl(2);
        dfs(i);
        ans+=cnt[0]*cnt[1];
    }
    ans-=n;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11136
from bisect import bisect,bisect_left

N = int(input())
L = list(map(int,input().split()))
L.sort()

ans = 0
for i in range(N-2):
    a = L[i]
    for j in range(i+1,N-1):
        b = L[j]
        k = bisect_left(L,a+b)
        ans += k-j-1
print(ans)

Measured memory_bytes: 3188
N = int(input())
a = [i for i in map(int,input().split())]
ball = [0 for i in range(N)]

a = [0]+a
ball = [0]+ball

for i in range(N,0,-1):
  num = 0
  for j in range(i,N+1,i):
    num += ball[j]
  if num%2 != a[i]:
    ball[i] += 1
    
print(sum([1 for i in range(len(ball)) if ball[i]]))
num_list = []
for i in range(1,len(ball)):
  if ball[i]:
    num_list.append(i)
    
print(*num_list)

Measured memory_bytes: 14252
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <functional>
#define fs first
#define se second

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<ld, ld> pdd;

char in[100001];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> in;
    int n = strlen(in);
    for (int i = n + 2 >> 1; ; ++i) {
        if (i > n || in[n >> 1] != in[i - 1] || in[n >> 1] != in[n - i]) {
            printf("%d\n", i - 1);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 384
class cumulative_sum:
    def __init__(self,A):
        N = len(A)
        self.S = [0]*(N+1)
        for i in range(N):
            self.S[i+1] = self.S[i] + A[i]
    def get(self,i,j=None):
        if j==None:j=len(self.S)-1
        if j<=i:return 0
        return self.S[j]-self.S[i]
def main():
    N,K = map(int,input().split())
    *A, = map(int,input().split())
    SA = cumulative_sum(A)
    B = {}

    for i in range(N):
        for j in range(i+1,N+1):
            s = SA.get(i,j)
            B[s] = B.get(s,0)+1

    ans = 0
    for i in range(40,-1,-1):
        x = ans + (1<<i)
        c = sum(n for b,n in B.items() if b&x==x)
        if c>=K:ans = x
    print(ans)
main()

Measured memory_bytes: 89448
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	for(;;){
		int a,b,c,s;
		cin>>a>>b>>c;
		if(a == -1 && b == -1 && c == -1){break;}
		s = a*3600+b*60+c;
		s = 2*60*60-s;
		printf("%02d:%02d:%02d\n",s/3600,(s%3600)/60,s%60);
		s*=3;
		printf("%02d:%02d:%02d\n",s/3600,(s%3600)/60,s%60);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <set>
using namespace std;
int main(){
    int N;
    cin >> N;
    set<int> A;
    for(int i=0; i<N; i++){
        int input;
        cin >> input;
        auto r = A.insert(input);
        //cout << r.second << endl;
        if(!r.second){
            A.erase(input);
        }
    }
    cout << A.size() << endl;
    return 0;
}

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

    
using namespace std;

signed main()
{	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int test=1;
    //cin>>test;
    while(test--){
        string s,t,u;
        int a,b;
        cin>>s>>t>>a>>b>>u;
        if(u==s) cout<<a-1<<" "<<b<<"\n";
        else cout<<a<<" "<<b-1<<"\n";
    }
    return 0;
}       

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Replacing Integer
 */

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

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

int main() {
  ll n, k;
  scanf("%lld%lld", &n, &k);

  if (n > k) n %= k;
  while (n * 2 > k) n = abs(n - k);
  printf("%lld\n", n);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int heya[4][3][10] = {0};
	int n;
	int b,f,r,v;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> b >> f >> r >> v;
		heya[b-1][f-1][r-1] += v;
	}
	for (int i = 0; i < 4; i++) {
		if (i != 0) {
			cout << "####################" << endl;
		}
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				cout << ' ' << heya[i][j][k] << flush;
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1164
f=lambda:map(int,input().split())
n,k,l=f()
def root(x):
  while p[x]>=0: x=p[x]
  return x
def unite(x,y):
  x,y=root(x),root(y)
  if x==y: return
  if x>y: x,y=y,x
  p[x]+=p[y]
  p[y]=x
def same(x,y):
  return root(x)==root(y)
def size(x):
  return -p[root(x)]
def root_all(x):
  global p
  p=[-1]*n
  for _ in range(x):
    a,b=f()
    unite(a-1,b-1)
  return [root(i) for i in range(n)]
H,R=root_all(k),root_all(l)
from collections import *
z=[*zip(H,R)]
C=Counter(z)
print(*[C[t] for t in z])

Measured memory_bytes: 56672
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

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

    int n;cin>>n;
    vector<pair<ll,ll>> v(n);
    rep(i,n){
        cin>>v[i].first>>v[i].second;
    }
    sort(ALL(v));
    ll pos=-LINF;
    int ans=0;
    rep(i,n){
        if(pos<=v[i].first-v[i].second){
            pos=v[i].first+v[i].second;
            ans++;
        }else{
            chmin(pos,v[i].first+v[i].second);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)

typedef long long ll;

int a[50][50], b[2][50][50];
int w,h,k;
int dx[4]={1,-1,0,0} , dy[4]={0,0,1,-1};

bool isok(int i,int j){
    return i>=0 && i<h && j>=0 && j<w;
}

void dfs(int i,int j){
    if (!a[i][j])
        b[k-1][i][j] = 1;
    REP(s,4){
        int ii=i+dx[s] , jj=j+dy[s];
        if (isok(ii,jj) && !b[k-1][ii][jj] && !a[ii][jj]){
            dfs(ii,jj);
        }
    }
}

int main(void) {
    while (cin>>w>>h && w){
        REP(i,h){
            REP(j,w){
                char c;
                cin >> c;
                if (c=='B')
                    a[i][j] = 1;
                else if (c=='W')
                    a[i][j] = 2;
                else
                    a[i][j] = 0;
                b[0][i][j] = 0;
                b[1][i][j] = 0;
            }
        }
        k=1;
        REP(i,h){
            REP(j,w){
                if (a[i][j]==1)
                    dfs(i,j);
            }
        }
        k=2;
        REP(i,h){
            REP(j,w){
                if (a[i][j]==2)
                    dfs(i,j);
            }
        }
        int bl = 0 , wh = 0;
        REP(i,h){
            REP(j,w){
                bl += (b[0][i][j] && !b[1][i][j]);
                wh += (b[1][i][j] && !b[0][i][j]);
            }
        }

        cout << bl << " " << wh << endl;

    }
    
    
    return 0;
}

Measured memory_bytes: 1220
public class Main {

  private static void solve() {
    char[] c = ns();
    for (char d : c) {
      if (d == '7') {
        System.out.println("Yes");
        return;
      }
    }
    System.out.println("No");

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 36704
N = int(input())
A = list(map(int,input().split()))
cnt1 = 0
cnt2 = 0
for i in A:
    if i % 2 == 1:
        cnt1 += 1
    elif i % 4 == 0:
        cnt2 += 1
if cnt1 + cnt2 == N:
    if cnt1 - 1 <= cnt2:
        print('Yes')
    else:
        print('No')
else:
    if cnt1 <= cnt2:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(args...) do { cout << "\033[32;1m" << #args << " -> "; err(args); } while (0)
#else
#define dbg(...)
#endif
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); }
template<typename T, typename... Args>
void err(T a, Args... args) { cout << a << ' '; err(args...); }
// -----------------------------------------------------------------------------
string a, b;
int main() {
#ifdef zerol
    freopen("in", "r", stdin);
#endif
    LL n, m; cin >> n >> m >> a >> b;
    LL s = n * m / __gcd(n, m);
    LL k = __gcd(n, m);
    FOR (i, 0, k) {
        if (a[n / k * i] != b[m / k * i]) { puts("-1"); exit(0); }
    }
    cout << s << endl;
}

Measured memory_bytes: 512
use proconio::{fastout, input};
// use proconio::marker::*;

#[fastout]
fn main() {
   input! {
      t: usize,
      nabcd: [(usize, usize, usize, usize, usize); t]
   }

   for (n, a, b, c, d) in nabcd {
      let mut m = std::collections::BTreeMap::new();
      m.insert(0, 0);
      m.insert(1, d);
      let ans = f(n, a, b, c, d, &mut m);
      println!("{}", ans);
   }
}

use std::cmp::min;
macro_rules !min {($a :expr $(,) *) =>{{$a } } ;($a :expr ,$b :expr $(,) *) =>{{std ::cmp ::min ($a ,$b ) } } ;($a :expr ,$($rest :expr ) ,+$(,) *) =>{{std ::cmp ::min ($a ,min !($($rest ) ,+) ) } } ;}

fn f(
   x: usize,
   a: usize,
   b: usize,
   c: usize,
   d: usize,
   m: &mut std::collections::BTreeMap<usize, usize>,
) -> usize {
   if let Some(&y) = m.get(&x) {
      y
   } else {
      let two = match x % 2 {
         0 => f(x / 2, a, b, c, d, m),
         _ => d + min(f(x / 2, a, b, c, d, m), f(x / 2 + 1, a, b, c, d, m)),
      } + a;
      let three = match x % 3 {
         0 => b + f(x / 3, a, b, c, d, m),
         i => min(
            i * d + f(x / 3, a, b, c, d, m) + if x / 3 == 0 { 0 } else { b },
            (3 - i) * d + f(x / 3 + 1, a, b, c, d, m) + b,
         ),
      };
      let five = match x % 5 {
         0 => c + f(x / 5, a, b, c, d, m),
         i => min(
            i * d + f(x / 5, a, b, c, d, m) + if x / 5 == 0 { 0 } else { c },
            (5 - i) * d + f(x / 5 + 1, a, b, c, d, m) + c,
         ),
      };
      let mut y = min!{two, three, five};
      if x <= y/d {
         y = min(y, d*x);
      }
      m.insert(x, y);
      y
   }
}


Measured memory_bytes: 2460
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeMap;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;
	String[] S;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		S = new String[N];
		// System.out.println(N);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		S[cnt] = str;
		// System.out.println(str);
		cnt++;
	}

	public void solve() {
		TreeMap<Character, Integer> cmapShare = calcMap(S[0]);
		for (int i = 1; i < N; i++) {
			TreeMap<Character, Integer> cmap = calcMap(S[i]);
			for (char c : cmapShare.keySet()) {
				if (cmap.containsKey(c)) {
					if (cmapShare.get(c) > cmap.get(c))
						cmapShare.put(c, cmap.get(c));
				} else {
					cmapShare.put(c, 0);
				}
			}
		}
		for (char c : cmapShare.keySet()) {
			for (int i = 0; i < cmapShare.get(c); i++) {
				System.out.print(c);
			}
		}
		System.out.println();
	}

	private TreeMap<Character, Integer> calcMap(String str) {
		TreeMap<Character, Integer> cmap = new TreeMap<Character, Integer>();
		for (int i = 0; i < str.length(); i++) {
			char c = str.charAt(i);
			if (cmap.containsKey(c))
				cmap.put(c, cmap.get(c) + 1);
			else
				cmap.put(c, 1);
		}
		return cmap;
	}
}


Measured memory_bytes: 22356
#include<iostream>
#include<cstdio>
#include<cmath>
#include<complex>
#include<algorithm>
#include<vector>
#include<queue>

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

typedef long long ll;

int main()
{
	int n;
	ll tmp = 0,sum = 0,ans = 1e18;
	ll card[200100];
	
	cin >> n;
	REP(i,n)
	{
		cin >> card[i];
		sum += card[i];
	}
	
	for(int i = 0;i < n-1;i++)
	{
		tmp += card[i];
		ll tmp2 = sum - tmp;
//		cout << tmp << ' ' << tmp2 << endl;;
		ans = min(ans,abs(tmp - tmp2));
	}
	
	cout << ans << endl;
	
	return 0;
}

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

void Main() {
  int N;
  long long K;
  cin >> N >> K;
  int A[N];
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[i] = a - 1;;
  }

  vector<int> k(N, -1);
  k[0] = 0;
  int now = 0;
  long long i, loop_start, loop_size;
  for (i = 1; i <= K; i++) {
    now = A[now];
    if (k[now] >= 0) {
      loop_start = k[now];
      loop_size = i - k[now];
      break;
    }
    k[now] = i;
  }
  if (i > K) cout << now + 1 << endl;
  else {
    // cout << loop_start << " " << loop_size << endl;
    long long step_num = (K - loop_start) % loop_size;
    for (int i = 0; i < step_num; i++) {
      now = A[now];
    }
    cout << now + 1 << endl;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 4784
#include<iostream>
#define ll long long
using namespace std;
int gcd2(int x,int y){
  if(y==0) return x;
  return gcd2(y,x%y);
}
int gcd(int a,int b,int c){
  return gcd2(gcd2(a,b),c);
}
int main(){
  int K;cin>>K;
  ll sum=0;
  for(int a=1;a<=K;a++){
    for(int b=1;b<=K;b++){
      for(int c=1;c<=K;c++){
        sum+=gcd(a,b,c);
      }
    }
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3628
//
//  main.c
//  Dirichlet's Theorem on Arithmetic Progressions
//
//  Created by x15071xx on 2016/06/06.
//  Copyright ?? 2016??´ AIT. All rights reserved.
//
//dm+a=n
//n???d??§?????£???a?????????&&?´???°?????°
#include <stdio.h>
#include <math.h>
#define NUM 1000000

int main(int argc, const char * argv[]) {
    
    int a,d,n,i,j;
    int hurui[NUM] = {0},count_n = 0;
    
    for (i=0; i<=NUM; i++) {
        hurui[i]=1;
    }
    hurui[1]=0;
    
    for (i=2; i<= NUM; i++) {
        if (hurui[i] == 1) {
            for(j = 2 * i; j <= NUM; j += i)
                hurui[j] = 0;
            
        }
    }
    
    while (1) {
        
        scanf("%d %d %d",&a,&d,&n);
        
        if(a==0&&d==0&&n==0){
            break;
        }
        
        for (i = a; i < NUM; i+=d) {
            if (hurui[i] == 1) {
                count_n++;
                if (count_n==n) {
                    printf("%d\n",i);
                    break;
                }
            }
        }
        count_n=0;
        
    }
    return 0;
}

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


int main() {
  int n;
  cin>>n;
  vector<int>r(n);
  rep(i,n){
    cin>>r[i];
  }
  int min=r[0];
  int max=r[1]-r[0];
  for(int j=1;j<n;j++){
    if(r[j]-min>max)max=r[j]-min;
    if(r[j]<min)min=r[j];
  }
  cout<<max<<endl;
}



Measured memory_bytes: 3628
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int par[1000000];
int Rank[1000000];

void init(int n){
	for(int i=0;i<n;i++){
		par[i] = i;
		Rank[i] = 0;
	}
}

int find(int x){
	if(par[x]==x) return x;
	else{
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x==y) return;

	if(Rank[x]<Rank[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(Rank[x]==Rank[y]) Rank[x]++;
	}
}

bool same(int x, int y){
	return find(x)==find(y);
}


int main(){
	int N, M, K;
	cin >> N >> M >> K;
	int A, B;
	int C, D;


	set<int> dame[N];

	init(N);
	for(int i=0;i<M;i++){
		cin >> A >> B; A--; B--;
		unite(A, B);
		dame[A].insert(B);
		dame[B].insert(A);
	}

	for(int i=0;i<K;i++){
		cin >> C >> D; C--; D--;
		if(find(C)==find(D)){
			dame[C].insert(D);
			dame[D].insert(C);
		}
	}

	int component[N];
	for(int i=0;i<N;i++) component[i] = 0;

	for(int i=0;i<N;i++){
		component[find(i)]++;
	}

	for(int i=0;i<N;i++){
		int mem = 0;
		mem += component[find(i)];
		mem -= dame[i].size();
		cout << mem - 1 << " ";
	} 
	cout <<endl;
  	return 0;
}


Measured memory_bytes: 29184
import sys

read = sys.stdin.read
readline = sys.stdin.readline


class BIT:
    def __init__(self, n):
        self.n = n
        self.tree = [[0] * (n + 1) for _ in range(26)]

    def bit_query(self, character, idx):
        if idx == 0:
            return 0
        sum_of_query = 0
        while idx > 0:
            sum_of_query += self.tree[character][idx]
            idx -= idx & (-idx)
        return sum_of_query

    def update(self, character, idx, x):
        while idx <= self.n:
            self.tree[character][idx] += x
            idx += idx & (-idx)
        return


N = int(input())
S = [i - 97 for i in map(ord, list(input()))]
S = [-1] + S
Q, *query = map(str, read().split())
bit = BIT(N)
for idx, i in enumerate(S[1:], 1):
    bit.update(i, idx, 1)
for a, b, c in zip(*[iter(query)] * 3):
    b = int(b)
    if a == '1':
        c = ord(c) - 97
        if S[b] == c:
            continue
        bit.update(c, b, 1)
        bit.update(S[b], b, -1)
        S[b] = c
    else:
        c = int(c)
        print(sum(1 for i in range(26) if bit.bit_query(i, c) - bit.bit_query(i, b - 1) > 0))


Measured memory_bytes: 163608
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto nm = readints;
    int n = nm[0], m = nm[1];

    auto balls = new int[n + 1]; // 各箱に入っているボールの数
    balls[] = 1;
    auto reds = new bool[n + 1]; // 赤いボールが入っている可能性
    reds[1] = true;

    for (int i = 0; i < m; i++) {
        auto xy = readints;
        int x = xy[0], y = xy[1];
        // x の箱のボールを y に移す
        balls[x]--;
        balls[y]++;
        if (reds[x]) {
            reds[y] = true;
            if (balls[x] == 0) reds[x] = false;
        }
    }

    auto ans = reds.count(true);
    writeln(ans);
}


Measured memory_bytes: 3580
#include<iostream>
#include<cmath>
#include<iomanip>
#include<vector>
#include<string>

using namespace std;

int main(){
  int n , temp;
  cin >> n;
  vector<int> x,y;
  for(int i = 0;i< n; i++){
    cin >> temp;
    x.push_back(temp);
  }
  for(int i = 0;i< n; i++){
    cin >> temp;
    y.push_back(temp);
  }

  // L1距離
  double L1 = 0;
  double maxdiff = 0;
  for(vector<int>::size_type i = 0; i < x.size(); i++){
    if(abs(x[i] - y[i]) > maxdiff)
      maxdiff = abs(x[i] - y[i]);
    L1 += abs(x[i] - y[i]);
  }

  // L2距離
  double L2 = 0;
  for(vector<int>::size_type i = 0; i < x.size(); i++){
    L2 += pow(x[i]-y[i], 2);
  }
  L2 = sqrt(L2);

  // L3距離
  double L3 = 0;
  for(vector<int>::size_type i = 0; i < x.size(); i++){
    L3 += pow(abs(x[i]-y[i]), 3);
  }
  L3 = pow(L3, 1/3.0);

  cout << fixed << setprecision(6) << L1 << endl;
  cout << fixed << setprecision(6) << L2 << endl;
  cout << fixed << setprecision(6) << L3 << endl;
  cout << fixed << setprecision(6) << maxdiff << endl;

}


Measured memory_bytes: 3436
#include<stdio.h>

int main() {
   int n;
   scanf("%d", &n);
   int c[n],v[n];
   int i;
   for(i = 0; i<n; i++){
       scanf("%d", &c[i]);
   }
   for(i = 0; i<n; i++){
       scanf("%d", &v[i]);
   }
   int delta[n];
   for(i = 0; i<n; i++){
       delta[i] = c[i]-v[i];
   }
   int sum =0;
     for(i = 0; i<n; i++){
       if(delta[i]>0){
           sum += delta[i];
       }
   }
   printf("%d", sum);


}

Measured memory_bytes: 128
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_NUM_KIND		3										// 数字種類数

// 内部構造体 - 値情報
typedef struct Val {
	int miVal;													// 値
	int miCnt;													// 個数
} Val;

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// 出力
int
fOut(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i, j;
	char lc1Buf[1024];

	// 配列数 - 取得
	int liACnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &liACnt);

	// 値情報 - 初期化
	Val lz1Val[D_NUM_KIND];
	memset(lz1Val, 0, sizeof(lz1Val));
	int liVCnt = 0;

	// 値情報 - 取得
	for (i = 0; i < liACnt; i++) {
		int liVal;
		fscanf(szpFpI, "%d", &liVal);

		// 同一値 - 検索
		for (j = 0; j < liVCnt; j++) {
			if (lz1Val[j].miVal == liVal) {
				lz1Val[j].miCnt++;
				break;
			}
		}
		
		// 値情報 - 追加
		if (j == liVCnt) {
			if (liVCnt >= D_NUM_KIND) {
				return -1;
			}

			lz1Val[liVCnt].miVal = liVal;
			lz1Val[liVCnt].miCnt = 1;
			liVCnt++;
		}
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 値情報数 = 1
	if (liVCnt == 1) {
		if (lz1Val[0].miVal != 0) {
			return -1;
		}
	}

	// 値情報数 = 2
	else if (liVCnt == 2) {
		if (lz1Val[0].miCnt == lz1Val[1].miCnt * 2) {
			if (lz1Val[1].miVal != 0) {
				return -1;
			}
		}
		else if (lz1Val[1].miCnt == lz1Val[0].miCnt * 2) {
			if (lz1Val[0].miVal != 0) {
				return -1;
			}
		}
		else {
			return -1;
		}
	}

	// 値情報数 = 3
	else if (liVCnt == 3) {
		if (lz1Val[0].miCnt != lz1Val[1].miCnt) {
			return -1;
		}
		if (lz1Val[0].miCnt != lz1Val[2].miCnt) {
			return -1;
		}

		// Xor
		int liXor = lz1Val[0].miVal ^ lz1Val[1].miVal;
		if (lz1Val[2].miVal != liXor) {
			return -1;
		}
	}

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	if (liRet == 0) {
		sprintf(lc1Buf, "Yes\n");
	}
	else {
		sprintf(lc1Buf, "No\n");
	}
	fOut(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



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

#define NIL -1
#define MAX (1 << 24)

struct Node {
	int dis = MAX;
	bool flag = false;
	vector<int> d;
	vector<int> id;
};

void dijkstra(vector<Node>& u)
{
	u[0].dis = 0;

	while (1)
	{
		int mini = MAX;
		int n;
		for (int i = 0; i < u.size(); i++)
		{
			if (!u[i].flag && u[i].dis < mini) {
				mini = u[i].dis;
				n = i;
			}
		}

		if (mini == MAX) return;
		u[n].flag = true;

		for (int i = 0; i < u[n].id.size(); i++)
		{
			if (u[u[n].id[i]].flag) continue;
			if ((u[n].dis + u[n].d[i]) < u[u[n].id[i]].dis) {
				u[u[n].id[i]].dis = u[n].dis + u[n].d[i];
			}
		}
	}
}

int main(void)
{
	int i, N, v, k, c, x;
	cin >> N;
	vector<Node> u(N);
	for (i = 0; i < N; i++)
	{
		cin >> v >> k;
		for (int j = 0; j < k; j++)
		{
			cin >> x >> c;
			u[v].id.push_back(x);
			u[v].d.push_back(c);
		}
	}

	
	dijkstra(u);

	for (i = 0; i < N; i++) cout << i << " " << u[i].dis << endl;

	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>

using namespace std;
#define  ll  long long;

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

        int min_suki;

        int d[10];
        for (int i = 0; i < 10; i++) {
                d[i] = 0;
        }
        for (int i = 0; i < k; i++) {
                int kirai;
                cin >> kirai;
                d[kirai] = 1;
        }

        for (int i = 0; i < 10; i++) {
                if (d[i] == 0) {
                        min_suki = i;
                        break;
                }
        }


        int nKeta[5];
        int keta_s = -1;
        int num = n;
        int ans;
        for (int i = 0; i < 5; i++) {
                nKeta[i] = 0;
        }

        for (int i = 3; i >= 0; i--) {
                nKeta[i] = num / pow(10,i);
                if (nKeta[i] != 0 && keta_s == -1) {
                        keta_s = i;
                }
                num = num - nKeta[i] * pow(10,i);
        }

        while(true) {
                ans = 0;
                for (int i = keta_s; i >= 0; i--) {
                        //cout << "nKeta[3]:" << nKeta[3] << endl;
                        for (int j = 0; j < 10; j++) {
                                if(nKeta[i] < j && d[j] == 0) {
                                        ans += j * pow(10,i);
                                        for (int k = 0; k < i; k++) {
                                                ans += min_suki * pow(10,k);
                                        }
                                        cout << ans << endl;
                                        return 0;
                                }
                                else if (nKeta[i] == j && d[j] == 0 ) {
                                        if (i == keta_s && j == 0){
                                                continue;
                                        }
                                        //cout << j << endl;
                                        ans += j * pow(10,i);
                                        break;
                                }
                        }
                }
                //cout << "ans:" << ans << endl;
                if (n > ans) {
                        keta_s++;
                        //cout << "increase keta" << endl;
                        //cout << "keta_s:" << keta_s << endl;
                }
                else {
                        //cout << "break" << endl;
                        break;
                }
        }
        cout << ans << endl;
        return 0;
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define per(i,n) for(ll i = n; i >= 0; i--)
#define sz(x) ll(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<ll,ll>;
using Pl = pair<ll,ll>;
using vi = vector<ll>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const ll dx[] = {0,1,0,-1,1,1,-1,-1};
const ll dy[] = {1,0,-1,0,1,-1,-1,1};
const ll inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }

ll dfs(ll &cur, vb &seen, vi &t, const vi &a) {
  seen[cur] = true;
  t.push_back(cur);
  ll ne = a[cur];
  if(seen[ne]) return ne;
  ll res = dfs(ne, seen, t, a);
  return res;
}

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

  ll n, k;
  cin >> n >> k;
  vi a(n);
  rep(i,n) {
    cin >> a[i];
    a[i]--;
  }
  vb seen(n);
  vi t;
  ll cur = 0;
  ll s = dfs(cur, seen, t, a);
  ll turn = sz(t);
  ll cnt = 0;
  rep(i,sz(t)) {
    if(t[i] == s) break;
    else cnt++;
  }
  turn -= cnt;
  if(k <= cnt) {
    cout << t[k]+1 << endl;
    return 0;
  }
  else k -= cnt;
  ll idx = (k+1) % turn;
  if(idx == 0) idx = turn;
  ll ans = t[cnt+idx-1] + 1;
  cout << ans << endl;
} 

Measured memory_bytes: 18724
#include <iostream>

using namespace std;

int main() {
    int p;
    cin >> p;
    int a[p];
    for (int i = 0; i < p; i++) {
        cin >> a[i];
    }

    int c[p][p];
    for (int i = 0; i < p; i++) {
        c[i][0] = c[i][i] = 1;
        for (int j = 1; j < i; j++) {
            c[i][j] = (c[i-1][j-1] + c[i-1][j]) % p;
        }
    }

    int e[p][p];
    for (int i = 0; i < p; i++) {
        for (int j = 0; j < p; j++) {
            e[i][j] = j == 0 ? 1 : e[i][j-1] * i % p;
        }
    }

    int fac[p];
    for (int i = 0; i < p; i++) {
        fac[i] = i == 0 ? 1 : fac[i-1] * i % p;
    }

    int inv[p];
    for (int i = 1; i < p; i++) {
        inv[i] = i == 1 ? 1 : p - p / i * inv[p%i] % p;
    }

    int b[p];
    for (int i = p - 1; i >= 0; i--) {
        int y = 0;
        int neg = 1;
        for (int j = i; j >= 0; j--) {
            y = ((y + a[j] * c[i][j] * neg) % p + p) % p;
            neg = -neg;
        }
        b[i] = y * inv[fac[i]] % p;

        for (int j = 0; j < p; j++) {
            a[j] = ((a[j] - b[i] * e[j][i]) % p + p) % p;
        }
    }

    for (int i = 0; i < p; i++) {
        cout << b[i] << (i == p - 1 ? '\n' : ' ');
    }

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int ninzuu = 0;
  
  for (int i = 0; i < N; i++) {
  	int l, r;
    cin >> l >> r;
    ninzuu += (r - l) + 1; 
  }
  
  cout << ninzuu << endl;
  
}



Measured memory_bytes: 256
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

int N;

double ans;

signed main(){

    in(N);
    while(N--){
        double x;
        string u;
        in(x,u);
        if(u=="BTC"){
            x*=380000.0;
        }
        ans+=x;
    }

    out(ans);

    return 0;
}


Measured memory_bytes: 888
#A - Table Tennis Training
N,A,B = list(map(int, input().split()))

Lab = B-A
La = A-1
Lb = N-B

if Lab%2==0:
    #case Lab is even
    ans = Lab//2
else:
    #case Lab is odd
    ans = min(La,Lb) + 1 + (Lab-1)//2
    
print(ans)

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

map<string,int> cnt;
set<string> o;

int main()
{
    int N;cin >> N;
    string s;
    _for(i,0,N){
        cin >> s;
        cnt[s]++;
    }
    int maxnum = 0;
    for(auto a:cnt){
            maxnum = max(maxnum,a.second);
    }

    for(auto a:cnt){
        if(a.second == maxnum){
            o.insert(a.first);
        }
    }

    for(auto a:o){
        cout << a <<endl;
    }

    return 0;
}


Measured memory_bytes: 34560
#include <stdio.h>

char S[100005];

int main() {

	int N;

	scanf("%d",&N);

	scanf("%s", S);

	int ans = 1;
	char prev = S[0];

	int i;

	for (i = 1; i < N; i++) {
		if (prev != S[i]) { ans++;}
		prev = S[i];
	}

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

	return 0;
}

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

using namespace std;

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, a, b) for (int i = a; i < b; i++)

int N, M;
long x[1000];
long y[1000];
long z[1000];

long r0[10000];
long r1[10000];
long r2[10000];
long r3[10000];
long r4[10000];
long r5[10000];
long r6[10000];
long r7[10000];

long rr[8];

int main()
{
	cin >> N >> M;
	rep(i, N) cin >> x[i] >> y[i] >> z[i];
	rep(i, N) {
		r0[i] += x[i]; r0[i] += y[i]; r0[i] += z[i];
		r1[i] += x[i]; r1[i] += y[i]; r1[i] -= z[i];
		r2[i] += x[i]; r2[i] -= y[i]; r2[i] += z[i];
		r3[i] += x[i]; r3[i] -= y[i]; r3[i] -= z[i];
		r4[i] -= x[i]; r4[i] += y[i]; r4[i] += z[i];
		r5[i] -= x[i]; r5[i] += y[i]; r5[i] -= z[i];
		r6[i] -= x[i]; r6[i] -= y[i]; r6[i] += z[i];
		r7[i] -= x[i]; r7[i] -= y[i]; r7[i] -= z[i];
	}
	sort(r0, r0 + N, greater<long>());
	sort(r1, r1 + N, greater<long>());
	sort(r2, r2 + N, greater<long>());
	sort(r3, r3 + N, greater<long>());
	sort(r4, r4 + N, greater<long>());
	sort(r5, r5 + N, greater<long>());
	sort(r6, r6 + N, greater<long>());
	sort(r7, r7 + N, greater<long>());
	rep(j, M) {
		rr[0] += r0[j];
		rr[1] += r1[j];
		rr[2] += r2[j];
		rr[3] += r3[j];
		rr[4] += r4[j];
		rr[5] += r5[j];
		rr[6] += r6[j];
		rr[7] += r7[j];
	}
	sort(rr, rr + 8);
	cout << rr[7] << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  bool sat = false;
  int n;
  for(n = sqrt(N)/2; (n+1)*n <= 2*N; ++n){
    if((n+1)*n == 2*N){
      sat = true;
      break;
    }
  }
  YesNo(sat);
  if(!sat)return 0;
  vector<vector<int> > v(n+1,vector<int>(n+1,0));
  int id = 0;
  rep(i,n+1){
    rep(j,i){
      if(v[j][i-1] == 0) break;
      v[i][j] = v[j][i-1];
    }
    repp(j,i,n) v[i][j] = ++id;
  }
  cout << n + 1 << endl;
  rep(i,n+1){
    cout << n SPF;
    rep(j,n) cout << v[i][j] SPF;
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main (){
    int a ;
        char b;
    string op;
    cin >> a;
    for( int i = 0; i < a; i++){
        cin >> b;
        if(b == 'Y'){
        op ="Four";
      break;
        }
        else{
            op = "Three";
        }
    }
        cout << op << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k;
    string ans = (e - a <= k) ? "Yay!" : ":(";
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3540
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
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; }
#define H 300100
#define W 300100

lli h, w, m;

int main(void){
    cin >> h >> w >> m;
    vector<lli> a(H);
    vector<lli> b(W);
    map<pair<lli, lli>, bool> e;
    rep(i, m){
        lli hi, wi;
        cin >> hi >> wi;
        a[hi]++;
        b[wi]++;
        e[{hi, wi}] = true;
    }
    lli am = *max_element(a.begin(), a.end());
    lli bm = *max_element(b.begin(), b.end());
    vector<lli> p;
    vector<lli> q;
    for(int i = 1; i <= h; i++) if(a[i] == am) p.push_back(i);
    for(int i = 1; i <= w; i++) if(b[i] == bm) q.push_back(i);
    for(auto i : p){
        for(auto j : q){
            if(e[{i, j}] == false){
                cout << am+bm << endl;
                return 0;
            }
        }
    }
    cout << max(0LL, am+bm-1) << endl;
    return 0;
}


Measured memory_bytes: 35012
import itertools
N, M, X = map(int, input().split())
books = list()
tst = [0] * M
for _ in range(N):
    C, *A = map(int, input().split())
    books.append((C, A))
    for i, aa in enumerate(A):
        tst[i] += aa
if len([t for t in tst if t < X]) > 0:
    print("-1")
    exit()
r = None
for i in range(1, N+1):
    for j in itertools.combinations(range(len(books)), i):
        cost = 0
        tst = [0] * M
        for b in j:
            co, ms = books[b]
            cost += co
            for i, aa in enumerate(ms):
                tst[i] += aa
        if len([t for t in tst if t < X]) == 0:
            if r is None or r > cost:
                r = cost
print(r)

Measured memory_bytes: 9240
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 21:34:02 2020

@author: shinba
"""
import sys
sys.setrecursionlimit(500000)

n,k = map(int,input().split())

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

data = [0]*n
data[0] = 1

li = [0]

while k > 0:
    b = a[li[-1]]-1
    if data[b] == 0:
        data[b] = 1
        li.append(b)
        k -= 1
    else:
        break

if k != 0:
    for i in range(len(li)-1,-1,-1):
        if li[i] == b:
            s = i
            break
    newli = li[s:]
    l = (k-1) % len(newli)
    print(newli[l]+1)
else:
    print(li[-1]+1)
    

Measured memory_bytes: 31040