akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
using namespace std;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
//     tree_order_statistics_node_update>;
 
typedef long long int ll;
const ll N = 5e5+9;
const ll p = 31;
// const ll m = 1e9 + 7;
const ll inf= 1ll<<60;
const ll mod = 1e9+7;
#define x first
#define y second
#define pb push_back
#define mp make_pair
using pii = pair<ll, ll>;
ll powm(ll a, ll b) { a = a%mod;ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; }
#define BLOCK 708 // ~sqrt(N)
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")



int main()
{   
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif                           
    ll T= 1;
    // cin >> T;
    while(T--){
    	string s,t;cin>>s>>t;
    	ll n = s.size();
    	if(t.size()== n+1){
    		if(s == t.substr(0,n)){
    			cout<<"Yes"<<'\n';
    		}
    		else{
    			cout<<"No"<<'\n';
    		}
    	}
    	else{
    		cout<<"No\n";
    	}
    }
}   

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

typedef long long ll;
ll a, b, k, ans;
ll f(ll p, ll q) {
	ll m = p / (q * 2);
	ll pl = max(min(p % (q * 2) - q + 1, q), 0ll);
	return m * q + pl;
}
int main()
{
	ll i, z;
	cin >> a >> b;
	for (k = 1; k <= b; k *= 2) {
		z = f(b, k) - f(a - 1, k);
		if (z % 2) ans += k;
	}
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
$<.readlines.drop(1).map {|a| a.split.map(&:to_r)}.each do |x1, y1, x2, y2, x3, y3, x4, y4|
  puts ((x2 - x1) * (y4 - y3) == (x4 - x3) * (y2 - y1) ? "YES" : "NO")
end


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

int main(){
  int n,d;
  cin >> n >> d;
  int answer;
  if(n % (2 * d + 1) == 0)answer = n  / (2 * d + 1);
  else answer = n  / (2 * d + 1) + 1;
  
  cout << answer << endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;
lint p=1000*1000*1000+7;



int main(){
  lint bl[8],wh[8],ari[8];
  bl[0]=0;
  wh[0]=1;
  FOR(i,1,8){
    bl[i]=0;
    wh[i]=0;
    bl[i]=wh[i-1];
    wh[i]=bl[i-1]+wh[i-1];
  }
  REP(i,8)ari[i]=bl[i]+wh[i];
  // REP(i,8)cerr<<ari[i]<<endl;

  int H,W,K;
  cin>>H>>W>>K;
  if(W==1){
    cout<<1<<endl;
    return 0;
  }
  lint dp[H+1][W];
  REP(i,W)dp[0][i]=0;
  dp[0][0]=1;
  FOR(h,1,H+1){
    REP(w,W){
      lint temp=0;
      if(w==0){
        temp+=dp[h-1][w]*ari[W-2];
        temp%=p;
        temp+=dp[h-1][w+1]*ari[W-3];
        temp%=p;
      }else if(w==W-1){
        temp+=dp[h-1][w-1]*ari[W-3];
        temp%=p;
        temp+=dp[h-1][w]*ari[W-2];
        temp%=p;
      }else{
        temp+=dp[h-1][w-1]*ari[max(0,w-2)]*ari[max(0,W-w-2)];
        temp%=p;
        temp+=dp[h-1][w]*ari[w-1]*ari[max(0,W-w-2)];
        temp%=p;
        temp+=dp[h-1][w+1]*ari[w-1]*ari[max(0,W-w-3)];
        temp%=p;
      }
      dp[h][w]=temp;
    }
  }
  // REP(i,H+1){
  //   REP(j,W)cerr<<dp[i][j]<<" ";
  //   cerr<<endl;
  // }
  cout<<dp[H][K-1]<<endl;
  return 0;
}


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

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

  int cnt = 0;

  for(int a = 1; a < n; a++) {
    for(int b = 1; b < n; b++) {
      if(n <= a * b) break;
      if( n > a * b) cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 3628
def resolve():
    n = int(input())
    h = list(map(int, input().split()))
    OK = True
    for i in range(1, len(h)):
        if h[i] == h[i-1]:
            continue
        elif h[i] > h[i-1]:
            h[i] -= 1
        else:
            OK = False
            break
    if OK:
        print("Yes")
    else:
        print("No")
resolve()

Measured memory_bytes: 14224
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	ll n, m;
	scanf("%ld %ld", &n, &m);
	V links[n];
	REP(i, 0, m){
		ll a, b;
		scanf("%ld %ld", &a, &b);
		links[a-1].push_back(b-1);
		links[b-1].push_back(a-1);
	}

	V ans(n, -1);
	std::queue<P> que;
	que.emplace(-1, 0);
	while(!que.empty()){
		auto [from, now] = que.front();
		que.pop();
		if(ans[now]>=0) continue;
		ans[now] = from + 1;
		for(ll to: links[now]){
			if(ans[to]>=0) continue;
			que.emplace(now, to);
		}
	}
	puts("Yes");
	REP(i, 1, n) printf("%ld\n", ans[i]);
	return 0;
}



Measured memory_bytes: 14108
#include<iostream>
#include<string>
#include<cstdio>
#include <cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
    int K, X; cin >> K >> X;
    int mini = X - K + 1, maxi = X + K - 1;
    for(int i = mini; i <= maxi; i++) {
        cout << i << " ";
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFLL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  if (n == k) {
    cout << 1 << endl;
  } else {
    cout << 1 + (n-2) / (k-1) << endl;
  }

  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);
    vector<pair<int,int> > z;
    int i;
    for(i=0; i<n; i++) {
        int tmp;
        scanf("%d", &tmp);
        z.push_back(make_pair(tmp,i));
    }
    sort(z.begin(),z.end());

    vector<int> ans(n);
    for(i=0; i<n; i++) {
        if(i<n/2) ans[z[i].second]=z[n/2].first;
        else      ans[z[i].second]=z[n/2-1].first;
    }
    for(i=0; i<n; i++) {
        printf("%d\n", ans[i]);
    }

    return 0;
}



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

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

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n; cin >> n;
	vi a(n);
	rep(i, n-1) cin >> a[i];

	vi ans(n + 1, 0);
	rep(i, n-1){
		ans[a[i]-1]++;
	}

	rep(i, n){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
int a,b,c,d,e;
int main()
{
	cin>>a>>c>>b>>d>>e;
	re((b-a)*60+d-c-e)
	return 0;}

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

int main(){
    int w, a, b;
    cin >> w >> a >> b;

    if(b+w < a){
        cout << a-(b+w) << endl;
    }else if(b > a+w){
        cout << b-(a+w) << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n, k; cin >> n >> k;
    int r, s, p; cin >> r >> s >> p;
    string t; cin >> t;

    map<char, char> mp;
    mp['r'] = 'p';
    mp['s'] = 'r';
    mp['p'] = 's';

    for (int i = 0; i < t.length(); ++i) {
        t[i] = mp[t[i]];
    }

    for (int i = 0; i < k; ++i) {
        int tmp = i;
        while (tmp < n) {
            if (tmp + k < n && t[tmp] == t[tmp + k]) {
                t[tmp + k] = 'x';
            }

            tmp += k;
        }
    }

    map<char, int> point;
    point['r'] = r;
    point['s'] = s;
    point['p'] = p;
    point['x'] = 0;

    int ans = 0;
    for (int i = 0; i < t.length(); ++i) {
        ans += point[t[i]];
    }

    cout << ans << endl;
}

Measured memory_bytes: 512
using System;

namespace ITP1_1_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);

            if (a < b)
                Console.WriteLine("a < b");

            else if (a > b)
                Console.WriteLine("a > b");

            else
                Console.WriteLine("a == b");
        }
    }
}

