akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt(); // A個口のタップ
        int B = sc.nextInt(); // ゴール

        int sum = 1;   // 口数の合計
        int count = 0; // 電源タップの数
        while (sum < B) {
            sum += (A -1);
            count++;
        }

        System.out.print(count);
    }

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

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


// 重み付き有向グラフの edge(Node)
struct edge
{ 
    int to;    // 繋がる edge の値
    int cost;  // 辺の重み
};


// 深さ優先探索
// x[i] を計算し、条件を満たす x[i] がなければ false を返す
bool isCorrectx( int i, vector<int>& x, vector<edge>* G )
{
    for( int j = 0; j < (int) G[i].size(); ++j ){  // G[i] の周りの edge を見る
        // i -> G[i][j].to
        if( x[G[i][j].to] < INT_MAX ){
            if( x[G[i][j].to] != x[i] + G[i][j].cost ) return false;
        }else{
            x[G[i][j].to] = x[i] + G[i][j].cost;
            if( !isCorrectx( G[i][j].to, x, G ) ) return false;
        }
    }
    return true;
}


int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> L(M), R(M), D(M);
    for( int i = 0; i < M; ++i ) cin >> L[i] >> R[i] >> D[i];

    vector<edge> G[N+1];  // vector の配列, G[i] が vector<edge> 型
    // 重み   D[i] で L[i] -> R[i] を、
    // 重み - D[i] で R[i] -> L[i] を繋ぐ
    for( int i = 0; i < M; ++i ){
        L[i]--, R[i]--;
        G[L[i]].push_back( edge{R[i],   D[i]} );
        G[R[i]].push_back( edge{L[i], - D[i]} );
    }

    bool isCorrect = true;
    vector<int> x(N, INT_MAX);
    // 各 i について x[i] を計算し、それを満たすなければ break する
    for( int i = 0; i < N; ++i ){  
        if( x[i] == INT_MAX ){
            x[i] = 0;
            if( !isCorrectx( i, x, G ) ){
                isCorrect = false;
                break;
            }
        }
    }
    
    if( isCorrect ) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

testinomy = [[-1 for _ in range(N)] for _ in range(N)]

for i in range(N):
    A = int(input())
    testinomy[i][i] = 1
    for j in range(A):
        x, y = map(int, input().split())
        testinomy[i][x - 1] = y

ans = 0

for honests in range(2 ** N):
    bit = '{:015b}'.format(honests)[::-1]
    ok_flag = True
    for i in range(N):
        if bit[i] == '1':
            for j, k in enumerate(testinomy[i]):
                str_k = str(k)
                if bit[j] == '1' and str_k != '0':
                    pass
                elif bit[j] == '0' and str_k != '1':
                    pass
                else:
                    ok_flag = False
                    break
                # if str_k != '-1':
                #     if str_k == '1' and bit[j] == '1':
                #         pass
                #     elif str_k == '0' and bit[j] == '0':
                #         pass
                #     else:
                #         ok_flag = False
                #         break
        if ok_flag == False:
            break
    if ok_flag:
        ans = max(ans, sum(map(int, bit)))

print(ans)

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

void test()
{
    int x, n;
    cin >> x >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i];

    sort(v.begin(), v.end());
    int ans;
    if (binary_search(v.begin(), v.end(), x))
    {
        int in = lower_bound(v.begin(), v.end(), x) - v.begin();

        int temp = 0;
        while (in - temp >= 0 && v[in - temp] == x - temp)
            temp++;
        ans = x - temp;
        // cout << "in " << in << endl;
        // cout << "first " << ans << endl;
        temp = 0;
        while (in + temp < v.size() && v[in + temp] == x + temp)
            temp++;
        if (abs(x + temp - x) < abs(x - ans))
            ans = x + temp;
        cout << ans << endl;
    }
    else
    {
        cout << x << endl;
        return;
    }
}
int32_t main()
{

    int t = 1;
    // cin >> t;
    while (t--)
    {
        test();
    }

    return 0;
}

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

using namespace std;

int main()
{
    int K,A,B,flag=0;
    cin>>K;
    cin>>A>>B;

    for(int i=A;i<=B;i++)
    {
        if(i%K==0)
        {
            flag=1;
            cout<<"OK"<<"\n";
            break;
        }
    }
    if(flag==0)
    {
        cout<<"NG"<<"\n";
    }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
// atoi : atoi(変数名.c_str())
// to_string(数値)
// %0桁数d とすると表示桁数が「桁数」に満たない場合に0埋めされる
// find(): int i = 変数名.find(“文字列”) 何番目にあるかを得る
// cout << (条件 ? "Yes" : "No") << endl;
// printf("%02d:%02d:%02d",hour,minute,second);
// 降順 sort(a.begin(),a.end(),greater<int>());
// bitset<ビット数> 変数名;  // すべてのビットが0の状態で初期化される
// bitset<ビット数> 変数名("ビット列");  // 指定したビット列で初期化される
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int x,y,z,k;
  cin >> x >> y >> z >> k;
  vector<long> a(x);
  vector<long> b(y);
  vector<long> c(z);
  rep(i,x) cin >> a.at(i);
  rep(i,y) cin >> b.at(i);
  rep(i,z) cin >> c.at(i);
  vector<long> data(x*y);
  rep(i,x){
    rep(j,y){
      data.at(i*y+j) = a.at(i) + b.at(j);
    }
  }
  sort(data.begin(),data.end(),greater<long>());
  sort(c.begin(),c.end(),greater<long>());
  //rep(i,x*y) cout << data.at(i) << " ";
  long maxi = min(k,x*y);
  vector<long> sum(maxi*z);
  rep(i,maxi){
    rep(j,z){
      //cout << "st " << i*maxi+j << endl;
      sum.at(i*z+j) = data.at(i) + c.at(j);
    }
  }
  sort(sum.begin(),sum.end(),greater<long>());
  rep(i,k){
    cout << sum.at(i) << endl;
  }
}

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

