akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    ll ans = 0;
    ans += n*(n-1)/2;
    ans += m*(m-1)/2;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
from collections import deque
N = int(input())
a = list(map(int, input().split()))

q = deque()

for i in range(N):
  if i % 2:
    q.append(a[i])
  else:
    q.appendleft(a[i])

print(*list(q) if N % 2 else reversed(list(q)))

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(),a.end());
	cout << a[2]*10+a[0]+a[1] << endl;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++) 
using LL = long long;

const LL MOD = 1e9+7;
 
int N;
int A[114514];
int T[114514];
int L[114514];
int R[114514];

int main() {
  scanf("%d", &N);
  rep(i, N) {
    scanf("%d", &T[i+1]);
  }
  rep(i, N) {
    scanf("%d", &A[i+1]);
  }
  rep(i, N) {
    if (T[i] < T[i+1]) {
      R[i+1] = L[i+1] = T[i+1];
    } else {
      L[i+1] = 1;
      R[i+1] = T[i+1];
    }
  }
  LL ans = 1;
  rep(i, N) {
    int j=i+1;
    if (A[j] > A[j+1]) {
      L[j] = max(L[j], A[j]);
      R[j] = min(R[j], A[j]);
    } else {
      L[j] = max(L[j], 1);
      R[j] = min(R[j], A[j]);
    }
    
    if (L[j] > R[j]) {
      puts("0");
      return 0;
    }
    (ans *= LL(R[j]-L[j]+1)) %= MOD;
  }
  printf("%lld\n", ans);
}
      
    
    


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


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

  int ans = 1;

  for(int i=0; i<N; i++){
    if(ans > K){
      ans += K;
    }
    else{
      ans *= 2;
    }
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n;	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int sml = a[0], rng = 2 * sml, s = 1;
	if (sml==a[1]) {
		rng--;
		s++;
		if (sml == a[2]) {
			cout << "Impossible" << endl;
			return 0;
		}
	}
	int cnt = 0, val = 0;
	while (s < a.size()) {
		cnt = 1;	val = a[s];
		if (val != a[s - 1]+1) {
			cout << "Impossible" << endl;
			return 0;
		}
		s++;
		while (s < a.size() && val == a[s]) {
			cnt++;	s++;
		}
		if (cnt < 2) {
			cout << "Impossible" << endl;
			return 0;
		}
	}
	if (a[n - 1] != rng) {
		cout << "Impossible" << endl;
		return 0;
	}
	cout << "Possible" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int K = sc.nextInt();
        char[][] c = new char[H][W];
        for (int i=0; i<H; i++){
            c[i] = sc.next().toCharArray();
        }
        
        int ans=0;
        
        for(int h=0; h<(1<<H); h++){
            for(int w=0; w<(1<<W); w++){
                int black = 0;
                
                for(int x=0; x<W; x++){
                    for(int y=0; y<H; y++){
                        if(c[y][x]=='#' && ((1 & h>>y)==0 && (1 & w>>x)==0)){
                            black++;
                        }
                    }
                }

                if(K==black){
                    ans++;
                }
            }
        }

        System.out.println(ans);
    }

}

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

typedef std::vector<int> vi;

int main()
{
	int n, m, x, y;
	cin>>n>>m>>x>>y;

	vi ax(n); vi ay(m);

	int mx = INT_MIN, my = INT_MAX;

	for(int i=0; i<n; i++)
	{
		cin>>ax[i];
		mx = max(mx, ax[i]);
	}
		
	for(int i=0; i<m; i++)
	{
		cin>>ay[i];
		my = min(my, ay[i]);
	}	

	if(x<y && mx<my && x<my && mx<y)
		cout<<"No War";
	else
		cout<<"War";
	return 0;

}

Measured memory_bytes: 256
def calcA(S):
    Num=0
    for i in range (1,len(S)):
        A = int("".join(S[:i]))
        lenB=len(S[i:])
        Num += A*(2**(lenB-1))+calcA(S[i:])
    
    Num += int("".join(S))
    return Num


N = list(input())
print(calcA(N))


Measured memory_bytes: 3060
require 'prime'

#約数一覧
def divisors(n)
  n.prime_division.inject([1]) do |ary, (p, e)|
    (0..e).map{ |e1| p ** e1 }.product(ary).map{ |a, b| a * b }
  end.sort
end

def calc(n, a)
  while n % a == 0 do n /= a end
  n %= a if n > a
  n
end

N = gets.to_i

ans = []
divisors(N).each{|n|
  next if n == 1
  ans << n if calc(N, n) == 1
}
divisors(N-1).each{|n|
  next if n == 1
  ans << n if calc(N, n) == 1
}

puts ans.uniq.size


Measured memory_bytes: 14604
#include <iostream>
#include <sstream>
//#include <fstream>

using namespace std;

