akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
//max_element


signed main()
{
	int A, B, K;
	cin >> A >> B >> K;

	int rest = -(A - K);
	A = max(0LL, A - K);
	rest = max(rest, 0LL);
	B = max(0LL, B - rest);

	cout << A << " " << B << endl;
}




Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;

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

    int max = 1;
    for(int i = 1;i <= n;i++){
        if(i*(i+1)/2 >= n){
            max = i;
            break;
        }
    }
    for(int i = 1; i <= max;i++){
        if(i != max*(max+1)/2 - n) cout << i << endl;
    }
    
    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
int main(){
  int n,m,a,b;
  cin>>n>>m;
  vector<int> to[100005];
  for(int i=0;i<m;i++){
    cin>>a>>b;
    a--;
    b--;
   to[a].push_back(b);
    to[b].push_back(a);
  }
  queue<int> q;
  vector<int> dist(n,100005);
  vector<int> pre(n,-1);
  dist[0]=0;
  q.push(0);
  while(!q.empty()){
    int v=q.front();
    q.pop();
    for(int u:to[v]){
      if(dist[u]!=100005) continue;
      dist[u]=dist[v]+1;
      pre[u]=v;
      q.push(u);
    }
  }
  cout<<"Yes"<<endl;
  for(int i=1;i<n;i++){
    int ans=pre[i];
    ans++;
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 10648
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	/*ll t;cin>>t;
	while(t-->0)
    {
    }*/
    ll a,b;
    cin>>a>>b;
    cout<<a*b<<"\n";
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
/*  
- Our collaboration has been a thing of beauty.
- And for those who fear Allah , He will make their path easy. 
*/
bool isUpper(char c)
{
   return (c>=65 && c<97);
}
int main()
{
  string s;
  getline(cin,s);
  int len = s.length();
  if(isUpper(s[0]))
   cout<<s[0];
  for(int i =1 ;i<len;++i)
  {
 
    if(isUpper(s[i])&& s[i-1]==' ')
              cout<<s[i];
 
  }
 }

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



/// Info.
///****************************************************************************************************************************************///
/// author                : BAHAA El-DEEN OSAMA .
/// Problem name          : N - Phone Numbers
/// Method                : brute force
/// Online judge          : vjudge(Contest)
/// Date                  : 8/7/2020
///****************************************************************************************************************************************///

typedef long long ll ;
typedef unsigned long long ull ;

ll N;
string name = "";

int main()
{

    cin >> N;

	//1:a
	//26:z
	//27:aa
	while (N)
    {
		int s = (N-1) % 26;
		name = (char)('a' + s) + name;
		N = (N-1)/ 26;
	}
	cout << name << endl;

	   return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;

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

        for (int i = 1; i <= 1000; i++) {
            int aa = i * 8 / 100;
            int bb = i * 10 / 100;
            if (aa > 0 && bb > 0 && a == aa && b == bb) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(-1);
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+1;
const int mod = 1e9+7;
int main() {
	int n,l,ans=0;
	int k,mn=INF;
	sd(n);sd(l);
	for(int i = 1; i <= n; i++){
		int x=l+i-1;
		if(abs(x)<mn){
			mn=abs(x);k=x;
		}
		ans+=x;
	}
	ans-=k;
	pd(ans);
	return 0;
}

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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


int main() {
  int N;
  cin>>N;
  vector<int> b(N);
  for(int i(0);i<N;i++){
    cin>>b[i];
  }
  vector<int> ans;
  for(int i(0);i<N;i++){
    int maxi(-1);
    for(int j(0);j<int(b.size());j++){
      if(b[j] == j+1){
        maxi = j;
      }
    }
    //cout << maxi << endl;
    if(maxi == -1){
      cout << -1 << endl;
      return 0;
    }
    ans.push_back(b[maxi]);
    b.erase(b.begin()+maxi);
  }
  for(int i(0);i<N;i++){
    cout << ans[N-i-1] << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
A =[[] for j in range(2)]
for i in range(2):
    A[i] = list(map(int, input().split()))
    
cum_sum = [[0 for i in range(N)] for j in range(2)]
cum_sum[0][0] = A[0][0]
cum_sum[1][N - 1] = A[1][N - 1]
for i in range(1, N):
    cum_sum[0][i] = cum_sum[0][i - 1] + A[0][i]

for i in range(N - 2, -1, -1):
    cum_sum[1][i] = cum_sum[1][i + 1] + A[1][i]

ans = 0
for i in range(N):
    ans = max(ans, cum_sum[0][i] + cum_sum[1][i])
    
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

const int maxn = 20005;
int n;
int a[maxn], b[maxn], p[maxn];

int main(){
  scanf("%d", &n);
  for(int i = 1;i <= n;++i)scanf("%d", &p[i]);
  for(int i = 1;i <= n;++i){
    a[i] = i * n;
    b[i] = (n - i + 1) * n;
  }
  for(int i = 1;i <= n;++i){
    int x = p[i];
    b[x] += i;
  }
  for(int i = 1;i <= n;++i)printf("%d%c", a[i], i == n ? '\n' : ' ');
  for(int i = 1;i <= n;++i)printf("%d%c", b[i], i == n ? '\n' : ' ');
  return 0;
}


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

typedef long long LL;
const LL inf = 0x3f3f3f3f3f3f3f3f;
const int N = 100005;

int n, e, t, x[N];
LL dp[N];

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n >> e >> t;
	for (int i = 1; i <= n; ++i) std::cin >> x[i];
	int k = 0; LL left_min = inf;
	for (int i = 1; i <= n; ++i) {
		while (2 * (x[i] - x[k + 1]) > t) left_min = std::min(left_min, dp[k] - 2 * x[k + 1]), ++k;
		dp[i] = std::min(left_min + 2 * x[i], dp[k] + t);
	}
	std::cout << dp[n] + e << '\n';
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
using namespace std;

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


int main()
{
	int n;
	cin >> n;
	int deb = 100000;
	REP(i, n)
	{
		deb *= 1.05;
		if (deb % 1000 != 0)
		{
			deb = (deb / 1000 + 1)*1000;
		}
	}
	cout << deb << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <iostream>

using namespace std;

struct dice{
	int q1,q2,q3,q4,q5,q6;
};

void mN(dice &d){
	int tmp=d.q1;
	d.q1=d.q2;
	d.q2=d.q6;
	d.q6=d.q5;
	d.q5=tmp;
}

void mE(dice &d){
	int tmp=d.q1;
	d.q1=d.q4;
	d.q4=d.q6;
	d.q6=d.q3;
	d.q3=tmp;
}
void mW(dice &d){
	int tmp=d.q1;
	d.q1=d.q3;
	d.q3=d.q6;
	d.q6=d.q4;
	d.q4=tmp;
}
void mS(dice &d){
	int tmp=d.q1;
	d.q1=d.q5;
	d.q5=d.q6;
	d.q6=d.q2;
	d.q2=tmp;
}

void spin(dice &d){
	int tmp=d.q2;
	d.q2=d.q3;
	d.q3=d.q5;
	d.q5=d.q4;
	d.q4=tmp;
}

int main(){
	dice y, z;
	bool flag = false;
	
	scanf(" %d %d %d %d %d %d", &y.q1, &y.q2, &y.q3, &y.q4, &y.q5, &y.q6);
	scanf(" %d %d %d %d %d %d", &z.q1, &z.q2, &z.q3, &z.q4, &z.q5, &z.q6);
	
	for(int i=0; i<4; ++i){
		for(int j=0; j<4; ++j){
			//printf("now: %d %d %d %d %d %d\n", y.q1, y.q2, y.q3, y.q4, y.q5, y.q6);
		
			if(y.q1==z.q1 && y.q2==z.q2 && y.q3==z.q3 && y.q4==z.q4 && y.q5==z.q5 && y.q6==z.q6) {
				flag = true;
				break;
			}
			spin(y);	
		}
		if(flag) break;
		mN(y);
	}
	
	mE(y);
	
	//printf("now: %d %d %d %d %d %d\n", y.q1, y.q2, y.q3, y.q4, y.q5, y.q6);
	
	for(int i=0; i<4; ++i){
		for(int j=0; j<4; ++j){
			//printf("now: %d %d %d %d %d %d\n", y.q1, y.q2, y.q3, y.q4, y.q5, y.q6);
		
			if(y.q1==z.q1 && y.q2==z.q2 && y.q3==z.q3 && y.q4==z.q4 && y.q5==z.q5 && y.q6==z.q6) {
				flag = true;
				break;
			}
			spin(y);	
		}
		if(flag) break;
		mN(y);
	}	
			
	if(flag)printf("Yes\n");
	else printf("No\n");
		
	return 0;
}



Measured memory_bytes: 3164
n,Y=map(int,input().split())
x,y,z=-1,-1,-1
for i in range(n+1):
    total=10000*i
    for j in range(n-i+1):
        total2=total+5000*j
        if n-(i+j)==(Y-total2)//1000:
            x,y,z=i,j,n-(i+j)
            break
        #print(total2)
print(str(x)+" "+str(y)+" "+str(z))

Measured memory_bytes: 40940
#include<stdio.h>
#include<stdlib.h>



int main()
{
  long  a;
  scanf("%ld",&a);

  getchar();
  if(a==1){
    printf("0\n");
  }else
  {
       long rn=0;
       while (rn*rn<=a) rn++;
       long re = a-1;
       for(long  i=2;i<=rn;i++){
        if(a%i==0){
            long  temp = i+a/i-2;
            if(temp<re){
                re = temp;
            }
        }
       }
       printf("%ld\n",re);
  }
  return 0;
}


Measured memory_bytes: 128
import sys

def main():
    input = sys.stdin.readline
    A = [c for c in input().strip()]
    B = [c for c in input().strip()]
    C = [c for c in input().strip()]

    card = A.pop(0)
    while True:
        if card == 'a':
            if len(A) == 0:
                return 'A'
            else:
                card = A.pop(0)

        elif card == 'b':
            if len(B) == 0:
                return 'B'
            else:
                card = B.pop(0)

        else:
            if len(C) == 0:
                return 'C'
            else:
                card = C.pop(0)


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3064
const max=5000;
var
  r,b,g:array[0..max] of longint;
  n,i,j:longint;
  ans:int64;
  s:ansistring;
begin
  readln(n);
  readln(s);
  for i:=n downto 1 do
  begin
    r[i]:=r[i+1];
    g[i]:=g[i+1];
    b[i]:=b[i+1];
    if (s[i]='R') then inc(r[i]);
    if (s[i]='G') then inc(g[i]);
    if (s[i]='B') then inc(b[i]);
  end;
  for i:=2 to n-1 do
   begin
     for j:=i-1 downto 1 do
     if (s[i]<>s[j]) then
     begin
       if (s[i]='R') and (s[j]='G') or (s[i]='G') and (s[j]='R') then
       begin
         ans:=ans+b[i+1];
         if (i-j+i<=n) then if (s[i-j+i]='B') then dec(ans);
       end;
       if (s[i]='R') and (s[j]='B') or (s[i]='B') and (s[j]='R') then
       begin
         ans:=ans+g[i+1];
         if (i-j+i<=n) then if (s[i-j+i]='G') then dec(ans);
       end;
       if (s[i]='G') and (s[j]='B') or (s[i]='B') and (s[j]='G') then
       begin
         ans:=ans+r[i+1];
         if (i-j+i<=n) then if (s[i-j+i]='R') then dec(ans);
       end;
     end;
   end;
   writeln(ans);
end.


Measured memory_bytes: 1384
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    ab.sort(key=lambda x: (x[1], -x[0]))
    d = 0
    for a, b in ab:
        d += a
        if d > b:
            print('No')
            exit()
    print('Yes')


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 82140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String x=br.readLine();
		while(!x.equals("0")) {
			//文字列をカウント
			int n=x.length();
			//繰り返し
			int sum=0;
			for(int i=0;i<n;i++) {
				//strからi個目の文字を切り出す
				char a;
				a=x.charAt(i);
				int b=Integer.parseInt(String.valueOf(a));
				sum+=+b;
			}
			System.out.println(sum);
			x=br.readLine();
		}
	}

}



Measured memory_bytes: 25024
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 33003;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
using namespace std;
ll arr[N];
ll dp[100][100][50*50+10];
int main() {
ll n,a;
cin>>n>>a;
rep(i,0,n)
cin>>arr[i];
dp[1][1][arr[0]]=1;
dp[1][0][0]=1;
rep(i,2,n+1)
rep(j,0,n+1)
rep(k,0,50*50+2)
{
	if(j==0||k<arr[i-1])
	dp[i][j][k]=dp[i-1][j][k];
	else
	dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-arr[i-1]];
}
ll ans=0;
rep(i,0,n+1)
ans+=dp[n][i][a*i];
cout<<ans-1;
}


Measured memory_bytes: 98560
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N; cin >> N;
	
	bool ok = false;
	for (int c = 0; c <= N/4; ++c){
		int remain = N - 4 * c;
		if (remain % 7 == 0){
			ok |= true;
		} // end if
	} // end for

	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
    int x,y,z;
    int num=0;
    cin>>x>>y>>z;
    int held=z;
    while(held<=x){
        held+=(y+z);
        num+=1;
    }
    if(held>x)num-=1;
    cout<<num<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,M,A[10001];
	scan(N>>M);
	int sum=0;
	rep(i,M){
		scan(A[i]);
		sum+=A[i];
	}
	if(sum>N) prin(-1);
	else prin(N-sum);
	return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define INF 1LL<<62
#define inf 1000000007 

int main() {
	ld w,h,x,y;
	cin>>w>>h>>x>>y;
	printf("%.10Lf\n",w*h/2.0);
	if(x==w/2&&y==h/2){
		cout << " 1";
	}
	else{
		cout << " 0";
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
V_C = [V[i]-C[i] for i in range(N)]
ans = 0
for i in range(N):
    if V_C[i]>0:
        ans += V_C[i]
print(ans)

Measured memory_bytes: 3064
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 
vector<int> P,Q;

int main(){

    int N;
    
    cin >> N;
    int A;

    for( int ni = 0 ; ni <N ; ni++ ){
        cin >> A;
        P.push_back(A);
        Q.push_back(A);
    }
    sort(Q.begin(),Q.end());

    int cnt=0;
    for( int ni = 0 ; ni <N ; ni++ ){
        if(P[ni]!=Q[ni]){
            cnt++;
        }
    }
    //cout << cnt << endl;
    if(cnt<=2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 256
def isPrime(x):
  for i in range(2,int(x**0.5)+1):
    if x%i==0:
      return False
  return True

q=int(input())
f=[1]*(10**5+1)
f[0],f[1]=0,0
n=len(f)
for i in range(2,n):
  if isPrime(i):
    for j in range(i*2,n,i):
      f[j]=0

c=[0]*(10**5+1)
for i in range(2,10**5+1):
  if i%2==1:
    if f[i]==1 and f[(i+1)//2]==1:
      c[i]=c[i-1]+1
      continue
    c[i]=c[i-1]
  else:
    c[i]=c[i-1]
for i in range(q) :
   l,r=map(int,input().split())
   print(c[r]-c[l-1])

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

int main(){
	int n;
	while (cin >> n){
		int j[65000];
		unsigned long int s = 0;
		if (n == 0){
			break;
		}
		for (int i = 0; i < n; i++){
			int p;
			cin >> p;
			s += p;
		}
		for (int i = 0; i < n - 1; i++){
			cin >> j[i];
			s += j[i];
		}
		sort(j, j + n - 1);
		unsigned long int cost = s;
		int i = 0;
		while (cost < (s - j[i])*(2 + i) && i < n - 1 ){
			s -= j[i];
			cost = s*(2 + i);
			i++;
		}
		cout << cost << endl;
	}
	return 0;
}


Measured memory_bytes: 1424
require "numo/narray"

class Animal
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize(n)
    @n = n
    @d = Array.new(3){ [nil] * n }
  end

  def [](i); d[i]; end

  def dot(y,x,v)
    return false if d[y][x] && d[y][x] != v
    d[y][x] = v
    true
  end

  def line(y,x,v)
    3.times do |i|
      return false unless dot(i, (x-y+i)%n, v)
    end
    true
  end
end

class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @n = gets.to_s.to_i
    @s = gets.chomp.tr("xo","10").chars.map(&:to_i)
  end

  def each_animals
    [0, 1].repeated_permutation(3) do |i,j,k|
      next if s[0] != [i,j,k].inject(:^)
      a = Animal.new(n)
      a.line(0,0,i) or next
      a.line(1,0,j) or next
      a.line(2,0,k) or next
      yield a
    end
  end

  def valid?(a)
    1.upto(n-1).all? do |x|
      v = a[1][x] ^ a[2][x] ^ s[x]
      a.line(0,x,v)
    end
  end

  def solve
    each_animals do |a|
      valid?(a) and return a[1]
    end
    return -1
  end

  def show(ans)
    puts ans == -1 ? -1 : ans.join.tr("10", "WS")
  end
end

Problem.new.instance_eval do
  show(solve)
end


Measured memory_bytes: 32792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  vector<vector<int>> to(N);
  for(int i = 0; i < N-1; i++){
    int a,b; cin >> a >> b; a--; b--;
    to[a].push_back(b); to[b].push_back(a);}
  // フェネックが0,すぬけがN-1番ノードから出発する
  // 回路は木だから、フェネック←→すぬけの間の経路は一通りしかない
  //最適戦略は、上の経路上を両者とも塗り続けること
  vector<int> visited1(N,-1);
  vector<int> visited2(N,-1);
  
  queue<int> Q; Q.push(0); visited1[0] = 0;
  while(!Q.empty()){
    int p = Q.front(); Q.pop();
    for(int i = 0; i < to[p].size(); i++){
      int q = to[p][i];
      if( visited1[q] != -1){ continue;}
      visited1[q] = visited1[p] + 1; Q.push(q);
    }}
  
  Q.push(N-1); visited2[N-1] = 0;
  while(!Q.empty()){
    int p = Q.front(); Q.pop();
    for(int i = 0; i < to[p].size(); i++){
      int q = to[p][i];
      if(visited2[q] != -1){ continue;}
      visited2[q] = visited2[p]+1; Q.push(q);
    }}
   int fennec = 0; int snuke = 0;
  for(int i = 0; i < N; i++){
    if( visited1[i] < visited2[i]){ fennec++;}
    if( visited1[i] > visited2[i]){ snuke++;}
    if( visited1[i] == visited2[i]){ fennec++;}
  }
  if( fennec > snuke){ cout << "Fennec" << endl;}
  if( snuke > fennec){ cout << "Snuke" << endl;}
  if( snuke == fennec){ cout << "Snuke" << endl;}
  return 0;}
 
  

Measured memory_bytes: 6528
from collections import deque

K = int(input())
d = [-1] * K
Q = [0] * (K + 1)
p = 0 # Qの先頭（次に取り出す場所）
q = 0 # Qの末尾（次に入れる場所）
d[1] = 1
Q[q] = 1
q += 1

while q - p > 0:
    # 距離0の探索
    sp = p
    ep = q
    while ep - sp > 0:
        for i in range(sp, ep):
            x = Q[i]
            y = 10 * x % K
            if d[y] < 0:
                d[y] = d[x]
                Q[q] = y
                q += 1
        sp, ep = ep, q
    # 距離1の探索
    for i in range(p, q):
        x = Q[i]
        p += 1
        y = (x + 1) % K
        if d[y] < 0:
            d[y] = d[x] + 1
            Q[q] = y
            q += 1

print(d[0])


Measured memory_bytes: 8052
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>
 
#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cerr << v[a][b] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;
 
int main()
{
	int n,tme = 0;
	double ans = 0;
	
	cin >> n;
	
	vector<int> t(n);
	vector<int> v(n+1);
	
	REP(i,n)
	{
		cin >> t[i];
		tme += t[i];
	}
	REP(i,n)
	{
		cin >> v[i];
	}
	v[n] = 0;
	
	
	double nowv = 0,nowt = 0;
	
	while(nowt < tme)
	{
		double tmp = 0;
		int flag = 0,cou = 0;
		REP(i,n)
		{
			tmp += t[i];
			if(nowt >= tmp)
			{
				cou++;
				continue;
			}
			
			double han = tmp - nowt - (nowv - v[i+1]);
			if(han >= 1)continue;
			else if(han >= 0.5)
			{
				flag = 1;
				continue;
			}
			else
			{
				flag = 2;
				break;
			}
		}
		
		if(flag == 0 && v[cou] > nowv)
		{
			ans += (nowv*2 + 0.5) * 0.25;
			nowv += 0.5;
		}
		else if(flag == 2)
		{
			ans += (nowv*2 - 0.5) * 0.25;
			nowv -= 0.5;
		}
		else
		{			
			ans += nowv * 0.5;
		}
		
		nowt += 0.5;
		//printf("%5f %5f\n",nowv,ans);
	}
	
	printf("%.6f\n",ans);
	
	return 0;
}

Measured memory_bytes: 384
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k>max(a):
  print("IMPOSSIBLE")
  exit(0)

from fractions import gcd
gcd_v=a[0]
for i in range(1,n):
  gcd_v=gcd(a[i],gcd_v)
for aa in a:
  if (aa-k)%gcd_v==0:
    print("POSSIBLE")
    exit(0)
print("IMPOSSIBLE")




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

using namespace std;
int main()
{
    while(true){
        int i;
        long long N = 0;
        cin >> i;
        
        if( i == 0 )
            break;
        
        vector<int> a(i);
        
        for(int j = 0 ; j < i ; j++)
            cin >> a[j];
        
        sort( a.begin(), a.end() );
        
        for(int j = 0 ; j < i ; j++)
            N = N + a[j] * (i-j-1);
        
        
        cout << N <<endl;
    }
}

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


int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b;
    cin>>a>>b;
    if (a <= 1){
        cout<<a<<"\n";
        return 0;
    }
    if (b == 1) {
        cout<<"0\n";
        return 0;
    }
    int number_of_sockets = 0;
    int ans = 0;
    while (true) {
        number_of_sockets += a;
        ans++;
        if (number_of_sockets >= b) {
            cout<<ans<<"\n";
            return 0;
        }
        number_of_sockets--;
    }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

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

    map<ll,ll> m;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        m[a[i]]++;
    }

    ll sum=0;
    for(auto e : m){
        sum+=e.second*(e.second-1)/2;
    }
    //cout<<sum<<endl;
    rep(i,n){
        ll x=m[a[i]];
        ll tmp=x*(x-1)/2-(x-1)*(x-2)/2;
        cout<<sum-tmp<<endl;
    }
}

Measured memory_bytes: 12732
#include <iostream>
#include <string>
using namespace std;
string s,t;
string b="~";
bool isSame(string a1,string a2)
{
	for(int i=0;i<a1.size();i++)
		if (a1[i]!='?'&&a1[i]!=a2[i])
			return false;
	return true;
} 
int main()
{
	cin>>s>>t;
	for(int i=0;i<=(int)s.size()-(int)t.size();i++)
	{
		string u=s.substr(i,t.size());
		if (isSame(u,t))
		{
			string v=s;
			for(int j=i;j<i+t.size();j++)
				v[j]=t[j-i];
			for(int j=0;j<i;j++)
				if(v[j]=='?')
					v[j]='a';
			for(int j=i+t.size();j<v.size();j++)
				if(v[j]=='?')
					v[j]='a';
			b=min(b,v);
		}
	}
	if (b=="~")
		cout<<"UNRESTORABLE";
	else
		cout<<b;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    try {
      boolean ans = true;
      String pre = "";
      HashMap<String, Integer> map = new HashMap<String, Integer>();
      int n = sc.nextInt();
      for (int i = 0; i < n; i++) {
        String s = sc.next();
        if (i > 0 && s.charAt(0) != pre.charAt(pre.length()-1)) {
          ans = false;
        }
        if (map.containsKey(s)) ans = false;
        map.put(s, 1);
        pre = s;

      }
      System.out.println(ans ? "Yes" : "No"); 
    } finally {
      sc.close();
    }
  }
}


Measured memory_bytes: 35804
import java.util.*;
import java.io.*;
 
public class Main{
    public static void main(String[] args){
        Main m = new Main();
        m.input();

    }
 
    
    public void input(){
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        long a = sc.nextLong();
        long b = sc.nextLong();
        long c = sc.nextLong();
        int x = sc.nextInt();
        int y = sc.nextInt();
        sc.close();
        int min = Math.min(x,y);
        
        if(a + b >= c * 2){
            ans += (c * 2) * min;
        }else{
            ans += (a + b) * min;
        }
        if(x > y){ //aピザ余り
            ans += Math.min(a,c * 2) * (x - y);
        }else if(x < y){
            ans += Math.min(b,c * 2) * (y - x);
        }
        System.out.println(ans);
    }

}

Measured memory_bytes: 23636
// luogu-judger-enable-o2
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if((a+b)%2==0)
    cout<<(a+b)/2;
    else
    cout<<(a+b)/2+1;
    cout<<endl;
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, n; cin >> h >> n;
	vector<int> a(n), b(n);
	for(int i=0; i<n; ++i) cin >> a[i] >> b[i];
	vector<int> dp(1e5, 1e9);
	dp[0] = 0;
	for(int i=0; i<=h; ++i)
		for(int j=0; j<n; ++j)
			dp[i+a[j]] = min(dp[i+a[j]], dp[i]+b[j]);
	int ans = dp[h];
	for(size_t i=h; i<dp.size(); ++i)
		ans = min(ans, dp[i]);
	cout << ans << "\n";
}

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

int main() {
  int h,w;
  cin>>h>>w;
  string s[h];
  for (int i=0;i<h;i++) cin>>s[i];
  int dx[4]={1,0,-1,0};
  int dy[4]={0,1,0,-1};
  bool can=true;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if (s[i][j]=='.') continue;
      int num=0;
      for(int d=0;d<4;d++){
        int ni=i+dx[d];
        int nj=j+dy[d];

        if(ni<0 || h<=ni) continue;
        if(nj<0 || w<=nj) continue;
        if(s[ni][nj]=='#') num++;
      }
      if(num==0) {
        can=false;
        break;
      }
    }
    if(!can) break;
  }
  if(can) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
honsuu = [0,2,5,5,4,5,6,3,7,6]
aval = []
for a in A:
  aval += [honsuu[a]]
aval.sort()

dp = [0]+ [-float("INF")]*N 
# i 本のマッチで作れる最高の桁数
for i in range(1,N+1):
  for b in aval:
    if i < b:
      continue
    elif dp[i-b] >= 0:
      dp[i] = dp[i-b] + 1
      break
      
#作れる桁数はdp[-1]=dp[N] で, 最高桁にi が使えるかどうかの条件は, 
#a in A かつ dp[N- honsuu[a]] = dp[N] -1
A.sort(reverse=True)
ans = []
for i in range(dp[N],1,-1):
  for a in A:
    if N - honsuu[a] < 0:continue
    if dp[N - honsuu[a]] == dp[N] - 1:
      N -= honsuu[a]
      ans += [a]
      break
      
final = 0
for i in range(10):
  if i in A and honsuu[i] == N:
    final = i
ans += [final]
print(''.join(map(str, ans)))

Measured memory_bytes: 3700
#include<stdio.h>
#include<math.h>

typedef struct
{
  double x;
  double y;
}co;

void koch(int num,co p1,co p2)
{
  if(num==0) return;
  co n,m,o;
  double angle=M_PI*60.0/180.0;

  n.x=(2.0*p1.x+1.0*p2.x)/3.0;
  n.y=(2.0*p1.y+1.0*p2.y)/3.0;
  m.x=(1.0*p1.x+2.0*p2.x)/3.0;
  m.y=(1.0*p1.y+2.0*p2.y)/3.0;
  o.x=(m.x-n.x)*cos(angle)-(m.y-n.y)*sin(angle)+n.x;
  o.y=(m.x-n.x)*sin(angle)+(m.y-n.y)*cos(angle)+n.y;

  koch(num-1,p1,n);
  printf("%.8f %.8f\n",n.x,n.y);
  koch(num-1,n,o);
  printf("%.8f %.8f\n",o.x,o.y);
  koch(num-1,o,m);
  printf("%.8f %.8f\n",m.x,m.y);
  koch(num-1,m,p2);
}

int main()
{
  co p1,p2;
  int n;
  scanf("%d",&n);
  p1.x=0;
  p1.y=0;
  p2.x=100;
  p2.y=0;

  printf("%.8f %.8f\n",p1.x,p1.y);
  koch(n,p1,p2);
  printf("%.8f %.8f\n",p2.x,p2.y);
  return 0;
}

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

using ll = long long;

int main() {
    int N;  cin >> N;
    map<string, ll> mp;
    for (int i = 0; i < N; ++i) {
        string s;  cin >> s;
        sort(s.begin(), s.end());
        ++mp[s];
    }
    ll ans = 0;
    for (auto e : mp) {
        ans += e.second * (e.second - 1) / 2;
    }
    cout << ans << endl;
}


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

a_list = []
b_list = []
c_list = []
for i in range(N):
    a, b, c = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
    c_list.append(c)

dp = [[0]*3 for i in range(N)]
dp[0][0] = a_list[0]
dp[0][1] = b_list[0]
dp[0][2] = c_list[0]

for i in range(1,N):
    dp[i][0] = max(dp[i-1][1]+a_list[i], dp[i-1][2]+a_list[i])
    dp[i][1] = max(dp[i-1][0]+b_list[i], dp[i-1][2]+b_list[i])
    dp[i][2] = max(dp[i-1][0]+c_list[i], dp[i-1][1]+c_list[i])

ans = max(dp[N-1])
print(ans)

Measured memory_bytes: 106048
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <unordered_map>
//#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007

int main() {
    int n;
    int r;
    int ans;

    cin >> n >> r;
    if(n>=10){
        ans=r;
    }else{
        ans=r+100*(10-n);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define M 1000000007
using namespace std;
signed main()
{
	fast
	int n,x,t;
	cin>>n>>x>>t;
	int ans=ceil((float)n/x);
	cout<<ans*t<<endl;
}

Measured memory_bytes: 3660
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	TreeSet<String> set;

	void catAndAdd(String a, String b) {
		String s = "" + a + b;
		set.add(s);
	}

	void run() {
		Scanner sc = new Scanner(System.in);

		for (int T = sc.nextInt() - 1; 0 <= T; T--) {
			StringBuilder s = new StringBuilder(sc.next());

			set = new TreeSet<String>();
			for (int i = 1; i < s.length(); i++) {
				String a = s.substring(0, i);
				String aRev = new StringBuilder(a).reverse().toString();
				String b = s.substring(i, s.length());
				String bRev = new StringBuilder(b).reverse().toString();

				catAndAdd(a, b);
				catAndAdd(aRev, b);
				catAndAdd(a, bRev);

				catAndAdd(b, a);
				catAndAdd(bRev, a);
				catAndAdd(b, aRev);
				
				catAndAdd(aRev, bRev);
			}

			System.out.println(set.size());
		}
	}

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

Measured memory_bytes: 56592
package main

import (
  "fmt"
  "strings"
)

func main() {
  var h, w int 
  fmt.Scan(&h, &w)
  board := make([]string, h + 2)
  board[0] = strings.Repeat("#", w + 2)
  board[h+1] = strings.Repeat("#", w + 2)
  for i := 1; i < h + 1; i++ {
    var s string 
    fmt.Scan(&s)
    board[i] = "#" + s + "#"
  }
  for _, s := range board {
    fmt.Println(s)
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <numeric>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
    
ll a[200010];
ll dp[200010][5];
int main(){
    int n;
    cin >> n;
    rep(i,n)cin >> a[i+1];
    for(int i=1;i<=n;i++){
        dp[i][0] = dp[i-1][0]+ a[i];
        if(a[i]==0) dp[i][1] = min(dp[i-1][0]+2,dp[i-1][1]+2);
        else dp[i][1] = min(dp[i-1][0]+a[i]%2,dp[i-1][1]+a[i]%2);
        dp[i][2] =  min({dp[i-1][2]+(a[i]+1)%2,dp[i-1][1]+(a[i]+1)%2,dp[i-1][0]+(a[i]+1)%2});
        if(a[i]==0) dp[i][3] = min({dp[i-1][3]+2,dp[i-1][2]+2,dp[i-1][1]+2,dp[i-1][0]+2});
        else dp[i][3] = min({dp[i-1][3]+a[i]%2,dp[i-1][2]+a[i]%2,dp[i-1][1]+a[i]%2,dp[i-1][0]+a[i]%2});
        dp[i][4] = min({dp[i-1][4]+a[i],dp[i-1][3]+a[i],dp[i-1][2]+a[i],dp[i-1][1]+a[i],dp[i-1][0]+a[i]});
    }
    cout << min({dp[n][0],dp[n][1],dp[n][2],dp[n][3],dp[n][4]}) << endl;
    return 0;
}

Measured memory_bytes: 9600
#include<stdio.h>

#define MAX 100005
#define NIL -1

struct Node{
  int p;
  int l;
  int r;
};

struct Node N[MAX];

int n, H, D[MAX];

int getDepth(int u){
  int d = 0;
  
  while(N[u].p >= 0){
    u = N[u].p;
    d++;
  }
  
  return d;
}

void printTree(int u){
  int t;

  if(N[u].p == NIL) printf("node %d: parent = %d, depth = %d, root, ", u, N[u].p, D[u]);
  
  else if(N[u].l == NIL) printf("node %d: parent = %d, depth = %d, leaf, ", u, N[u].p, D[u]);
  
  else printf("node %d: parent = %d, depth = %d, internal node, ", u, N[u].p, D[u]);
    
  printf("[");

  t = u;

  if(N[t].l != NIL){
    printf("%d", N[t].l);

    if(N[N[t].l].r == NIL) printf("]\n");

    else printf(",");

    t = N[t].l;

    while(N[t].r != NIL){
      printf(" %d",N[t].r);
      
      if(N[N[t].r].r == NIL) printf("]\n");

      else printf(",");

      t = N[t].r;
    }
  }
  
  else printf("]\n");
}

int main(){
  int i, j, d, v, c, l, r;
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++){
    N[i].p = N[i].l = N[i].r = NIL;
  }
  
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);

    for(j = 0; j < d; j++){
      scanf("%d", &c);

      N[c].p = v;
      
      if(j == 0) N[v].l = c;
      
      else if (j >= 1) N[r].r = c;
      r = c;
    }
  }
  
  for(i = 0; i < n; i++) D[i] = getDepth(i);
  
  for(i = 0; i < n; i++) printTree(i);
  return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	ll n;
	vector<ll> a(5);
	cin>>n>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
	
	cout<<4+ll(ceil(n*1.0/(*min_element(a.begin(),a.end()))))<<endl;
}

Measured memory_bytes: 256
s = input()[::-1]
l = ["resare","esare","remaerd","maerd"]
i = 0

while not i == len(s):
    for a in l:
        if s[i:i+len(a)] == a:
            i += len(a)
            break
    else:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 40688
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using IP = pair<int, int>;


#define INF 999999999
#define atcoder(int)1e9+7
#define Endl endl
#define all(v) (v.begin(),v.end())
#define pb(a) push_back(a)

int main() {

	string s;

	cin >> s;

	for (int i = 0; i < s.length() - 1; i++) {
		if (s[i] == 'A' && s[i + 1] == 'C') {
			cout << "Yes" << Endl;
			return 0;
		}
	}
	cout << "No" << Endl;

	return 0;
}

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

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a.at(i);
	int ma = 1000000000;
	rep(i, n-k+1){
		if(a.at(i+k-1) <= 0){
			if(ma > -a.at(i)) ma = -a.at(i);
		}else if(a.at(i) >= 0){
			if(ma > a.at(i+k-1)) ma = a.at(i+k-1);
		}else{
			if(ma > a.at(i+k-1)*2 - a.at(i)) ma = a.at(i+k-1)*2 - a.at(i);
			if(ma > a.at(i+k-1) - a.at(i)*2) ma = a.at(i+k-1) - a.at(i)*2;
		}
//	cout << i+k-1 << endl;
	}
	cout << ma << endl;
	return 0;
}

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


Measured memory_bytes: 2136
/*
	written by Pankaj Kumar.
	country:-INDIA
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<pair<ll,ll>> vpl;
typedef vector<string> vs;
typedef map<ll,ll> ml;
typedef set<char>sc;
typedef set<ll> sl;
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
// define values.
#define mod 1000000007
#define phi 1.618
/* Bit-Stuff */
#define get_set_bits(a) (__builtin_popcount(a))
#define get_set_bitsll(a) ( __builtin_popcountll(a))
#define get_trail_zero(a) (__builtin_ctz(a))
#define get_lead_zero(a) (__builtin_clz(a))
#define get_parity(a) (__builtin_parity(a))
/*  Abbrevations  */
#define ff first
#define ss second
#define mp make_pair
#define line cout<<endl;
#define pb push_back
#define Endl "\n"
// loops
#define forin(arr,n) for(ll i=0;i<n;i++) cin>>arr[i];
// Some print
#define no cout<<"NO"<<endl;
#define yes cout<<"YES"<<endl;
#define cc ll test;cin>>test;while(test--)
// sort
#define all(V) (V).begin(),(V).end()
#define srt(V) sort(all(V))
#define srtGreat(V) sort(all(V),greater<ll>())
// function

ll power(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y%2==1)res*=x;
		y/=2; x*=x;
	}
	return res;
}
/* ascii value 
A=65,Z=90,a=97,z=122
*/
/*  -----------------------------------------------------------------------------------*/

ll solve()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max({(a*d),(a*c),(b*c),(b*d)})<<endl;
	return 0;
}