int main(void) {

	int N = 0;
	double D = 0;

	cin >> N >> D;

	double** A = new double *[N];
	double* B = new double[N];

	for (int i = 0; i < N; i++) {
		A[i] = new double[2];
	}

	for (int i = 0; i < N; i++) {
		cin >> A[i][0] >> A[i][1];
	}

	int c = 0;

	for (int i = 0; i < N; i++) {
		B[i] = sqrt(pow(A[i][0],2) +pow( A[i][1],2));
		if (B[i] <= D)
			c++;
	}

	cout << c;

}

Measured memory_bytes: 13244
#include <bits/stdc++.h>
using namespace std;
bool chk(int i, string s, string t) {
  if (s.size() < i + t.size()) return false;
  for (int j = 0; j < t.size(); ++j) {
    if (s[i + j] != '?' && t[j] != s[i + j]) return false;
  }
  return true;
}
int main() {
  string ss, t;
  cin >> ss >> t;
  const int n = ss.size();
  bool hasAns = false;
  string ret = "";
  for (int i = n; i >= 0; --i) {
    string s = ss;
    if (chk(i, s, t)) {
      int j = 0;
      while (j < i) {
        if (s[j] == '?') s[j] = 'a';
        j++;
      }

      while (j < i + t.size()) {
        s[j] = t[j - i];
        j++;
      }

      while (j < n) {
        if (s[j] == '?') s[j] = 'a';
        j++;
      }
      cout << s << endl;
      return 0;
    }
  }

  cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
n=int(input())
ans=n
for i in range(n+1):
    buf=0
    j=n-i
    while i>0:
        i0=i%6
        i=(i-i0)//6
        buf+=i0
    while j>0:
        j0=j%9
        j=(j-j0)//9
        buf+=j0
    if buf<ans:
        ans=buf
print(ans)

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

int main() {
	int H,W;
	cin >> H >> W;
	vector<vector<int>> a(H, vector<int>(W));
	vector<pair<P,P>> r;
	rep(i,H)
		rep(j,W)
			cin >> a.at(i).at(j);
	
	rep(i,H)
		rep(j,W) {
			if(i==H-1 && j==W-1)
				continue;

			if(!(i%2) && a.at(i).at(j)%2) {
				P p,q;
				--a.at(i).at(j);
				p = P(i+1,j+1);
				if(j < W-1) {
					++a.at(i).at(j+1);
					q = P(i+1,j+2);
				} else {
					++a.at(i+1).at(W-1);
					q = P(i+2, W);
				}
				r.push_back(make_pair(p, q));
			} else if((i%2) && a.at(i).at(W-1-j)%2)  {
				P p,q;
				--a.at(i).at(W-1-j);
				p = P(i+1,W-j);
				if(j < W-1) {
					++a.at(i).at(W-2-j);
					q = P(i+1,W-1-j);
				} else {
					++a.at(i+1).at(0);
					q = P(i+2, 1);
				}
				r.push_back(make_pair(p, q));
			}
		}
	
	cout << r.size() << endl;
	rep(i,r.size()) {
		cout << r.at(i).first.first << " " << r.at(i).first.second << " ";
		cout << r.at(i).second.first << " " << r.at(i).second.second << endl;
	}
}

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

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define rep(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define vll vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	 ll n;
  cin >> n;
 
  ll sum = 0;
  ll i0 = 0;
  vll ans;
  for (ll i = 1; i <= n; i++) {
    if (sum + i >= n) {
      i0 = i;
      ans.push_back(i0);
      break;
    }
    sum += i;
  }
  n -= i0;
  for (ll i = i0 - 1; i >= 1; i--) {
    if (n == 0) break;
    if (n < i) continue;
    n -= i;
    ans.push_back(i);
  }
 
  rep(i, (ll)ans.size()) cout << ans[i] << endl;
	return 0;
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

const int MOD = 1'000'000'007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  map<int, int> mp;
  for (int aa : a) {
    mp[aa]++;
  }
  ll res = 1;
  for (auto x : mp) {
    if (x.second != 2 && x.first != 0) {
      cout << 0 << endl;
      return 0;
    }
    res = res * x.second % MOD;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 6572
def resolve():
    import sys
    import numpy as  np
    input = sys.stdin.readline
    hwk = [int(x) for x in input().rstrip().split(" ")]
    h = hwk[0]
    w = hwk[1]
    k = hwk[2]
    matrix = np.zeros((h, w))

    for i in range(h):
        # 0白 1黒
        row = input().rstrip()
        for j in range(w):
            matrix[i, j] = 0 if row[j] == "." else 1
    
    import itertools
    ans = 1 if np.count_nonzero(matrix) == k else 0
    for n in range(1,h+w):
        for pair in itertools.combinations(list(range(h+w)), n):
            tmp = matrix.copy()
            # print(pair)
            # print(tmp)
            for i in pair:
                if(i < h):
                    tmp[i, :] = 0
                else:
                    tmp[:, i-h] = 0
            
            if np.count_nonzero(tmp) == k:
                ans += 1
            
            # print(tmp)
            # print(np.count_nonzero(tmp))
    print(ans)
        

        
            




if __name__ == "__main__":
    resolve()


# を理解する。そうすると、明らかに制限時間内に実行が終わらないソースコードを出さなくなる。ちなみに、競プロでは 108108 ～ 109109 回程度のループが回せるといわれている。

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

using namespace std;

typedef long long ll;

int main() {
    ll n,l,t;
    cin >> n >> l >> t;
    ll x[n], y[n];
    int w[n];
    for(int i=0;i<n;i++){
        cin >> x[i] >> w[i];
        if(w[i] == 1){
            y[i] = (x[i] + t) % l;
        }else{
            y[i] = (((x[i] - t) % l) + l) % l;
        }
    }
    sort(y, y+n);

    ll i0 = 0LL;
    for(int i=0;i<n;i++){
        if(w[i] == 1){
            if(l-x[i] > t) continue;
            i0 -= (t-(l-x[i])+l-1)/l;
        }else{
            if(x[i] > t) continue;
            i0 += (t-x[i]+l-1)/l;
        }
    }

    i0 = (i0 % n) + n;
    ll ans[n];
    for(int i=0;i<n;i++){
        ans[(i0+i)%n] = y[i];
    }
    for(int i=0;i<n;i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 3968
#include<stdio.h>
#define M 100

int n,r[M],c[M][M],l[M][M];

int Matrix(int *r){
  int i,j,k,x,y;
  
  for(i=1; i<=n; i++)
    c[i][i] = 0;

  for(j=2; j<=n; j++){

    for(i=1; i<=n-j+1; i++){
      l[i][i+j-1] = 200000000;

      for(k=i; k<=i+j-2; k++){
	x = l[i][i+j-1];
	y = l[i][k] + l[k+1][i+j-1] + r[i-1] * r[k] * r[i+j-1];
	if(x > y){
	  l[i][i+j-1] = y;
	}
      }
    }
  }
  return l[1][n];
}
  
int main()
{
  int i;
  scanf("%d",&n);

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

  printf("%d\n",Matrix(r));
    return 0;
}



Measured memory_bytes: 2048
//#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e4 + 100;
int n,p,cnt1,cnt2;
ll ans1,ans2;
int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    scanf("%d%d", &n, &p);
    ans2 = 1;
    for (int i = 0; i < n; ++i)
    {
        int x;
        scanf("%d", &x);
        x %= 2;
        if (x == 0)
        {
            ans1 *= 2;
            ans2 *= 2;
        }
        else
        {
            ans1 = ans2 = ans1 + ans2;
        }
    }
    if (p)
        printf("%lld\n", ans1);
    else
        printf("%lld\n", ans2);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char s[28];
	int t,t1;
	scanf("%s",s);
	for(t=0;s[t]!='\0';t++)
	{
		for(t1=t+1;s[t1]!='\0';t1++)
		{
			if(s[t] == s[t1])
			{
				printf("no\n");
				return 0;
			}
		}
	}
	printf("yes\n");
	return 0;
}

Measured memory_bytes: 128
m,k = map(int, input().split())
if k==0:
    ans=[]
    for i in range(2**m):
        ans.append(i)
        ans.append(i)
    print(*ans)
    exit()
if m==1:
    print(-1)
    exit()
if k > 2**m - 1:
    print(-1)
    exit()

ans=[]

for i in range(2**m):
    if i!=k:
        ans.append(i)
ans.append(0)
ans.append(k)
for i in reversed(range(1,2**m)):
    if i!=k:
        ans.append(i)
ans.append(k)

print(*ans)

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

int main(){
  int a,b,c,d;
  int i;
  //ab取得
  cin >> a;
  cin >> b;
  if(b == 100){
    c = (a*1000) + b;
  }
  else if(9 < b){
    c = (a*100) + b;
  }
  else{
    c = (a*10) + b;
  }

  //平方数かどうか取得
  for(i=1; i<=1000; i++)
  {
    if(c == i*i){
      cout << "Yes" << endl;
      break;
    }
    if(i == 1000){
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/numeric>
#define S second
#define F first


using namespace std;
using namespace __gnu_cxx;

const int N = 1e2 + 5, M = N * 2, mod = 1e9 + 7;

typedef long long ll;

#define arr(t, n, s, e) t _##n[e-s+1], *n= _##n+(-s);

int dp[N][4][4][4], n;

int solve(int ind, int f, int s, int t)
{
    if(ind == n) return 1;
    int &ret = dp[ind][f][s][t];
    if(~ret) return ret;
    ret = 0;
    for(int i = 0 ; i < 4 ; i++)
    {
        if(i == 1 and s == 0 and t == 2) continue;
        if(i == 1 and s == 2 and t == 0) continue;
        if(i == 1 and f == 0 and s == 2) continue;
        if(i == 1 and f == 0 and t == 2) continue;
        if(i == 2 and s == 0 and t == 1) continue;
        ret = (ret + solve(ind + 1, s, t, i)) % mod;
    }
    return ret;
}

int main()
{
//    freopen("input.in", "r", stdin);
//    freopen("out.out", "w", stdout);
    memset(dp, -1, sizeof dp);
    scanf("%d", &n);
    printf("%d\n", solve(0, 3, 3, 3));
    return 0;
}



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

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (auto &v : vec)
    is >> v;
  return is;
}
#define all(x) (x).begin(), (x).end()
#define rep(i, N) for (int i = 0; i < (int)(N); i++)

void solve()
{
  int N;
  vector<int> D(3);
  cin >> N >> D;
  vector<string> s(N);
  cin >> s;

  vector<char> ans;
  rep(i, N)
  {
    int first = s[i][0] - 'A';
    int second = s[i][1] - 'A';
    if (D[first] == 0 and D[second] == 0)
    {
      cout << "No" << endl;
      return;
    }

    int greater;
    int less;

    int rest = 0 + 1 + 2 - first - second;
    if (D[first] == 1 and D[second] == 1 and i + 1 < N and count(all(s[i + 1]), (char)('A' + rest)) == 1)
    {
      if (count(all(s[i + 1]), (char)('A' + first)) == 1)
      {
        greater = second;
        less = first;
      }
      else
      {
        greater = first;
        less = second;
      }
    }
    else if (D[first] >= D[second])
    {
      greater = first;
      less = second;
    }
    else
    {
      greater = second;
      less = first;
    }

    D[greater]--;
    D[less]++;
    ans.push_back('A' + less);
  }
  cout << "Yes" << endl;
  rep(i, N) cout << ans[i] << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 6736
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
# import numpy as np
# import scipy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def main():
    a = str(input())
    if a == 'z':
        print('a')
        return
    x = ord(a)
    x+=1
    print(chr(x))

if __name__ == "__main__":
    main()

Measured memory_bytes: 39148
n = int(input())
s = input()

tmp = 0
for i in range(1, n):
    if s[i] == "E":
        tmp += 1
count = tmp

for i in range(1, n):
    if s[i-1] == "W":
        tmp += 1
    if s[i] == "E":
        tmp -= 1
    count = min(count, tmp)
print(count)


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s[0]=='S' && s[1]=='U')
    cout<<"7";
  else if(s[0]=='M' && s[1]=='O')
    cout<<"6";
   else if(s[0]=='T' && s[1]=='U')
    cout<<"5";
  else if(s[0]=='W' && s[1]=='E')
    
    cout<<"4";
  else if(s[0]=='T' && s[1]=='H')
    cout<<"3"; 
  else if(s[0]=='F' && s[1]=='R')
    cout<<"2"; 
  else cout<<"1";
  return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#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 <numeric> // next_parmutation
#define ll long long


using namespace std;

int main() {
    ll A, B, C, K;
    cin >> A >> B >> C >> K;
    ll x, y;
    ll sum = 0;

    if(A <= K){
        sum += A;
        x = K - A;

        if(B < x){
            sum -= x - B;
        }
    }else sum += K;

    cout << sum << endl;



}

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

int main(){
  int com[1000][2];
  int n,x;
  int count = 0;
  int i = 0;
  while(1){
    cin >> com[i][0] >> com[i][1];
    if(com[i][0] == 0 && com[i][1] == 0){ 
      break;
    }   
    i++;
  }

  for(int g = 0;g < i;g++){
count = 0;
    n = com[g][0];
    x = com[g][1];
    for(int a = 1;a <= n;a++){
      for(int b = a+1; b <= n;b++){
        for(int c = b+1;c <= n;c++){
          if(a+b+c==x){
            count+=1;
          }   
        }   
      }   
    }   
    cout << count << endl;
  }
}

Measured memory_bytes: 3084
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#define For(i,j,k) for(int i=j;i<=k;i++)
#define Dow(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
using namespace std ;
inline int read() {
	int x = 0 , f = 1 ;
	char ch = getchar() ;
	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }
	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }
	return x * f ;
}

const int N = 1011, mod = 1e9+7;

int n;
int f[1011],ans;

int main() {
	scanf("%d",&n);
	For(i, 2, n) {
		int x = i;
		for(int j=2; j*j<=i; j++) 
			while( x%j==0 ) f[j]++,x/=j; 
		if(x!=1) f[x]++;
	}
	ans = 1;
	For(i, 2, 1000) 
		ans = 1ll*ans*(f[i]+1)%mod;
	printf("%d\n",ans);
	return 0;
}







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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec;
    for(int i = 0; i < N; i++) {
      int A;
      cin >> A;
      vec.push_back(A);
      for(int j = 0; j < vec.size() - 1; j++) {
        if(vec.at(j) == A) {
          vec.pop_back();
          continue;
        }
      }
      
    }
    
  cout << vec.size() << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using Pair = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;

/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  sort(rall(v));
  ll ans = 0;
  for(int i=0;i<k;i++){
    ans += v[i];
  }
  cout << ans << endl;
}

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

const int Mod=1e9+7;
int n,m,a[1005][1005],f[1005][1005];
char c[1005];

int main(void){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",c);
		for(int j=0;j<m;j++)
		if(c[j]=='.')a[i][j+1]=0;
		else a[i][j+1]=1;
	}
	if(a[1][1]==1||a[n][m]==1){
		printf("0");
		return 0;
	}
	f[1][1]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(i==1&&j==1)continue;
			if(a[i][j]==1)continue;
			f[i][j]=(f[i-1][j]+f[i][j-1])%Mod;
		}
	}
	printf("%d\n",f[n][m]);
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> count(n, 0);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    count.at(a-1)++;
    count.at(b-1)++;
  }

  for (int i = 0; i < n; i++) cout << count.at(i) << 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;