Measured memory_bytes: 8900
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int main() {
	int n, m; cin >> n >> m;
	vector<int>p(m), y(m);
	for (int i = 0; i < m; ++i)cin >> p[i] >> y[i], --p[i];
	//vals[v]:=p[i]=vであるようなiについてのy[i]の値を集めたもの
	vector<vector<int>>vals(n);
	for (int i = 0; i < m; ++i) {
		vals[p[i]].push_back(y[i]);
	}
	for (int v = 0; v < n; ++v) {
		sort(vals[v].begin(), vals[v].end());
		vals[v].erase(unique(vals[v].begin(), vals[v].end()), vals[v].end());
	}
	for (int i = 0; i < m; ++i) {
		int v = p[i];
		cout << setw(6) << setfill('0') << v + 1;
		int id = lower_bound(vals[v].begin(), vals[v].end(), y[i]) - vals[v].begin();
		cout << setw(6) << setfill('0') << id + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 7808
n=int(input())
h=list(map(int,input().split()))
dp=[0]*n
for i in range(1,n):
	dp[i]=dp[i-1]+abs(h[i]-h[i-1])
	if i>1:
		dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

Measured memory_bytes: 13980
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
S1 = list(input())
S2 = list(input())

if S1[0] == S2[0]:
    ans = 3
    start = 1
else:
    ans = 6
    start = 2

i = start
while i <= N-1:
    if S1[i] == S2[i]:
        if S1[i-1] == S2[i-1]:
            ans *= 2
            ans %= mod
        i += 1
    else:
        if S1[i-1] == S2[i-1]:
            ans *= 2
            ans %= mod
        else:
            ans *= 3
            ans %= mod
        i += 2
print(ans)

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

int main() {
  int n;cin>>n;
  string s;cin>>s;
  int ans=0,cnt=0;
  rep(i,n){
    if(s[i]=='I')cnt++;
    if(s[i]=='D')cnt--;
    ans=max(ans,cnt);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3592
import java.util.Scanner;

class Main{

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

int[] buf=new int[3];

for(int i=0;i<buf.length;i++){
    buf[i]=sc.nextInt();
}

int work;
for(int i=0;i<buf.length;i++){
   for(int j=0;j<buf.length-i-1;j++){
       if(buf[j]>buf[j+1]){
            work=buf[j];
            buf[j]=buf[j+1];
            buf[j+1]=work;
       }
   }
}


System.out.print(buf[0]+" "+buf[1]+" "+buf[2]);
System.out.println();

sc.close();
}

}


Measured memory_bytes: 26216
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
struct Dice {
	int d[6], E, S, U;
	Dice(int a[]) {
		rep(i, 6)d[i] = a[i];
		E = 2; S = 1; U = 0;
	}
	void rotate(char C) {
		int a = E, b = S, c = U;
		switch (C) {
		case'E':E = U; U = 5 - a; break;
		case'N':U = S; S = 5 - c; break;
		case'S':S = U; U = 5 - b; break;
		case'W':U = E; E = 5 - c; break;
		case'R':S = E; E = 5 - b; break;
		case'L':E = S; S = 5 - a; break;
		}
	}
	int rotate(int a, int b) {
		rep(k, 2) {
			rep(i, 4) {
				rep(j, 4) {
					if (a == d[U] && b == d[S])return d[E];
					rotate('E');
				}
				rotate('S');
			}
			rotate('L');
		}
	}
};
int main() {
	int a[6]; rep(i, 6)cin >> a[i];
	Dice d(a);
	int q; cin >> q;
	rep(i, q) {
		int a, b; cin >> a >> b;
		cout << d.rotate(a, b) << endl;
	}
}


Measured memory_bytes: 3088
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#define rep(i,m,n) for(int i=m; i<(n); i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
typedef long long ll;
using namespace std;

const int INF = 1001001001;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    vector<int> ans(n);
    rep(sv,0,n)
    {
        vector<int> dist(n, INF);
        queue<int> q;
        auto push = [&](int v, int d)
        {
            if(dist[v] != INF) return ;
            dist[v] = d;
            q.push(v);
        };
        push(sv, 0);
        while(!q.empty())
        {
            int v = q.front(); q.pop();
            int d = dist[v];
            if(v-1 >= 0) push(v-1, d+1);
            if(v+1 < n) push(v+1, d+1);
            if(v == x) push(y, d+1);
            if(v == y) push(x, d+1);
        }
        rep(i,0,n) ans[dist[i]]++;
    }
    rep(i,0,n) ans[i] /= 2;
    rep(i,1,n) cout << ans[i] << endl;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
 
now = 1
ok = False
 
a.sort()
 
for i in range(len(a)):
	now *= a[i]
	if now > 1000000000000000000 :
			print(-1)
			ok = True
			break
 
if ok == False:
	print(now)
 

Measured memory_bytes: 21640
def check(number):
    if number % 2 == 1:
        return True
    if number % 3 == 0 or number % 5 == 0:
        return True
    return False


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

flag = True

for num in array:
    if check(num) is False:
        flag = False
        break

if flag:
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 2940
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (const T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	int n;
	cin >> n;
	set<string> st;
	while(n--)
	{
		string s;
		cin >> s;
		st.insert(s);
	}
	cout << st.size();
}


Measured memory_bytes: 19200
//g++  7.4.0

#include <iostream>
#include <string>
using namespace std;

int main()
{
    int k;
    cin >> k;
    std::string s;
    cin >> s;

    if(s.length() <= k){
        cout << s << endl;
    }else{
        cout << s.substr(0, k) << "..." << endl;
    }
}

Measured memory_bytes: 3612
#include <cassert>
#include <cstring>
#include <iostream>
using namespace std;
int main() {
    int n, k; cin >> n >> k;
    const int o = 2*n*(n+1);
    long long dp[2][n][2*o+1];
    const int M = 1000000007;
    int cur = 0, prev = 1;
    memset(dp, 0, sizeof(dp[0][0][0])*2*n*(2*o+1));
    dp[prev][0][o] = 1;
    for (int i = 1; i <= n; i++) {
        memset(dp[cur], 0, sizeof(dp[0][0][0])*n*(2*o+1));
        for (int j = 0; j < i; j++) {
            for (int w = 0; w <= 2*o; w++) {
                const long long v = dp[prev][j][w] % M;
                if (v == 0) continue;
                dp[cur][j][w] += (2 * j + 1) * v % M;
                if (j+1 < n) dp[cur][j+1][w-2*i] += v;
                if (j > 0) dp[cur][j-1][w+2*i] += v * j * j % M;
                if (j > 0) assert (w - 2*i >= 0);
            }
        }
        swap(cur, prev);
    }
    cout << dp[prev][0][o+k] % M << endl;
}


Measured memory_bytes: 8192
import java.util.*;

public class Main {
    private static Scanner scanner;

    public static int[] inputIntArray(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; ++i) {
            res[i] = scanner.nextInt();
        }

        return res;
    }

    // public static String[] <T> ToStringArray(T[] arr) {
    // String[] res = new String[arr.length];
    // for(int i = 0; i < arr.length; ++i) {
    // res[i] = String.valueOf(arr[i]);
    // }

    // return res;
    // }

    private static List<Integer> asIntergerList(int[] arr) {
        List<Integer> intList = new ArrayList<Integer>();
        for (int i = 0; i < arr.length; i++) {
            intList.add(arr[i]);
        }

        return intList;
    }

    public static int func(int depth, int from, int left) {
        if (depth == 0) {
            if (left == 0) {
                return 1;
            }

            return 0;
        }

        int res = 0;
        for (int v = from; v <= 9; ++v) {
            res += func(depth - 1, v + 1, left - v);
        }

        return res;
    }

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

        while (true) {
            int n = scanner.nextInt();
            int s = scanner.nextInt();

            if (n == 0) {
                return;
            }

            System.out.println(func(n, 0, s));
        }

    }
}



Measured memory_bytes: 26108
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
ball = [0]*N
C = 0
for i in range(N):
  if ball[A[i]-1] == 0:
    C += 1
  ball[A[i]-1] += 1
if C <= K:
  ans = 0
else:
  ans = 0
  ball = [i for i in ball if i > 0]
  ball.sort()
  for i in range(C-K):
    ans += ball[i]
print(ans)

Measured memory_bytes: 25748
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

int main(){
	int h,w,d; cin>>h>>w>>d;
	vector<pii> a(h*w+1);
	rep(i,h)rep(j,w){
		int t; cin>>t;
		a[t]={i,j};
	}
	vvi ps(d);
	ps[0].push_back(0);
	range(i,1,h*w+1){
		auto md=a[i];
		if(i>d) md.first-=a[i-d].first, md.second-=a[i-d].second;
		ps[i%d].push_back(abs(md.first)+abs(md.second));
	}
	for(auto&l:ps) partial_sum(all(l),l.begin());
	int m; cin>>m;
	rep(i,m){
		int l,r; cin>>l>>r;
		//for(auto i:ps[r%d])cout<<i<<",";cout<<endl;
		cout<<ps[r%d][r/d]-ps[r%d][l/d]<<endl;
	}
	return 0;
}


Measured memory_bytes: 6016
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <math.h>
using namespace std;
int main ()
{
	int n,m,x,a[110];
	scanf("%i%i%i",&n,&m,&x);
	for(int i=1;i<=m;i++)
	{
		scanf("%i",&a[i]);
	}
	int res1=0,res2=0;
	for(int i=1;i<=m;i++)
	{
		if(a[i]>x)
		{
			res2++;
		}
		else if(a[i]<x)
		{
			res1++;
		}
	}
	if(res1<=res2)
	{
		printf("%i",res1);
	}
	else printf("%i",res2);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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

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

     int count = 1;
     int nx = a[0];
     b[nx - 1]++;

     while(nx != 2)
     {
          nx = a[nx - 1];
          b[nx - 1]++;
          if(b[nx - 1] > 1)
          {
               printf("-1\n");
               return 0 ;
          }
          count++;
     } 
     printf("%d\n", count);
     return 0;
}

Measured memory_bytes: 896
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let s = get!(String);
    println!("{}", match s.as_str() {
        "Sunny" => "Cloudy",
        "Cloudy" => "Rainy",
        "Rainy" => "Sunny",
        _ => ""
    });
}


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