string itos (int n )
{
	stringstream ss;
	ss << n;

	return ss.str();
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.yesnumber", "r", stdin );
	string str = "";
	
	while (getline (cin, str ) ){
		string res = "";
		if (str == "END OF INPUT" ){
			break;
		} // end if
		int len = str.length();
		str += '_';
		int count = 0;

		for (int i = 0; i < len; ++i){
			if (str[i] != ' ' && str[i+1] != ' ' ){
				++count;
			}else if (str[i] != ' ' && str[i+1] == ' '){
				++count;
				res += itos(count);
				count = 0;
			}else if (str[i] == ' ' && str[i+1] == ' '){
				res += itos (0);
				count = 0;
			} // end if
		} // end for
		if (count != 0 ){
			res += itos (count);
		} // end if

		cout << res << endl;	
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>

int main(void){
	char S[256]={0};
	int min=1000;
	int X,i,sa;
	
	scanf("%s",S);
	//printf("%d\n",strlen(S));
	for(i=0;i<=strlen(S)-3;++i){
		X=(S[i]-'0')*100+(S[i+1]-'0')*10+(S[i+2]-'0')*1;
		//printf("%d\n",X);
		if(X>=753){ 
		sa=X-753;
		}else	sa=753-X;
		if(sa<min) min=sa; 
	}
	
	printf("%d\n",min);	
	return 0;	
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#define PI 3.141592653589793238462643383279


void change(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}
int compare_int(const void *a, const void *b){
	return *(int*)a - *(int*)b;
}

int gcd(int a, int b)
{
    int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}
int main(void){
	
	char s[5];
	int flag=0;	//0:NA, 1:MY, 2:YM, 3:AMB
	
	scanf("%s", &s );
	int k=0;
	if(s[k]=='0'){
		if(s[k+1]!='0')	flag++;
	}else if(s[k]=='1'){
		if(s[k+1]=='0' || s[k+1]=='1' || s[k+1]=='2')	flag++;
	}
	k+=2;
	if(s[k]=='0'){
		if(s[k+1]!='0')	flag+=2;
	}else if(s[k]=='1'){
		if(s[k+1]=='0' || s[k+1]=='1' || s[k+1]=='2')	flag+=2;
	}
		
	switch(flag){
	case 0:	printf("NA");break;
	case 1:	printf("MMYY");break;
	case 2:	printf("YYMM");break;
	case 3:	printf("AMBIGUOUS");break;
	}
	
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y,ll z){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2,z);
        ll w=(p*p)%z;
        if(y%2==0)
         return w;
        else
        return (x*w)%z;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    int x;
    cin>>x;
    cout<<1-x;}
    
    
    
    

Measured memory_bytes: 3584
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
ll dx[4]={0,1,-1,0};
ll dy[4]={1,0,0,-1};

// スタックオーバーフローの罠を解決する

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int k;
    cin>>k;
    int n = (1<<k);
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int ans = 0;
    for(int i=1;i<n;i++){
        int ma = 0, mi = 0;
        for(int u=n-1;u>=0;u--){
            u &= i;
            if(ma <= a[u]){
                chmax(mi,ma);
                ma = a[u];
            }
            else chmax(mi,a[u]);
        }
        chmax(ans,mi+ma);
        cout << ans <<"\n";
    }

}

Measured memory_bytes: 4640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;

template<typename T>
struct edge {
    int from;
    int to;
    T cost;
};

template<typename T>
vector<T> BellmanFord(int s, int v, const vector<edge<T>> &g) {
    const T INF = numeric_limits<T>::max();
    vector<T> dist(v,INF);
    dist[s] = 0;
    for(int i = 0; i < v-1; ++i) {
        for(auto& e : g) if(dist[e.from]!=INF) {
            dist[e.to] = min(dist[e.to],  dist[e.from]+e.cost);
        }
    }
    for(auto &e : g) if(dist[e.from]!=INF) {
        if(dist[e.from] + e.cost < dist[e.to]) return vector<T>();
    }
    return dist;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int v,e,r; cin >>  v >> e >>  r;
    vector<edge<int>> g;
    REP(i,e) {
        int s,t,d; cin >> s >> t >> d;
        g.push_back({s,t,d});
    }
    vector<int> dist = BellmanFord(r,v,g);
    if(dist.empty()) cout << "NEGATIVE CYCLE" << endl;
    for(auto x : dist) {
        if(x==numeric_limits<int>::max()) cout << "INF" << '\n';
        else cout << x << '\n';
    }
    return 0;
}


Measured memory_bytes: 3224
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    final int n = scanner.nextInt();
    final String s = scanner.next();
    final String s1 = s.replaceAll("ABC", "a");
    List<String> sl = Arrays.asList(s1.split(""));
    System.out.println(sl.stream()
        .filter(e -> e.equals("a"))
        .count());
  }
}


Measured memory_bytes: 28620
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

unordered_map<long, unordered_set<long>> load;
unordered_map<long, unordered_set<long>> railway;

void union_find(long root, long current, vector<long> &group, bool isLoad) {
  if (group[current-1]) return;
  group[current-1] = root;
  for (auto neibor: (isLoad ? load[current] : railway[current]))
    union_find(root, neibor, group, isLoad);
}