typedef long long ll;
using P = pair<int,int>;
const int MOD = 1000000007;

int main() {
    int h,w;
    cin>>h>>w;
    vector<string> c(h),ans;
    rep(i,h) {
        cin>>c[i];
        rep(j,2) ans.push_back(c[i]);
    }
    rep(i,2*h) cout<<ans[i]<<endl;
}


Measured memory_bytes: 256
while True:
    try:
        a = int(input())
        t=0
        h=0
        for i in range(a):
            b,c=input().split()
            if b>c:
                t+=3
            elif c>b:
                h+=3
            else:
                t+=1
                h+=1
        print(t,h)
    except EOFError:break


Measured memory_bytes: 5604
#include <stdio.h>

int N;
int parent[100001];
int sibling[100001];
int degree[100001];

int calcDepth(int i) {
  if(parent[i] == -1) return 0;
  return calcDepth(parent[i]) + 1;
}

int calcHeight(int i) {
  int j, h;
  h = 0;
  for(j = 0; j < N; ++j) {
    if(parent[j] == i) {
      int tmp = calcHeight(j) + 1;
      if(tmp > h) h = tmp;
    }
  }
  return h;
}

int main() {
  int i,j;
  scanf("%d", &N);
  for(i = 0; i < N; ++i) {
    parent[i] = -1;
    sibling[i] = -1;
    degree[i] = 0;
  }
  for(i = 0; i < N; ++i) {
    int id, left, right;
    scanf("%d %d %d", &id, &left, &right);
    if(left != -1) {
      parent[left] = id;
      sibling[left] = right;
      ++degree[id];
    }
    if(right != -1) {
      parent[right] = id;
      sibling[right] = left;
      ++degree[id];
    }
  }

  for(i = 0; i < N; ++i) {
    int depth = calcDepth(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
           i, parent[i], sibling[i], degree[i], depth, calcHeight(i));
    if(depth == 0) {
      printf("root\n");
    } else if(degree[i] == 0) {
      printf("leaf\n");
    } else {
      printf("internal node\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    vector<string> v = {"maerd", "remaerd", "esare", "resare"};
    while (1)
    {
        int a = 0;
        for (int i = 0; i < 4; i++)
        {
            if (s.find(v[i])==0)
            {
                s.erase(0, v[i].size());
                a++;
            }
        }
        if (a == 0)
        {
            break;
        }
    }
    if (s.size() == 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N;
    cin >> N;
    vector<string> vec(N);
    rep(i, N) cin >> vec.at(i);

    sort(all(vec));
    uni(vec);

    cout << vec.size() << endl;
}

Measured memory_bytes: 9596
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef bitset<16> BS;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 2E+05;

int N, K;

int S[MAX_N + 1];

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

    cin >> N >> K;

    for (int i = 0; i < N; i++) {
        int s;
        cin >> s;
        S[s]++;
    }

    sort(S + 1, S + N + 1);

    int ans = 0;
    int n = 0;
    int spn = S + N + 1 - lower_bound(S + 1, S + N + 1, 1);

    for (int i = 1; i <= N; i++) {
        if (n >= spn - K)
            break;
        if (S[i] != 0) {
            ans += S[i];
            n++;
        }
    }
    /*
    cout << "spn = " << spn << "\n";
    for (int i = 1; i <= N; i++) {
        cout << "i = " << i << ", S = " << S[i] << "\n";
    }
    */

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 4360
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin>>k;
    long a[k*k];
    int t=0;
    for(long int i=1;i<=k;i++)
    {
        for(long int j=1;j<=k;j++)
        {a[t]=__gcd(i,j);
        t++;
        }
    }
    long long ans=0;
    for(long int i=1;i<=k;i++)
    {
        for(int t=0;t<k*k;t++)
        {
            ans+=__gcd(i,a[t]);
        }
    }
    cout<<ans;
    
}

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  ll N,A,B;
  cin >> N >> A >> B;
  ll ans = 0;
  if(N == 1 && (B > A)){
    ans = 0;
  } else if(A > B){
    ans = 0;
  } else { 
    ans = (A+B*(N-1)) - (B+A*(N-1)) + 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
until(n,m=gets.split.map(&:to_i))==[0,0]do
r,p,a=[],[],[]
n.times{r.unshift(gets.gsub("?",".").split)}
m.times{p<<gets.split}
p.each{|p|r.each{|r|if p[0]=~/#{r[1]}/&&p[1]=~/#{r[2]}/
a<<p*" "if r[0]=~/p/
break
end}}
puts a.size,a
end

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

int ans(int,int);
int num[2000];
int m[2000];
int n;

int main(){
  int i,j,q;

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


  
  for(i=0;i<q;i++){
    if(ans(0,m[i]))printf("yes\n");
    else printf("no\n");
  }
 
  return 0;
}

int ans(int x, int y){
  
  if(num[x] == y){
    return 1;
  }
  
  if(x+1  == n){
    return 0;
  }
  
  if(ans(x+1,y-num[x]) || ans(x+1,y)){
    return 1;
  }

  return 0;
}


Measured memory_bytes: 2108
import java.util.Scanner;

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

        int N = sc.nextInt();
        int l[] = new int[N];
        //System.out.println(N);

        for(int i = 0;i<N;i++){
        
            l[i] = sc.nextInt();
            //System.out.println(l[i]);
        }
        
        int temp,num = 0, M;

        M = N;

        if(N == 1){

            System.out.println(l[0]);
            System.out.println(0);
        }else{

        while(true){

            for(int i = 0;i<M-1;i++){
                if(l[i] > l[i+1]){

                    temp = l[i];
                    l[i] = l[i+1];
                    l[i+1] = temp;

                    num++;

                }
            }
            M--;
            if(M==1){
                break;
            }
        }

        for(int i = 0;i<N;i++){
            if(i == N-1){
                System.out.println(l[i]);
            }else{
            System.out.print(l[i] + " ");
            }
        }
        //System.out.println("\n");
        System.out.println(num);
    }
    }
}


Measured memory_bytes: 26360
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
//string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    int t,i,j,n,m,l,r;
    cin>>n>>m;
    int a[n+2];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int s=0;
    for(i=0;i<m;i++)
    {
        s+=a[i];
    }
    cout<<s<<"\n";
    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <string.h>
#include <cstring>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define NEWLINE cout << '\n'
#define loop(n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define MULTI_TEST int t; cin >> t; while (t--) 

#define EXTERNAL_FILES 0
#if EXTERNAL_FILES
ifstream fin("input.txt");
ofstream fout("output.txt");
#define cin fin
#define cout fout
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<vi, int> msi;

#define EXTERNAL_OUT 0
#if EXTERNAL_OUT 
ofstream fout("output.txt");
#define cout fout
#endif

ll gcd(ll a, ll b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

string binary(int n) {
	string bin;
	while (n) {
		bin += (n % 2 ? '1' : '0');
		n /= 2;
	}
	reverse(bin.begin(), bin.end());
	return bin;
}
bool isPalindrome(string s) {
	for (int i = 0, j = s.size() - 1; i < j; i++, j--)
		if (s[i] != s[j]) return 0;
	return 1;
}
bool isPrime(ll n) {
	if (n <= 1) return false;
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0) return false;
	}
	return true;
}
inline vi sieve(int n) {
	vector<bool> isPrime(n + 1, true);
	for (int i = 2; i <= sqrt(n); i++) {
		if (isPrime[i])
			for (int j = 2 * i; j <= n; j += i) {
				isPrime[j] = false;
			}
	}
	vi primes;
	for (int i = 2; i <= n; i++)
		if (isPrime[i]) primes.push_back(i);
	return primes;
}

inline vi primeFactors(int n) {
	vi factors;
	vi primes = sieve(100000);
	int i = 0;
	while (n != 1 && i < primes.size()) {
		if (n % primes[i] == 0) {
			factors.push_back(primes[i]);
			n /= primes[i];
		}
		else {
			i++;
		}
	}
	return factors;
}

void shift_right(vi& A, int x) {
	int n = A.size();
	x %= n;
	vi B(n);
	for (int i = 0; i < n; i++)
		B[(i + x)%n] = A[i];
	A = B;
}
inline vector<bool> sieveQuery(int n) {
	vector<bool> isPrime(n + 1, true);
	for (int i = 2; i <= sqrt(n); i++) {
		if (isPrime[i])
			for (int j = 2 * i; j <= n; j += i) {
				isPrime[j] = false;
			}
	}
	return isPrime;
}



int main()
{
	IOS;
	
	string s; cin >> s;
	int sum_digits = 0;
	for (char c : s)
		sum_digits += c - '0';
	cout << (sum_digits % 9 ? "No" : "Yes");
}

Measured memory_bytes: 3736
//package ;
import java.io.*;
import java.util.*;

public class Main {
	static int n ,k,a[],dp[][];
	static int dp(int rem,int turn)
	{
		if(rem==0)
			return 0; // loose
		if(rem<0)
			return 1; // win
		
		if(dp[turn][rem]!=-1)
			return dp[turn][rem];
		
		int max=n-1;
		
//		System.out.println(rem+" "+max);
		
		int ans=0;
		while(max>=0)
			ans+=1-dp(rem-a[max--],1-turn);
		
		if(ans>0)
			ans=1;
		
		return dp[turn][rem]=ans;
	}
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter pw = new PrintWriter(System.out);
		n=sc.nextInt();k=sc.nextInt();
		a=sc.nextIntArray(n);
		dp=new int[2][k+1];//0 first ,1 second
		Arrays.fill(dp[0], -1);
		Arrays.fill(dp[1], -1);
		System.out.println(dp(k,0)==1?"First":"Second");
//		System.out.println(dp(k,0));
		pw.close();
	}
	static int bs(int v)
	{
		int lo=0,hi=n-1;int ans=-1;
		while(lo<=hi)
		{
			int mid=lo+hi>>1;
			if(a[mid]==v)
				return mid;
			if(a[mid]>v)
				hi=mid-1;
			else
			{
				ans=lo;
				lo=mid+1;
			}
		}
		return ans;
	}
	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}
			return st.nextToken();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		boolean hasnext() throws IOException {
			return br.ready();
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] a = new Integer[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		char[] nextCharArray() throws IOException {
			return br.readLine().toCharArray();
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] ans = new double[n];
			for (int i = 0; i < n; i++)
				ans[i] = nextDouble();
			return ans;
		}

	}
}