#define rep(i, a, b) for (int i = a, i##end = b; i <= i##end; ++i)
#define per(i, a, b) for (int i = a, i##end = b; i >= i##end; --i)
#define rep0(i, a) for (int i = 0, i##end = a; i < i##end; ++i)
#define per0(i, a) for (int i = (int)a-1; ~i; --i)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define chkmax(a, b) a = max(a, b)
#define chkmin(a, b) a = min(a, b)
#define x first
#define y second
#define enter putchar('\n')

typedef long long ll;
typedef double DB;

const DB eps = 1e-12;

int sgn(DB x) { return fabs(x) < eps ? 0 : (x > 0 ? 1 : -1); }

struct Point {
	DB x, y;
	Point(DB x = 0, DB y = 0) : x(x), y(y) {}
	Point operator + (Point a) { return Point(x + a.x, y + a.y); }
	Point operator - (Point a) { return Point(x - a.x, y - a.y); }
	Point operator - () { return Point(-x, -y); }
	friend Point operator * (DB k, Point a) { return Point(k * a.x, k * a.y); }
	DB operator % (Point a) { return x * a.x + y * a.y; }
	DB operator / (Point a) { return x * a.y - y * a.x; }
	operator DB() { return sqrt(*this % *this); }
};

Point gp() { Point a; scanf("%lf%lf", &a.x, &a.y); return a; }
void wp(Point a) { printf("%.10lf %.10lf ", a.x, a.y); }

