akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;

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

  int h,w;
  cin>>h>>w;
  char a[h][w];
  rep(i,h) {
    rep(j,w) {
      cin>>a[i][j];
    }
  }
  int nx = 0, ny = 0;
  int dx[2] = {1,0};
  int dy[2] = {0,1};
  int dz[2] = {-1,0};
  int dw[2] = {0,-1};
  
  int nextx, nexty;
  while(true) {
    int k = 0;
    int j = 0;
    rep(i,2) {
      if(nx + dx[i]<= h-1 && ny + dy[i] <= w-1 && a[nx + dx[i]][ny + dy[i]] == '#') {
        k++;
        nextx = nx + dx[i], nexty = ny + dy[i];
      }
      if(nx + dz[i] >= 0 && ny + dw[i] >= 0 && a[nx + dz[i]][ny + dw[i]] == '#') {
        j++;
      }
    }
    // debug(k);
    // debug(nx),debug(ny);
    if(nx == h-1 && ny == w-1 && j != 2) {
      cout << "Possible" << endl;
      return 0;
    } else if(k == 0 || k == 2 || j == 2) {
      cout << "Impossible" << endl;
      return 0;
    }
    nx = nextx, ny = nexty;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long 
#define f(j) for(ll i=0;i<j;i++)
#define pb(i) push_back(i)
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;    
typedef vector<vector<long long> > matrix; 
// Recursive solution with memoization is not under the correct time limit
/*int n;
double prob[3000] , dp[3000][3000][2] ,ans=0;
double solve(int odd , int even ,int flag){ // 0-odd
	if(odd>even && n-odd <=n/2)		return 0;
	if(odd+even == n){
		if(flag)	return prob[n];
		return 1-prob[n];
	}
	if(dp[odd][even][flag])	{
		//cout<<odd<<" "<<even<<" "<<flag<<" "<<dp[odd][even][flag]<<"\n";
	return dp[odd][even][flag];
	}
	double temp;
	if(flag){
		temp = solve(odd+1,even,0) * prob[odd+even];
		temp+=solve(odd,even+1,1) * prob[odd+even];
	}
	else{
		temp = solve(odd+1,even,0) * (1-prob[odd+even]);
		temp+=solve(odd,even+1,1) * (1-prob[odd+even]);
	}
	dp[odd][even][flag] = temp;
	//cout<<odd<<" "<<even<<" "<<flag<<" "<<temp<<"\n";
	return temp;
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	// faster
	cin>>n;
	f(n)	cin>>prob[i+1];	
	ans = solve(1,0,0);
	ans += solve(0,1,1);
	printf("%.10lf",ans);
return 0;	
}*/

// Improved Solution
double dp[3001][3001]; 
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	// faster
	int n;
	cin>>n;
	double prob[n];
	// dp[i][j] = probability of getting j heads with i coin tosses 
	f(n)	cin>>prob[i+1];	
	dp[0][0]=1; // probability of getting 0 heads with 0 tosses
	for(int i=1;i<=n;i++)
		for(int j=0;j<=n;j++)
			if(j==0)
				dp[i][j] = (1-prob[i])*dp[i-1][j];
			else
				dp[i][j] = prob[i]*dp[i-1][j-1] + (1-prob[i])*dp[i-1][j];
	double ans=0;
	for(int i=n/2+1;i<=n;i++)
		ans+=dp[n][i];
	printf("%.10lf",ans);
return 0;	
}

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

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const int inf = 1000000000 + 7;
const int N = 1e6 + 5;

typedef long long ll;

int n, m, a[N], b[N];
map <int, int> z, x;
map <int, int> :: iterator it;

int main()
{
      cin >> n;

      for(int i = 1; i <= n; i ++)
      {
            cin >> a[i];
            z[a[i]] ++;
      }

      cin >> m;

      for(int i = 1; i <= m; i ++)
      {
            cin >> b[i];
            x[b[i]] ++;
      }

      for(it = x.begin(); it != x.end(); it ++)
      {
            if(z[it -> fr] - (it -> sc) < 0)
            {
                  puts("NO");
                  return 0;
            }
      }
      puts("YES");
}


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

int main(void){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int l=a+b,r=c+d;
	if(l>r)
		cout<<"Left"<<endl;
	else if(l==r)
		cout<<"Balanced"<<endl;
	else
		cout<<"Right"<<endl;
}

Measured memory_bytes: 256
function Main(input){
    input = input.split(" ");

    var a = parseInt(input[0], 10);
    var b = parseInt(input[1], 10);

    if(b%a == 0){
      console.log(a+b);
    }else{
      console.log(b-a);
  }
}
   
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
from numpy import argmax
import numpy as np
from collections import defaultdict

def cross(a, b):
    return a[0]*b[1]-a[1]*b[0]

n = int(input())
H = [np.array([int(j) for j in input().split()]) for i in range(n)]

if n == 1:
    print(1)
    exit()
# else n == 2:
#     print(0.5)
#     print(0.5)
#     exit()

convex = [min(H, key=lambda x:x[1])]

for i in range(n):
    a = H[0] if (H[0] != convex[-1]).any() else H[-1]
    for b in H:
        ac = a-convex[-1]
        bc = b-convex[-1]
        cross_ = cross(ac, bc)
        if cross_ < 0 or (cross_ == 0 and np.linalg.norm(ac) < np.linalg.norm(bc)):
            a = b
    if (a == convex[0]).all():
        break
    convex.append(a)