int main(void) {
  long N, K, L;
  cin >> N >> K >> L;
  rep (i, K) {
    long a, b;
    cin >> a >> b;
    load[a].insert(b);
    load[b].insert(a);
  }
  rep (i, L) {
    long a, b;
    cin >> a >> b;
    railway[a].insert(b);
    railway[b].insert(a);
  }
  vector<long> load_group(N, 0);
  vector<long> railway_group(N, 0);
  for (long i = 1; i <= N; i++) union_find(i, i, load_group, true);
  for (long i = 1; i <= N; i++) union_find(i, i, railway_group, false);

  map<pair<long, long>, long> count;
  rep (i, N) count[make_pair(load_group[i], railway_group[i])]++;

  bool flag = false;
  rep (i, N) {
    if (flag) cout << " ";
    flag = true;
    cout << count[make_pair(load_group[i], railway_group[i])];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 68844
import numpy as np

_N, _D, *_X = open(0).read().split()
N = int(_N)
D = int(_D)
X = np.array(list(zip(*[map(int, iter(_X))]*D)))

import itertools

ans = 0

for x, y in itertools.combinations(X, 2):
    d = np.linalg.norm(x - y)

    if d%1 == 0:
        ans += 1

print(ans)

Measured memory_bytes: 12500
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
            x[i] = p[i];
        }
        Arrays.sort(x);
        int cnt = 0;
        for(int j = 0; j < n; j++) {
            if (x[j] != p[j]) {
                cnt++;
            }
        }
        String message = "";
        if (cnt > 2) {
            message = "NO";
        } else {
            message = "YES";
        }
        System.out.println(message);
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
int n,arr[100005],patokan,z[100005],total=0,arrbaru[100005]={},beda,tambahz,totbaru,tottemp;
long long totaltemp=0,totaltambah=0;
vector <int> bedalist;
bool ans=true;
void printbaru()
{
	cout<<"this is baru "<<endl;
	for(int i=1;i<=n;i++)
		cout<<arrbaru[i]<<" ";
	cout<<endl<<endl;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&arr[i]);
	bedalist.push_back(arr[1]-arr[n]);
	for(int i=2;i<=n;i++)
		bedalist.push_back(arr[i]-arr[i-1]);
	patokan=bedalist[0];
	for(int i=1;i<bedalist.size();i++)
	{
		patokan=max(patokan,bedalist[i]);
		if((bedalist[i]-bedalist[i-1])%n!=0)
		{
			ans=false;
			goto output;
		}
	}
	for(int i=0;i<bedalist.size();i++)
		z[i+1]=(patokan-bedalist[i])/n,total+=z[i+1];
	if(total!=patokan)
	{
		ans=false;
		goto output;
	}
	totbaru=0;
	tottemp=0;
	for(int i=1;i<=n;i++)
	{
		totbaru+=z[i]*(n-i+1);
		tottemp+=(n-i+1);
	}
	if(((arr[n]-totbaru)<0)||(((arr[n]-totbaru)%tottemp)!=0))
	{
		ans=false;
		goto output;
	}
	tambahz=(arr[n]-totbaru)/tottemp;
	for(int i=1;i<=n;i++)
		z[i]+=tambahz;
	for(int i=1;i<=2*n;i++)
	{
		if(i<=n)
		{
			totaltemp+=z[i];
			totaltambah+=totaltemp;
			arrbaru[i]+=totaltambah;
		}
		else
		{
			totaltemp-=z[i-n];
			totaltambah-=(long long) z[i-n]*n;
			totaltambah+=totaltemp;
			arrbaru[i-n]+=totaltambah;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(arrbaru[i]!=arr[i])
		{
			ans=false;
			goto output;
		}
	}
	//printbaru();
	output:
	if(ans)
		printf("YES\n");
	else
		printf("NO\n");
}

Measured memory_bytes: 1912
#include <bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;

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

     int cnt_odd = 0, cnt_4 = 0;
     rep(i, 0, N) {
       int tmp;
       cin >> tmp;
       if (tmp % 2 == 1) cnt_odd++;
       else if (tmp % 4 == 0) cnt_4++;
     }

     string ans = "Yes";

     if (cnt_odd - cnt_4 > 1) ans = "No";
     else if (cnt_odd - cnt_4 == 1 && cnt_odd + cnt_4 != N) ans = "No";

     cout << ans << endl; 
 }


Measured memory_bytes: 256
from collections import deque

N = int(input())
E = [None] * (N+1)
for _ in range(N):
    u, k, *vs = list(map(int, input().split()))
    E[u] = vs

d = [-1] * (N+1)
d[1] = 0
q = deque([(1, 0)])
while q:
    v, c = q.popleft()
    for u in E[v]:
        if d[u] < 0:
            d[u] = c+1
            q.append((u, c+1))

for i in range(1, N+1):
    print(i, d[i])


Measured memory_bytes: 6032
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin >> n >>m;

	int x=0,y=0;
	if(n>1){
		x=n*(n-1)/2;
	}
	if(m>1){
			y=m*(m-1)/2;
		}
	cout << x+y;
	
		
			
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

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

        @SuppressWarnings("unchecked")
        List<Long>[] sum = new List[8];
        // sum[0] = + xi + yi + zi
        // sum[1] = + xi + yi - zi
        // sum[2] = + xi - yi + zi
        // sum[3] = + xi - yi - zi
        // sum[4] = - xi + yi + zi
        // sum[5] = - xi + yi - zi
        // sum[6] = - xi - yi + zi
        // sum[7] = - xi - yi - zi
        for (int i = 0; i < 8; i++) {
            sum[i] = new ArrayList<>();
        }

        for (int i = 0; i < n; i++) {
            long x = sc.nextLong();
            long y = sc.nextLong();
            long z = sc.nextLong();
            sum[0].add(+x + y + z);
            sum[1].add(+x + y - z);
            sum[2].add(+x - y + z);
            sum[3].add(+x - y - z);
            sum[4].add(-x + y + z);
            sum[5].add(-x + y - z);
            sum[6].add(-x - y + z);
            sum[7].add(-x - y - z);
        }

        long ans = 0;
        for (int i = 0; i < 8; i++) {
            Collections.sort(sum[i]);
//            System.out.println(sum[i]);
//            System.out.println("----");
            long candidate = 0;
            for (int j = 0; j < m; j++) {
                candidate += sum[i].get(n - 1 - j);
            }
//            System.out.println(candidate);
            if (candidate > ans) {
                ans = candidate;
            }
        }
        System.out.println(ans);

        sc.close();
    }

}