struct Poly {
	std::vector<Point> a;
	Poly(int n = 0) { a.resize(n); rep0(i, n) a[i] = gp(); }
	Point &operator [] (int i) { int n = a.size(); return a[i >= n ? i-n : i]; }
};

Point Proj(Point P, Point P1, Point P2) { // Projection
	Point v = P2-P1; DB t = (P-P1)%v / (v%v);
	return P1 + t*v;
}

int Direct(Point P, Point P1, Point P2) { return sgn((P1-P)/(P2-P)); }

bool IsInter(Point P1, Point P2, Point Q1, Point Q2) {
	if (min(P1.x, P2.x) <= max(Q1.x, Q2.x) && max(P1.x, P2.x) >= min(Q1.x, Q2.x) && min(P1.y, P2.y) <= max(Q1.y, Q2.y) && max(P1.y, P2.y) >= min(Q1.y, Q2.y))
		if (Direct(P1, P2, Q1) * Direct(P1, P2, Q2) <= 0 && Direct(Q1, Q2, P1) * Direct(Q1, Q2, P2) <= 0) return 1;
	return 0;
}

int q;

int main() {
	scanf("%d", &q);
	while (q--) {
		Point P1 = gp(), P2 = gp(), Q1 = gp(), Q2 = gp();
		printf("%d\n", IsInter(P1, P2, Q1, Q2));
		//wp(Proj(P, P1, P2)); enter;
	}
	return 0;
}


