akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;
typedef vector<pair<int, int>> vp;

const int INF = 1000000000;
const int MOD = 1000000007;

vector<vector<int>> edge;
vector<bool> flg;

void dfs(int node) {
    if (flg[node]) return;
    flg[node] = true;
    for (auto i : edge[node]) dfs(i);
}

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

    edge.resize(N);
    rep(i, M) {
        int X, Y, Z;
        cin >> X >> Y >> Z;
        X--, Y--;

        edge[X].push_back(Y);
        edge[Y].push_back(X);
    }

    int ans = 0;
    flg.resize(N, false);
    rep(i, edge.size()) {
        if (!flg[i]) {ans++;
            dfs(i);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 8832
s1 = ""
try:
	while True:
		t = input()
		if t == "":
			break
		s1 += t
except EOFError:
	pass
n = [0] * 26
s = s1.lower()
for i in range(len(s)):
	j = ord(s[i]) - 97
	if j >= 0 and j < 26:
		n[j] += 1
for i in range(26):
	print('%s : %d' %(chr(i + 97), n[i]))



Measured memory_bytes: 5556
N = int(input())
P = list(map(int, input().split()))

flg = False
ans = 0
for k, v in enumerate(P):
    if k+1 == v:
        if flg: 
            flg = False
        else:
            ans += 1
            flg = True
        continue
    if flg:
        flg = False
print(ans)

Measured memory_bytes: 20596
#include<iostream>
#include<cstring>
using namespace std;
int i,len;
char a[70];
int main(){
    cin>>a;
    len=strlen(a);
    for(i=0;i<len;i++){
        if(a[i]!=','){
            cout<<a[i];
        }
        else{
            cout<<' ';
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
int arr[100005];
int main(){
    cs;
    memset(arr,0,sizeof arr);
    int m,n,x,y;
    cin>>m>>n;
    string s;cin>>s;
    rep(i,m-1){
        if(s[i]=='A'&&s[i+1]=='C') arr[i+1]++;
        arr[i+1]+=arr[i];
    }
    rep(i,n){
        cin>>x>>y;
        cout<<arr[y-1]-arr[x-1]<<'\n';
    }
}

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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using Pair = pair<int, int>;
const ll mod = 1e9 + 7;

struct Edge {
  int to, idx;
  Edge(int to, int idx): to(to), idx(idx) {}
  friend ostream& operator<<(ostream& os, const Edge& e) {
    os << "(" << e.to << "," << e.idx << ")";
    return os;
  }
};

vector<int> path;
bool dfs(int v, int to, vector<vector<Edge>> edges, int p=-1, Edge e=Edge(0,0)) {
  if (v == to) {
    path = vector<int>();
    return true;
  }
  for (auto edge: edges[v]) {
    if (edge.to == p) continue;
    if (dfs(edge.to, to, edges, v, edge)) {
      path.push_back(edge.idx);
      return true;
    }
  }
  return false;
}

int lsbpos(int x) {
  int lsb = x&(-x);
  if (!lsb) return -1;
  int i=1, pos=0;
  while (!(lsb&i)) {
    i = i << 1;
    pos++;
  }
  return pos;
}

int main(int argc, char const* argv[])
{
  int n;
  cin >> n;

  vector<vector<Edge>> edges(n+1);

  for (int i = 0; i < n-1; i++) {
    int a, b;
    cin >> a >> b;
    Edge e1(b, i);
    Edge e2(a, i);
    edges[a].push_back(e1);
    edges[b].push_back(e2);
  }

  int m;
  cin >> m;
  // 各制約のpathをbitで表現したもの
  // vector<vector<int>> constraint(m, {0});
  vector<ll> constraint(m);

  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;

    // edgesからdfsで経路に含まれるedgeのidのリストを取る
    dfs(u, v, edges);
    // edgeのidに対応するbitを立てる
    for (auto elem: path) {
      constraint[i] |= (ll)pow(2, elem);
    }
  }

  ll ans = 0;
  for (ll i = 0; i < pow(2, m); i++) {
    ll constbit = i;
    ll constcount = __builtin_popcountll(constbit);
    ll edge = 0;

    while(constbit) {
      edge |= constraint[lsbpos(constbit)];
      constbit -= constbit&(-constbit);
    }
    ll white = __builtin_popcountll(edge);
    ll count = pow(2, n-1-white);
    if (constcount%2) ans -= (ll)count;
    else ans += (ll)count;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int n;
	cin>>n;
	cout<<a[n-1]<<endl;
	return 0;
}

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

map<string,int> mem;

int main()
{
	int n;
	cin >> n;
	
	for (int i = 0; i < n; ++i)
	{
		string s;
		cin >> s;
		mem[s]++;
	}
	
	//int max = mem.rbegin() -> second;
	int maxv = 0;
	for (const auto& x : mem)
	{
		int v = x.second;
		if (v > maxv)
		{
			maxv = v;
		}
	}
	
	//cout << "-----" << endl;
	
	/*
	for (auto x : mem)
	{
		cout << x.first << " " << x.second << endl;
		
		
		if (x.second == max)
		{
			cout << x.first << endl;
		}
	}
	*/
	
	for (auto it = mem.begin(); it != mem.end(); it++)
	{
		if (it -> second == maxv)
		{
			cout << it -> first << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 25216
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int c = 0;
        for(int i=0; i<n; i++) {
            int h = in.nextInt();
            if(h >= k) {
                c++;
            }
        }
        System.out.println(c);
    }
}


Measured memory_bytes: 46908
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int q;
  cin >> q;
  while (q--) {
    int k;
    cin >> k;
    ll m = 0, c = 0, dmc = 0, ans = 0;
    int j = 0;
    for (int i = 0; i < n; ++i) {
      while (j < n && j - i < k) {
        if (s[j] == 'M') {
          m++;
        } else if (s[j] == 'C') {
          c++;
          dmc += m;
        }
        j++;
      }
      if (s[i] == 'D') {
        ans += dmc;
      }
      if (i == j) {
        j++;
      } else {
        if (s[i] == 'M') {
          m--;
          dmc -= c;
        } else if (s[i] == 'C') {
          c--;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1412
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        FastReader scan = new FastReader();
        //PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("something.in")));
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        Task solver = new Task();
        //int t = scan.nextInt();
        int t = 1;
        for(int i = 1; i <= t; i++) solver.solve(i, scan, out);
        out.close();
    }
    static class Task {
        public void solve(int testNumber, FastReader sc, PrintWriter pw) {
            String str = sc.nextLine();
            str = sc.nextLine();
            pw.println(str.length()%2==0&&str.substring(0,str.length()/2).equals(str.substring(str.length()/2))?"Yes":"No");
        }
		/*
		public long exp(long base, int power){
			if(power == 0) return 1;
			if(power == 1) return (base + mod) % mod;
			long ans = exp(base,power/2);
			ans = (ans*ans + mod) % mod;
			if(power%2 == 1) ans = (ans*base + mod) % mod;
			return (ans + mod) % mod;
		}*/

    }
    static class tup implements Comparable<tup>{
        int a, b;
        tup(int a, int b){
            this.a=a;
            this.b=b;
        }

        @Override
        public int compareTo(tup o) {
            return Integer.compare(o.a,a);
        }
    }
    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }
    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 23380
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <queue>

using namespace std;
typedef long long ll;

int main() {
    ll N,M;
    cin >> N >> M;
    vector<vector<ll>> S(M);
    for(int i=0;i<M;i++){
        ll k;cin >> k;
        for(int j=0;j<k;j++){
            ll tmp;
            cin >> tmp;
            tmp--;
            S[i].push_back(tmp);
        }
    }
    vector<ll> P;
    for(int i=0;i<M;i++){
        ll tmp;
        cin >> tmp;
        P.push_back(tmp);
    }
    ll ans=0;
    ll ct=0;
    for(int i=0;i<(1<<N);i++){
        for(int l=0;l<M;l++){
            ct=0;
            for(int j=0;j<S[l].size();j++){
                ll tmp=i;
                if((tmp>>S[l][j])&1) ct++;
            }
            if(ct%2==P[l]) {
                if(l==M-1) ans++;
                else continue;
            }
            else break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)1e9+7
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n, a[114514];
signed main() {
	cin >> n;
	REP(i, n + 1)cin >> a[i];
	a[n + 1] = inf;
	REP(i, n + 1) {
		if (a[i - 1] < a[i])a[i]--;
		if (a[i] > a[i + 1]) {
			cout << "No" << endl; return 0;
		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 1024
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;cin>>n;
    vector<int>p(n),q(n);
    for(int i=0;i<n;i++)cin>>p[i];
    for(int i=0;i<n;i++)cin>>q[i];
    int a=0,b=0;
    int aa[9];
    for(int i=0;i<n;i++)aa[i]=i+1;
    int cnt=0;
    
    while(next_permutation(aa, aa+n)){
        //cout<<aa[0]<<" "<<aa[1]<<" "<<aa[2]<<endl;
        bool abc=1;
        cnt++;
        for(int i=0;i<n;i++)
        {
            if(aa[i]!=p[i])
                abc=0;
        }
        if(abc==1)
            a=cnt;
        abc=1;
        for(int i=0;i<n;i++)
        {
            if(aa[i]!=q[i])
                abc=0;
        }
        if(abc==1){
            b=cnt;
        }
        //break;
    }
    cout<<abs(a-b)<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------







Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f3f3f3f3f3f
#define pi 3.1415926535898
#define N 200050
using namespace std;
int a[10000010];
int main()
{
    ll x;
    cin>>x;
    if(x%2==0||x%5==0)
    {
        cout<<-1<<endl;
    }
    else
    {
        ll sum=7;
        ll k=1;
        int flag=0;
        while(sum%x!=0)
        {
            sum=(sum*10+7)%x;
            if(!a[sum])
            {
                a[sum]++;
            }
            else 
            {
                flag=1;
                break;
            }
            k++;
        }
        if(flag==0)
        cout<<k<<endl;
        else 
        {
            cout<<-1<<endl;
        }
    }


    return 0;
}


Measured memory_bytes: 7464
using System;
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] t1 = Console.ReadLine().Split(' ');
            int[] t = new int[t1.Length];
            for(int i = 0; i < t1.Length; i++)
            {
                t[i] = int.Parse(t1[i]);
            }
            int m = int.Parse(Console.ReadLine());
            int[][] px = new int[m][];
            for(int i = 0; i < m; i++)
            {
                string[] px1 = Console.ReadLine().Split(' ');
                px[i] = new int[2];
                px[i][0] = int.Parse(px1[0]);
                px[i][1] = int.Parse(px1[1]);
            }
            for(int i = 0; i < m; i++)
            {
                int ans = 0;
                for (int j = 0; j < n; j++)
                {
                    if(j == px[i][0] - 1)
                    {
                        ans += px[i][1];
                    }
                    else
                    {
                        ans += t[j];
                    }
                }
                Console.WriteLine(ans);
            }
        }
    }

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

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

    ll N, M, a[57], b[57], ans[57], ans_distance[57];
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < M; i++) {
        ll c, d;
        cin >> c >> d;
        if (i == 0) {
            for (int j = 0; j < N; j++) {
                ans_distance[j] = abs(a[j] - c) + abs(b[j] - d);
                ans[j] = i + 1;
            }
        } else {
            for (int j = 0; j < N; j++) {
                ll distance = abs(a[j] - c) + abs(b[j] - d);
                if (distance < ans_distance[j]) {
                    ans_distance[j] = distance;
                    ans[j] = i + 1;
                }
            }
        }
    }

    for (int i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}


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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N + 1);
  for (int i = 0; i < N; i++) {
    cin >> A[i + 1];
  }
  vector<int> B(N + 1);
  B[0] = A[0];
  for (int i = 1; i < N + 1; i++) {
    B[i] = B[i - 1] + A[i];
    B[i] %= K;
  }
  for (int i = 0; i < N + 1; i++) {
    B[i] -= i;
    B[i] %= K;
    if (B[i] < 0) {
      B[i] += K;
    }
  }

  map<int, int> m;
  long long ans = 0;
  for (int i = 0; i < N + 1; i++) {
    if (i - K >= 0) {
      m[B[i - K]]--;
    }
    ans += m[B[i]];
    m[B[i]]++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11136
#pragma GCC optimize("O3")   //
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef unsigned long long ull;

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);

uniform_int_distribution<> DD(0, (1ll << 31));

ll random2(){
    return (ll(DD(eng))*(1ll << 31) + ll(DD(eng))) & ((1ll << 62ll)-1);
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 1000001;

vector<string> S;
vi ind;
int dip[MAXN] = {0};
int rise[MAXN] = {0};

bool comp(ll i, ll j){
    if(rise[i] >= 0 && rise[j] >= 0){
        return dip[i] > dip[j];
    }
    if(rise[i] < 0 && rise[j] < 0){
        return dip[i] - rise[i] < dip[j] - rise[j];
    }
    return rise[i] > rise[j];
}

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

    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d,e;

    cin >> n;
    rep(c1,0,n){
        string s;
        cin >> s;
        S.push_back(s);
        ind.push_back(c1);
        d = 0;
        a = 0;
        trav(ch,s){
            if(ch == '('){
                a++;
            }
            else{
                a--;
            }
            d = min(a,d);
        }
        dip[c1] = d;
        rise[c1] = a;
    }

    sort(all(ind), comp);
    a = 0;
    d = 0;
    trav(i,ind){
        trav(ch, S[i]){
            if(ch == '('){
                a++;
            }
            else{
                a--;
            }
            d = min(a,d);
        }
    }
    if(a != 0 || d < 0){
        cout << "No\n";
    }
    else{
        cout << "Yes\n";
    }

    return 0;
}


Measured memory_bytes: 50392
N, M, C = map(int, input().split())
B = [int(i) for i in input().split()]
A = [[int(j) for j in input().split()] for i in range(N)]

count = 0
for i in range(N):
    sum = 0
    for j in range(M):
        sum += A[i][j]*B[j]
    if sum + C > 0:
        count += 1

print(count)


Measured memory_bytes: 3060
#include<stdio.h>
int main()
{

    int A,B,C,D,Right,Left;
    scanf("%d",&A);
    scanf("%d",&B);
    scanf("%d",&C);
    scanf("%d",&D);
    Right=C+D;
    Left=A+B;
    if(Right>Left){
        printf("Right\n");

    }
    else if(Left>Right){
        printf("Left\n");
    }
else{
     printf("Balanced\n");
}
    return 0;
}



Measured memory_bytes: 1664
while True:
 
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for k in range(W):
            if i == 0 or i == H-1 or k == 0 or k == W-1:
                print("#",end = "")
            else:
                print(".",end = "")
        print()
    print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
#include <unistd.h>
#include <random>

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
      cin.tie(0);
      ios::sync_with_stdio(false);
      long long int N, M;
      cin >> N >> M;
      vector<pair<LL,LL>> IllegalDrugs (N);
      for(int i = 0;i < N;i++){
      	cin >> IllegalDrugs[i].first >> IllegalDrugs[i].second;
      }
      SORT(IllegalDrugs)
      long long int ans = 0;
      for(int i = 0;M != 0;i++){
      	if(M <= IllegalDrugs[i].second){
      		ans += M*IllegalDrugs[i].first;
      		M = 0;
      	}
      	else{
      		ans += IllegalDrugs[i].first*IllegalDrugs[i].second;
      		M -= IllegalDrugs[i].second;
      	}
      }
      cout << ans << endl;
}

Measured memory_bytes: 1792
// https://atcoder.jp/contests/agc046/tasks/agc046_a
#include<bits/stdc++.h>
using namespace std;

int main(int argc, char* argv[]) {
	int x, i = 1;
	cin >> x;
	while ((360*i)%x) {
		++i;
	}
	cout << (360*i)/x << endl;
	return 0;
}

Measured memory_bytes: 3632
N = int(input())
words = {}

for i in range(N):
	Si = input()
	if Si not in words.keys():
		words[Si] = 1
	else:
		words[Si] += 1

        
max_num = max(words.values())
max_words = [word for word, val in words.items() if val==max_num]
for word in sorted(max_words):
	print(word)

Measured memory_bytes: 33884
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::string S;
  std::cin >> N >> S;
  std::cout << (N % 2 == 0 && S.substr(0, N / 2) == S.substr(N / 2, N / 2) ? "Yes" : "No") << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLL = vector<PLL>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();
const unsigned long long int ULLINF = numeric_limits<unsigned long long int>::max();

int main() {
    
    LL a, b, c, d;
    cin >> a >> b >> c >> d;

    VLL ans(4,0);
    ans[0] = a * c;
    ans[1] = b * d;
    ans[2] = a * d;
    ans[3] = b * c;

    LL anss;
    anss = max(ans[0], ans[1]);
    anss = max(anss, ans[2]);
    anss = max(anss, ans[3]);

    cout << anss << endl;

    return 0;

}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
#pragma GCC optimize ("Ofast")
#define ll long long
#define pll pair<long long,long long>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define forn(i, n) for(int i=0; i<int(n); i++)
#define Forn(i, n) for(int i=1; i<=int(n); i++)

using namespace std;

/*#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;*/

string nxt(string s)
{
    if(s.size() == 1)
    {
        if(s[0] == '9') return "10";
        else
        {
            s[0]++;
            return s;
        }
    }
    for(int i = s.size()-2; i>=0; i--)
    {
        if(s[i+1]!='9' && s[i] >= s[i+1])
        {
            s[i+1]++;
            for(int j=i+2; j<s.size(); j++)
            {
                if(s[j-1] == '0') s[j] = '0';
                else s[j] = s[j-1] - 1;
            }
            return s;
        }
    }
    if(s[0]<'9')
    {
        s[0]++;
        for(int i=1; i<s.size(); i++)
        {
            if(s[i-1] == '0') s[i] = '0';
            else s[i] = s[i-1] - 1;
        }
        return s;
    }
    string ss = "";
    ss.pb('1');
    forn(i, s.size()) ss.pb('0');
    return ss;
}

int main()
{
    cin.tie(0);ios_base::sync_with_stdio(false);
    string now = "1";
    int k;
    cin >> k;
    forn(i, k-1)
    {
        //cout << now << endl;
        now = nxt(now);
    }
    cout << now << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int nax = 20;
char grid[nax][nax];
int dist[nax][nax];
int n, m;

int solve(int sx, int sy) {
	queue<pii> q;
	q.push({sx, sy});
	REP(i, n) REP(j, m) dist[i][j] = -1;
	dist[sx][sy] = 0;
	while (!q.empty()) {
		pii cur = q.front(); q.pop();
		vector<pii> dd{{0,1}, {0,-1}, {1, 0}, {-1, 0}};
		for (auto d : dd) {
			int nx = cur.st + d.st, ny = cur.nd + d.nd;
			if (nx >= 0 && nx < n && ny >=0 && ny < m && grid[nx][ny] == '.' && dist[nx][ny] == -1) {
				q.push({nx, ny});
				dist[nx][ny] = 1 + dist[cur.st][cur.nd];
			}
		}
	}
	int res = -1;
	REP(i, n) REP(j, m) if (dist[i][j] > 0) {
		res = max(res, dist[i][j]);
	}
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);

	scanf("%d %d", &n, &m);
	REP(i, n) {
		scanf("%s", grid[i]);
	}
	int best = -1;
	REP(sx, n) REP(sy, m) {
		if (grid[sx][sy] == '#') {
			continue;
		}
		best = max(best, solve(sx, sy));
	}
	printf("%d\n", best);
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int W=cin.nextInt();
			int H=cin.nextInt();
			if((W|H)==0)break;
			int[][] field=new int[W][H];
			int[][] dp=new int[W][H];
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					field[j][i]=cin.nextInt();
				}
			}
			for(int i=0;i<W;i++){
				dp[i][0]=1;
			}
			int ans=0;
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
					if(field[j][i]==1){
						dp[j][i]=0;
					}
					else if(field[j][i]==2){
						if(i+2>=H){
							ans+=dp[j][i];
						}
						else{
							dp[j][i+2]+=dp[j][i];
						}
					}
					else{
						if(i+1>=H){
							ans+=dp[j][i];
							continue;
						}
						if(j-1>=0){
							if(field[j-1][i+1]==0)
								dp[j-1][i+1]+=dp[j][i];
						}
						if(j+1<W){
							if(field[j+1][i+1]==0)
								dp[j+1][i+1]+=dp[j][i];
						}

						dp[j][i+1]+=dp[j][i];
					}
				}
			}
			for(int i=0;i<H;i++){
				for(int j=0;j<W;j++){
//					System.out.print(dp[j][i]+" ");
				}
//				System.out.println();
			}
			System.out.println(ans);
		}

	}

}

Measured memory_bytes: 23472
N, M = map(int, input().split())
H = list(map(int, input().split()))
H.insert(0, None)
towers = set(range(1, N+1))
for _ in range(M):
    A, B = map(int, input().split())
    if H[A] >= H[B]:
        towers.discard(B)
    if H[A] <= H[B]:
        towers.discard(A)
print(len(towers))


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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("F.in", "r", stdin);
	freopen ("F.out", "w", stdout);
#endif
}