ans = defaultdict(float)

for c, a, b in zip([convex[-1]]+convex[:-1], convex, convex[1:] + [convex[0]]):
    ca = c-a
    ba = b-a
    i = np.inner(ca, ba)
    n = np.linalg.norm(ca) * np.linalg.norm(ba)
    ans[tuple(a)] = (np.pi - np.arccos(np.clip(i/n, -1, 1))) / (2*np.pi)

for i in H:
    print(ans[tuple(i)])


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

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

	string s, t; cin >> s >> t;
	vector<int> ps(s.size() + 1), pt(t.size() + 1);
	for (int i = 1; i <= s.size(); i++) {
		ps[i] = ps[i-1] + (s[i-1] == 'A');
	} 
	for (int i = 1; i <= t.size(); i++) {
		pt[i] = pt[i-1] + (t[i-1] == 'A');
	} 

	int q; cin >> q;
	while (q--) {
		int a, b, c, d; cin >> a >> b >> c >> d;

		int psa = (ps[b] - ps[a-1]) % 3;
		int psb = ((b - a + 1) - psa) % 3;

		int pta = (pt[d] - pt[c-1]) % 3;
		int ptb = ((d - c + 1) - pta) % 3;

		if ((2*psa + psb) % 3 == (2*pta + ptb) % 3) {
			cout << "YES\n";
		} else {
			cout << "NO\n";
		}
	}

	return 0;
}


Measured memory_bytes: 1744
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,k=map(int,input().split())
H=list(map(int,input().split()))
dp=[inf]*n; dp[0]=0
for i in range(n):
  for ki in range(1,k+1):
    if not (0<=i+ki<n): continue
    dp[i+ki]=min(dp[i+ki],dp[i]+abs(H[i]-H[i+ki]))
print(dp[n-1])

Measured memory_bytes: 59376
#include<stdio.h>
#define N 10000

int main(void){
  int i,num,j,cc;
  int n[N],pm[N],pe[N],pj[N];
  int class[N];

  for(i=0,cc=0;;i++){
    scanf("%d",&n[i]);
    if(n[i]==0)
      break;
    for(j=0;j<n[i];j++)
      scanf("%d%d%d",&pm[j],&pe[j],&pj[j]);
    for(j=0;j<n[i];j++){
      if(pm[j]==100 ||
          pe[j]==100 ||
          pj[j]==100 ||
          pm[j]+pe[j]>=180 ||
          pm[j]+pe[j]+pj[j]>=240)
        class[cc]=1;
      else if(pm[j]+pe[j]+pj[j]>=210 ||
          (pm[j]+pe[j]+pj[j]>=150 && (pm[j]>=80 || pe[j]>=80)))
        class[cc]=2;
      else
        class[cc]=3;
      cc++;
    }
  }
  num=cc;
  for(i=0;i<num;i++)
    if(class[i]==1)
      printf("A\n");
    else if(class[i]==2)
      printf("B\n");
    else if(class[i]==3)
      printf("C\n");
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define repr(i,k,n) for(int i = (k); i < (n); i++)
#define rep(i,n) repr(i,0,n)
#define ALL(a) begin(a),end(a)
const int MOD = 1000000007;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
  }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    float N, Ai;
    float An;
    cin >> N;
    rep(i,N){
        cin >> Ai;
        An += (1/Ai);
    }
    cout << 1/An << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rg register
#define MEM(NAME) memset(NAME,0,sizeof NAME)
using namespace std;
typedef long long ll;
template<typename T>
inline bool read(T &n) {
    T ans = 0, flag = 1;
    char ch;
    while ((ch = getchar()) < '0' || ch > '9') if (ch == '-') flag = -1; else if (ch == EOF) return false;
    ans = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9') ans = ans * 10 + ch - '0';
    n = ans * flag;
    return true;
}
inline ll read() {
    ll ans = 0, flag = 1;
    char ch;
    while ((ch = getchar()) < '0' || ch > '9') if (ch == '-') flag = -1;
    ans = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9') ans = ans * 10 + ch - '0';
    return ans * flag;
};
int pre[100005];
unordered_map<int,int> M;
vector<int> v,v2;
int main() {
    int n,cnt=0;read(n);
    for(rg int i=1;i<=n;i++){
        read(pre[i]);
        if(M.find(pre[i])==M.end()) {
            M[pre[i]]=++cnt;
            v.push_back(1);
            v2.push_back(pre[i]);
        }
        else v[M[pre[i]]-1]++;
    }
    if(n%3==0){
        if((v.size()==2&&max(v[0],v[1])==2*min(v[0],v[1])&&(v2[0]==0||v2[1]==0)||(v.size()==1&&pre[1]==0)||(v.size()==3&&v[0]==v[1]&&v[1]==v[2]&&((v2[0]^v2[1])==v2[2])))) puts("Yes");
        else puts("No");
    }   
    else{
        if(v.size()==1&&pre[1]==0) puts("Yes");
        else puts("No");
    }
    return 0;
}

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

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int o=0,e=0;
    for(int i=0;i<s.length();i++)
    {
        if((s[i]-'0')==0)
            o++;
        else
            e++;
    }
    cout<<2*min(o,e)<<endl;
    return 0;
}