Measured memory_bytes: 3252
n = int(input())
a = list(map(int, input().split()))

d = {}
for num in a:
    d.setdefault(num, 0)
    d[num] += 1

keys = sorted(d.keys())
if len(keys) == 1 and keys[0] == 0:
    print('Yes')
elif len(keys) == 2 and d[0] * 2 == d[keys[1]]:
    print('Yes')
elif len(keys) == 3 and d[keys[0]] == d[keys[1]] == d[keys[2]] and keys[0] ^ keys[1] ^ keys[2] == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14708
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
INF = 10 ** 20
MOD = 10**9 + 7
def combmod(n, k, mod=MOD):
    if k == 0:
        return 1
    if k == 1:
        return n
    ret = 1
    for i in range(n - k + 1, n + 1):
        ret *= i
        ret %= mod

    for i in range(1, k + 1):
        ret *= pow(i, mod - 2, mod)
        ret %= mod

    return ret

def main():
    n, m, k = getList()
    ans = 0
    mul = combmod(n*m-2, k-2)
    for i in range(0, n):
        for j in range(0, m):
            tmp = (j+i) * (n-i) * (m-j) * mul
            if i != 0 and j != 0:
                tmp *= 2
            ans += tmp
            ans %= MOD
            # print(ans,mul)

    print(ans)
if __name__ == "__main__":
    main()



Measured memory_bytes: 39408
N, Y = map(int, input().split())
x_ans = -1
y_ans = -1
z_ans = -1
for x in range(N+1):
    for y in range(N+1-x):
        if 10000*x + 5000*y + 1000*(N-x-y) == Y:
            x_ans = x
            y_ans = y
            z_ans = N-x-y
            print(x_ans, y_ans, z_ans)
            exit()
print(x_ans, y_ans, z_ans)

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

map<string,int> len;
map<string,map<int,int> > content;
map<int,int> val;

int p;
string str;
map<int,int>::iterator f(){
	if( str[p] >= '0' && str[p] <= '9' ){
		int x = 0;
		while( str[p] >= '0' && str[p] <= '9' ) {
			x = x * 10 + str[p++] - '0';
		}
		val[x] = x;
		return val.find(x);
	}else{
		string arr;
		while( str[p] != '[' ) arr += str[p++];
		p++;
		auto got = f();
		if( len.count(arr) == 0 ) throw "not found";
		if( len[arr] <= got->second || got->second < 0 ) throw "index ga over";
		map<int,int>::iterator res;
		if( !content[arr].count(got->second) ){
			content[arr][got->second] = -1;	
		}
		res = content[arr].find(got->second);
		p++;
		return res;
	}	
}

int main(){
	while(true){
		len.clear();
		content.clear();
		string s;
		vector<string> l;
		while( cin >> s && s != "." ) l.push_back(s);
		if( l.size() == 0 ) break;
		for(int i = 0 ; i < l.size() ; i++){
			try{
				if( l[i].find("=") == -1 ){
					int a = l[i].find("[");
					int b = l[i].find("]");
					string arrname = l[i].substr(0,a);
					string val = l[i].substr(a+1,b-a-1);
					len[arrname] = atoi(val.c_str());
					content[arrname] = map<int,int>();
					continue;
				}else{			
					
					int x = l[i].find("=");
					l[i][x] = ' ';
					stringstream ss(l[i]);
					p = 0;
					ss >> str;
					str += "~";
					auto a = f();
					p = 0;
					ss >> str;
					str += "~";
					auto b = f();
					if( b->second == -1 ) throw "oh not found";
					a->second = b->second;
				}
			}catch(const char *msg){
				cout << i+1 << endl;
				goto done;
			}
		}
		cout << 0 << endl;
		done:;
	}
}