Measured memory_bytes: 25832
from collections import deque 

R,W = map(int,input().split())
sy,sx = 1,1
gy,gx = R,W
C = [list(input()) for i in range(0,R,1)]

task_list = deque([])
ans = 0

siro = 0
for i in range(R):
    for j in range(W):
        if C[i][j]==".":
            siro += 1
def bfs(y,x,count):#関数にしない方がわかりやすいかも

    if x==gx-1 and y==gy-1:
        return True

    if x < 0 or  W <= x or y < 0 or R <= y:
        return False
    if C[y][x]=="#":
        return False#何もしない
    if C[y][x]==".":
        C[y][x]="#"
        task_list.append([y+1,x,count+1])
        task_list.append([y-1,x,count+1])
        task_list.append([y,x-1,count+1])
        task_list.append([y,x+1,count+1])
    

task_list.append([sy-1,sx-1,0])
ok = False
while(len(task_list)):
    y,x,t = task_list.popleft()
    ans = t
    if bfs(y,x,t):
        ok = True
        break
print(siro-1-ans if ok else -1)

Measured memory_bytes: 74208
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n==0||n==1)return dp[n]=1;
  if(dp[n]!=-1)return dp[n];
  return dp[n]=fib(n-1)+fib(n-2);
}

int main(){

  int i,n;

  for(i=0;i<50;i++){
    dp[i]=-1;
  }

  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
  
  
}



Measured memory_bytes: 2104
#include <iostream>
using namespace std;
 
int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a == 5 && b == 5 && c == 7){
    cout << "YES" << endl;
  }
   else if(a == 5 && b == 7 && c == 5){
    cout << "YES" << endl;
}
   else if(a == 7 && b == 5 && c == 5){
    cout << "YES" << endl;
}
   else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 3488
N=int(input())
P=tuple(int(i) for i in input().split())
Q=tuple(int(i) for i in input().split())

import itertools

seq = range(1,N+1)
for i,l in enumerate(itertools.permutations(seq)):
    if l == P:
        ans1 = i
    if l == Q:
        ans2 = i
print(abs(ans1-ans2))

Measured memory_bytes: 39152
import sys

N, Y = [int(n) for n in input().split()]