Measured memory_bytes: 35284
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

struct matrix{
    vvi cell;
    int n;
    
    matrix(int n){
        this->n=n;
        cell.resize(n,vi(n));
    }
    
    matrix operator*(const matrix &b){
        matrix c(n);
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                for(int k=0;k<n;k++){
                    c.cell[i][k]+=cell[i][j]*b.cell[j][k]%MOD;
                    c.cell[i][k]%=MOD;
                }
            }
        }
        return c;
    }
    
    matrix I(int n){
        matrix I(n);
        for(int i=0;i<n;i++)I.cell[i][i]=1;
        return I;
    }
    
    matrix pow(int k){
        if(k==0)return this->I(n);
        matrix ans=this->pow(k/2);
        ans=ans*ans;
        if(k&1)ans=ans*(*this);
        return ans;
    }
};

signed main(){
    FASTER;
    int n,k;cin>>n>>k;
    matrix adj(n);
    matrix dp(n);
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>adj.cell[i][j],dp.cell[i][i]=1;
    
    dp=dp*adj.pow(k);
    
    int ans=0;
    for(int i=0;i<n;i++)for(int j=0;j<n;j++)ans=(ans+dp.cell[i][j])%MOD;
    cout<<ans;
}


Measured memory_bytes: 3660
#include<iostream>
#include<string>