Measured memory_bytes: 1576
N = int(input())
arr = []*N
for _ in range(N):
	arr.append(list(map(int,input().split())))

dp = [0,0,0]
for a in arr:
	dp = [a[0]+max(dp[1],dp[2]),a[1]+max(dp[0],dp[2]),a[2]+max(dp[0],dp[1])]

print(max(dp))

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

int main() {
  int n,m,c,ans=0;
  cin >> n >> m >> c;
  vector<int> vec(m);
  for(int i = 0; i < m; i++) cin >> vec[i];
  for(int i = 0; i < n; i++) {
    int count = 0;
    for(int j = 0; j < m; j++) {
      int a;
      cin >> a;
      count += a*vec[j];
    }
    if(count+c > 0) ans++;
  }
  cout << ans << endl;
}

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

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

const int INF = 1000000007;

int main(void){
	set<int> st;
	int n; cin>>n;
	for(int i=0;i<n;i++){
		int d;
		cin>>d;
		st.insert(d);
	}

	cout<<st.size()<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
int main(){
    int n,m,ans=0;
    map<string,int>mp;
    string s;
    cin>>n;
    for(int i=0;i<n;i++){
      cin>>s;
      mp[s]++;
    }
    cin>>m;
    for(int i=0;i<m;i++){
      cin>>s;
      mp[s]--;
    }
    for(auto x:mp)ans=max(ans,x.second);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main () {
	int n, a, b, c, x;
	while (cin >> n >> a >> b >> c >> x, n || a || b || c || x) {
		int y[n];
		for (int i = 0; i < n; i++) {
			cin >> y[i];
		}
		int frame = 0;
		for (int i = (y[0] == x); i < n; i++) {
			do {
				x = (a * x + b) % c;
				frame++;
				if (frame == 10001) {
					cout << -1 << endl;
					goto NEXT;
				}
			} while (x != y[i]);
		}
		cout << frame << endl;
NEXT: continue;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>
#include<cmath>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

struct Segtree{
    int N;
    vector<int> data;
    const int DEFAULT = 0;

    Segtree(int n){
        N=1;
        while(N <= n) N*=2;
        data.resize(2*N-1);
        for(int i=0;i<2*N-1;i++){
            data[i] = DEFAULT; 
            //maxの時は-1とか-INFとか、sumなら0
        }
    }

    void update(int k, int a){
        k+=N-1;//kは0-indexed
        data[k] = a;

        while(k > 0){
            k = (k-1)/2;
            data[k] = data[2*k+1]+data[2*k+2]; 
            //min,max,sumなどで可変
        }
    }
    int query(int a,int b){return query(a, b, 0, 0, N);}
    int query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return DEFAULT; //初期化値
        if(a <= l && r <= b) return data[k];
        int vl = query(a, b, 2*k+1, l, (l+r)/2);
        int vr = query(a, b, 2*k+2, (l+r)/2, r);
        return vl+vr;//minじゃなくても
    }

    int a(int k){
        return data[N+k-1]; //kは0-indexed
    }
};

int main(){
    vector<Segtree> Seg;
    int n,Q;
    string S;
    cin>>n;
    cin>>S;
    cin>>Q;
    rep(i,0,26){
        Seg.push_back(Segtree(n));
    }
    rep(i,0,n){
        Seg[int(S[i]-'a')].update(i,1);
    }
    rep(i,0,Q){
        int a;
        cin>>a;
        if(a == 1){
            int b;
            char c;
            cin>>b>>c;
            b--;
            rep(j,0,26){
                if(Seg[j].a(b) == 1){
                    Seg[j].update(b,0);
                }
            }
            Seg[c-'a'].update(b,1);
        }
        else if(a == 2){
            int l,r;
            cin>>l>>r;
            l--;r--;
            int sum = 0;
            rep(j,0,26){
                if(Seg[j].query(l,r+1) > 0){
                    sum++;
                }
            }
            cout << sum << endl;
        }
    }
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

int a[50];

int main() {
    ios_base::sync_with_stdio(false);
    string s, t;
    getline(cin,s);
    getline(cin,t);
    int len = s.length(), k = 0, len2 = t.length();
    bool ch = false;
    for (int i = 0; i < len; ++i) {
        string q = s.substr(i,len2);
        for (int j = 0; j < len2; ++j) {
            if (q[j] != t[j] && q[j] != '?') {
                break;
            }
            if (q[j] == t[j] && j == len2-1 || q[j] == '?' && j == len2-1) {
                a[k]=i;
                k++;
                ch = true;
            }
        }
    }
    if (!ch) {
        cout << "UNRESTORABLE" << endl;
    } else {
        for (int i = 0; i < len; ++i) {
            if (i == a[k-1]) {
                cout << t;
                i+=len2-1;
            } else if (s[i] == '?') {
                cout << 'a';
            } else {
                cout << s[i];
            }
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;

int w = 100;
int h = 100;
int f[100][100];

void show() {
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (f[i][j] == 0) cout << ".";
			else cout << "#";
		}
		cout << endl;
	}
}

int main() {
	int a, b;
	cin >> a >> b;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			f[i][j] = 0;
		}
	}
	a--;
	int x = 0;
	int y = 0;
	int dx[8] = { 0,1,2,2,2,1,0,0 };
	int dy[8] = { 0,0,0,1,2,2,2,1 };
	while (a > 0 && b > 0) {
		for (int d = 0; d < 8; ++d) {
			f[y + dy[d]][x + dx[d]] = 1;
		}
		x += 4;
		if (x+4 >= 100) {
			x = 0;
			y += 4;
		}
		a--;
		b--;
	}
	if (a > 0) {
		x = 0;
		y += 3;
		for (int d = 0; d < 8; ++d) {
			f[y + dy[d]][x + dx[d]] = 1;
		}
		a--;
		y += 3;
		while (a > 0) {
			for (int d = 0; d < 8; ++d) {
				f[y + dy[d]][x + dx[d]] = 1;
			}
			x += 3;
			if (x + 4 >= 100) {
				x = 0;
				y += 3;
			}
			a--;
		}
	}
	while (b > 0) {
		for (int d = 0; d < 8; ++d) {
			f[y + dy[d]][x + dx[d]] = 1;
			f[y + 1][x + 1] = 1;
		}
		x += 4;
		if (x+4 >= 100) {
			x = 0;
			y += 4;
		}
		b--;
	}
	cout << 100 << " " << 100 << endl;
	show();
	return 0;
}

Measured memory_bytes: 256
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
from bisect import *
input=lambda :sys.stdin.readline().rstrip()

S=input()
N=len(S)
lst=[]
for bitlst in [[i>>m&1 for m in range(N-1)] for i in range(2**(N-1))]:
    z=S[0]
    num=0
    for i,b in enumerate(bitlst):
        if b==1:
            num+=int(z)
            z=S[i+1]
        else:
            z+=S[i+1]
    num+=int(z)
    lst.append(num)
print(sum(lst))


Measured memory_bytes: 5108
import sys
from math import sqrt
def input(): return sys.stdin.readline().strip()


def main():
    a, b = input().split()
    n = int(a + b)
    r = round(sqrt(n))
    if r * r == n:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 62040
////////////////いろいろあるよ//////////////////////////////////
//include,namespace
 #include<bits/stdc++.h>
 #include<iostream>
 #include<bitset>
 using namespace std;
//REPmacro
 #define all(x) (x).begin(),(x).end()             //ソート
 #define FOR(i,x,n)for(int i=(x);i<(n);i++)
 #define FOR_R(i,x,n) for(int i=(n-1);i>=(x);i--)
 #define REP(i, n) FOR(i, 0, n)
 #define REP_R(i, n) FOR_R(i, 0, n)
//long long(define)
 using ll = long long;
 typedef long long ll;
 typedef long long int64;
 typedef long long lint;
 typedef long long lli;
 
//bit
 /*
 const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
 const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
 const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
 const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
 const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
 const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
 const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
 const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000 
 */
 
//variable
 //const int INF = 1000000;
 //int dp[INF][INF];
 //int ans=0;
 
 //int dx[4]={1,0,-1,0};
 //int dy[4]={0,1,0,-1};
 
////////////////いろいろあるよ//////////////////////////////////
 
int main(){
 	char N;
  cin >> N;
  printf("%c\n", N+1);
	
 	return 0;
}

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

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

void output(int A[], int N){
    string out;
    for(int i = 0; i<N;i++){
        out += to_string(A[i]);
        if(i == N-1) out += '\n';
        else out += " ";   
    }
    cout << out;
}

int main() {
    int N;
    cin >> N;
    int A[N];
    int v;
    for (int i = 0;i<N; i++) cin >> A[i];
/*
N = 6;
int A[6] = {5,2,4,6,1,3};
*/
    for(int i = 0; i<N;i++){
        v = A[i];
        int j = i - 1;
        while(j >=0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        output(A,N);
    }
    return 0;

}


Measured memory_bytes: 3264
fun main(args: Array<String>) {
    val a = (0 until 3).map { readLine()!!.split(' ').map { it.toInt() } }
    val b = Array(3) { BooleanArray(3) { false } }
    val n = readLine()!!.toInt()

    repeat(n) {
        val x = readLine()!!.toInt()
        for (i in 0 until 3) {
            for (j in 0 until 3) {
                if (a[i][j] == x) {
                    b[i][j] = true
                }
            }
        }
    }

    var ans = false

    for (i in 0 until 3) {
        if (b[i][0] && b[i][1] && b[i][2]) ans = true
    }

    for (i in 0 until 3) {
        if (b[0][i] && b[1][i] && b[2][i]) ans = true
    }

    if (b[0][0] && b[1][1] && b[2][2]) ans = true
    if (b[0][2] && b[1][1] && b[2][0]) ans = true

    println(if (ans) "Yes" else "No")
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    ll ans = 1e18;
    ll tmp = 0;
    ll tmpsum = 0;
    for(i = 0;i < n;++i){
        tmpsum += a.at(i);
        if(i%2){
            if(tmpsum <= 0){
                tmp += abs(tmpsum) + 1;
                tmpsum = 1;
            }
        }else{
            if(tmpsum >= 0){
                tmp += abs(tmpsum) + 1;
                tmpsum = -1;
            }
        }
    }
    ans = min(ans, tmp);
    tmp = 0;    tmpsum = 0;
    for(i = 0;i < n;++i){
        tmpsum += a.at(i);
        if(i%2){
            if(tmpsum >= 0){
                tmp += abs(tmpsum) + 1;
                tmpsum = -1;
            }
        }else{
            if(tmpsum <= 0){
                tmp += abs(tmpsum) + 1;
                tmpsum = 1;
            }
        }
    }
    ans = min(ans, tmp);
    cout << ans << endl;
    return 0;
}

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

int main() {
	UL A, B, X; cin >> A >> B >> X;
	A = min(A, B * 2);
	B = min(A, B);
	X = (X - 1) / 500 + 1;
	UL ans = X / 2 * A + X % 2 * B;
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <map>
#include <vector>
#include <iomanip>

using namespace std;

int main(void) {
  string s;
  cin >> s;
  for (int i = 0; i < 12; i++) {
    if (i == 4) {
      cout << " ";
    }
    cout << s[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds;  
using namespace std;

typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
    
//defines
typedef long long ll;
typedef long double ld;

ll a,b,c,n,m,k;

ll t=1;


void solve()
{
    cin>>n;
    vector<ll>v(n);
    for(ll i=0;i<n;i++)cin>>v[i];
    sort(v.begin(),v.end());
    k=v[0];
    for(ll i=0;i<n;i++)
    k=__gcd(k,v[i]);
    m=0;
    map<ll,ll>visited;
    for(ll j=0;j<n;j++){
        
        if(visited[v[j]]>=1 and v[j]!=1LL){m=1;break;}
        
        for(ll i=2;i*i<=v[j];i++)
        {
            if(v[j]%i==0 and (visited[i]>=1 or visited[v[j]/i]>=1)){m=1;break;}
            else if(v[j]%i==0)visited[i]++,visited[v[j]/i]++;
        }
        if(m==1)break;
        visited[v[j]]++;
    }
    
    if(m==1)
    {
        cout<<((k==1)?"setwise coprime":"not coprime");
    }
    else cout<<"pairwise coprime";
 if(t>0)cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  //cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}


Measured memory_bytes: 11096
#![allow(unused_imports)]
use proconio::input;
use proconio::marker::*;
use std::collections::{HashSet, HashMap};

fn size(
  parents: &mut Vec<isize>,
  i: isize
) -> isize {
  let ii = find(parents, i) as usize;
  -1 * parents[ii]
}

fn find(
  parents: &mut Vec<isize>,
  i: isize
) -> isize {
  let ui = i as usize;
  if -1 < parents[ui] {
    parents[ui] = find(parents, parents[ui]);
    parents[ui]
  } else {
    i
  }
}

fn connect(
  parents: &mut Vec<isize>,
  a: isize,
  b: isize,
) -> bool {
  let pa = find(parents, a);
  let pb = find(parents, b);
  
  if pa == pb { return false }
  
  let av = size(parents, pa);
  let bv = size(parents, pb);
  
  let upa = pa as usize;
  let upb = pb as usize;
  if av < bv {
    parents[upb] += parents[upa];
    parents[upa] = pb;
  } else {
    parents[upa] += parents[upb];
    parents[upb] = pa;
  }
  true
}

fn main() {
  input! {
    n: usize,
    m: usize,
    vals: [Usize1;n],
    queries: [(Isize1, Isize1);m]
  }
  
  let mut parents: Vec<isize> = vec![-1;n];
  for (a, b) in queries.iter() {
    connect(&mut parents, *a, *b);
  }

  let mut map: HashMap<usize, HashSet<usize>> = HashMap::new();
  
  for i in 0..n {
    let v = parents[i];
    if v < 0 {
      let entry = map.entry(i).or_insert(HashSet::new());
      entry.insert(i);
    } else {
      let v = find(&mut parents, v);
      let uv = v as usize;
      let entry = map.entry(uv).or_insert(HashSet::new());
      entry.insert(i);
    }
  }
  
  let mut result = 0;
  for (_, v) in map {
    for vv in v.iter() {
      let vvv = vals[*vv];
      if v.contains(&vvv) {
        result += 1;
      }
    }
  }
  
  println!("{}", result);
}

Measured memory_bytes: 21956