int main()
{
	//freopen("input.txt"a, "r", stdin);
	pan;
	solve();
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

//! [高さHまで見た時に][左からi番目にたどり着くような]=あみだくじの本数
ll dp[105][10];

int H, W, K;
ll S[30];
//! lからrに横線を引く場合の数
ll get(int l, int r)
{
    if (l > r || l < 0 || r >= W)
        return 1;
    return S[r - l];
}

int main()
{
    cin >> H >> W >> K;
    S[0] = 1;
    S[1] = 2;
    FOR(i, 30, 2)
    {
        S[i] = S[i - 1] + S[i - 2];
    }
    REP(i, 105)
    {
        REP(j, 10)
        {
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    REP(i, H)
    {
        REP(j, W)
        {
            //! 左からくる
            if (j > 0)
            {
                ll t = dp[i][j - 1] * get(0, j - 2) * get(j + 1, W - 1);
                dp[i + 1][j] += t % MOD;
                dp[i + 1][j] %= MOD;
            }
            //! そのまま降りる
            {
                ll t = dp[i][j] * get(0, j - 1) * get(j + 1, W - 1);
                dp[i + 1][j] += t % MOD;
                dp[i + 1][j] %= MOD;
            }
            //! 右からくる
            if (j < W - 1)
            {
                ll t = dp[i][j + 1] * get(0, j - 1) * get(j + 2, W - 1);
                dp[i + 1][j] += t % MOD;
                dp[i + 1][j] %= MOD;
            }
        }
    }
    cout << dp[H][K - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
import math

a, b, x = map(int, input().split())
if(x <= a*a*b*0.5):
    t = math.atan(0.5*a*b*b/x)
else:
    t = math.atan(2*(a*a*b-x)/(a*a*a))
print(math.degrees(t))

Measured memory_bytes: 3060
import java.util.Scanner

object Main{
  val sc = new Scanner(System.in)

  def main(srgs: Array[String]):Unit ={

    val a = List.fill(6)(sc.nextInt)

    val t =
      a.foldLeft((0,0,0,0)) { (tuple, acc) =>
        acc match {
          case 1 => (tuple._1 + 1, tuple._2, tuple._3, tuple._4)
          case 2 => (tuple._1, tuple._2 + 1, tuple._3, tuple._4)
          case 3 => (tuple._1, tuple._2, tuple._3 + 1, tuple._4)
          case 4 => (tuple._1, tuple._2, tuple._3, tuple._4 + 1)
        }
    }

    val res = t._1 * t._2 * t._3 * t._4
    println( if( res == 4) "YES" else "NO")

 }
}

Measured memory_bytes: 25552
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

struct dat{
	ll a,b,c;
};

int main(){
	ll x,y,z; cin >> x >> y >> z;
	ll n = x+y+z;
	vector<dat> v(n);
	rep(i,n) cin >> v[i].a >> v[i].b >> v[i].c;
	sort(all(v), [](dat s, dat t){return s.b - s.c > t.b - t.c;});
	vl ansxy(n,0), ansxz(n+1,0);
	priority_queue<ll,vector<ll>,greater<ll>> pqy, pqz;
	rep(i,y){
		pqy.push(v[i].b - v[i].a);
		ansxy[i+1] = ansxy[i] + v[i].b;
	}
	for(int i=y; i<x+y; i++){
		if(pqy.top() > v[i].b - v[i].a) ansxy[i+1] = ansxy[i] + v[i].a;
		else{
			ansxy[i+1] = ansxy[i] + v[i].b - pqy.top();
			pqy.pop();
			pqy.push(v[i].b - v[i].a);
		}
	}
	for(int i=n-1; i>=x+y; i--){
		pqz.push(v[i].c - v[i].a);
		ansxz[i] = ansxz[i+1] + v[i].c;
	}
	for(int i=x+y-1; i>=y; i--){
		if(pqz.top() > v[i].c - v[i].a) ansxz[i] = ansxz[i+1] + v[i].a;
		else{
			ansxz[i] = ansxz[i+1] + v[i].c - pqz.top();
			pqz.pop();
			pqz.push(v[i].c - v[i].a);
		}
	}
	ll ans = 0;
	for(int i=y; i<=x+y; i++){
		chmax(ans, ansxy[i] + ansxz[i]);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 8236
N = int(input())
ans = []

if N == 1:
    print(1)
    exit()

for num in range(2, N + 1, 2): # N^2/2
    current = 0
    while True:
        if num % 2 == 0:
            current += 1
            num /= 2
        else:
            break
    ans.append(current)

print((ans.index(max(ans)) + 1) * 2)


Measured memory_bytes: 2940
while 1:
    a = input()
    if a == "-":
        break
    b = int(input())
    for i in range(b):
        c = int(input())
        a = a[c:] + a[:c]
    print(a)
#word = "ABCDE"
#print(word[2:]) ## => CDE
#print(word[:3]) ## => ABC


Measured memory_bytes: 5596
#!/usr/bin/python3

import os
import sys


def main():
    N = read_int()
    S = inp()
    print(solve(N, S))


def solve(N, S):
    D = set()
    D.add('')
    R = set()

    for ch in S:
        for d in list(D):
            if len(d) == 2:
                R.add(d + ch)
            else:
                D.add(d + ch)
    return len(R)


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

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41580
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
 
using namespace std;

int arr [200000];
long long arr2 [200000];
long long arr3[200000];
long long cul(int c, int b){
	
	if(c==0)return arr[0];
	if(c==1)return max(arr[0],arr[1]);
	if(c==2)return max(max(arr[0],arr[1]),arr[2]);
	if(c%2!=0)return arr3[c];
	return max(max(arr3[c-1],arr2[c-2]),arr[c]+cul(c-2,b));
	
}
	
	
	
int main()
{ 
	for(int i=0;i<200000;i++){arr[i]=0;arr2[i]=0;}
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>arr[i];
	arr2[0]=arr[0];
	for(int i=2;i<n;i=i+2)arr2[i]=arr2[i-2]+arr[i];
	arr3[1]=max(arr[0],arr[1]);
	for(int i=3;i<n;i=i+2)arr3[i]=max(arr3[i-2]+arr[i],arr2[i-1]);
	cout<<cul(n-1,n)<<endl;
	return 0;
}
	

Measured memory_bytes: 10656
#include<stdio.h>

#define N 500

double p[N+1], q[N+1];
double r[N+2][N+2], s[N+2][N+2];
double t[N+1][N+1];

int main(void){
    int n;
    scanf("%d", &n);
    for(int i=1; i<=n; ++i){
        scanf("%lf", &p[i]);
    }
    for(int i=0; i<=n; ++i){
        scanf("%lf", &q[i]);
    }
    for(int i=1; i!=n+2; ++i){
        s[i][i-1]=q[i-1];
        r[i][i-1]=q[i-1];
    }
    for(int l=1; l<=n; ++l){
        for(int i=1; i<=n-l+1; ++i){
            int j=i+l-1;
            s[i][j]=(1<<21);
            r[i][j]=r[i][j-1]+p[j]+q[j];
            for(int k=i; k<=j; ++k){
                double u = s[i][k-1]+s[k+1][j]+r[i][j];
                if(u < s[i][j]){
                    s[i][j]=u;
                    t[i][j]=k;
                }
            }

        }
    }
    printf("%f\n", s[1][n]);
    return 0;
}



Measured memory_bytes: 7760