akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def warshall_floyd(N: int, graph: list) -> list:
    """ ワーシャルフロイド(頂点数, 隣接行列(0-indexed)) """
    from copy import deepcopy

    res = deepcopy(graph)
    for i in range(N):
        # 始点 = 終点、は予め距離0にしておく
        res[i][i] = 0
    # 全頂点の最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                res[i][j] = min(res[i][j], res[i][k] + res[k][j])
    # 負の閉路(いくらでもコストを減らせてしまう場所)がないかチェックする
    for i in range(N):
        if res[i][i] < 0:
            return []
    return res

def build_grid(H, W, intv, _type, space=True, padding=False):
    # 入力がスペース区切りかどうか
    if space:
        _input = lambda: input().split()
    else:
        _input = lambda: input()
    _list = lambda: list(map(_type, _input()))
    # 余白の有無
    if padding:
        offset = 1
    else:
        offset = 0
    grid = list2d(H+offset*2, W+offset*2, intv)
    for i in range(offset, H+offset):
        row = _list()
        for j in range(offset, W+offset):
            grid[i][j] = row[j-offset]
    return grid

def check1(A, B):
    for i in range(N):
        for j in range(N):
            # 1つでも最短経路が更新されていればNG
            if A[i][j] != B[i][j]:
                return False
    return True

def check2(G):
    res = 0
    S = set()
    for k in range(N):
        for i in range(N):
            for j in range(N):
                # 3頂点が異なってかつ、経由のが近い場合は直接の辺は不要
                if i != j and j != k and k != i \
                        and G[i][k] + G[k][j] == G[i][j]:
                    if (i, j) not in S:
                        S.add((i, j))
                        res += G[i][j]
    return res

N = INT()
G = build_grid(N, N, 0, int)

# 妥当性の確認
wf = warshall_floyd(N, G)
if not check1(G, wf):
    print(-1)
    exit()

# 全体から不要な辺のコストを引く
total = 0
for i in range(N):
    for j in range(N):
        total += wf[i][j]
ans = (total - check2(wf)) // 2
print(ans)


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

using namespace std;

int main(){
  int a, b, c, d ,e,f,sum;

  cin >> a >> b >> c >> d>> e>>f;

sum = a + b * 5 + c * 10 + d * 50 +e * 100 +f * 500;

 if(sum >= 1000)cout <<  "1" << endl;
 else cout<< "0" << endl;

 return 0;
}



Measured memory_bytes: 3096
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	b , c = IN()
	ee='error'
	ret = b+c if b+c<10 else ee
	print(ret)
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 38384
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  string a;cin>>a;
  ll b=0;
  if(a[0]=='1')b++;
  if(a[1]=='1')b++;
  if(a[2]=='1')b++;
  cout<<b;
}


Measured memory_bytes: 27040
N = int(input())
dp = [[0] *3 for i in range(N+1)]
for i in range(N):
    a, b, c = map(int, input().split())
    dp[i+1][0] = max(dp[i][1], dp[i][2]) + a
    dp[i+1][1] = max(dp[i][0], dp[i][2]) + b
    dp[i+1][2] = max(dp[i][0], dp[i][1]) + c
print(max(dp[N]))

Measured memory_bytes: 59884
import sys
sys.setrecursionlimit(10**9)
H,W = map(int,input().split())
move_x = [1,-1,0,0]
move_y = [0,0,1,-1]
Field = [[c for c in input()] for _ in range(H)]
seen = [[False for _ in range(W)] for _ in range(H)]
queue = []
black = 0
for i in range(H):
    for j in range(W):
        if Field[i][j] == '#':
            black += 1
dist = [[0 for _ in range(W)] for _ in range(H)]
res = -1 
def bfs(start_x,start_y,Field,seen,queue,dist):
    global res
    seen[start_x][start_y] = True
    for i in range(0,4):
        x = start_x + move_x[i]
        y = start_y + move_y[i]
        if x < 0 or y < 0 or x >= H or y >= W:
            continue #out of range
        if Field[x][y] == '#':
            continue #we don't visit black square.
        if seen[x][y]:
            continue #already visited
        if Field[x][y] in queue:
            continue #already in queue.
        dist[x][y] = dist[start_x][start_y] + 1
        if x == (H-1) and y == (W-1):
            res = H*W - dist[x][y] - black #H*W - counting(seen) - black 
        queue.append((x,y))
    for element in queue:
        x,y = element
        if seen[x][y]:
            continue
        seen[x][y] = True
        queue.remove(element)
        bfs(x,y,Field,seen,queue,dist)    
bfs(0,0,Field,seen,queue,dist)
if res != -1:
	print(res-1)