const int N = 110, inf = 0x3f3f3f3f;

template<int Maxn, int Maxm>
struct Dinic {

	int Head[Maxn], Next[Maxm], cap[Maxm], to[Maxm], e;

	Dinic() { e = 1; }

	inline void add_edge(int u, int v, int flow) {
		to[++ e] = v; Next[e] = Head[u]; Head[u] = e; cap[e] = flow;
	}

	inline void Add(int u, int v, int flow) {
		add_edge(u, v, flow); add_edge(v, u, 0);
	}

	int S, T, dis[Maxn];
	bool Bfs() {
		queue<int> Q; Q.push(S); Set(dis, 0); dis[S] = 1;
		while (!Q.empty()) {
			int u = Q.front(); Q.pop();
			for (int i = Head[u], v = to[i]; i; v = to[i = Next[i]])
				if (cap[i] && !dis[v])
					dis[v] = dis[u] + 1, Q.push(v);
		}
		return dis[T];
	}

	int cur[Maxn];
	int Dfs(int u, int flow) {
		if (u == T || !flow) return flow;
		int res = 0, f;
		for (int &i = cur[u]; i; i = Next[i]) {
			int v = to[i];
			if (dis[v] == dis[u] + 1 && (f = Dfs(v, min(flow, cap[i])))) {
				cap[i] -= f, cap[i ^ 1] += f, res += f;
				if (!(flow -= f)) break;
			}
		}
		if (!res) dis[u] = 0;
		return res;
	}