using namespace std;

int main(){
	string S;
	int K;
	
	cin >> K;

	cin >> S;

	if(K < S.length()){
		cout << S.substr(0, K) + "..." << endl;
	}else{
		cout << S << endl;
	}

}

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

int main(){
    int H,W,K;
    cin >> H >> W >> K ;
    char C[H][W];
    rep(i,H){
        rep(j,W){
            cin >> C[i][j] ;
        }
    }
    int ans=0,c;
    int blackH,blackW;
    rep(blackH,1<<H){
        rep(blackW,1<<W){
            c=0;
            rep(i,H){
                rep(j,W){
                    if(((1<<i)&blackH) and ((1<<j)&blackW) and C[i][j]=='#')
                    c++;
                }
            }
            if(c==K) ans++;
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3620
N = int(input())
edges = [[] for _ in range(N)]

for i in range(N - 1):
    fr, to = map(lambda a: int(a) - 1, input().split())
    edges[fr].append((i, to))
    edges[to].append((i, fr))

ans = [-1] * (N - 1)
st = [(0, -1)]
while st:
    now, pr = st.pop()

    C = []
    D = set()
    for i, _ in edges[now]:
        D.add(ans[i])
    for i in range(len(edges[now]) + 1)[::-1]:
        if i in D:
            continue
        C.append(i)

    for i, to in edges[now]:
        if to == pr:
            continue
        ans[i] = C.pop()
        st.append((to, now))

print(max(ans) + 1)
for a in ans:
    print(a + 1)


Measured memory_bytes: 38908
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <fstream>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;


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


bool isPrime[1000100];
int prime[1000100];

int p;
void erats(){
  for(int i=0;i<1000100;i++)
    isPrime[i]=true;
  p=0;
  isPrime[0]=isPrime[1]=false;
  for(int i=2;i<1000100;i++){
    if(isPrime[i]){
      prime[p++]=i;
      for(int j=2*i;j<1000100;j+=i)
        isPrime[j]=false;
    }
  }
}


int N,M;
map<pair<short,short>,int> m;
pair<short,short> idToPii[1000200];
pii dp[1000100];

pii dfs(int pos){
  if(dp[pos].first>=0)return dp[pos];
  pii res=pii(isPrime[pos],isPrime[pos]?pos:0);
  for(int i=-1;i<=1;i++){
    pii nxt=idToPii[pos];
    nxt.first++;
    nxt.second+=i;
    if(m.count(nxt)&&m[nxt]<=M){
      pii p=dfs(m[nxt]);
      if(isPrime[pos])p.first++;
      if(res.first<p.first)res=p;
      else if(res.first==p.first){
        if(res.second<p.second)
          res=p;
      }
    }
  }
  return dp[pos]=res;
}

int main(){
  erats();
  
  int sum=1;
  int pos=0;
  pii now=pii(0,0);
  m[now]=1;
  idToPii[sum]=now;
  sum++;
  for(int i=1;;i++){
    for(int j=0;j<2;j++){
      // posの方向へiだけ進む
      for(int k=0;k<i;k++){
        now.first+=dy[pos];
        now.second+=dx[pos];
        m[now]=sum;
        idToPii[sum]=now;
        sum++;
        if(sum>=1000100)break;
      }
      pos=(pos+1)%4;
    }
    if(sum>=1000100)break;
  }
  //return 0;
  while(cin>>M>>N&&(N|M)){
    for(int i=0;i<=M;i++)
      dp[i].first=dp[i].second=-1;
    pii p=dfs(N);
    cout<<p.first<<" "<<p.second<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 62736
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>
using namespace std;

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define llrp(i,n) for(long long i=0;i<n;i++)
#define llrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define vcin(a); rp(i,a.size()){cin>>a[i];}
#define vcout(a); rp(i,a.size()){cout<<a[i]<<endl;}
#define allchar(c) for(char c='a';c<='z';c++)

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;
typedef queue<int> qi;

const int mod=1e9+7;

ll modpow(ll a,ll b,ll p){
    if(b==0){
        return 1;
    }elif(b%2==0){
        return modpow((a*a)%p,b/2,p);
    }else{
        return (a*modpow(a,b-1,p))%p;
    }
}

int main(){
    int n;
    cin >> n;
    vi a(n);
    vcin(a);
    bool first=false;
    rp(i,n){
        if(a[i]%2){
            first=true;
        }
    }
    cout << (first?"first":"second") << endl;
    return 0;
}

Measured memory_bytes: 640
def min(a,b); a < b ? a : b; end
def max(a,b); a > b ? a : b; end

A,B,C,X,Y = gets.split.map(&:to_i)
puts (0 .. max(X,Y) * 2).inject(A * X + B * Y){|s,n| min(s, A * max(X - n/2, 0) + B * max(Y - n/2, 0) + n * C) }

Measured memory_bytes: 1788
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
 
int main()
{
	int a,b,c,count=0;
	std::cin >> a >> b >> c;
	int pointx[10000] = {};
	int pointy[10000] = {};
	for (int i = 0; i < c;i++)
	{
		std::cin >> pointx[i];
		std::cin >> pointy[i];
	}
	for (int i = 0; i < c-1;i++) 
	{
		count += abs(pointx[i + 1] - pointx[i]);
		count += abs(pointy[i + 1] - pointy[i]);
		//次が右上

		if (pointx[i + 1] - pointx[i] > 0 && pointy[i + 1] - pointy[i]>0) {
			count -= std::min(pointx[i + 1] - pointx[i], pointy[i + 1] - pointy[i]);

	
		}
		//次が左下
		else if (pointx[i] - pointx[i+1]>0 && pointy[i] - pointy[i+1]>0) {
			count -= std::min(pointx[i] - pointx[i + 1], pointy[i] - pointy[i + 1]);

		
			
		}
		else {
			count -= 0;
		
		
		}

	}

	std::cout << count << std::endl;

	return 0;
}



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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

bool acgt(char c) { return string("ACGT").find(c) != string::npos; }

int main() {
  in(string, s);
  int ans = 0;
  rep(i, s.size()) for (int j = i; j < s.size(); ++j) {
    bool ok = true;
    for (int k = i; k <= j; ++k)
      if (!acgt(s[k])) ok = false;
    if (ok) ans = max(ans, j - i + 1);
  }
  out(ans);
}


Measured memory_bytes: 3620
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int main(){
  int a,b;
  double y;
  cin>>a>>b;
  if(b==100) a*=10;
  if(b<10) a*=10;
  else a*=100;
  y=a+b;
  y=sqrt(y);
  if(floor(y)==ceil(y)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
x,y = map(int,input().split())
if y-(2*x) < 0:
    print('No')
elif y-(2*x) == 0:
    print('Yes')
else:
    if (y-(2*x))%2 != 0:
        print('No')
    else:
        if x-(y-(2*x))//2 >= 0:
            print('Yes')
        else:
            print('No')


Measured memory_bytes: 9152
S = list(input())
syo = 'abcdefghijklmnopqrstuvwxyz'
syo = list(syo)
check = 0
if S[0] == 'A':
    pass
else:
    check = 1

tmp = S[2:-1]
if tmp.count('C') == 1:
    iii = S.index('C')
    for i in range(len(S)):
        if i == 0 or i == iii:
            pass
        else:
            if S[i] in syo:
                pass
            else:
                check = 1
else:
    check = 1



if check == 0:
    print('AC')
else:
    print('WA')




Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){

    ll l,r,ans;
    cin >> l >> r;

    if ((l < 2019) && (r < 2019)){
        ans = ((l + 1)*l)%2019;
    }
    else if ((l <= 2019) && (2019 <= r)){
        ans = 0;
    }
    else{
        if (r/2019 != l/2019){
            ans = 0;
        }
        else{
            ll temp, min_num = 2020;
            for (ll a=l; a<=r; a++){
                for (ll b=a+1; b<=r; b++){
                    temp = ((a%2019)*(b%2019))%2019;
                    min_num = min(min_num, temp);
                }
            }
            ans = min_num;
        }
    }

    cout << ans << endl;
    return 0;
}

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

#define pb push_back

vector<int>g[100003];
vector<int>v(100003);
queue<int>q;

int main()
{
    int s,w;
    cin>>s>>w;
    if(s>w)
    {
        cout<<"safe"<<endl;
    }
    else
    {
        cout<<"unsafe"<<endl;
    }
}





Measured memory_bytes: 5940
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,maxi=0, mini=1000;
    cin>>n;
    while(n--)
    {
        int num;
        cin>>num;

        if(num>maxi)
            maxi=num;
        if(num<mini)
            mini=num;
    }
    cout<<maxi-mini<<endl;
    return 0;
}

Measured memory_bytes: 384