for x in range((Y//10000)+1):
    rest = Y - x * 10000
    if rest < 0:
        continue
    
    for y in range((rest//5000)+1):
        rest2 = rest - y * 5000
        if rest2 < 0:
            continue

        z = rest2//1000

        total = x + y + z

        if total == N:
            print(x, y, z)
            sys.exit(0)
print('-1 -1 -1')

Measured memory_bytes: 9184
s = str(input())

if len(s)%2:
    print('No')
    exit()
for i in range(len(s)):
    if not i%2 and s[i] == "h":
        continue
    elif i%2 and s[i] == "i":
        continue
    else:
        print("No")
        exit()
print('Yes')

Measured memory_bytes: 3060
n=int(input())
l=[int(input()) for i in range(n)]

num=l[0]
cnt=0
for i in range(10**5):
  if num==2:
    cnt+=1
    break
  else:
    num=l[num-1]
    cnt+=1
    
if cnt==10**5:
  cnt=-1
  
print(cnt)

Measured memory_bytes: 13060
#include<bits/stdc++.h>
#define ll long long
#define MP make_pair
#define PB push_back
using namespace std;
namespace io{
	const int Sz=1<<13;
	char ibuf[Sz],*ips=ibuf+Sz-1;
	inline int getchar(){
		if(++ips==ibuf+Sz)fread(ips=ibuf,1,Sz,stdin);
		return *ips;
	}
	char obuf[Sz],*ops=obuf;
	inline void flush(){
		fwrite(obuf,1,ops-obuf,stdout);
		ops=obuf;fflush(stdout);
	}
	inline void putchar(int c){
		if(ops==obuf+Sz)flush();
		*ops=c,ops++;
	}
	void gets(char *s){
		int c=getchar();
		while(c<=32)c=getchar();
		while(c>32)*s=c,++s,c=getchar();
		*s=0;
	}
	void puts(const char *s){
		while(*s)putchar(*s),++s;
	}
}
#define getchar io::getchar
#define putchar io::putchar
#define gets io::gets
#define puts io::puts
int read(){
	int x=0,f=1,c=getchar();
	for(;c<48||c>57;c=getchar())
		if(c=='-')f=-f;
	for(;c>=48&&c<=57;c=getchar())
		x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
void write(int x){
	int stk[20],tp=0;
	if(!x)putchar(48);
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)stk[tp++]=(x-x/10*10)^48;
	for(;tp;)putchar(stk[--tp]);
}
struct Flusher{~Flusher(){io::flush();}}flusher;
// ------------------------- Template End ------------------------- //
const int N=2e5;
int n,m;
int deg[N];
int id[N];
int head[N],nxt[N],to[N],tot;
void add(int u,int v){
	nxt[tot]=head[u];head[u]=tot;
	to[tot]=v;++tot;
}
int prv[N];
int que[N],lb,rb;
vector<int>no;
void bfs(int s){
	lb=rb=0;
	que[rb++]=s;
	memset(prv,~0,sizeof prv);
	prv[s]=0;
	for(;lb<rb;){
		int u=que[lb++];
		for(int e=head[u];~e;e=nxt[e]){
			bool ok=1;
			for(int i=0;i<no.size();++i)
				if(no[i]==e||(no[i]^1)==e)ok=0;
			if(!ok)continue;
			int v=to[e];
			if(!~prv[v]){
				prv[v]=e;
				que[rb++]=v;
			}
		}
	}
}
int main(){
	memset(head,~0,sizeof head);
	n=read(),m=read();
	for(int i=0;i<m;++i){
		int u=read()-1,v=read()-1;
		deg[u]++;deg[v]++;
		add(u,v);add(v,u);
	}
	for(int i=0;i<n;++i)id[i]=i;
	sort(id,id+n,[&](int a,int b){
		return deg[a]>deg[b];
	});
	for(int i=0;i<n;++i)if(deg[i]&1){
		puts("No");return 0;
	}
	if(deg[id[0]]>=6)puts("Yes");
	else if(deg[id[0]]>=4&&deg[id[1]]>=4&&deg[id[2]]>=4)puts("Yes");
	else if(deg[id[0]]>=4&&deg[id[1]]>=4){
		bfs(id[0]);no.PB(prv[id[1]]);
		bfs(id[0]);if(~prv[id[1]])no.PB(prv[id[1]]);else{puts("No");return 0;}
		bfs(id[0]);if(~prv[id[1]])puts("No");else puts("Yes");
	}
	else puts("No");
	return 0;
}



Measured memory_bytes: 4608
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		boolean bh[] = new boolean[h];
		boolean bw[] = new boolean[w];
		char[][] a = new char[h][w];
		String[] s = new String[h];
		for(int i = 0; i < h; i++) {
			s[i] = sc.next();
			a[i] = s[i].toCharArray();
		}
		
		for(int i = 0; i < h; i++) {
			bh[i] = false;
			for(int j = 0; j < w; j++) {
				if(a[i][j] == '#') {
					bh[i] = true;
					break;
				}
			}
		}
		for(int i = 0; i < w; i++) {
			bw[i] = false;
			for(int j = 0; j < h; j++) {
				if(a[j][i] == '#') {
					bw[i] = true;
					break;
				}
			}
		}
		for(int i = 0; i < h; i++) {
			if(bh[i]) {
				for(int j = 0; j < w; j++) {
					if(bw[j])
						System.out.print(a[i][j]);
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 25940
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repm(i,m,n) for (int i = (m); i < (n); i++)
#define rrep(i,n) for (int i = (n); i >= 0; i--)
using namespace std;
typedef long long ll;
 
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  int mx = max({A,B,C});
  int ans = A + B + C + 9*mx;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

template <class T> class SegmentTree {
public:
  SegmentTree(const int n, const T id, function<T(T, T)> op,
              function<T(T, T)> updateOp);
  void update(const int index, const T value);
  T find(const int l, const int r);

private:
  int leftChildIndex(const int parent);
  int rightChildIndex(const int parent);
  int parent(const int child);
  int leaf(const int index);
  T query(const int l, const int r, const int node, const int al, const int ar);

private:
  vector<T> data;
  int leafNum;
  T id;
  function<T(T, T)> op;
  function<T(T, T)> updateOp;
};

template <class T>
SegmentTree<T>::SegmentTree(const int n, const T id, function<T(T, T)> op,
                            function<T(T, T)> updateOp)
    : id(id), op(op), updateOp(updateOp) {
  leafNum = 1;
  while (leafNum < n)
    leafNum *= 2;
  data = vector<T>(2 * leafNum - 1, id);
}

template <class T> int SegmentTree<T>::leftChildIndex(const int parent) {
  return parent * 2 + 1;
}

template <class T> int SegmentTree<T>::rightChildIndex(const int parent) {
  return parent * 2 + 2;
}

template <class T> int SegmentTree<T>::parent(const int child) {
  return (child - 1) / 2;
}

template <class T> int SegmentTree<T>::leaf(const int index) {
  return index + leafNum - 1;
}

template <class T> T SegmentTree<T>::find(const int l, const int r) {
  return query(l, r, 0, 0, leafNum);
}

template <class T>
T SegmentTree<T>::query(const int l, const int r, const int node, const int al,
                        const int ar) {
  if (r <= al || ar <= l)
    return id;
  if (l <= al && ar <= r)
    return data[node];
  int mid = (al + ar) / 2;
  int leftValue = query(l, r, leftChildIndex(node), al, mid);
  int rightValue = query(l, r, rightChildIndex(node), mid, ar);
  return op(leftValue, rightValue);
}

template <class T> void SegmentTree<T>::update(const int index, const T value) {
  int i = leaf(index);
  data[i] = updateOp(data[i], value);
  while (i > 0) {
    i = parent(i);
    data[i] = op(data[rightChildIndex(i)], data[leftChildIndex(i)]);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  SegmentTree<ll> st(n, 0, [](ll a, ll b) -> ll { return a + b; },
                     [](ll a, ll b) -> ll { return a + b; });
  REP(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    x--;
    if (com == 1) {
      cout << st.find(x, y) << endl;
    } else {
      st.update(x, y);
    }
  }
}



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

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

	vector<string> s(n);
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}

	sort(s.begin(), s.end());

	s.erase(unique(s.begin(), s.end()), s.end());

	std::cout << s.size() << std::endl;

	return 0;
}

Measured memory_bytes: 7640
#include <iostream>
#include <cstdint>
#include <algorithm>

using namespace std;

int main()
{
    int D, G;
    int p[10], c[10];

    cin >> D >> G;
    for (int i = 0; i < D; i++)
    {
        cin >> p[i] >> c[i];
    }

    int solved_min = 1'000;
    for (int16_t flags = 0; flags < (1 << D); flags++)
    {
        int score = 0;
        int solved = 0;
        int effective = -1;
        for (int i = 0; i < D; i++)
        {
            if ((flags & (1 << i)) != 0)
            {
                score += p[i] * 100 * (i + 1) + c[i];
                solved += p[i];
            }
            else
            {
                effective = i;
            }
        }

        if (G <= score)
        {
            solved_min = min(solved, solved_min);
        }
        else if (effective >= 0)
        {
            int rem = G - score;
            int additional = (rem - 1) / ((effective + 1) * 100) + 1;
            if (additional < p[effective])
            {
                solved_min = min(solved_min, solved + additional);
            }
        }
    }

    cout << solved_min << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	var max, cnt int
	for _, c := range s {
		if c == 'A' || c == 'C' || c == 'G' || c == 'T' {
			cnt++
		} else {
			cnt = 0
		}

		if cnt > max {
			max = cnt
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif

int main() {
   Int x, y;
   std::cin >> x >> y;
   Int res = 0;
   if( x == 1 and y == 1 ) {
      res = 1;
   }
   else if( x == 1 ) {
      res = y-2;
   }
   else if( y == 1 ) {
      res = x-2;
   }
   else {
      res = std::max((Int)0, x-2) * std::max((Int)0, y-2);
   }
   printf("%ld\n", res);
}


Measured memory_bytes: 256
N=int(input())
P=[int(i) for i in input().split()]
mes=0
for i in range(len(P)):

	if i!=0 and i!=N-1:
		if (P[i+1]<P[i] and P[i+1]<=P[i-1] and P[i]<=P[i-1])or(P[i-1]<P[i] and P[i-1]<=P[i+1] and P[i]<=P[i+1]):
			mes+=1
print(mes)
	

Measured memory_bytes: 38256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    cin>>s;
    string A={"BDEFGHIJKLMNOPQRSTUVWXYZ"};
    int x=0;
    for(int i =0;i<s.size();i++){
        for(int j=0;j<24;j++){
            if(s[i]==A[j]){
                x=1;
                break;
            }
        }
        if(x==1) break;
    }
    if(s[0]!='A') x=1;
    int n=0;
    for(int i=2;i<s.size()-1;i++){
        if(s[i]=='C') n++;
    }
    if(n!=1) x=1;
    if(x==0) cout<<"AC";
    else cout<<"WA";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll n, maximum{0}, x{0};
    cin >> n;
    string s;
    cin >> s;
    for (auto && c : s) {
        if (c == 'I') x++;
        else x--;
        maximum = max(maximum, x);
}
    cout << maximum;
    return 0;
}

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

#pragma GCC optimize("O3")

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

int main() {
    int n, m;
    cin >> n >> m;
	map<int, char> data;
	string s = string(n, '*');
	for(int i = 0; i < m; ++i) {
		int k;
		char c;
		cin >> k >> c;
		
		if(data.find(k) != data.end() && data.at(k) != c) {
			s = "-1";
		} else {
			data.insert(pair<int, char>(k, c));
		}
	}
	
	if(s == "-1") {
		cout << -1;
	} else {
		for(int i = 0; i < n; ++i) {
			if(data.find(i+1) != data.end()) {
				s[i] = data.at(i+1);
				if(i == 0 && data.at(i+1) == '0' && n > 1) {
					s = "-1";
					break;
				}
			} else {
				if(i == 0 && n > 1) s[i] = '1';
				else s[i] = '0';
			}
		}
		cout << s;
	}
	

    return 0;
}


Measured memory_bytes: 3568
N = int(input())
a = list()
for i in range(N):
	a.append(int(input()))

temp = 1
count = 0
while temp != 2 and count <= 100001:
	temp = a[temp - 1]
	count += 1

if count > 100000:
	print(-1)
else:
	print(count)

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

using namespace std;

int n;
int a[100010];
set<int> s;

int main()
{
    cin.tie(0); ios_base::sync_with_stdio(false);
    //freopen("bitstrings_as_a_service.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    cin >> n;
    bool all0 = 1;
    for(int i=0; i<n; i++)
    {
        int x;
        cin >> x;
        a[i] = x;
        if(x) all0 = 0;
        s.insert(x);
    }
    if(all0)
    {
        cout << "Yes" << endl;
        return 0;
    }
    if(n%3)
    {
        cout << "No" << endl;
        return 0;
    }
    if(s.size()==1 || s.size()>=4) cout << "No" << endl;
    else if(s.size()==2)
    {
        auto ite = s.begin();
        int num1 = *ite;
        ite++;
        int num2 = *ite;
        int cnt1 = 0;
        int cnt2 = 0;
        for(int i=0; i<n; i++)
        {
            if(a[i] == num1) cnt1++;
            else cnt2++;
        }
        if(num1 == 0 && cnt2 == cnt1 * 2) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else
    {
        auto ite = s.begin();
        int num1 = *ite;
        ite++;
        int num2 = *ite;
        ite++;
        int num3 = *ite;
        int cnt1, cnt2, cnt3;
        cnt1 = cnt2 = cnt3 = 0;
        for(int i=0; i<n; i++)
        {
            if(a[i] == num1) cnt1++;
            else if(a[i] == num2) cnt2++;
            else cnt3++;
        }
        if(cnt1 == cnt2 && cnt2 == cnt3 && ((num1^num2) == num3)) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define SZ(x) ((int)(x).size())
#define MEM(x,a) memset(x,a,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1000000007,N=1e5+5,M=1e5+5,INF=0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;
    cin>>n>>k;
    cout<<min(n%k,k-n%k);
    return 0;
}

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

string list[] = { "North","East","West","South","Right","Left" };
enum{ UE, TEMAE, MIGI };

int main() {
	
	int n;
	while (cin >> n, n!=0){
		int dice[3] = { 1, 2, 3 };
		int score = 1;

		for (int i = 0; i < n; ++i){
			string s;
			cin >> s;
			
			if (s == list[0]){
				int ue_tmp;
				ue_tmp = dice[UE];
				dice[UE] = dice[TEMAE];
				dice[TEMAE] = 7 - ue_tmp;
			}
			if (s == list[1]){
				int migi_tmp = dice[MIGI];
				dice[MIGI] = dice[UE];
				dice[UE] = 7 - migi_tmp;
			}
			
			if (s == list[2]){
				int ue_tmp = dice[UE];
				dice[UE] = dice[MIGI];
				dice[MIGI] = 7 - ue_tmp;
			}
			if (s == list[3]){
				int temae_tmp = dice[TEMAE];
				dice[TEMAE] = dice[UE];
				dice[UE] = 7 - temae_tmp;
				// 手前 => 上から
				// 上　=> 手前のうら
			}
			if (s == list[4]){
				int temae_tmp = dice[TEMAE];
				dice[TEMAE] = dice[MIGI];
				dice[MIGI] = 7 - temae_tmp;
			}
			if (s == list[5]){
				int migi_tmp = dice[MIGI];
				dice[MIGI] = dice[TEMAE];
				dice[TEMAE] = 7 - migi_tmp;
			}
			score += dice[UE];
		}

		cout << score << endl;

	}

	return 0;
}

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

const double PI = 3.1415926535897932;
const int INF = (int)1e9;
const ll LINF = 1e18;
const int IMOD = 1000000007;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};

using namespace std; 

int main(void)
{
    ll x;
    cin >> x;

    irep(i, 1001) {
        irep2(j, -1000, 1000) {
            if(i*i*i*i*i - j*j*j*j*j == x) {
                printf("%d %d\n", i, j);
                return 0;
            }
        }
    }
    return 0;
}
/** atcoder **/



Measured memory_bytes: 3736
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

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

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

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

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

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

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

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

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

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N := sc.nextInt()
	S := sc.nextStr()
	// [now][next], SS, SW, WS, WW
	okNextMap := [][]int{[]int{0, 1}, []int{1, 0}}
	// [now][next], SS, SW, WS, WW
	ngNextMap := [][]int{[]int{1, 0}, []int{0, 1}}
	isTrue := false
	var ans []int
	for last := 0; last < 2; last++ {
		for first := 0; first < 2; first++ {
			var next int
			if S[0] == 'o' {
				next = okNextMap[last][first]
			} else {
				next = ngNextMap[last][first]
			}
			now := first
			arr := []int{now}
			for i := 1; i < N; i++ {
				tmp := next
				if S[i] == 'o' {
					next = okNextMap[now][next]
				} else {
					next = ngNextMap[now][next]
				}
				now = tmp
				arr = append(arr, now)
			}
			if next == first && now == last {
				isTrue = true
				ans = arr
			}
		}
	}
	if !isTrue {
		fmt.Fprintln(wtr, "-1")
	} else {
		for i := 0; i < N; i++ {
			if ans[i] == 0 {
				fmt.Fprint(wtr, "S")
			} else {
				fmt.Fprint(wtr, "W")
			}
		}
		fmt.Fprintln(wtr)
	}
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
int main(void){
    char c;
    cin>>c;
    if(c=='A') cout<<"T"<<endl;
    if(c=='T') cout<<"A"<<endl;
    if(c=='C') cout<<"G"<<endl;
    if(c=='G') cout<<"C"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace ABC084D{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //---------------------------------
            var getLike2017Sums = GetLike2017Sums();
            var Q = sr.Next<int>();
            var qs = sr.Next<int>(2, Q).Select(a => new{l = a[0], r = a[1]});
            foreach(var q in qs) sw.WriteLine(getLike2017Sums[q.r] - getLike2017Sums[q.l - 1]);
            //---------------------------------
            sw.Flush();
        }

        public static int[] GetLike2017Sums(){
            const int MAX = 100010;
            var ret = new int[MAX];
            for(var i = 3; i < MAX; i++){
                ret[i] = ret[i - 1];
                if(IsLike2017(i)) ret[i] += 1;
            }
            return ret;
        }

        public static bool IsLike2017(int n){
            return Prime.Is(n) && Prime.Is((n + 1) / 2);
        }
    }

    public static class Prime {
        public static bool Is(int n) {
            for(var i = 2; i * i <= n; i++) if(n % i == 0) return false;
            return n > 1;
        }

        public static IEnumerable<int> Sieve(int n) {
            var sieve = new bool[n + 1];
            for(var i = 2; i <= n; i++) {
                if(!sieve[i]) {
                    yield return i;
                    for(var j = i << 1; j <= n; j += i) sieve[j] = true;
                }
            }
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T) typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T) Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int x, int y){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 22844
#include <iostream>
using namespace	std;
int main(){

  for(int n,cnt=0;cin>>n,n;cnt++){
    int a[4],c[4],r0=1e9;
    for(int i=0;i<4;i++) cin>>a[i];
    for(int i=0;i<=a[0];i++) for(int j=0;j<=a[1];j++) for(int k=0;k<=a[2];k++) for(int l=0;l<=a[3];l++){
            int b=n-(i*10+j*50+k*100+l*500);
            if(b>0) continue;
            int r=0;
            b*=-1;
            for(;b>=500;b-=500) r++;
            for(;b>=100;b-=100) r++;
            for(;b>=50;b-=50) r++;
            for(;b>=10;b-=10) r++;
            if(r0>r+a[0]-i+a[1]-j+a[2]-k+a[3]-l) c[0]=i,c[1]=j,c[2]=k,c[3]=l,r0=r+a[0]-i+a[1]-j+a[2]-k+a[3]-l;
          }
    if(cnt) cout<<endl;
    if(c[0]) cout<<"10 "<<c[0]<<endl;
    if(c[1]) cout<<"50 "<<c[1]<<endl;
    if(c[2]) cout<<"100 "<<c[2]<<endl;
    if(c[3]) cout<<"500 "<<c[3]<<endl;
  }
  return 0;

}




Measured memory_bytes: 2992
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

enum POSITION{ONLINE_BACK = -2, CCW = -1, ON_SEGMENT = 0,
              CW = 1, ONLINE_FRONT = 2};

struct Point{
    long x;
    long y;
    Point(long x, long y) : x(x), y(y) {}
    Point(){}
    Point operator-(Point p){
        return Point(x - p.x, y - p.y);
    }
};
typedef Point Vector;
double cross(Vector v1, Vector v2){
    return v1.x * v2.y - v1.y * v2.x;
}
double dot(Vector v1, Vector v2){
    return v1.x * v2.x + v1.y * v2.y;
}

struct Segment{
    Point p1;
    Point p2;
    Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
    Segment(){}
};
typedef vector<Point> Polygon;

POSITION get_position(Segment s, Point p){
    double c = cross(s.p2 - s.p1, p - s.p1);
    if (c > 0) return CCW;
    if (c < 0) return CW;
    double d = dot(s.p2 - s.p1, p - s.p1);
    if (d < 0) return ONLINE_BACK;
    if (d > dot(s.p2 - s.p1, s.p2 - s.p1)) return ONLINE_FRONT;
    return ON_SEGMENT;
}

bool intersect(Segment s1, Segment s2){
    if (get_position(s1, s2.p1) * get_position(s1, s2.p2) != -1) {
        return false;
    }
    if (get_position(s2, s1.p1) * get_position(s2, s1.p2) != -1) {
        return false;
    }
    return true;
}

int determine_containment(Point p, Polygon poly){
    Segment s_right(p, Point(p.x + 1e5, p.y));
    int count = 0;
    for (int i = 0, n = poly.size(); i < n; i++) {
        if (get_position(Segment(poly[i], poly[(i+1)%n]), p) == ON_SEGMENT) {
            return 1;
        }
        if (intersect(s_right, Segment(poly[i], poly[(i+1)%n]))) {
            count++;
            continue;
        }
        if (get_position(s_right, poly[i]) == ON_SEGMENT) {
            int i_pre = (i == 0 ? n - 1 : i - 1);
            POSITION pos_pre = get_position(s_right, poly[i_pre]);
            while (pos_pre != CCW && pos_pre != CW) {
                i_pre = (i_pre == 0 ? n - 1 : i_pre - 1);
                pos_pre = get_position(s_right, poly[i_pre]);
            }
            int i_aft = (i + 1) % n;
            POSITION pos_aft = get_position(s_right, poly[i_aft]);
            while (pos_aft != CCW && pos_aft != CW) {
                i_aft = (i_aft + 1) % n;
                pos_aft = get_position(s_right, poly[i_aft]);
            }
            if (get_position(s_right, poly[i_pre]) * get_position(s_right, poly[(i+1)%n]) == -1) {
                count++;
            }
        }
    }
    if (count % 2) return 2;
    return 0;
}
int main(){
    int q;
    cin >> q;
    Polygon poly(q);
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        poly[i].x = x;
        poly[i].y = y;
    }
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        cout << determine_containment(Point(x, y), poly) << endl;
    }
    return 0;
}



Measured memory_bytes: 3120
import math
import itertools
#n = int(input())
#n, d = list(input().split())
s = input()
point = 0

for i in range(len(s)):
    a = s[i]
    point += int(a)

n = int(s)
if n%point==0:
    print("Yes")
else:
    print("No")

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

int main()
{
    int n;
    int a[1001],b[1001],c[1001];
    int ans=0;
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin>>b[i];
    }
    for (int i = 0; i < n-1; i++)
    {
        cin>>c[i];
    }

    int mae=-100;
    for (int i = 0; i < n; i++)
    {
        ans+=b[a[i]-1];
        if(mae+1==a[i]-1){
            ans+=c[mae];
        }
        mae=a[i]-1;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
A = [int(a) for a in input().split()]
Jump = [None] * n
Jump[0] = 1
Rireki = [-1] * (n+1)
Rireki[0] = 0
next = 0
for i in range(1,n+1):
    to = A[next]

    if Rireki[to] >= 0:
        start = Jump.index(to)
        end = i
        dis = end - start

        roop = (k-start) % dis
        print(Jump[start+roop])
        break
    Rireki[to] = i
    Jump[i] = to
    next = to-1
    if i ==k:
        print(to)
        break


Measured memory_bytes: 32320