	int Run() {
		int sum_flow = 0;
		while (Bfs()) {
			Cpy(cur, Head);
			sum_flow += Dfs(S, inf);
		}
		return sum_flow;
	}

};

Dinic<N * N * 2, N * N * N * 16> D;

int h, w; char S[N][N];

inline int id(int x, int y, int p) { 
	return p * h * w + (x - 1) * w + y; 
}

int main () {

	File();

	h = read(); w = read();

	For (i, 1, h) {
		scanf ("%s", S[i] + 1);
		For (j, 1, w) {
			if (S[i][j] == 'S') D.S = id(i, j, 0);
			if (S[i][j] == 'T') D.T = id(i, j, 1);
			D.Add(id(i, j, 0), id(i, j, 1), S[i][j] == 'S' || S[i][j] == 'T' ? inf : 1);
		}
	}

	For (i, 1, h) For (j, 1, w) if (S[i][j] != '.') {
		For (k, 1, h) if (i != k && S[k][j] != '.') {
			D.Add(id(i, j, 1), id(k, j, 0), inf);
			if (S[i][j] == 'S' && S[k][j] == 'T') return puts("-1"), 0;
		}
		For (k, 1, w) if (j != k && S[i][k] != '.') {
			D.Add(id(i, j, 1), id(i, k, 0), inf);
			if (S[i][j] == 'S' && S[i][k] == 'T') return puts("-1"), 0;
		}
	}

	printf ("%d\n", D.Run());

	return 0;

}