Measured memory_bytes: 3724
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
using namespace std;
int h, w, ans;
char map[30][30];
int mapi[30][30];
void f(int xi, int yi, int c) {
	mapi[xi][yi] = c;
	int xp = xi - 1, yp = yi;
	if (1 <= xp && xp <= h && 1 <= yp && yp <= w && map[xp][yp] != '#' && mapi[xp][yp] > c+1) f(xp, yp, c + 1);
	xp = xi + 1;
	if (1 <= xp && xp <= h && 1 <= yp && yp <= w && map[xp][yp] != '#' && mapi[xp][yp] > c+1) f(xp, yp, c + 1);
	xp = xi; yp = yi - 1;
	if (1 <= xp && xp <= h && 1 <= yp && yp <= w && map[xp][yp] != '#' && mapi[xp][yp] > c+1) f(xp, yp, c + 1);
	yp = yi + 1;
	if (1 <= xp && xp <= h && 1 <= yp && yp <= w && map[xp][yp] != '#' && mapi[xp][yp] > c+1) f(xp, yp, c + 1);
	return;
}
signed main() {
	cin >> h >> w;
	for1(i, h)for1(j, w)cin >> map[i][j];
	for1(x1, h)for1(y1, w) {
		if (map[x1][y1] == '.') {
			for1(i, h)for1(j, w)mapi[i][j] = mod;
			f(x1, y1, 0);
			for1(i, h)for1(j, w)if (map[i][j] == '.')ans = max(ans, mapi[i][j]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define si size()
#define bk back()
#define popb pop_back()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define ump unordered_map
#define forl(i,a,n) for(int i=a;i<n;i++)
#define rfor(i,n,a) for(int i=n;i>=a;i--)
#define fore(i,a,n) for(int i=a;i<=n;i++)
#define len length()
const int V=1e3;
const ll N=1e18L +5;
const int NUM=1e2;
ll dp[NUM*V+5];
int main()
{
    int n,w;
    cin>>n>>w;
    ll arr[n][2];
    forl(i,0,n) forl(j,0,2) cin>>arr[i][j];
    forl(i,0,n*V+1) dp[i]=N;
    dp[arr[0][1]]=arr[0][0];
    dp[0]=0;
    forl(i,1,n)
    {
        rfor(j,n*V,0)
        {
            if(j-arr[i][1]>=0)dp[j]=min(dp[j],dp[j-arr[i][1]]+arr[i][0]);
        }
    }
    ll maxval=0;
    forl(i,0,n*V+1) 
    {
        if(dp[i]<=w)maxval=i;
    }
    cout<<maxval<<endl;
   

}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,cnt;
double ans;
inline int read(){
	char ch=getchar();int o=0;
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') o=(o<<3)+(o<<1)+(ch^48),ch=getchar();
	return o;
}
int main(){
	cin>>n;
	for(register int i=1;i<=n;i++) if(i%2) cnt++;
	ans=cnt*1.0/n;
	printf("%.10lf",ans);
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<31)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
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; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> s;
    int ans = 0, g = 0, p = 0;
    rep(i, 0, s.size()) {
        if (s[i] == 'g') {
            if (g > p) p++, ans++;
            else g++;
        } else {
            if (g > p) p++;
            else g++, ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0013
{
    class Program
    {
        static void Main(string[] args)
        {
            string number = "";
            List<string> train = new List<string>();
            while ((number = Console.ReadLine()) != null)
            {
                if (number == "0")
                {
                    Console.WriteLine(train[train.Count - 1]);
                    train.RemoveAt(train.Count - 1);
                }
                else
                {
                    train.Add(number);
                }
            }
        }
    }
}



Measured memory_bytes: 15860
import sys
sys.setrecursionlimit(10**6)

def combinations(n, r):
    if n <= 0 or n < r:
        return 0
    if n == r or r == 0:
        return 1
    if r == 1:
        return n
    return combinations(n-1,r-1) + combinations(n-1,r)

def main():
    n = input().rstrip()
    k = int(input())
    if k == 1:
        print((int(n[0]) - 1) + 9 * (len(n) -  1) + 1)
    elif k == 2:
        a = (int(n[0]) - 1) * 9 * (len(n) - 1)
        b = int(combinations(len(n) - 1, 2) * 9*9)
        c = 0
        for i in range(1, len(n)):
            if n[i] != '0':
                c = int(n[i]) + 9 * (max(len(n) - i - 1, 0))
                break
        print(a + b + c)
    elif k == 3:
        a_a = 0
        a_b = 0
        a_c = 0
        for i in range(1, len(n)):
            if n[i] != '0':
                for j in range(i+1, len(n)):
                    if n[j] != '0':
                        a_a = int(n[j]) + 9 * (max(len(n) - j - 1, 0))
                        break
                a_b = (int(n[i]) - 1) * 9 * (max(len(n) - i - 1, 0))
                a_c = combinations(len(n) - i - 1, 2) * 9 * 9
                break
        b = (int(n[0]) - 1) * combinations(len(n) - 1, 2) * 9 * 9
        c = combinations(len(n) - 1, 3) * 9 * 9 * 9
        print((a_a + a_b + a_c) + b + c)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

void read_problem(vector<int>& preorder, vector<int>& inorder)
{
    int n;
    scanf("%d\n", &n);

    preorder.resize(n);
    inorder.resize(n);
    REP(i, n) {
        scanf("%d", &preorder[i]);
    }
    REP(i, n) {
        scanf("%d", &inorder[i]);
    }
}

struct Node {
    int id;
    //Node* parent;
    Node* left;
    Node* right;

    //Node(int i) : id(i), parent(nullptr), left(nullptr), right(nullptr) {}
    Node(int i) : id(i), left(nullptr), right(nullptr) {}
};

bool find_in_vector(const vector<int>& v, int x)
{
    return find(v.begin(), v.end(), x) != v.end();
}

void solve(Node* root, const vector<int>& preorder, const vector<int>& inorder)
{
    // inorder ?????§ root ????????????????????????????????¨?????¨?????????????????????????????¨?????¨
    auto it_inorder = find(inorder.begin(), inorder.end(), root->id);
    vector<int> inorder_l(inorder.begin(), it_inorder);
    vector<int> inorder_r(it_inorder+1,    inorder.end());

    // preorder ?????§ root ??????????????¨?????¨?????????????????????????????????????´??????¢???
    // ??????????????????????????? idx ??¨????????¨
    // preorder[1..idx-1] ????????¨?????¨???preorder[idx..] ????????¨?????¨
    auto it_preorder = find_if(preorder.begin(), preorder.end(),
                               [root, &inorder_l](int id) { return id != root->id && !find_in_vector(inorder_l, id); });
    vector<int> preorder_l(preorder.begin()+1, it_preorder);
    vector<int> preorder_r(it_preorder, preorder.end());

    // ?????¨?????¨????????§???????????° preorder_l[0] ??? root->left
    // ?????¨?????¨????????§???????????° preorder_r[0] ??? root->right
    if(!inorder_l.empty()) {
        Node* left = new Node(preorder_l[0]);
        root->left = left;
        solve(left, preorder_l, inorder_l);
    }
    if(!inorder_r.empty()) {
        Node* right = new Node(preorder_r[0]);
        root->right = right;
        solve(right, preorder_r, inorder_r);
    }
}

void postorder(vector<int>& result, const Node* node)
{
    if(node->left)
        postorder(result, node->left);
    if(node->right)
        postorder(result, node->right);
    result.emplace_back(node->id);
}

int main()
{
    vector<int> preorder;
    vector<int> inorder;
    read_problem(preorder, inorder);
    int n = preorder.size();

    Node root(preorder[0]);
    solve(&root, preorder, inorder);

    vector<int> result;
    postorder(result, &root);
    REP(i, n) {
        printf("%d%c", result[i], i == n-1 ? '\n' : ' ');
    }

    return 0;
}

Measured memory_bytes: 2768
#include <algorithm>
#include <bitset>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

const int N_MAX = 5e4 + 5;

int N, M, T;
vector<int> X, Y;
vector<pair<int, int>> XY;

void solve_uniforming() {
    vector<bitset<N_MAX>> acceptable(N);

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

    for (int i = M - 1; i >= 0; i--) {
        int x = X[i], y = Y[i];
        acceptable[x] = acceptable[y] = acceptable[x] | acceptable[y];
    }

    bitset<N_MAX> full;
    full.set();

    for (int i = 0; i < N; i++)
        full &= acceptable[i];

    if (full.none()) {
        cout << -1 << '\n';
        return;
    }

    int finish = -1;

    for (int i = 0; i < N; i++)
        if (full[i])
            finish = i;

    vector<bool> good(N, false);
    good[finish] = true;
    string answer(M, '.');

    for (int i = M - 1; i >= 0; i--) {
        int x = X[i], y = Y[i];

        if (!good[x])
            answer[i] = 'v';
        else
            answer[i] = '^';

        good[x] = good[y] = good[x] || good[y];
    }

    cout << answer << '\n';
}

void solve_non_uniforming() {
    if (N == 2) {
        cout << -1 << '\n';
        return;
    }

    string answer(M, '^');
    vector<int> relevant;

    for (int i = 0; i < M; i++)
        if (Y[i] < 3)
            relevant.push_back(i);

    if (relevant.empty()) {
        cout << answer << '\n';
        return;
    }

    int R = relevant.size();
    pair<int, int> current = {0, 1};

    if (current == XY[relevant.front()])
        current = {0, 2};

    for (int i = 0; i < R - 1; i++) {
        int index = relevant[i], next = relevant[i + 1];
        assert(current != XY[index]);

        pair<int, int> up = current;
        if (up.first == Y[index]) up.first = X[index];
        if (up.second == Y[index]) up.second = X[index];
        if (up.first > up.second) swap(up.first, up.second);

        pair<int, int> down = current;
        if (down.first == X[index]) down.first = Y[index];
        if (down.second == X[index]) down.second = Y[index];
        if (down.first > down.second) swap(down.first, down.second);

        if (up.first != up.second && up != XY[next]) {
            answer[index] = '^';
            current = up;
        } else {
            assert(down.first != down.second && down != XY[next]);
            answer[index] = 'v';
            current = down;
        }
    }

    cout << answer << '\n';
}

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

    cin >> N >> M >> T;
    X.resize(M);
    Y.resize(M);
    XY.resize(M);

    for (int i = 0; i < M; i++) {
        cin >> X[i] >> Y[i];
        X[i]--; Y[i]--;
        XY[i] = {X[i], Y[i]};
    }

    if (T == 1)
        solve_uniforming();
    else
        solve_non_uniforming();
}


Measured memory_bytes: 307584
N, Q = map(int, input().split())
S = input()
LR = [list(map(int, input().split())) for _ in range(Q)]

cnt, acc = [0] * N, 0
for i in range(1, N):
    if S[i-1:i+1] == "AC":
        acc += 1
    cnt[i] = acc

for l, r in LR:
    print(cnt[r-1] - cnt[l-1])



Measured memory_bytes: 30640
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors


if __name__ == "__main__":
    N = int(input())
    part = len(make_divisors(N-1)) - 1
    cnt = 0
    for k in make_divisors(N):
        if k == 1:
            continue
        tmp_n = N
        while tmp_n % k == 0:
            tmp_n /= k
        if tmp_n % k == 1:
            cnt += 1

    print(part + cnt)


Measured memory_bytes: 39536
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = [INT() for _ in range(N)]
A.sort()
T = deepcopy(A)
T = deque(T)

l = deque([])
l.append(T.popleft())

while T:
	l.appendleft(T.pop())
	if not T:
		break
	l.append(T.pop())
	if not T:
		break
	l.appendleft(T.popleft())
	if not T:
		break
	l.append(T.popleft())

l = list(l)
ans = 0
for i in range(1, N):
	ans += abs(l[i-1]-l[i])

T = deepcopy(A)
T = deque(T)
l = deque([])
l.append(T.pop())
while T:
	l.appendleft(T.popleft())
	if not T:
		break
	l.append(T.popleft())
	if not T:
		break
	l.appendleft(T.pop())
	if not T:
		break
	l.append(T.pop())

l = list(l)
tmp = 0
for i in range(1, N):
	tmp += abs(l[i-1]-l[i])

ans = max(ans, tmp)
print(ans)


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

int main(){
  string S;
  cin>>S;
  string ans="Yes";
  for(int i=0;i<S.size();i++){
    if((i+1)%2==1&&S.at(i)=='L'){ans="No";break;}
    else if((i+1)%2==0&&S.at(i)=='R'){ans="No";break;}
  }
  cout<<ans<<endl;
}


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

typedef long long ll;

ll a, b;

ll gcd(ll a, ll b) { return a? gcd(b % a, a): b; }

int main()
{
    cin >> a >> b;
    cout << a / gcd(a, b) * b << endl;
    return 0;
}


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

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



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

  ll a;
  double b;
  cin >> a >> b;
  ll ib = b*100+0.5;
  a *= ib;
  a /= 100;
  cout << a << endl;
}

Measured memory_bytes: 3716
def main():
    N = int(input())
    L = list(map(int,input().split()))
    for i in range(N):
        sum = 0
        for j in range(N):
            sum += L[j]
        sum = sum - L[i]
        if sum <= L[i]:
            return ('No')
    return ('Yes')

print(main())


Measured memory_bytes: 9172
#include<iostream>
#include <algorithm>
#include <functional>
using namespace std;

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

    int q, w, e;
    q = a + b;
    w = a - b;
    e = a * b;

    if(q <= w){
        if(w <= e){
            cout << e << endl;
        }else{
            cout << w << endl;
        }
    }else if(w < q){
        if(q <= e){
            cout << e << endl;
        }else{
            cout << q << endl;
        }
    }
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int P = int.Parse(str[0]);
            int Q = int.Parse(str[1]);
            int R = int.Parse(str[2]);

            int max = Math.Max(P, Q);
            max = Math.Max(max, R);

            int ans = P + Q + R - max;

            Console.WriteLine(ans);
        }
       
    }
}
/*
long a, b, c;
a = long.Parse(Console.ReadLine()); //標準入力
string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
b = long.Parse(str[0]);  //数値で受け取りたい場合は変換する
c = long.Parse(str[1]);
string S = Console.ReadLine();
char[] C = new char[N];
C = S.ToCharArray();
Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
Member = ReadLine().Split(' ').Select(long.Parse).ToArray();

string[] str = Console.ReadLine().Split(' ');
long[] a = new long[N];
for(long i = 0; i < N; i++) a[i] = long.Parse(str[i]);
 */
/*
      static long func(long n)
      {
          long d = 0;
          for (long i = 0; i < 10; i++)
          {
              if (n / longPow(10, i) == 0)
              {
                  d = i;
                  break;
              }
          }
          long ret = A * n + B * d;
          return ret;
      }
      static long longPow(long a, long n)
      {
          long b = 1;
          for (long i = 0; i < n; i++) b = b * a;
          return b;
      }
      */


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int g[15][15];
int main(){
    int n;
    cin >> n;
    rep(i,15)rep(j,15)g[i][j]=-1;
    rep(i,n){
        int a;
        cin >> a;
        rep(j,a){
            int x,y;
            cin >>x >> y;
            x--;
            g[i][x]=y;
        }
    }
    int ans=0;
    rep(i,1<<n){
        vector<int> d(n);
        rep(j,n){
            if(i>>j&1)d[j]=1;
        }
        bool ok=true;
        rep(j,n){
            if(d[j]==1){
                rep(k,n){
                    if(g[j][k]==-1)continue;
                    if(g[j][k]!=d[k])ok=false;
                }
            }
        }
        if(ok)ans=max(ans,__builtin_popcount(i));

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

Measured memory_bytes: 256
from collections import deque

h, w = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1
t = [[i for i in range(w)] for j in range(h)]
visited = [[0 for i in range(w)] for j in range(h)] # いったところ
ans = 0
for i in range(h):
  temp = input()
  for j in range(w):
    t[i][j] = temp[j]

d = deque([(Ch, Cw)])
ans = 0
a = [(1,0),(-1,0),(0,1),(0,-1)]

while True:
  # 移動A
  stemp = set()
  while len(d) != 0:
    Th, Tw = d.popleft()
    # s.add((Th, Tw))
    visited[Th][Tw] = 1
    stemp.add((Th, Tw))
    if (Th,Tw) == (Dh, Dw):
      print(ans)
      exit()
    for i, j in a:
      _h,_w = Th + i, Tw + j
      _p = (_h, _w)
      if 0 <= _h < h and 0 <= _w < w and t[_h][_w] == '.' and visited[_h][_w] == 0:
        d.append(_p)
        visited[_h][_w] = 1
  # 移動B
  ans += 1
  for Th,Tw in stemp:
    for i in range(-2, 3) :
      for j in range(-2, 3) :
        _h,_w = Th + i, Tw + j
        _p = (_h, _w)
        if 0 <= _h < h and 0 <=  _w < w and t[_h][_w] == '.' and visited[_h][_w] == 0:
          d.append(_p)
  if len(d) == 0:
    print('-1')
    exit()


Measured memory_bytes: 184716
/****Author: Barish Namazov****/
    #include <bits/stdc++.h>
     
    using namespace std;
     
    /***TEMPLATE***/
    #define all(v) (v).begin(),(v).end()
    #define rall(v) (v).rbegin(),(v).rend()
     
    #define F first
    #define S second
    #define pb push_back
     
    #define endl '\n'
     
    const int max4 = 10004;
    const int maxx = 100005;
    const int max6 = 1000006;
    const int lg5 = 17;
     
    const int INF = 2 * 1000000007;
    const long long INFLL = 4LL * 1000000000 * 1000000000;
     
    /***************/
     
    int powmod (int a, int b, int mod) {
        int res = 1; a %= mod;
        for (; b; b >>= 1) {
            if (b & 1) {
                res = 1LL * res * a % mod;
            }
            a = 1LL * a * a % mod;
        }
        return res;
    }
     
    int gcd (int a, int b) {
        while (b > 0) {
            int t = a % b;
            a = b, b = t;
        }
        return a;
    }
     
    int lcm (int a, int b) {
        return (a / gcd (a, b)) * b;
    }
     
    int is_prime (int n) {
        if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
            return 0;
        for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
            if (n % i == 0)
                return 0;
        return 1;
    }
     
    /******Don't forget to use long long when needed!!******/
     
    int main() {
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        ios_base :: sync_with_stdio(0);
        cin.tie(0), cout.tie(0);
        string s, t;
        cin >> s >> t;
        for (int i = 0; i < s.size(); i++) {
            string tmp = "";
            for (int j = i; j < s.size(); j++) {
                tmp += s[j];
            }
            for (int j = 0; j < i; j++) {
                tmp += s[j];
            }
            if (tmp == t) {
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
        return 0;
    }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n = 0;
  cin >> n;
  map<int,int> num;
  for(int i = 0;i < n;i++){
    int a = 0;
    cin >> a;
    num[a]++;
  }
  ll res = 0;
  for(auto i:num){
    int a,b;
    a = i.first;
    b = i.second;
    if(a > b)res += b;
    else res += b - a;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4736
#include <stdio.h>

using namespace std;
typedef long long llong;

#define MAX 1001
const llong mod = 1000000000 + 7;

int main()
{
  int K, A, B;
  scanf("%d", &K);
  scanf("%d%d", &A, &B);

  for (int i = A; i < B + 1; i++)
  {
    if (i % K == 0)
    {
      printf("OK\n");
      return 0;
    }
  }

  printf("NG\n");

  return 0;
}

Measured memory_bytes: 1620
import sys
input=sys.stdin.readline


def main():
	N,M=map(int,input().split())
	#S=input().rstrip()
	#N=int(input())
	#vA=list(map(int,input().split()))
	vAB=[tuple(map(int,input().split()))
		 for _ in [0,]*M]
	
	vN = [-1,]*N
	for p,q in vAB:
		if vN[p-1]!=-1 and vN[p-1]!= q:
			print(-1)
			return
		vN[p-1] = q
	
	#print(vN)
	if N==1 and vN[0]==0:
		print(0)
		return
	if N==1 and M==0:
		print(0)
		return
	
	for i in range(10**(N-1),10**N):
		s = str(i)
		#print(s)
		ok = True
		for j,sc in enumerate(s):
			if vN[j]!=-1 and vN[j]!=int(sc):
				#print(j,sc)
				ok = False
		
		if ok:
			print(i)
			return
	else:
		print(-1)
	
	
main()


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

int main(){

    int s; cin>>s;

    int ue = s / 100;

    int shita = s % 100;

    if(0<ue && ue <=12){
        if(0<shita && shita<=12)cout<<"AMBIGUOUS"<<endl;
        else cout<<"MMYY"<<endl;
    }

    else{
        if(0<shita && shita<=12)cout<<"YYMM"<<endl;
        else cout<<"NA"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
/*
 _     _    ___  ___  __ __ 
| |   | |  |__ \|__ \/_ /_ |
| |__ | |__   ) |  ) || || |
| '_ \| '_ \ / /  / / | || |
| |_) | |_) / /_ / /_ | || |
|_.__/|_.__/____|____||_||_|

*/
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;

//	cin>>TESTS;
	while(TESTS--)
	{
		ll l,r;
		cin>>l>>r;
		if(r-l+1>=2019)
			{cout<<0<<endl;return 0;}
		vi v;
		rep(i,l,r+1)
		v.pb(i%2019);
		ll n=v.size();
		ll ans=hell;
		rep(i,0,n)
		{
			rep(j,i+1,n)
			{
				ans=min(ans,(v[i]*v[j])%2019);
			}
		}
		cout<<ans<<endl;

	}
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

type Scanner struct {
	innerScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := new(Scanner)
	innerScanner := bufio.NewScanner(os.Stdin)
	innerScanner.Split(bufio.ScanWords)
	sc.innerScanner = innerScanner
	return sc
}

func (sc Scanner) scan() {
	sc.innerScanner.Scan()
}

func (sc Scanner) next() string {
	sc.scan()
	return sc.innerScanner.Text()
}

func (sc Scanner) nextInt() int {
	i, _ := strconv.Atoi(sc.next())
	return i
}

func (sc Scanner) nextFloat() float64 {
	f, _ := strconv.ParseFloat(sc.next(), 64)
	return f
}

func main() {
	sc := NewScanner()
	n := sc.nextInt()
	k := sc.nextInt()
	if n % k == 0 {
		fmt.Println(0)
	} else {
		fmt.Println(1)
	}
}

Measured memory_bytes: 640
n = int(input())
a = []
for i in range(n):
    a.append(input())
b = 0
c = 0
d = 0
e = 0
f = 0
for i in range(n):
    if a[i][0] =='M':
        b += 1
    elif a[i][0] =='A':
        c += 1
    elif a[i][0] =='R':
        d += 1
    elif a[i][0] =='C':
        e += 1
    elif a[i][0] =='H':
        f += 1
print(b*c*d+b*c*e+b*c*f+b*d*e+b*d*f+b*e*f+c*d*e+c*d*f+c*e*f+d*e*f)

Measured memory_bytes: 9772
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	A := sc.nextFloat()
	B := sc.nextFloat()
	H := sc.nextFloat()
	M := sc.nextFloat()

	radA := float64(H*60+M) * 0.5
	radB := float64(M * 6)
	var radAB float64
	if radA > radB {
		radAB = radA - radB
	} else {
		radAB = radB - radA
	}

	aa := float64(A*A+B*B) - float64(2*A*B)*math.Cos(radAB*math.Pi/180.0)

	fmt.Printf("%0.15f", math.Sqrt(aa))

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 1724
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int h,w;
	cin>>h>>w;
	int a,b;
	cin>>a>>b;
	int tmp[h][w];
	rep(i,h)rep(j,w)tmp[i][j]=0;
	rep(i,h){
		rep(j,w){
			if(i<b&&j<a)tmp[i][j]=1;
			if(b<=i&&a<=j)tmp[i][j]=1;
		}
	}
	rep(i,h){
		rep(j,w)cout<<tmp[i][j];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 7460
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ld long double
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int colors[100005];
void wf(vector<vector<int>> &k){
  int n=k.size();//存在しない辺をinfで渡す
  rep(o,n)rep(i,n)rep(j,n)k[i][j]=min(k[i][j],k[i][o]+k[o][j]);
}
bool is_bipartite_graph(const Graph &graph, int v, int c) {
    colors[v] = c;
    for (int u: graph[v]) {
        if (colors[u] == c) {
            return false;
        }
        if (colors[u] == 0 && !is_bipartite_graph(graph, u, -c)) {
            return false;
        }
    }
    return true;
}

int main(){
  int n;
  cin >> n;
  Graph k(n);
  vector<vector<int>> u(n,vector<int>(n,0));
  rep(i,n){
    string s;
    cin >> s;
    rep(j,n){
      u[i][j]=(s[j]-'0');
      if(u[i][j]==0)u[i][j]=1000000000;
      else k[i].push_back(j);
    }
  }
  if(is_bipartite_graph(k,0,1)){
    wf(u);
    int m=0;
    rep(i,n){
      rep(j,n){
        if(i==j)continue;
        m=max(m,u[i][j]+1);
      }
    }
    cout << m << endl;
  }
  else cout << -1 << endl;
}

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

int main(){
    int n;  cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        int x;  cin >> x;
        a.at(x-1) = i+1;
    }
    for(int i=0; i<n; i++)
        cout << a.at(i) << ' ';
    
}

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

int main() {
  int N,K;
  cin >> N >> K;
  
  int num = 1;
  
  for(int i = 0; i < N; i++) {
    if (num <= K){
      num *=2;
    }
    else {
      num += K;
    }
  }
  
  cout << num << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N;
    cin >> N;
    vi sw(N+1);
    rep(i, N) cin >> sw[i+1];

    int cnt = 0;
    int now = 1;
    while(cnt <= N) {
        cnt++;
        if(sw[now]==2) break;
        else now = sw[now];
    }

    if(cnt > N) cout << -1 << endl;
    else cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std; 
 
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(),vec.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define fr(i,a,b) for(int i=a;i>=b;i--)
#define fp(i,a,b,p) for(int i=a;i<b;i+=p)
#define SZ(x) (int)x.size()
#define INF 1e9
 
typedef  vector<string> vs;
typedef  vector<int> vi;
typedef  vector<long long> vl;	
 
 
int main(){
	
	int a,b,c,d;
	cin >>a >> b >> c>> d;
	
	if((abs(a-b)<=d && abs(b-c)<=d) || abs(a-c) <=d){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
 
    return 0;
}


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

//main関数
int main() {
    //入力
    string S;
    cin>>S;
    
    //計算
    long x=(S.at(5)-'0')*10+(S.at(6)-'0');
    //cout<<x<<endl;
    
    //出力
    if(x>=5){
        cout<<"TBD"<<endl;
    }else{
        cout<<"Heisei"<<endl;
    }
}

Measured memory_bytes: 764
object Main extends App {

  def solve(s: String): (Int, Int) = {
    def inner(cs: List[(Char, Int)]): (Int, Int) = cs match {
      case (c1, i1) :: (_, _) :: (c3, i3) :: _ if c1 == c3 => (i1 + 1, i3 + 1)
      case (c1, i1) :: (c2, i2) :: _ if c1 == c2           => (i1 + 1, i2 + 1)
      case _ :: tail                                       => inner(tail)
      case _                                               => (-1, -1)
    }
    val cs = s.toCharArray.zipWithIndex.toList
    inner(cs)
  }

  val sc = new java.util.Scanner(Console.in)
  val s  = sc.next()
  val t  = solve(s)
  println(s"${t._1} ${t._2}")
}

Measured memory_bytes: 42168
n = int(input())
W = list(map(int,input().split()))
ans = 9999
for i in range(n):
  a, b = 0, 0
  for j in range(n):
    if j<=i:
      a += W[j]
    else:
      b += W[j]
  ans = min(ans, abs(a-b))
print(ans)

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

int N,K,a,b;
long sum;

int main(){
    cin>>N>>K;
    for(int i=1;i<=N-K;++i){
        int b=K+i;
        int c=N/b;
        sum+=c*i;
        if(K==0) --sum;
        int d=N-c*b;
        if(d-K+1>0) sum+=d-K+1;
    }

    cout<<sum<<"\n";
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val x = readLine()!!.split("").drop(1).dropLast(1)
    val y = x.filter { it ==x[0] }
    val z  = x.filterNot {it ==x[0]}

if (y.size ==2 && z.size ==2 && z[0] ==z[1])
{
    print("Yes")
}
else {
    print("No")
}
}

Measured memory_bytes: 37896
A, B, C, D = map(int, input().split())

sw = 0
while sw == 0:
    if C > 0:
        C = C - B
    else:
        sw = 1
        break
    if A > 0:
        A = A - D
    else:
        sw = 2
        break
if sw == 1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9064
N = int(input())
k = 1
while (k*(k+1))//2<N:
    k += 1
if N==(k*(k+1))//2:
    for i in range(1,k+1):
        print(i)
else:
    ind = -1
    for j in range(1,k):
        tot = 0
        for i in range(1,k+1):
            if i!=j:
                tot += i
        if tot==N:
            ind = j
            break
    for i in range(1,k+1):
        if i!=ind:
            print(i)

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

int main(){
  	int N,ans=0;int count2=0;
  	cin>>N;
	string s;
	cin>>s;
  	set<char>a;set<char>b;
  	int mid=1;
  	while(mid<=N-1){
      int count=0;
      for(int i=0;i<mid;++i)a.insert(s[i]);
  	  for(int i=mid;i<N;++i)b.insert(s[i]);
  	  set<char>::iterator i;set<char>::iterator j;
      for(i=a.begin();i!=a.end();++i){
    	for(j=b.begin();j!=b.end();++j){
        	if(*i==*j)++count;
        }
      }ans=max(ans,count);++mid;a.clear();b.clear();
    }cout<<ans<<endl;
  	return 0;
}

Measured memory_bytes: 256
/**
 *      purpose : ABC 124 B
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'

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

  int n; cin >> n;
  int h[n]; rep(i, n) cin >> h[i];

  int ans = 1;
  for (int i = 1; i < n; ++i){
    bool ok = true;
    for (int j = 0; j <= i - 1; ++j){
      if (h[j] > h[i]) ok = false;
    }
    if (ok) ++ans;
  }
  print(ans);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long int;
vector<int>adj[100002];
bool v[100002];
int tam;

void dfs(int i)
{
    if (v[i])return;
    v[i] = true;
    tam++;
    for (int j=0;j<adj[i].size();j++)
    {
         dfs(adj[i][j]);
    }
}

int main()
{
    int n, m;
    cin>>n>>m;
    set<int>node;
    for (int i=0;i<m;i++)
    {
        int a,b;cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
        node.insert(a);
        node.insert(b);
    }
     tam = 0;
    int grafos = 0;
    for (int i=1;i<=n;i++)
    {
        if (!v[i] && node.count(i))
        {
            dfs(i);
            grafos++;
        }
    }
    //cout<<grafos<<" "<<tam<<endl;
    int ans = 0;
    ans+= (grafos - 1);
    ans += (n - tam);
    cout<<ans;

}


Measured memory_bytes: 13644