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

using namespace std;

typedef long long ll;

#define INF (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
//#define N 100005
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795


ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}

struct fjgkf{
bool operator()(const pair<ll,ll>& a,const pair<ll,ll>& b)const
{
 

  if(a.first<b.first)return true;
  if(a.first==b.first)return a.second>b.second;
  
  else return false;
}
};



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


ll n;cin>>n;
set<pair<ll,ll>,fjgkf>s;
vl a(n+1);
 
for(int i=1;i<=n;i++)
{
  cin>>a[i];
 // s.insert({a[i],i});
}
 
for(int i=1;i<=n;i++)
{
  s.insert({a[i],i});
  auto it=s.find({a[i],i});
 
  if(it!=s.begin())
  {
    advance(it,-1);
// cout<<"hi"<<" "<<(*it).first<<"\n";
    s.erase(it);
  }
}
 
//for(auto x:s)cout<<x.first<<" "<<x.second<<"\n";
 
 
cout<<s.size()<<"\n";


return 0;

}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
#define Mx 2000001

typedef long long  L;
typedef pair<L, L> pii;
L a,a1,a2,a3,b,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,q,q1,q2,q3,q4,r,s,t,
u,v,x,y,z,sum,mx,mn,flg,flg1,flg2,id1,id2,id3,id4,lim,id;
L A[Mx],B[Mx];
void solve(){
    d1=n/500;
    c=d1*1000;
    n=n%500;
    d1=n/5;
    c+=(d1*5);
    printf("%lld\n",c );
}
int main()
{
    scanf("%lld",&n);
    solve();
    return 0;
}
/// lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


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

#define sc(x) scanf("%d",&x)
#define pf(c) scanf("%d",x);
#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\n"
#define mp map<int,int>

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n,m;
	cin >> n >> m;
	ll ans = 0;
		
	if(n!=0)
	for(int i=n-1;i>=1;i--) ans += i;
	
	if(m!=0)
	for(int i=m-1;i>=1;i--) ans += i;
	
	cout << ans << endl;
	
	return 0;
}


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

#define ll long long int
#define ld long double
using namespace std;

int main(){
    string s;
    cin >> s;
    int a = (s[0] - '0') * 10 + (s[1] - '0');
    int b = (s[2] - '0') * 10 + (s[3] - '0');
    bool yymm = false, mmyy = false;
    if(0 < b && b < 13) yymm = true;
    if(0 < a && a < 13) mmyy = true;
    if(yymm && mmyy){
        cout << "AMBIGUOUS" << endl;
    }
    else if(yymm){
        cout << "YYMM" << endl;
    }
    else if(mmyy){
        cout << "MMYY" << endl;
    }
    else{
        cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 3604
#include<cstdio>
#include<iostream>
#include<cctype>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
	int R[MAX], n;

	cin >> n;
	for (int i = 0; i < n; i++)cin >> R[i];

	int maxv = 1 - 1000000000;
	int minv = R[0];

	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);

	}
	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int D,T,S;
  double A,B;
  cin >>D>>T>>S;
  A=(double)T*S;
  B=D;
  if(A>=B)
  {cout<< "Yes"<<endl;}
  else
  {cout<<"No"<<endl;}
}


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

namespace B_AISING2020
{
    class MainClass
    {

        static int[] s,a;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            a = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);

            var ans = 0;


            for(int i = 0;i<s[0];i++){
                if(i%2==0&&a[i]%2==1) ans++;
            }
            WriteLine(ans);
            
        }

        public static int LowerBound<T>(T[] a, T v)
        {
            return LowerBound(a, v, Comparer<T>.Default);
        }

        public static int LowerBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res == -1) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
        public static int UpperBound<T>(T[] a, T v)
        {
            return UpperBound(a, v, Comparer<T>.Default);
        }

        public static int UpperBound<T>(T[] a, T v, Comparer<T> cmp)
        {
            var l = 0;
            var r = a.Length - 1;
            while (l <= r)
            {
                var mid = l + (r - l) / 2;
                var res = cmp.Compare(a[mid], v);
                if (res <= 0) l = mid + 1;
                else r = mid - 1;
            }
            return l;
        }
    }
}


Measured memory_bytes: 28016
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stdbool.h>

typedef long long ll;

int asc(const void *arg1,const void *arg2) {return *((int *)arg2)-*((int *)arg1);}

bool used[100000],flag;
ll n,a[100000],count=0;

void dfs(int x){
  	count++;
    if(used[x-1]){ flag=false; return;}
    if(a[x-1]==2){ flag=true; return;} 
  	used[x-1]=true;
  	dfs(a[x-1]);
}

int main(){
    scanf("%lld",&n);
    for(int i=0;i<n;i++) scanf("%lld",&a[i]);
    dfs(1);
    if(flag)printf("%lld",count);
    else printf("-1");
    
    return 0;
}