Measured memory_bytes: 53504
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ans := 0
	for i := 1; i <= n; i++ {
		cnt := 0
		for j := 1; j <= i; j++ {
			if j%2 == 1 && i%j == 0 {
				cnt++
			}
		}
		if cnt == 8 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
// TEMPLATE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i=(a);(i)<(b);(i)++)
#define FORS(i, a, b) for (int i=(a);(i)<=(b);(i)++)
#define REP(i, n) for (int i=0;(i)<(n);(i)++)
#define REPS(i, n) for (int i=1;(i)<=(n);(i)++)
#define RREP(i, n) for (int i=(n-1);(i)>=0;(i)--)
#define RREPS(i, n) for (int i=n;(i)>0;(i)--)
#define len(x) ((int)(x).size())
#define print(x) (cout<<(x)<<"\n")

// LIBRARY


// SOLVE
ll f(ll b, ll n) {
    if (n<b) return n;
    return f(b, n/b) + n%b;
}

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

    ll n; cin>>n;
    ll s; cin>>s;

    // 自明
    if (n==s) {
        print(n+1);
        return 0;
    }
    if (s > n) {
        print(-1);
        return 0;
    }
    // sqrt(n)までは全探索
    ll sq = sqrt(n) + 1;
    FOR(i, 2, sq) {
        if (f(i, n) == s) {
            print(i);
            return 0;
        }
    }
    // 残りは2桁 上の桁で探索
    ll ans = 1e18+1;
    FOR(i, 1, sq) {
        ll b = (n-s)/i + 1;
        if ((n-s)%i==0 && f(b, n) == s) {
            ans = min(ans, b);
        }
    }
    if (ans == 1e18+1) {
        print(-1);
        return 0;
    }
    print(ans);
}


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

    const int N = 2E5 + 5;

    queue<int> q, cur;
    int n, a[N], b[N], dsu[N];
    long long ans = 0;

    int trace(int u)
    {
        return (dsu[u] < 0 ? u : dsu[u] = trace(dsu[u]));
    }

    void unity(int u, int v)
    {
        if ((u = trace(u)) == (v = trace(v)))
            return;
        if (dsu[u] > dsu[v])
            swap(u, v);
        dsu[u] += dsu[v];
        dsu[v] = u;
    }

    int main()
    {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++)
        {
            scanf("%d", a + i);
            dsu[i] = -1;
            b[i] = i;
        }
        sort(b + 1, b + n + 1, [](const int &x, const int &y) { return a[x] < a[y]; });
        for (int i = 1; i <= n; i++)
            a[b[i]] = i;
        for (int i = 1; i <= n; i++)
            q.push(a[i]);
        for (int i = 1; i <= n; i++)
        {
            while (trace(q.front()) != trace(i))
            {
                ans -= dsu[trace(q.front())];
                cur.push(q.front());
                q.pop();
            }
            ans -= (dsu[trace(i)] + 1);
            q.pop();
            while (!cur.empty())
            {
                unity(cur.front(), i);
                cur.pop();
            }
            if (dsu[trace(i)] < -1)
            {
                ++dsu[trace(i)];
                q.push(trace(i));
            }
        }
        printf("%lld\n", ans);
    }


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