else:
  print(-1)

Measured memory_bytes: 5620
#include <bits/stdc++.h>
//#include <boost/array.hpp>
//#include <boost/range/numeric.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multiprecision/cpp_int.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
//using namespace boost::multiprecision;

constexpr long long INF = LLONG_MAX;
constexpr long long MOD = 1000000007;
constexpr long double PI = M_PI;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define CALL(x) x.cbegin(),x.cend()
#define RALL(x) x.rbegin(),x.rend()
#define CRALL(x) x.crbegin(),x.crend()

#define cout cout << fixed << setprecision(12)
#define dbglf cerr << '\n'

#define ACCM(arr) accumulate(ALL(arr),0LL)
#define Yes(ex) cout << ((ex) ? "Yes" : "No") << endl
#define YES(ex) cout << ((ex) ? "YES" : "NO") << endl

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void veccin(vector<T>& v) {
    for (auto && e : v) { cin >> e; }
}

template < typename T >
inline void dbg(T a) { cerr << a << ' '; }

ll n, m, k;
ll ans = 0, sum = 0, cnt = 0;
ld d;
string s/*1, s2, s3*/;
char c/*1, c2, c3*/;
bool flag = false;

/*--------------------template--------------------*/

// Prime factor
map<ll, ll> prime_factor(ll n) {
    map<ll, ll> ret;
    ret[1] = 1;
    for (ll i = 2; i*i <= n; ++i) {
        while (n % i == 0) {
            ++(ret[i]);
            n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

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

    cin >> n;
	vi test(100);
	test[0] = 1;
	FOR(i,1,100){
    	test[i] = (i+1)+test[i-1];
    	//dbg(test[i]);
    }
	if(n==1){cout<<0; return 0;}
	map<ll,ll> pf = prime_factor(n);
	for(auto itr = begin(pf); itr!=end(pf); ++itr){
      const auto& ho = *itr;
      auto rst=upper_bound(ALL(test),ho.second);

      //dbg(ho.second);
      ans += distance(test.begin(),rst);
    }
    
	cout << ans-1 << endl;
}


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n; i < (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
void debug(vector<vector<ll>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
void debug(vector<ll>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}
//m.emplace(x,0).fi->second++;

int main(){
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>p(n);
  rep(i,0,n)cin>>p[i];
  //reverse(ALL(p));
  rep(i,0,n){
    if(p[i]!=i+1)res++;
  }
  //cout<<res<<endl;
  ans2(res<=2);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>



int main(void){
    int n;
    int c =0,max =0;
scanf("%d",&n);
int h[20]; 
for(int i=0;i<n;i++ ){

scanf("%d",&h[i]);

}
while(1<=max<=100){
for(int i=0;i<n;i++ ){
    if(h[i]>= max){
        max = h[i];
        c = c+1;
    }
}
printf("%d\n",c);
break;
}
return 0;
}

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

int main() {
    int n;
    cin >> n;
    
    for (int i = 1; i <= n; ++i) {        
        if (i % 3 == 0 || i % 10 == 3) {
            cout << " " << i;
            continue;
        }
        int x = i;
        do {
            if (x % 10 == 3) {
                cout << " " << i;
                break;
            }
             x /= 10;
        } while (x > 0);
    }
    
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define N_MAX 1000
#define ll long long int
using namespace std;

int dig(int x) {
	int cnt = 0;
	while (x) {
		cnt++;
		x /= 10;
	}
	return cnt;
}

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

Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    a,b,c = MI()
    print("YNEOS"[not(b-a==c-b)::2])
if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >=0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
 
typedef long long ll;
#define INF 1e9
 
int main(){
  int N, M, maxl = 0, minr=INF;
  cin >> N >> M;
  vector<int> L(M), R(M);
  REP(i, M){
    cin >> L[i] >> R[i];
    maxl = max(maxl, L[i]);
    minr = min(minr, R[i]);
  }
  if(minr < maxl){
    cout << 0 << endl;
  }
  else if(minr != INF && maxl != 0){
    cout << minr - maxl +1 << endl;
  }

  else{
    cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cctype>
#include <map>
#include <cstring>
#include <typeinfo>
#include <utility>
#define REP(i,n) for(int i = 0;i < n ;i++)
#define FOR(i,m,n) for(int i= m ;i<n;i++)
using namespace std;

int main(void){
  string str,ans;
  cin >> str;
  int i;
  for(i=0;i<str.size();i++){
    if(str[i]=='B'){
      if(ans.empty()!=1)ans.erase(ans.end()-1,ans.end());
    }else{
      ans+=str[i];
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int n,k;
  cin >>n >>k;
  if(500*n >= k) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
mi=float("inf")
piv=0
pivid=[0]*n
id=1
cnb=[0]*n
for i in range(n):
    piv=a[i]
    mi=float("inf")
    while id<n:
        #print(a,piv,pivid,id,a[id],mi)
        if abs(piv / 2 - a[id]) < mi:
            mi = abs(piv / 2 - a[id])
            id = id + 1
        else:
            id=id-1
            break

        #input()
    pivid[i]=min(id,n-1)

print(a[0],a[pivid[0]])

Measured memory_bytes: 62704
#include <stdio.h>

int main(void){
  int data;
  int count[1000]={0};
  int i=0,max;

  while(scanf("%d",&data)!=EOF){
    count[data]++;
  }
  max=0;
  for(i=1;i<=100;i++){
    if(max<count[i]){
      max=count[i];
    }
  }
  for(i=1;i<=100;i++){
    if(max==count[i]){
      printf("%d\n",i);
    }
  }
  return(0);
}
	

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

inline int num (const std::string& S, int idx){ return S.at(idx) - '0'; }
inline unsigned int bitMask(int i){ return (1 << i); }
inline bool isTrue(unsigned int bit, int i){ return bit & bitMask(i); }

int main(){
	int N;
	cin >> N;
	vector<int> v(N);
	for(auto& e : v) cin >> e;
	sort(v.begin(), v.end());
	if(v[0]==v[1]){
		cout << "NO" << endl;
		return 0;
	}
	for(std::size_t i=1; i<v.size(); ++i){
		if(v[i]==v[i-1]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(void){
    ll x, k, d;
    cin >> x >> k >> d;
    ll ans = 0;
    if(abs(x) / d > k){
        if(x >= 0){
            ans = x - d * k;
        }
        else{
            ans = x + d * k;
        }
    }
    else{
        if(k % 2 == (abs(x) / d) % 2){
            ans = x - ((x / d) * d);
        }
        else{
            ans = x - ((x / d) * d);
            if(x <= 0){
                ans += d;
            }
            else{
                ans -= d;
            }
        }
    }
    cout << abs(ans) << endl;
    return 0;
}

Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.AGC_033
{
    class A
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] hw = ReadInts();
            int h = hw[0];
            int w = hw[1];
            bool[,] grid = new bool[h, w];
            var queue = new Queue<int[]>();
            for (int i = 0; i < h; i++)
            {
                string s = Read();
                for(int j=0;j<w;j++)
                {
                    if (s[j] == '#') queue.Enqueue(new int[3] { i, j, 0 });
                }
            }
            int max = 0;
            while (queue.Count > 0)
            {
                int[] pos = queue.Dequeue();
                if (grid[pos[0], pos[1]] == true) continue;

                grid[pos[0], pos[1]] = true;
                max = Max(max, pos[2]);
                if (pos[0] > 0)
                {
                    queue.Enqueue(new int[3]
                    { pos[0] - 1, pos[1], pos[2] + 1 });
                }
                if (pos[1] > 0)
                {
                    queue.Enqueue(new int[3]
                    { pos[0], pos[1]-1, pos[2] + 1 });
                }
                if (pos[0]+1 <h)
                {
                    queue.Enqueue(new int[3]
                    { pos[0] +1, pos[1], pos[2] + 1 });
                }
                if (pos[1]+1<w)
                {
                    queue.Enqueue(new int[3]
                    { pos[0], pos[1]+1, pos[2] + 1 });
                }
            }
            WriteLine(max);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 255712
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
N = int(input())
x = readints()
ans = INF
for i in range(1, 101):
    tmp = 0
    for j in range(N):
        tmp += (x[j]-i)*(x[j]-i)
    ans = min(ans, tmp)
print(ans)


Measured memory_bytes: 38996
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int N;
  char S;
  bool is_four = false;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == 'Y') {
      is_four = true;
      break;
    }
  }
  if (is_four) {
    cout << "Four" << endl;
  } else {
    cout << "Three" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>

void print_array(int a[],int n){
    
    for (int k=0; k<n; k++){
        if (k>0) std::cout << ' ';
        std::cout << a[k] ;
    }
    std::cout << '\n';
}

int main(){
    int n;
    std::cin >> n;
    int a[n],key;
    for (int i = 0;i<n; i++){
        std::cin >> a[i];
    }
    for (int i=1;i<n;i++){
        
        print_array(a,n);
        key = a[i];
        for (int j = i; j>=0; j--){
            if(key < a[j-1]){
                a[j] = a[j-1];
            }else {
                a[j] = key;
                break;
            }
        }
    }
    print_array(a,n);
    
    return 0;
}



Measured memory_bytes: 3072
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <math.h>

using namespace std;

//与えられた数が素数かどうか判定する
int isPrime(unsigned long long int x) {
	if(x == 0) return 0;
	if(x == 1) return 0;

	int flg = 1;
	for(int i = 2; i < (int)sqrt((double)x) + 1; i++) {
		if(x % i == 0) {
			flg = 0;
			break;
		}
	}
	return flg;
}


int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	while(1) {
		unsigned long long int a, d, n;
		unsigned long long int ans, tmp;
		int cnt = 0;
		cin >> a >> d >> n;
		tmp = a;
		if( a == 0 && d == 0 && n == 0 ) break;	//終了処理

		//素数を求めるループ
		while(1) {
			if( isPrime(tmp) ) cnt ++;
			if( cnt ==  n ) {
				ans = tmp;
				break;
			}
			tmp += d;
		}

		//出力
		cout << ans << endl;
	}


	
	//while(1){}
	return 0;
}

Measured memory_bytes: 1148
#include<iostream>
#include<stack>
#include<string>
#include<sstream>
#include<cstdio>
using namespace std;

double to_num(const string& str) {
  double d;
  stringstream ss;
  ss << str;
  ss >> d;
  return d;
}

int main() {
  string str;

  while (getline(cin,str)) {
    stringstream ss(str);
    stack<double> st;
    string e;

    while (ss >> e) {
      if (e == "+") {
        double b = st.top();
        st.pop();
        double a = st.top();
        st.pop();
        st.push(a + b);

      } else if (e == "-") {
        double b = st.top();
        st.pop();
        double a = st.top();
        st.pop();
        st.push(a - b);

      } else if (e == "*") {
        double b = st.top();
        st.pop();
        double a = st.top();
        st.pop();
        st.push(a * b);

      } else if (e == "/") {
        double b = st.top();
        st.pop();
        double a = st.top();
        st.pop();
        st.push(a / b);

      } else {
        st.push( to_num(e) );
      }
    }
    printf("%6f\n",st.top());

  }
}

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

int main() {
    int n;
    string s;
    cin >> n>> s;
    int ans;
    ans=0;
    for(int i=0; i<n; ++i){
        if(!(s[i]==s[i+1])){
            ans +=1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#include <bits/extc++.h>


using namespace std;
using namespace __gnu_pbds;

#define int long long
#define rep(x,m,n) for(int x = m; x < n;x++)
#define repp(x,m,n) for(int x = m; x <= n;x++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update, ordered_set>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//find_by_order(), order_of_key();
#define MOD 1000000007
void solve();


int fastpow(int n, int p){
	int res = 1;
	while(p){
		if(p&1) res = (res * n) % MOD;
		n = (n * n) % MOD;
		p>>=1;
	}
	return res;
}


signed main(){
	fastio
	int t = 1;
	//cin >> t;
	rep(i,0,t) solve();
}

void solve(){
	int n;
	cin >> n;
	int grid[n][n];
	rep(i,0,n) rep(j,0,n) cin >> grid[i][j];
	vector<int> dp(1<<n);
	dp[0] = 1;
	for(int j = 0;j < 1<<n;j++){
		int i = __builtin_popcount(j);
		for(int k = 0;k < n;k++){
			if(grid[i][k]&&!(j&(1<<k))) dp[j^(1<<k)] = (dp[j^(1<<k)] + dp[j])%MOD; 
		}
	}
	
	cout << dp[(1<<n)-1] << "\n";
}

Measured memory_bytes: 19564
#include <stdio.h>

int main(void)
{
	int i,n,m=100000,mod;

	scanf("%d",&n);
	for(i=0;i<n;i++) {
		m*=1.05;
		mod=m%1000;
		m-=mod;
		m+=(mod==0)?0:1000;
	}
	printf("%d\n",m);
	return 0;
}

Measured memory_bytes: 592
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int t=0;

        while(x!=0||y!=0){
            if(x>y){
                t=x;
                x=y;
                y=t;
                System.out.println(x+" "+y);
            }else{
                System.out.println(x+" "+y);
            }
        x = scanner.nextInt();
        y = scanner.nextInt();
        }
    }
    
}


Measured memory_bytes: 35792
while 1:
    try:
        x1,y1,x2,y2,x3,y3,xp,yp=map(float,input().split())
        a=((x1-x2)**2+(y1-y2)**2)**0.5
        b=((x2-x3)**2+(y2-y3)**2)**0.5
        c=((x3-x1)**2+(y3-y1)**2)**0.5
        s=(a+b+c)/2
        S=(s*(s-a)*(s-b)*(s-c))**0.5
        d=((x1-xp)**2+(y1-yp)**2)**0.5
        e=((x2-xp)**2+(y2-yp)**2)**0.5
        f=((x3-xp)**2+(y3-yp)**2)**0.5
        sa=(a+d+e)/2
        sb=(b+e+f)/2
        sc=(c+f+d)/2
        Sa=(sa*(sa-a)*(sa-d)*(sa-e))**0.5
        Sb=(sb*(sb-b)*(sb-e)*(sb-f))**0.5
        Sc=(sc*(sc-c)*(sc-f)*(sc-d))**0.5
        Sp=Sa+Sb+Sc
        if abs(S-Sp)<=0.001**2:
            print("YES")
        else:
            print("NO")
    except:break


Measured memory_bytes: 5688
from collections import Counter

def solve():
    N = int(input())
    A = [int(x) for x in input().split()]
    C = Counter(A)
    #3 <= N <= 2 * 10**5

    cache = {}
    D = {}

    total = 0
    for a, c in C.items():
        if c == 1:
            D[a] = 0
            continue
        choose = c * (c-1) // 2
        D[a] = choose
        total += choose

    for k in range(N):
        a = A[k]
        if a in cache:
            print(cache[a])
            continue
        
        c = C[a]
        x = total
        x -= D[a]
        if c >= 3:
            x += (c-1) * (c-2) // 2

        cache[a] = x
        print(x)
solve()


Measured memory_bytes: 41088
//#define _GLIBCXX_DEBUG
//#define _CRTDBG_MAP_ALLOC
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

const ll LINF = 9187201950435737471;
const ll nLINF = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const ull ULINF = numeric_limits<ull>::max();
const int MAXN = 2e5 + 15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const int BLOCK = 500;
const double PI = acos(-1);
//auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
auto seed = 194113341;
mt19937 rnd(seed);

bool is_equal(double a, double b) {
    return abs(a - b) <= EPS;
}


#define all(_v) _v.begin(), _v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define sqr(_v) ((_v) * (_v))
#define vi vector <int>
#define vii vector <pair <int, int> >
#define eb emplace_back
#define pb push_back
#define mod(x, m) ((x) % m + (x < 0 ? m: 0))


inline void IO() {
#if buyolitsez
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
}

template <typename T>
istream& operator >> (istream& in, vector<T>& a) {
    for (auto& i : a)
        in >> i;
    return in;
}

template <typename T>
ostream& operator << (ostream& out, const vector<T>& a) {
    for (auto& i : a) {
        out << i << " ";
    }
    return out;
}

template <typename T, typename D>
istream& operator >> (istream& in, pair<T, D>& a) {
    in >> a.first >> a.second;
    return in;
}

template <typename T, typename D>
ostream& operator << (ostream& out, const pair<T, D>& a) {
    out << a.first << " " << a.second;
    return out;
}

#define int int64_t

int get(char x) {
    if (x == 'R') {
        return 0;
    }
    else if (x == 'G') {
        return 1;
    }
    return 2;
}
vector <int> pos[3];

inline void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < n; ++i) {
        pos[get(s[i])].eb(i);
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n; ++j) {
            set <int> ost;
            ost.insert(0);
            ost.insert(1);
            ost.insert(2);
            ost.erase(get(s[i]));
            ost.erase(get(s[j]));
            if (sz(ost) != 1) {continue;}
            int need = *ost.begin();
            int less = lower_bound(all(pos[need]), j) - pos[need].begin();
            int c = sz(pos[need]) - less;
            int k = j + (j - i);
            if (k < n && get(s[k]) == need) {
                c--;
            }
            ans += c;
        }
    }
    cout << ans;
}

signed main() {
    IO();
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

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

#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mt make_tuple
template<class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); }
template<class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using vld = vector<ld>; 
using vi = vector<int>; using vvi = vector<vi>;
using P = pair<ll, ll>;

template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) {  o << "(" << v.first << ", " << v.second << ")"; return o; }
template<size_t...> struct seq{}; template<size_t N, size_t... Is> struct gen_seq : gen_seq<N-1, N-1, Is...>{}; template<size_t... Is> struct gen_seq<0, Is...> : seq<Is...>{};
template<class Ch, class Tr, class Tuple, size_t... Is>
void print_tuple(basic_ostream<Ch,Tr>& os, Tuple const& t, seq<Is...>){ using s = int[]; (void)s{0, (void(os << (Is == 0? "" : ", ") << get<Is>(t)), 0)...}; }
template<class Ch, class Tr, class... Args> 
auto operator<<(basic_ostream<Ch, Tr>& os, tuple<Args...> const& t) -> basic_ostream<Ch, Tr>& { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; }
ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; cout << endl; } return o; }
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size()-1 ? ", " : ""); o << "]";  return o; }
template <typename T>  ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]";  return o; }
template <typename T, typename U>  ostream &operator<<(ostream &o, const unordered_map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]";  return o; }
#define VN(v) # v
#define print(a) cout << a << "#" << VN(a) << endl;

static const double EPS = 1e-14;
static const long long INF = 1e18;
static const long long mo = 1e9+7;

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll a(100010); 
    rep(i, n) {
        ll l, r; cin >> l >> r;
        a[l]++; a[r+1]--;
    }
    rep(i, a.size()-1) {
        a[i+1] += a[i];
    }
    ll ret = 0;
    rep(i, a.size()) {
        if (a[i] + 1 >= i)
            chmax(ret, i);
    }
    cout << ret - 1 << endl;

    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int n;
string s;

int32_t main()
{
	IOS;
	cin >> n >> s;
	map<int, set<int>> m;
	for(int i = 0; i < n; i++)
		m[s[i] - '0'].insert(i);
	int ans = 0;
	for(int i = 0; i <= 9; i++)
	{
		for(int j = 0; j <= 9; j++)
		{
			for(int k = 0; k <= 9; k++)
			{
				auto x = m[i].lower_bound(0);
				if(x == m[i].end())
					continue;
				auto y = m[j].upper_bound(*x);
				if(y == m[j].end())
					continue;
				auto z = m[k].upper_bound(*y);
				if(z == m[k].end())
					continue;
				ans++;
			}	
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int A,B,C,D,E,F,a,b,c,d;
    cin>>A>>B>>C>>D>>E>>F;
    a=max(E,F);
    b=max(max(A,B),max(C,D));
    c=min(max(A,B),max(C,D));
    d=max(min(A,B),min(C,D));
    cout<<a+b+c+d<<endl;
    
    
    
    return 0;
}



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


Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

int R,G,B,N;

signed main(){
	cin>>R>>G>>B>>N;
	int ans=0;
	for(int i=0;i<=N;i++){
		for(int j=0;j<=N;j++){
			int k=N-i*R-j*G;
			if(k%B==0&&0<=k&&N==i*R+j*G+k){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
vector<int>topo_sort(const vector<vector<int>>&edges) {
	int size_ = edges.size();
	vector<int>nums(size_);	
	for(const auto& es:edges){
		for (auto e : es) {
			nums[e]++;
		}
	}
	queue<int>que;
	for (int i = 0; i < size_; ++i) {
		if (!nums[i]) {
			que.push(i);
		}
	}
	vector<int>topo;
	while (!que.empty()) {
		int ver(que.front());
		topo.push_back(ver);
		que.pop();
		for (auto e : edges[ver]) {
			nums[e]--;
			if (!nums[e])que.push(e);
		}
	}
	if (topo.size() == size_)return topo;
	else return vector<int>();
}
int main() {
	int V, E; cin >> V >> E;
	vector<vector<int>>edges(V);
	for (int i = 0; i < E; ++i) {
		int s, t; cin >> s >> t;
		edges[s].push_back(t);
	}
	auto vs=topo_sort(edges);
	for (auto v : vs) {
		cout << v << endl;
	}
	return 0;
}

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

long long GCD(long long A, long long B) {
	if (B == 0) return A;
	return GCD(B, A % B);
}

int main() {
	long long A, B, C;
	vector<long long> V;
	cin >> A >> B;
	C = GCD(A, B);
	V.push_back(1);
	for (long long i = 2; i * i <= C; i++) {
		if (C % i == 0) {
			V.push_back(i);
			while (C % i == 0) {
				C /= i;
			}
		}
	}
	V.push_back(C);
	sort(V.begin(), V.end());
	V.erase(unique(V.begin(), V.end()), V.end());
	cout << V.size() << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
  int A, B;
  cin>>A>>B;
  cout<<A*B<<endl;
}

Measured memory_bytes: 3644
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    sc.nextLine()
    val s = new Array[String](n)
    val mp = scala.collection.mutable.Map[Char, Long](
      ('M', 0), ('A', 0), ('R', 0), ('C', 0), ('H', 0))
    for (i <- 0 until n) {
      s(i) = sc.nextLine()
      val index = s(i)(0)
      if (index == 'M' || index == 'A' || index == 'R' || index == 'C' || index == 'H') {
        mp(index) += 1
      }
    }

    var ans = 0L
    val values = mp.values.toList
    for (i <- 0 until 5; j <- i + 1 until 5; k <- j + 1 until 5) {
      ans += values(i) * values(j) * values(k)
    }

    println(ans)
  }
}


Measured memory_bytes: 108580
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, l;
  cin>>n>>l;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  sort(s.begin(),s.end());
  string ans;
  for(int i=0;i<n;i++){
    ans+=s[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
function main(input) {
  var N = input[0]-0;
  var list = [];
  var idx = 0;
  for(var i=0;i<N;i++){
    var a = input[++idx]-0;
    var alist = [];
    list.push(alist);
    for(var j=0;j<a;j++){
      var obj = input[++idx].split(" ").map(v=>v-0);
      --obj[0];
      alist.push(obj);
    }
  }

  var ans = 0;
  for(var i=1;i<Math.pow(2,N);i++){
    ans = Math.max(ans, calc(list, i));
  }
  console.log(ans);

}

function calc(list, pt){
  var ptn = ("0000000000000000" + pt.toString(2)).slice(-1*list.length);
  for(var i=0;i<list.length;i++){
    var data = list[i];
    if(ptn[i]=="1") for(var j=0;j<data.length;j++){
      var d = data[j];
      if(d[1]=="1" && ptn[d[0]] != "1") return 0;
      else if(d[1]=="0" && ptn[d[0]] != "0") return 0;
    }
  }
  return ptn.replace(/0/g,"").length;
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


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

int main(){
    int n;
    cin >> n;
    int p[n];
    for(int i=0;i<n;i++)cin >> p[i];
    sort(p,p+n);
    int a=0;
    for(int i=0;i<n-1;i++)a+=p[i];
    a+=p[n-1]/2;
    cout << a << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		long first = sc.nextLong();
		long second = sc.nextLong();
		long xor = 0;
		for (int i = 2; i < N; i++) {
			xor ^= sc.nextLong();
		}
		long total = first + second;
		long ans = -1;
		if (total >= xor) {
			long dif = total - xor;
			long dupMask = dif >> 1;
			if (dif % 2 == 0 && (dupMask & xor) == 0 && dupMask <= first) {
				long finalFirst = dupMask;
				while (xor > 0) {
					long bit = Long.highestOneBit(xor);
					if ((finalFirst | bit) <= first) {
						finalFirst |= bit;
					}
					xor ^= bit;
				}
				if (finalFirst > 0) {
					ans = first - finalFirst;
				}
			}
		}
		out.println(ans);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 32732
N, M = map(int, input().split())
ps = [[] for _ in range(N)]
for i in range(M):
    p, s = input().split()
    p = int(p) - 1
    ps[p].append(s)
wa = 0
ac = 0
for ss in ps:
    tmp_wa = 0
    for s in ss:
        if s == "WA":
            tmp_wa += 1
        else:
            ac += 1
            wa += tmp_wa
            break
print("{} {}".format(ac, wa))

Measured memory_bytes: 20376
#include<bits/stdc++.h>
using namespace std;
#define N 500
#define inf 0x3f3f3f3f
int n;
struct node
{
	int x,y;
}A[N],B[N];
bool vis[N];
int a[N][N],matc[N],ans;
bool dfs(int x)
{
	for(int i=1;i<=2*n;++i) 
	{
		if(a[x][i] && !vis[i])
		{
			vis[i]=1;
			if(!matc[i] || dfs(matc[i]))
			{
				matc[i]=x;
				return 1;
			}
		}
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) 
		scanf("%d%d",&A[i].x,&A[i].y);
	for(int i=1;i<=n;++i) 
		scanf("%d%d",&B[i].x,&B[i].y);	
	for(int i=1;i<=n;++i) 
		for(int j=1;j<=n;++j) 
			if(B[j].x>A[i].x && B[j].y>A[i].y)
				a[i][j+n]=1;
	for(int i=1;i<=n;++i) 
	{
		memset(vis,0,sizeof(vis));
		if(dfs(i)) ans++;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF=1e18;

int memo[200][200];
int gcd(int a, int b) {
    if (memo[a][b] != 0)
    {
        return memo[a][b];
    }

    if (b == 0)
        return a;

    return gcd(b, a % b);
}


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

    int K;
    cin >> K;

    ll result = 0;

    for (int a=1; a<=K; a++) {
        for (int b=1; b<=K; b++) {
            int first = gcd(a, b);
            for (int c=1; c<=K; c++) {
                result += gcd(first, c);
            }
        }
    }

    cout << result << '\n';

    return 0;
}

Measured memory_bytes: 3652
def is_good(mid, key):
    return sum((a + mid - 1) // mid for a in A) - N <= key


def binary_search(bad, good, key):
    while good - bad > 1:
        mid = (bad + good) // 2
        if is_good(mid, key):
            good = mid
        else:
            bad = mid
    return good


N, K, *A = map(int, open(0).read().split())
print(binary_search(0, 1_000_000_000, K))


Measured memory_bytes: 31532
#include<bits/stdc++.h>
using namespace std;
 
#define int long long 
#define ll long long 
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define ff first
#define ss second
#define vi vector<ll>
#define vii vector<vector<ll>>
#define vpi vector<pii>
#define mod 1000000007
#define MOD 1000000007
#define full(a) a.begin(),a.end()
#define inf INT_MAX
#define minf INT_MIN
#define dd double
#define fori(x,n) for(ll i=x;i<n;i++)
#define modd 998244353
#define umap unordered_map<ll,ll>
#define mmap map<ll,ll>
#define mm 100000000


int32_t main() 
{ 
  
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif


    
    ll t;
    t=1;
    // cin>>t;
    while(t--){
      ll n;
      cin>>n;
      ll a[n];
      fori(0,n)cin>>a[i];
      ll prev=a[0];
      ll ans=0;
      fori(1,n){
        if(a[i]<prev){
          ans += prev-a[i];
        }
        else prev = a[i];
      }

      cout<<ans;

      
  
    }





return 0;
}     



Measured memory_bytes: 5216
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n, bsum = 0;
    cin >> n;
    vector<int> a(n+1), b(n+1);
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
        if(n/2 < i){
            b[i] = a[i];
            bsum += b[i];
        }
    }
    for(int i = n/2; i >= 1; i--){
        for(int j = i*2; j <= n; j += i){
            b[i] += b[j];
        }
        b[i] = (b[i] % 2 != a[i] ? 1 : 0);
        bsum += b[i];
    }
    /*
    b[1] = (bsum % 2 != a[1] ? 1 : 0);
    bsum += b[1];
     */
    cout << bsum << endl;
    for(int i = 1; i <= n; i++){
        if(b[i]) printf("%d ", i);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 2432
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <numeric>
#include <math.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;



int main() {
    string S, T;
    cin >> S >> T;
    rep(i, S.size()) {
        if (S[i] != T[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;

}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;
using ll=long long;
using pint=pair<int,int>;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define el '\n'
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define ceil_div(a,b) ((a+(b-1))/b)
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl
#define $in(v,n) ;rep(II,0,n)cin>>v[II]
inline void IN(void){return;}
template<typename F,typename... R>inline void IN(F& f, R&... r){cin>>f;IN(r...);}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}


int main(){
	int n,k; IN(n,k);
	vector<int> h(n)$in(h,n);
	int ans = 0;
	rep(i,0,n){
		if(h[i] >= k) ans++;
	}
	cout << ans << el;
	return 0;
}


Measured memory_bytes: 3128
from collections import Counter
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
Num = list(input().split())
C = Counter(Num)
ans = 0

l = [0]
v = len(C)
odd = len(list(filter(lambda x: x % 2 == 1, C.values())))
even = v - odd
ans += odd + even//2*2
print(ans)


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

long gcd(long a, long b) {

  if (b == 0) {
    return a;
  }

  return gcd(b, a % b);

}

long lcm(long a, long b) {
  
  return a / gcd(a, b) * b;

}

int main() {

  int N;
  cin >> N;

  vector<long> T(N);
  for (int i = 0; i < N; i++) {
    cin >> T[i];
  }

  long g = T[0];
  
  for (int i = 1; i < N; i++) {
    g = lcm(g, T[i]);
  }
  
  cout << g << endl;

}

Measured memory_bytes: 256
lis=[1,2,4,8,16,32,64,128,256,512,9,27,81,243,729,25,125,625,216,36,343,49,100,1000]
for i in range(11,32):
    t=i*i
    lis.append(t)
listt=list(set(lis))
listt=sorted(listt)
a=int(input())
for i in range(300):
    if a < listt[i]:
        print (listt[i-1])
        break
    elif a == listt[i]:
        print(listt[i])
        break

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    map<string,int> m;
    int n;
    cin>>n;
    string s;
    for(int i=0;i<n;i++){
        cin>>s;
        if(m[s]){
            m[s]=m[s]+1;
        }
        else{
            m[s]=1;
        }
    }
    map<string,int>::iterator it;
    int max=INT_MIN;
    for(it=m.begin();it!=m.end();it++){
        if(it->second>max)
        max=it->second;
    }
    for(it=m.begin();it!=m.end();it++){
        if(max==it->second)
        cout<<it->first<<"\n";
    }
    return 0;
}

Measured memory_bytes: 19232
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,c,s;
cin>>a>>b>>c;
  for(long long i=0;i<10;i++)
  {
	s=(a*c)-b;
	c=s;
	cout<<s<<endl;
  }
return 0;
}

Measured memory_bytes: 256