Measured memory_bytes: 2584
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int ab = c * 2;
	int ans = 0;
	while (x > 0 || y > 0)
	{
		if (x > 0 && y > 0)
		{
			if (ab <= a + b)
			{
				ans += ab;
				x--; y--;
			}
			else
			{
				ans += a+b;
				x--; y--;
			}
		}
		else if (x > 0)
		{
			ans += min(ab, a);
			x--;
		}
		else
		{
			ans += min(ab, b);
			y--;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
S=input()
a=S[0]
flag=False
b=""
for i in range(4):
  if(S[i]!=a and b==""):
    flag=True
    b=S[i]
  if(S[i]!=a and S[i]!=b and flag==True):
    print("No")
    exit()
if(flag):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <iostream>
 
using namespace std;
 
int main()
{
   int a, b, arr[4] = {0}, i;
  
   for(i = 0; i < 3; i++){
    cin >> a >> b;
     
   	if( ++arr[a-1] == 3){
       cout << "NO" <<endl;
       return 0;
    }
 
    if( ++arr[b-1] == 3){
       cout << "NO" <<endl;
       return 0;
    }
   }
   
   for(i = 0; i < 4; i++){
       if(!arr[i]){
           cout << "NO" <<endl;
           return 0;
       }
   }
   		
    cout << "YES" <<endl;
   
   return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	

	public void solve(){
        Scanner in = new Scanner(System.in);
        for(int i = 0 ; i < 9; i++){
        	String name = in.next();
            int a = in.nextInt();
            int b = in.nextInt();
            System.out.println(name+" "+(a + b)+" "+(a *200 +b*300 ));
        	
        }
		
		return;
	}
	
    public static void main(String[] args) {
    	Main a = new Main();
    	a.solve();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#include <vector>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP2(i, m, n) for (int i = (m); i < (int)(n); ++i)
#define REPR(i, n) for (int i = (n)-1; i >= 0; --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTG(a) sort(ALL(a), greater<int>())
#define REVERSE(a) reverse(ALL(a))
#define bit_search(bit, n) REP(bit, 1<<(n))
#define bit_check(bit, i) (bit>>(i)) & 1
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL((a))), (a).end());} while(0)
#define ENDL cout << endl;
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VI = vector<int>;
using VVI = vector<VI>;
using Vll = vector<ll>;
using VVll = vector<Vll>;
using VC = vector<char>;
using VS = vector<string>;
using VB = vector<bool>;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

VPII optake;
VPII opput;

void move(auto &y, auto &x, auto &dir, auto &H, auto &W, auto &coin, auto &a)
{
  int prex = x, prey = y;
  if (dir == 'R')
  {
    if (x == W-1)
    {
      dir = 'L';
      y++;
    }
    else x++;
  }
  else
  {
    if (x == 0)
    {
      dir = 'R';
      y++;
    }
    else x--;
  }
  if (coin > 0)
  {
    optake.push_back(PII(prey+1, prex+1));
    opput.push_back(PII(y+1, x+1));
    coin--;
    a.at(y).at(x)++;
    if (a.at(y).at(x) % 2) a.at(y).at(x) = 1;
    else a.at(y).at(x) = 0;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  VVI a(H, VI(W));
  REP(i, H)
  {
    REP(j, W)
    {
      int c;
      cin >> c;
      if (c % 2) a.at(i).at(j) = 1;
      else a.at(i).at(j) = 0;
    }
  }
  int y = 0, x = 0;
  int coin = 0;
  char dir = 'R';
  REP(i, H*W-1)
  {
    if (a.at(y).at(x) == 1)
    {
      coin++;
      a.at(y).at(x) = 0;
    }
    move(y, x, dir, H, W, coin, a);
  }
  cout << opput.size() << endl;
  REP(i, opput.size())
  {
    int takey, takex, puty, putx;
    takey = optake.at(i).first;
    takex = optake.at(i).second;
    puty = opput.at(i).first;
    putx = opput.at(i).second;
    cout << takey << ' ' << takex << ' ' << puty << ' ' << putx << endl;
  }


  return 0;
}

Measured memory_bytes: 5356
#include<stdio.h>

int main() {
	int loop,a,b,c,i;
	scanf("%d", &loop);
	for (i = 0; i < loop; i++) {
		scanf("%d %d %d",&a,&b,&c);
		if (a*a + b*b == c*c || b*b + c*c == a*a || c*c + a*a == b*b) {
			printf("YES\n");
		}
		else printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 580
k = gets.to_i

z = [1,2,3,4,5,6,7,8,9]

a = 0
k.times{
	a = z.shift
	b = a % 10
	z << 10*a + b - 1 if b != 0
	z << 10*a + b
	z << 10*a + b + 1 if b != 9
}
p a

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

using namespace std;

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

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;

int main() {
    double a,b,x;
    cin>>a>>b>>x;
    cout << fixed << setprecision(15);
    if (2*x<a*a*b){
        double y=2.0*x/(a*b);
        double theta=atan(b/y);
        cout<<theta*180.0/pi<<endl;
    }
    else{
        double y=2.0*(b-x/(a*a));
        double theta=atan(y/a);
        cout<<theta*180.0/pi<<endl;
    }
    
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }

long long n;
int main() {
    cin >> n;
    long long sum = 0;
    vector<long long> a(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> a.at(i);
        sum += a.at(i);
    }

    sort(a.begin(), a.end());
    int bsum = sum % 2;
    int bmin = a.at(0) % 2;

    if(n % 2 == 0) {
        if(bsum == 0 && bmin == 0) {
            cout << "Second" << endl;
        }else {
            cout << "First" << endl;
        }
    }else {
        if(bsum == 0) {
            cout << "Second" << endl;
        }else {
            cout << "First" << endl;
        }
    }
}


Measured memory_bytes: 4348
#include <stdio.h>

int main(void){
	int E,Y,ans;
	scanf("%d %d",&E,&Y);
	if(E==0){
		if(1868<=Y&&Y<=1911){
			ans=Y-1867;
			printf("M%d\n",ans);
		}
		
		if(1912<=Y&&Y<=1925){
			ans=Y-1911;
			printf("T%d\n",ans);
		}
		
		if(1926<=Y&&Y<=1988){
			ans=Y-1925;
			printf("S%d\n",ans);
		}
		
		if(1989<=Y&&Y<=2016){
			ans=Y-1988;
			printf("H%d\n",ans);
		}
	}
	
	else switch(E){
	case 1:
		printf("%d\n",Y+1867);
		break;
	case 2:
		printf("%d\n",Y+1911);
		break;
	case 3:
		printf("%d\n",Y+1925);
		break;
	case 4:
		printf("%d\n",Y+1988);
		break;
	}
	
	return 0;
}
		

Measured memory_bytes: 1860
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vll A(N);
    rep(i, N) cin >> A[i];

    vll Bl(N + 1), Br(N + 1);
    for (int i = 0; i < N; ++i) {
        Bl[i + 1] = max(Bl[i], A[i]);
    }
    for (int i = N; i > 0; --i) {
        Br[i - 1] = max(Br[i], A[i - 1]);
    }

    rep(i, N) {
        write(max(Bl[i], Br[i + 1]));
    }
}

Measured memory_bytes: 6272
/*
 * written by Yaqi Zhang
 * University of Wisconsin-Madison
 * 2020
 */

#include<algorithm>
#include<cstring>
#include<climits>
#include<iostream>
#include<map>
#include<set>
#include<stdio.h>
#include<vector>

#define INF 0x3f3f3f3f
typedef long long ll;

using namespace std;

const int N = 3005;

long long memo[N][N];

int nums[N];

long long pre_nums[N];


long long solve(int lo, int hi) {
    if(lo > hi) return 0;
    if(lo == hi) return nums[lo];
    if(memo[lo][hi] != -1) return memo[lo][hi];
    long long total = pre_nums[hi + 1] - pre_nums[lo];
    long long ans = max(total - solve(lo + 1, hi), total - solve(lo, hi - 1));
    memo[lo][hi] = ans;
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> nums[i];
    memset(memo, -1, sizeof memo);
    long long sum = 0LL;
    for(int i = 0; i < n; ++i) sum += nums[i];
    for(int i = 1; i < n + 1; ++i) pre_nums[i] = pre_nums[i - 1] + nums[i - 1];
    long long ans = solve(0, n - 1);
    cout << ans - (sum - ans) << endl;
    return 0;
}


Measured memory_bytes: 71040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  unsigned long long sum=0;
  string N;
  cin >> N;

  string a;
  for(int i=0; i < N.length(); i++) {
    a = N.at(i);
    sum += atoi(a.c_str());
  }
  if (sum % 9 > 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3748
from collections import deque

H, W = map(int, input().split())
grid = [input() for _ in range(H)]

ini = -1
q = deque()

dy = (-1, 0, 1, 0)
dx = (0, 1, 0, -1)
ans = 0

for y in range(H):
    for x in range(W):
        dist = [[ini for _ in range(W)] for _ in range(H)]
        if grid[y][x] == "#": continue
        dist[y][x] = 0
        q.append((y, x))

        while(len(q) > 0):
            oy, ox = q.popleft()
            for di in range(4):
                ny = oy + dy[di]
                nx = ox + dx[di]

                if (ny < 0 or ny >= H or nx < 0 or nx >= W): continue
                if grid[ny][nx] == "#": continue
                if dist[ny][nx] != ini: continue

                dist[ny][nx] = dist[oy][ox] + 1
                q.append((ny, nx))

        ans = max(max(map(max, dist)), ans)

print(ans)

Measured memory_bytes: 9492
N = int(input())
MOD = 10 ** 9 + 7


def pow_mod(a, b):
    if b <= 0:
        return 1
    elif b % 2 == 0:
        d = pow_mod(a, b // 2)
        return d ** 2 % MOD
    else:
        return a * pow_mod(a, b - 1) % MOD


ans = pow_mod(10, N) - pow_mod(9, N) * 2 + pow_mod(8, N)
if ans < 0:
    ans += MOD * 2
print(ans % MOD)

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

using namespace std;

struct Item {
  int value;
  Item* prev;
  Item* next;
  Item() : value(-1), prev(nullptr), next(nullptr) {}

  Item* first() {
    Item* ret = this;
    while (ret->prev) {
      ret = ret->prev;
    }
    return ret;
  }
  Item* last() {
    Item* ret = this;
    while (ret->next) {
      ret = ret->next;
    }
    return ret;
  }

  bool isSame(int v) const {
    const Item* next_ = this;
    while (next_) {
      if (next_->value == v) {
        return true;
      }
      next_ = next_->next;
    }
    const Item* prev_ = this->prev;
    while (prev_) {
      if (prev_->value == v) {
        return true;
      }
      prev_ = prev_->prev;
    }
    return false;
  }
};

std::vector<int> calc(int n, const std::vector<bool>& qs,
                      const std::vector<int>& xs, const std::vector<int>& ys) {
  std::vector<Item> items(n, Item());
  for (int i = 0; i < n; ++i) {
    items[i].value = i;
  }

  std::vector<int> ret;
  for (int i = 0; i < qs.size(); ++i) {
    bool const query = qs[i];
    int const x = xs[i];
    int const y = ys[i];
    bool const isSame = items[x].isSame(y);
    if (query) {
      ret.push_back(isSame ? 1 : 0);
    } else {
      // merge
      if (isSame) {
        continue;
      }
      Item* const lastItem = items[x].last();
      Item* const firstItem = items[y].first();
      lastItem->next = firstItem;
      firstItem->prev = lastItem;
    }
  }
  return ret;
}

int main() {
  int n, q;
  std::cin >> n >> q;
  std::vector<bool> qs(q, false);
  std::vector<int> xs(q, 0);
  std::vector<int> ys(q, 0);
  for (int i = 0; i < q; ++i) {
    int query;
    std::cin >> query;
    qs[i] = query == 1;
    std::cin >> xs[i];
    std::cin >> ys[i];
  }
  auto ret = calc(n, qs, xs, ys);
  for (int v : ret) {
    std::cout << v << std::endl;
  }
  return 0;
}


Measured memory_bytes: 4208
#include <iostream>
#include <string>
#include <vector>
#include <tuple>

auto app(int a1, int a2, std::string& S){
  std::vector<int> a_arr(S.size()+2);
  a_arr[0] = a1;
  a_arr[1] = a2;
  for(int i = 1; i < S.size()+1; i++){
    char s = S[i%(S.size())];
    if((s == 'o' && a_arr[i] == 0) || (s == 'x' && a_arr[i] == 1)) a_arr[i+1] = a_arr[i-1];
    else a_arr[i+1] = 1-a_arr[i-1];
  }
  if(a_arr[S.size()] == a_arr[0] && a_arr[S.size()+1] == a_arr[1]) return std::make_tuple(true, a_arr);
  return std::make_tuple(false, a_arr);
}

int main(){
  int N;
  std::cin >> N;

  std::string S;
  std::cin >> S;

  std::vector<int> ans_arr, tmp;
  bool b = false;
  int init_arr[4][2] = {{0,0},{0,1},{1,0},{1,1}};
  for(int i = 0; i < 4; i++){
    std::tie(b,ans_arr) = app(init_arr[i][0], init_arr[i][1], S);
    if(b) break;
  }

  if(b == false) std::cout << -1 << std::endl;
  else{
    for(int i = 0; i < N; i++){
      std::cout << (ans_arr[i] == 0 ? "S":"W");
    }
    std::cout << std::endl;
  }

  return 0;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int n;
    cin >> n;
    vi v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    map<int, int> evendict, odddict;
    for (int i = 0; i < n; i+=2) {
        evendict[v[i]]++;
        odddict[v[i+1]]++;
    }

    // cout << "even " << evendict.size() << " odd " << odddict.size() << endl;
    if (evendict.size() == 1 && odddict.size() == 1) {
        if (v[0] != v[1]) {
            // cout << "hoge" << endl;
            cout << 0 << endl;
            return;
        }else{
            // cout << "piyo" << endl;
            cout << n/2 << endl;
            return;
        }
    }

    // int emax=0, omax=0, e1=0, e2=0, o1=0, o2=0;
    vector<pair<int, int>> evencand, oddcand;
    for (auto itr = evendict.begin(); itr != evendict.end(); itr++){
        evencand.push_back(make_pair(itr->second, itr->first));
    }
    for (auto itr = odddict.begin(); itr != odddict.end(); itr++){
        oddcand.push_back(make_pair(itr->second, itr->first));
    }
    sort(all(evencand));
    sort(all(oddcand));
    int lene=evencand.size(), leno=oddcand.size();
    if (evencand[lene-1].second == oddcand[leno-1].second) {
        int e1=evencand[lene-1].first;
        int e2=evencand[lene-2].first;
        int o1=oddcand[leno-1].first;
        int o2=oddcand[leno-2].first;
        if (evendict.size() == 1) {
            e2 = 0;
        }
        if (odddict.size() == 1) {
            o2 = 0;
        }

        // cout << "fuga" << endl;
        // cout << e1 << " " << e2 << " " << o1 << " " << o2 << endl;
        cout << n - max(e1+o2, e2+o1) << endl;
    }else{
        int ans=0;
        if (evendict.size() != 1) {
            ans += n/2 - evencand[lene-1].first;
        }
        if (odddict.size() != 1) {
            ans += n/2 - oddcand[leno-1].first;
        }
        cout << ans << endl;
    }



    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 6520
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define inf 10000000000000007
#define eps 1e-13
#define PI 3.14159265359
#define sp printf(" ")
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pcc pair<char, char>
#define mp make_pair
#define FF first
#define SS second
#define pb(x) push_back(x)
#define sd(x) scanf("%d", &(x))
#define pd(x) printf("%d", (x))
#define pdn(x) printf("%d\n", (x))
#define sld(x) scanf("%ld", &(x))
#define pld(x) printf("%ld", (x))
#define pldn(x) printf("%ld\n", (x))
#define slf(x) scanf("%lf", &(x))
#define plf(x) printf("%.9lf", (x))
#define plfn(x) printf("%.9lf\n", (x))
#define sch(x) scanf("%c", &(x))
#define pch(x) printf("%c", (x))
#define pchn(x) printf("%c\n", (x))
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define ios ios::sync_with_stdio(false); cin.tie(0)
#define endl '\n'
using namespace std;
int a[100],b[100];
int main()
{
    int n;
    cin>>n;
    for(int j=0;j<26;j++)b[j]=10000;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        for(int j=0;j<26;j++)a[j]=0;
        for(int j=0;j<s.size();j++)a[s[j]-'a']++;
        for(int j=0;j<26;j++)b[j]=min(b[j],a[j]);
    }
    for(int i=0;i<26;i++)
    {

        for(int j=1;j<=b[i];j++)
        {
            int k='a';k+=i;
            printf("%c",k);

        }
    }
cout<<endl;

}




Measured memory_bytes: 256
#include <stdio.h>

void merge_sort(int a[], int start, int end) {
    int i, j, k, mid;
    int work[end-start+1];
    if(start < end) {
        mid = (start + end) / 2;
        merge_sort(a, start, mid);
        merge_sort(a, mid+1, end);

        for(i=mid; i>=start; i--) {
            work[i-start] = a[i];
        }
        for(j=mid+1; j<=end; j++) {
            work[j-start] = a[end-(j-mid-1)];
        }
        i = start-start;
        j = end-start;
        for(k=start; k<=end; k++) {
            if(work[i]<work[j]) {
                a[k] = work[i++];
            } else {
                a[k] = work[j--];
            }
        }
    }
}

void print_array(int a[], int array_size) {
    int i;
    for(i=0; i<array_size; i++) {
        printf("%d :%d\n", i+1, a[i]);
    }
}

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

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

    int count;
    for(i=0; i<n; i++) {
        b[a[i]-1] += 1;
        if(b[a[i]-1]==1) {
            count += 1;
        }
    }

    // print_array(b, n);
    merge_sort(b, 0, n-1);
    // print_array(b, n);

    i=0;
    int ans=0;
    k = count - k;
    while(k) {
        if(k<0) {
            break;
        }
        if(b[i]>0) {
            ans += b[i];
            k--;
        }
        i++;
    }

    printf("%d\n", ans);

    return 0;
    
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

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

    vector<pi> a(m);
    rep(i,m)
    {
        int x,y;
        scanf(" %d %d", &x, &y);
        a[i] = pi(x,y-1);
    }

    sort(all(a));

    vector<int> d(m),u(m);
    vector<int> last(n,-1);
    rep(i,m)
    {
        int y = a[i].se;

        int add=0;
        if(y-1>=0 && last[y-1]!=-1) add = u[last[y-1]];
        u[i] = 1+add;

        add=0;
        if(y+1<n && last[y+1]!=-1)add = d[last[y+1]];
        d[i] = 1+add;

        last[y] = i;
    }

    rep(i,n)
    {
        int ans = 1;
        if(last[i]!=-1) ans += d[last[i]];
        if(i-1>=0 && last[i-1]!=-1) ans += u[last[i-1]];

        printf("%d%c", ans, (i==n-1?'\n':' '));
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<ll, ll>;

int n;
void input() {
    cin >> n;
}

void calc() {
    int log = 0, bit = -1;
    for (int i = 0; i < 20; i++) {
        if (n == (1 << i)) {
            cout << "No";
            return;
        }
        if ((1 << i) < n) {
            log = i;
        }
        if (bit == -1 && (n & (1 << i)) > 0) {
            bit = i;
        }
    }
    log = max(log, 2);
    cout << "Yes\n";
    if (n % 2 == 0) {
        vector<int> ord;
        ord.push_back(1);
        ord.push_back(1 << bit);
        for (int i = 2; i < (1 << log); i++) {
            if (i == (1 << bit)) continue;
            ord.push_back(i);
        }
        int p = -1;
        for (int i : ord) {
            if (p != -1) {
                cout << p << ' ' << i << '\n';
            }
            p = i;
        }
        for (int i : ord) {
            if (p != -1) {
                cout << p << ' ' << i + n << '\n';
            }
            p = i + n;
        }
        for (int i = (1 << log); i < n; i += 2) {
            if (i == (n ^ (1 << bit))) continue;
            cout << 1 << ' ' << i << '\n';
            cout << 1 << ' ' << i + 1 << '\n';
            cout << i << ' ' << i + n + 1 << '\n';
            cout << i + 1 << ' ' << i + n << '\n';
        }
        int a = (n ^ (1 << bit));
        cout << (1 << bit) << ' ' << a + n << '\n';
        cout << a + n << ' ' << n + n << '\n';
        cout << (1 << bit) << ' ' << n << '\n';
        cout << a << ' ' << n << '\n';
        cout << a + 1 << ' ' << n << '\n';
        cout << 1 << ' ' << a + n + 1 << '\n';
    }
    else {
        int p = -1;
        for (int i = 1; i < (1 << log); i++) {
            if (p != -1) {
                cout << p << ' ' << i << '\n';
            }
            p = i;
        }
        for (int i = 1; i < (1 << log); i++) {
            if (p != -1) {
                cout << p << ' ' << i + n << '\n';
            }
            p = i + n;
        }
        for (int i = (1 << log); i <= n; i += 2) {
            cout << 1 << ' ' << i << '\n';
            cout << 1 << ' ' << i + 1 << '\n';
            cout << i << ' ' << i + n + 1 << '\n';
            cout << i + 1 << ' ' << i + n << '\n';
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    input();
    calc();
    return 0;
}

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
  vector<int> vec(9);
  rep(i, 9){
    cin >> vec.at(i);
  }
  bool check = false;
  rep(a1, 101){
    rep(a2, 101){
      rep(a3, 101){
        rep(j, 3){
          int b = vec.at(j) - a1;
          int bb = vec.at(3 + j) - a2;
          int bbb = vec.at(6 + j) - a3;
          if(b != bb || bb != bbb || b != bbb)
            break;
          if(j == 2)
            check = true;
        }
      }
    }
  }
  if(check)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

using namespace std;

int main()
{
    int n;

    cin >> n;

    string p;

    cin >> p;

    int cnt=0,i;

    for(i=0;i<n;i++)
    {
        if(p[i]=='A' && p[i+1]=='B' && p[i+2]=='C')
        {
            cnt++;

            i=i+2;
        }
    }

    cout << cnt << endl;

    return 0;
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= m; i--)
#define ll long long
#define pb push_back
#define popb pop_back
using namespace std;

int solve(int x, int y, int b, int p){
  vector<int> money;
 if(b >= 5 && p >= 2){
 money.pb((x * b + y * p)* 0.8); 
 }else{
   if(b >= 5) money.pb((x * b + y * 2) * 0.8);
   if(p >= 2) money.pb((x * 5 + y * p) * 0.8);
   money.pb(x * b + y * p);
 } 
 sort(money.begin(), money.end());
 return money.front();
}

int main(){
  int n,t,q,r,s;
  vector<int> x,y,b,p;
  cin >> n;

  REP(i, n){
    cin >> t >> q >> r >> s ;
    x.pb(t);
    y.pb(q);
    b.pb(r);
    p.pb(s);
  }

  REP(j, n){
   cout <<  solve(x[j], y[j] , b[j] , p[j]) << endl;
    } 
  return 0;
  }




Measured memory_bytes: 3156
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
int n;
int m;
int sum;
int main(void) {
    cin >> n;
    vector<int> vec(n);
    rep(i, n) {
        cin >> vec[i];
        m = max(m, vec[i]);
        sum += vec[i];
    }
    cout << sum - m / 2 << endl;
    return 0;
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  vector<bool> b(n - k, 0);
  rep(i, n) cin >> a.at(i);
  REP(i, k - 1, n - 1) {
    if (a.at(i - k + 1) < a.at(i + 1)) b.at(i - k + 1) = 1;
  }
  rep(i, b.size()) {
    if (b.at(i) == 1)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

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

int main() {
	// your code goes here
	long long n[99999],num,i,ans=0;
	cin>>num;
	for(i=0;i<num;i++){
		cin>>n[i];
	}
	sort(n,n+num);
	cout<<n[0]<<" ";
	for(i=0;i<num;i++){
		ans=ans+n[i];
	}
	cout<<n[num-1]<<" "<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3252
using System;

public class Example {
    public static void Main() {
        while (true) {
            string input = Console.ReadLine();
            if (input == null) break;
            decimal[] num = Array.ConvertAll<string, decimal>(input.Split(' '), delegate(string value) {
                return decimal.Parse(value);
            });
            Console.WriteLine(Math.Round((num[2]*num[4]-num[1]*num[5])/(num[0]*num[4]-num[1]*num[3]), 3, MidpointRounding.AwayFromZero).ToString()+" "+(Math.Round((num[2]*num[3]-num[0]*num[5])/(num[1]*num[3]-num[0]*num[4]), 3, MidpointRounding.AwayFromZero)).ToString());
        }
    }
}

Measured memory_bytes: 9516
#include<bits/stdc++.h>
using namespace std;	
int n,a[100005],b[100005];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
	{
	   cin>>a[i];b[a[i]]=i;
	}
    for(int i=1;i<=n-1;i++)
	{
	   cout<<b[i]<<" ";
	}
	cout<<b[n];
	return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main(){
  int height[300], weight[300];
  int i = 0, j = 0, count = 0, l = 0;

  for(i=1;i<=300;i++){
    scanf("%d %d", &height[i], &weight[i]);
    if(height[i]==0&&weight[i]==0) break;
    count++;
  }

  for(l=1;l<=count;l++){
    for(i=1;i<=height[l];i++){
      for(j=1;j<=weight[l];j++){
        if(i==1||i==height[l]){
          printf("#");
        }else if(j==1||j==weight[l]){
          printf("#");
        }else{printf(".");}
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 572
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.root = [-1]*n
        self.rank = [0]*n

    def find(self, x):
        if self.root[x-1] < 0:
            return x
        else:
            self.root[x-1] = self.find(self.root[x-1])
            return self.root[x-1]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        elif self.rank[x-1] > self.rank[y-1]:
            self.root[x-1] += self.root[y-1]
            self.root[y-1] = x
            self.n-=1
        else:
            self.n-=1
            self.root[y-1] += self.root[x-1]
            self.root[x-1] = y
            if self.rank[x-1] == self.rank[y-1]:
                self.rank[y-1] += 1

    def same(self, x, y):
        return self.find(x)==self.find(y)

    def count(self, x):
        return -self.root[self.find(x)-1]
    def num(self):
        return self.n

N,M=map(int,input().split())
uf=UnionFind(N)
for i in range(M):
    x,y,z=map(int,input().split())
    uf.unite(x,y)
print(uf.num())


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

int main(){
    int N,A,B,C,D;
    cin >> N >> A >> B >> C >> D;
    string S;
    cin >> S;
    string res = "Yes";
    string temp;
    if(D > C){
        string old=S.substr(A-1,1);
        for(int n=A; n<D; n++){
            temp = S.substr(n,1);
            if(old == "#" && temp == "#"){
                res = "No";
            }
            old = temp;
        }
    }
    else{
        int oinuki_flag = 0;
        string old_old = S.substr(B-2,1);
        string old = S.substr(B-1,1);
        for(int n=B; n<D+1; n++){
            temp = S.substr(n,1);
            if(old_old == "." && old == "." && temp == "."){
                oinuki_flag = 1;
            }
            old_old = old;
            old = temp;
        }
        if(oinuki_flag == 0){
            res = "No";
        }
        else{
            string old = S.substr(A-1,1);
            for(int n=A; n<C; n++){
                temp = S.substr(n,1);
                if(old == "#" && temp == "#"){
                    res = "No";
                }
                old = temp;
            }
        }
    }
    cout << res << endl;
}


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

int main() {
  int N;
  cin >> N;
  int c[N], v[N];
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> c[i];
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (v[i]-c[i] > 0) {ans = ans + v[i]-c[i];}
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll A, V, B, W, T;
  cin>>A>>V>>B>>W>>T;
  if((V-W)*T>=abs(A-B)) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}



Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<functional>
#include<cmath>
#include<unordered_map>

#define REP(i,n) for(int i=0;i<n;i++)
#define ll long long int

using namespace std;

int to_int(string s) {
  return atoi(s.c_str());
}

int a[100000];
ll sum[100001];

int main() {
  int m,n;
  cin >> n >> m;
  REP(i,n) cin >> a[i];
  unordered_map<int,int> mp;
  sum[0] = 0;
  mp[0] = 1;

  REP(i,n) {
    sum[i+1] = sum[i] + a[i];
    mp[sum[i+1]%m] += 1;
  }

  ll r = 0;
  REP(i,n+1) {
    ll tmp = mp[sum[i]%m];
    r += tmp*(tmp -1)/2;
    mp[sum[i]%m] = 0;
  }

  cout << r << endl;




}


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

int main(void){
    int a=0;
    int b=0;
    int c=0;
    int max=0;
    int min=0;

    cin >> a >> b >> c;

    min=a;
    if(min>=b)min=b;
    if(min>=c)min=c;

    if(min==c){
        cout << "No" << endl;
    }else if(min==a){
        if(c<=b)cout << "Yes" << endl;
        else cout << "No" << endl;
    }else if(min==b){
        if(c<=a)cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int main() {
    int h, w;
    cin >> h >> w;
	
	char grd[h][w];

	for (int i = 0; i < h; i++) {
	    for (int j = 0; j < w; j++) {
	        cin >> grd[i][j];
	    }
	}
	bool flg = true;
	for (int i = 1; i < h - 1; i++) {
	    for (int j = 1; j < w - 1; j++) {
        	if(grd[i][j]=='#'){
	            if(grd[i - 1][j]=='.' and grd[i][j - 1]=='.' and grd[i + 1][j]=='.' and grd[i][j + 1]=='.') flg = false;
	        }
	    }
	}
	
	if(flg)std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;
	
	return 0;
}

Measured memory_bytes: 256
// Rabbit Exercise
// * frank_c1
// * 2017 / 11/ 07

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int maxn = (int)(1e5) + 5;
int p[maxn], pt[maxn], tmp[maxn];
LL c[maxn], nc[maxn];

int main() {
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%lld", &c[i]);
	for (int i = n; i >= 1; --i) c[i] -= c[i - 1], p[i] = i;
	int m; LL K; scanf("%d%lld", &m, &K);
	for (int i = 1; i <= m; ++i) {
		int x; scanf("%d", &x); swap(p[x], p[x + 1]);
	}
	for (int i = 1; i <= n; ++i) pt[i] = i;
	for (; K; K >>= 1) {
		if (K & 1) {
			memcpy(tmp, pt, sizeof(pt));
			for (int i = 1; i <= n; ++i) pt[i] = tmp[p[i]];
		}
		memcpy(tmp, p, sizeof(p));
		for (int i = 1; i <= n; ++i) p[i] = tmp[tmp[i]];
	} LL ret = 0;
	for (int i = 1; i <= n; ++i) nc[i] = c[pt[i]];
	for (int i = 1; i <= n; ++i) printf("%lld\n", (nc[i] += nc[i - 1]));
	return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <cmath>
using namespace std;
int n,t,x,y,dx,dy,dt;
int main()
{
	cin>>n;
	bool temp=true;
	while(n--){
		cin>>t>>x>>y;
		int d=abs(dx-x)+abs(dy-y);
		if(abs(dt-t)<d||((abs(dt-t)-d)%2!=0)) temp=false;
		dx=x,dy=y,dt=t;
	}
	if(temp) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    char c[1001];
    cin>>c;
    rep(i,1001){
        if(c[i]==0) break;
        cout<<(char)((c[i]-'A'+23)%26+'A');
    }
    cout<<endl;
}

Measured memory_bytes: 1136
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int n;
	cin >> n;
	int v[n];
	for(int i = 0; i < n; i++)cin >> v[i];
	int even[100001] = {},odd[100001] = {};
	for(int i = 0; i < n; i += 2)even[v[i]]++;
	for(int i = 1; i < n; i += 2)odd[v[i]]++;
	int even_max = 0,even_max_num,odd_max = 0,odd_max_num;
	for(int i = 1; i <= 100000; i++){
		if(even_max < even[i]){
			even_max = even[i];
			even_max_num = i; 
		}
	}
	for(int i = 1; i <= 100000; i++){
		if(odd_max < odd[i]){
			odd_max = odd[i];
			odd_max_num = i;
		}
	}
	if(even_max_num != odd_max_num){
		cout << n - even_max - odd_max << endl;
	}else{
		sort(even, even + 100001);
		sort(odd, odd + 100001);
		cout << min(n - even_max - odd[99999], n - even[99999] - odd_max) << endl;
	}
}

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

const int N = 2e5+5;
ll n, k;
int a[N];
bool vis[N];
vector<int> path;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
        cin >> a[i];

    memset(vis, 0, sizeof vis);
    int pos = 1;
    vis[pos] = 1;
    path.push_back(1);
    while(!vis[a[pos]] && k > 0)
        pos = a[pos], vis[pos] = 1, path.push_back(pos), k--;

    if(k == 0)
        cout << pos << '\n';
    else {
        int x = a[pos];
        int idx = 0;
        while(path[idx] != x) idx++;
        ll m = path.size() - idx;
        k = (k+m-1)%m;
        int p = 0;
        while(p < k) p++;
        cout << path[idx+p] << '\n';
    }

    return 0;
}

Measured memory_bytes: 5216
# coding: utf-8
n, k = map(int, input().split())
p = list(map(int, input().split()))
pm = pp = sum(p[0:k])
for i in range(n - k):
    pp = pp - p[i] + p[k+i]
    pm = pp if (pp >= pm) else pm
ans = (pm + k) / 2
print(ans)


Measured memory_bytes: 24804
package main

import "fmt"

type Sara [4]float64

var n float64
var results [301][301][301]float64

func solve(s Sara) float64 {
	if r := results[int(s[0])][int(s[1])][int(s[2])]; r > 0 {
		return r
	}
	if s[0] == n {
		return 0
	}

	m := n - s[0]
	r := n / m
	if s[1] > 0 {
		r += solve(Sara{s[0] + 1, s[1] - 1, s[2], s[3]}) * s[1] / m
	}
	if s[2] > 0 {
		r += solve(Sara{s[0], s[1] + 1, s[2] - 1, s[3]}) * s[2] / m
	}
	if s[3] > 0 {
		r += solve(Sara{s[0], s[1], s[2] + 1, s[3] - 1}) * s[3] / m
	}
	results[int(s[0])][int(s[1])][int(s[2])] = r

	return r
}

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

	var s Sara

	for i := 0; i < int(n); i++ {
		var a int
		fmt.Scan(&a)
		s[a]++
	}

	fmt.Println(solve(s))
}


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

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

  auto a = vector<int>();


  auto f = [](int i){
      return i%2 ==0 ? i/2 : 3*i+1;
  };
  int j=0;
  a.push_back(s);
  for(int i=0;i<=1000000;i++){
      int num = f(a[i]);
      if(find(a.begin(),a.end(),num) != a.end())
        break;
     a.push_back(num);
     j=i;
  }
  cout << j+3;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int index = sc.nextInt();
        int list[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        System.out.println(list[index-1]);
    }
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int n = ri();
	int c[26];
	for (auto &i : c) i = ri();
	int a[n][26];
	for (auto &i : a) for (auto &j : i) j = ri();
	
	for (int i = 0; i < n; i++) {
		printf("%d\n", (int) (std::max_element(a[i], a[i] + 26) - a[i] + 1));
	}
	
	return 0;
}


Measured memory_bytes: 3860
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

int main(){
ll N;cin >> N;

if(N >= 30)cout << "Yes";
else cout << "No";
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
 
#define fastio1 ios_base::sync_with_stdio(false)
#define fastio2 cin.tie(NULL)
#define LL long long
#define MOD 1000000007
using namespace std;
 
int main(){
    fastio1; fastio2;
	LL n, k; cin >> n >> k;
	vector<LL> a(n);
	LL tracker[42] = {0};
	
	for (int i = 0; i < n; i++){
		cin >> a[i];
		LL temp = a[i];
		int b = 1;
		while(temp > 0){
			tracker[42-b] += temp % 2;
			temp /= 2;
			b++;
		}
	}
	
	LL x = 0;
	for (int i = 0; i < 42;i++){
		if (x + (tracker[i] < n-tracker[i])*(1LL<<(41-i)) <= k){
			x += (tracker[i] < n-tracker[i])*(1LL<<(41-i));
		}
	} 
	
	LL total = 0;
	for (int i = 0; i < n; i++){
		total += x^a[i];
	}
	cout << total << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define y1 yy1
#define x1 xx1
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int R, C, n, cnt = 0;
int x1[200010], y1[200010], x2[200010], y2[200010];
pair<int,int> pos[200010*2+10];
int que[200010];
bool vis[200010];
bool check(int x, int y)
{
	if (x == 0) return true;
	if (x == R) return true;
	if (y == 0) return true;
	if (y == C) return true;
	return false;
}
int deal(int x, int y)
{
	if (y == 0) return x;
	if (x == R) return R + y;
	if (y == C) return R + C + R - x;
	if (x == 0) return R + R + C + C - y;
	return 0;
}
int main()
{
	R=read(),C=read(),n=read();
	for (int i = 1; i <= n; i ++)
		x1[i] = read(),y1[i] = read(), x2[i] = read() ,y2[i] = read();
	for (int i = 1; i <= n; i ++)
		if (check(x1[i], y1[i]) && check(x2[i], y2[i]))
		{
			pos[++ cnt].second = i;
			pos[cnt].first = deal(x1[i], y1[i]);
			pos[++cnt].second = i;
			pos[cnt].first = deal(x2[i], y2[i]);
		}
	sort(pos + 1, pos + cnt + 1);
	for (int i = cnt + 1; i <= cnt * 2; i ++)
		pos[i] = pos[i - cnt];
	memset(que, 0, sizeof(que));
	memset(vis, false, sizeof(vis));
	int sz = 0;
	bool checkk = true;
	for (int i = 1; i <= cnt * 2; i ++)
		if (!vis[pos[i].second])
		{
			que[++ sz] = pos[i].second;
			vis[pos[i].second] = true;
		} else 
		{
			if (que[sz] != pos[i].second) checkk = false;
			vis[pos[i].second] = false;
			--sz;
		}
	if (checkk) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 6784