using namespace std;

int main(){
    int n;
    cin>>n;
    double ans=0.0;
    for (int i = 0; i < n; ++i) {
        int a;cin>>a;
        ans+=(double)1/(double)(a);
    }
    ans=(1/ans);
    cout<<setprecision(10);
    cout<<ans<<endl;
    return 0;
}

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

struct edge{ ll from, to, cost; };

int main(){
    int N, M;  cin >> N >> M;
    vector<edge> E(M);
    for(int i=0; i<M; i++){
        cin >> E[i].from >> E[i].to >> E[i].cost;
        E[i].from--;  E[i].to--;
    }
    
    ll inf = 1e18;
    vector<ll> dist(N,-inf);
    dist[0] = 0;
    bool loop = false;
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            edge e = E[j];
            if(dist[e.to] < dist[e.from] + e.cost){
                dist[e.to] = dist[e.from] + e.cost;
                if(i==N-1 && e.to == N-1) loop = true;
            }
        }
    }

    if(loop){
        cout << "inf" << endl;
    }else{
        cout << dist[N-1] << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int n,k,a[202020],sum,ans;
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n>>k;
	fo(i,0,n){
		cin>>a[i];
		a[i]++;
	}
	sum=ans=0;
	fo(i,0,k)sum+=a[i];
	fo(i,k,n){
		ans=max(ans,sum);
		sum+=a[i]-a[i-k];
	}
	ans=max(ans,sum);
	cout<<ans/2<<(ans%2==1?".5":".0")<<"00000000000\n";
	return 0;
}


Measured memory_bytes: 1024
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

namespace str{
    vector<ll> Manacher(const string &s){
        vector<ll> ret(s.size(),0);
        int j=0;
        for(int i=0;i<s.size();){
            while(i>=j && i+j<s.size() && s[i-j]==s[i+j]){j++;}
            ret[i]=j;
            int k=1;
            while(k<j && ret[i-k]+k<j){ret[i+k]=ret[i-k]; k++;}
            i+=k; j-=k;
        }
        return ret;
    }
    
    vector<ll> Z_Algorithm(const string &s){
        vector<ll> ret(s.size(),0);
        ret[0]=s.size();
        int j=0;
        for(int i=1;i<s.size();){
            while(i+j<s.size() && s[j]==s[i+j]){j++;}
            ret[i]=j;
            if(j==0){i++; continue;}
            int k=1;
            while(k+ret[k]<j){ret[i+k]=ret[k]; k++;}
            i+=k; j-=k;
        }
        return ret;
    }
};

using namespace str;


bool judge(string &s,ll t){
    if(s.size()%t!=0){return false;}
    for(int i=0;i<s.size();i++){
        if(s[i]!=s[i%t]){return false;}
    }
    return true;
}


int main(){
    string s;
    cin>>s;
    if(judge(s,1)){cout<<s.size()<<endl<<1<<endl; return 0;}
    bool j=false;
    for(ll i=2;i<s.size();i++){
        if(judge(s,i)){j=true;}
    }
    if(!j){cout<<1<<endl<<1<<endl; return 0;}
    vector<ll> ret=Z_Algorithm(s);
    vector<bool> judge(s.size()+1,true);
    judge[0]=false;
    for(ll i=1;i<s.size();i++){
        if(ret[i]>=i){
            for(ll t=2;i*(t-1)<=ret[i];t++){
                judge[i*t]=false;
            }
        }
    }
    reverse(s.begin(),s.end());
    reverse(judge.begin(),judge.end());
    judge[0]=false;
    ret=Z_Algorithm(s);
    for(ll i=1;i<s.size();i++){
        if(ret[i]>=i){
            for(ll t=2;i*(t-1)<=ret[i];t++){
                judge[i*t]=false;
            }
        }
    }
    ll count=0;
    for(int i=0;i<judge.size();i++){if(judge[i]){count++;}}
    //for(ll i=judge.size()-1;i>=0;i--){cout<<judge[i];}
    //cout<<endl;
    cout<<2<<endl<<count<<endl;
    
    
    
    
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

constexpr int d = 365;
constexpr int n = 26;

vector<int> c(n);
vector<vector<int>> s(d,vector<int>(n));

int main(){
  cin.ignore(3);
  cin >> c;
  for(auto&e:s)cin >> e;
  vector<int> ans(d);
  for(int i = 0; i < d; ++i){
    int maxp = -1001001001;
    int argi = 0;
    for(int j = 0; j < n; ++j){
      if(ChangeMax(maxp,s[i][j]))argi = j;
    }
    ans[i] = argi+1;
  }
  for(auto e:ans)cout << e << endl;
  return 0;
}


Measured memory_bytes: 3680
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll N, Q, A[112345], B[112345], C[112345];

int main() {

	cin >> N;
	rep(i, N) cin >> A[i];
	cin >> Q;
	rep(i, Q) cin >> B[i] >> C[i];

	ll ans = 0;

	map <ll, ll> cnt;

	rep(i, N) cnt[A[i]]++;

	for (auto ccc : cnt) {
		ans += ccc.first * ccc.second;
	}

	rep(i, Q) {
		ans += (C[i] - B[i]) * cnt[B[i]];
		cout << ans << endl;
		cnt[C[i]] += cnt[B[i]];
		cnt[B[i]] = 0;
	}




	return 0;
}


Measured memory_bytes: 11736
def main():
    N = int(input())
    D, X = map(int, input().split())
    A = [int(input()) for _ in range(N)]
    choco = 0
    for i in range(N):
        a = A[i]
        for j in range(D):
            if 1 + j*a <= D:
                choco += 1
    print(X + choco)
main()

Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>

#include <numeric>

#include <map>

#include <set>

#include <vector>

#include <memory>

using namespace std;

typedef unsigned long long LL;

LL sum;

int main() {

    int n; cin >> n;
    int cnt = 0;
    for (LL i = 1; i <= n ; ++i) {
        if (i % 3 == 0 || i % 5 == 0) {
            cnt += 0;
        } else {
            ++ cnt;
            sum += i;
        }
    }

    cout << sum << endl;


}

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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    str s;cin >> s;
    char m='a';int ans=0;
    rep(i,0,s.size()){
        if(m!=s[i]){
            ans++;
        }
        m=s[i];
    }
    cout << ans-1 << endl;
    return 0;
}


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

using namespace std;

long long v[40][3];

bool ok(long long a, long long b, long long c) {
    if( a & 1 ) return 0;
    if( b & 1 ) return 0;
    if( c & 1 ) return 0;

    for(int i=1; v[i][0] != 0 && v[i][1] != 0 && v[i][2] != 0; ++i)
        if(v[i][0] == a && v[i][1] == b && v[i][2] == c)
            return 0;

    return 1;
}

int main()
{
    //freopen("input", "r", stdin);
    //freopen("output", "w", stdout);

    //printf("-1");
    //return 0;

    long long n, i, a, b, c, ca, cb, cc;

    scanf("%lld%lld%lld", &a, &b, &c);

    long long ans = 0;

    while(ok(a, b, c))
    {
        v[ans][0] = a;
        v[ans][1] = b;
        v[ans][2] = c;
        sort(v[ans], v[ans]+3);

        ca = (b+c) / 2;
        cb = (a+c) / 2;
        cc = (a+b) / 2;
        ans++;

        a = ca;
        b = cb;
        c = cc;

    }

    if((a & 1) || (b & 1) || (c & 1))
        printf("%lld", ans);
    else printf("-1");

    return 0;
}


Measured memory_bytes: 256
k,a,b = (int(num) for num in input().split())
ans = 0
if a-b >= -2:
    ans = k+1
elif k <= a-1:
    ans = k+1
else:
    n_yen = (k-a+1)//2
    ans = k+1 - n_yen*2 + n_yen*(b-a)
print(ans)

Measured memory_bytes: 40496