akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long

//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}

int main(){
    int n;
    cin >> n;
    set<string> S;
    rep(i,n){
        string s;
        cin >> s;
        S.insert(s);
    }
    cout<<S.size()<<endl;
    return 0;
}



Measured memory_bytes: 19232
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

char A[1000][1000];
bool check[1000][1000];

class Data{
public:
    int x;
    int y;
    int dist;
};

int main(){

    int H, W;
    cin >> H >> W;
    queue<Data> q;

    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            check[i][j] = false;
        }
    }

    char temp;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> temp;
            A[i][j] = temp;
            if(temp == '#'){
                Data tempData;
                tempData.x = j;
                tempData.y = i;
                tempData.dist = 0;
                check[i][j] = true;
                q.push(tempData);
            }
        }
    }

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

    int ans = 0;
    while(!q.empty()){
        Data tempData = q.front();
        q.pop();

        ans = max(ans, tempData.dist);
        for(int i = 0; i < 4; i++){
            int nextX = tempData.x + dx[i];
            int nextY = tempData.y + dy[i];

            if(0 <= nextX && nextX < W && 0 <= nextY && nextY < H){
                if(!check[nextY][nextX]){
                    Data nextData;
                    nextData.x = nextX;
                    nextData.y = nextY;
                    nextData.dist = tempData.dist + 1;
                    check[nextData.y][nextData.x] = true;
                    q.push(nextData);
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 14352
//////////////////////////////////////////////
///  Fear is temporary, Regret is forever  ///
///               sat7978                  ///
///         extreme      blood             /// 
//////////////////////////////////////////////
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e6+100;
#define ll long long
#define pb push_back
#define S second
#define F first
void flash(){
    ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(2);
}


int main() {
    flash(); 
    int t;
    t=1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        cout<<arr[(n/2)]-arr[(n/2)-1];
    }
    return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(a.at(a.at(i) - 1) == i + 1) ans++;
  }
  
  cout << ans / 2 << '\n';
}

Measured memory_bytes: 640
import java.util.Scanner;

//  B - Some Sums

public class Main {
  public static void main(String[] args ) throws Exception {

    Scanner sc = new Scanner(System.in);
    int A = Integer.parseInt(sc.next());
    int B = Integer.parseInt(sc.next());
    int C = Integer.parseInt(sc.next());


    int totalAll = 0;
	for(int i = 1; i <= A; i++) {
		int total = kesan(i);
		if(total >= B && total <= C) {

			totalAll += i;
		}
	}


    System.out.println(totalAll);
  }

  public static int kesan(int i) {
		int total = 0;
		while(true) {
			if(i / 10 > 0) {
				total += i % 10;
				i /= 10;
			} else {
				total += i;
				return total;
			}
		}

  }
}

Measured memory_bytes: 21204
#include<iostream>
using namespace std;
int main()
{
	char arr[101],brr[101],crr[101];
	cin>>arr>>brr>>crr;
	int a=1,b=0,c=0;
	char t=arr[0];
	char n='A';
	while(t!='\0')
	{
		if(t=='a')
		{
			t=arr[a];
			a++;
			n='A';
		}
		else if(t=='b')
		{
			t=brr[b];
			b++;
			n='B';
		} 
		else
		{
			t=crr[c];
			c++;
			n='C';
		}
	}
	cout<<n<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
using namespace std;
int main() {
	int n, u, v, a, b;
	int t, co = 0;
	int max = 0;
	cin >> n >> u >> v;
	vector<vector<int>> g(n+1);
	queue<int> que;
	int r[100010] = { 0 }, r1[100010] = { 0 };
	for (int c = 0; c < n-1; c++) {
		cin >> a >> b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	if (n == 2) {
		if (a == u && b == v) {
			cout << "0" << endl;
			return 0;
		}
	}
	r[u] = 0;
	que.push(u);
	for (;;) {
		if (que.empty()) {
			break;
		}
		int t = que.front();
		que.pop();
		co++;
		for (int k = 0; k < g[t].size(); k++) {
			if (r[g[t][k]] != 0) {
				continue;
			}
			que.push(g[t][k]);
			r[g[t][k]] = r[t] + 1;
		}
	}
	r1[v] = 0;
	que.push(v);
	for (;;) {
		if (que.empty()) {
			break;
		}
		int t = que.front();
		que.pop();
		co++;
		for (int k = 0; k < g[t].size(); k++) {
			if (r1[g[t][k]] != 0) {
				continue;
			}
			que.push(g[t][k]);
			r1[g[t][k]] = r1[t] + 1;
		}
	}
	for (int m = 1; m <= n; m++) {
		if (r[m] <= r1[m] && max < r1[m]-1) {
			max = r1[m]-1;
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define lb(x) (x&-(x))
const int N = 101010;
int a,b,c,d;
int main(){
	cin>>a>>b>>c>>d;
	if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d))
	printf("Yes\n");
	else printf("No\n");


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a, b, c) for(int a = (b); a <= (c); ++ a)
using namespace std;
template <class T> void rd(T &x){
  x = 0; int f = 1; char ch = getchar();
  while(ch < '0' || ch > '9'){ if(ch == '-') f = -1; ch = getchar(); }
  while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  x *= f;
}

typedef pair <int, int> pii;
#define fi first
#define se second

const int maxn = 1e5 + 5;
int n;
int dis[maxn], vis[maxn];

struct edge{ int v, w, nxt; }; vector <edge> e; int head[maxn];

void adde(int u, int v, int w){
  e.push_back((edge){v, w, head[u]});
  head[u] = e.size() - 1;
}

void dijkstra(){
  memset(dis, 0x3f, sizeof(dis));
  priority_queue <pii> q; q.push(pii(dis[1] = 1, 1));
  while(!q.empty()){
	int u = q.top().se; q.pop();
	if(vis[u]) continue; vis[u] = 1;
	for(int i = head[u]; ~i; i = e[i].nxt){
	  int v = e[i].v;
	  if(dis[v] > dis[u] + e[i].w){
		dis[v] = dis[u] + e[i].w;
		q.push(pii(-dis[v], v));
	  }
	}
  }
}

int main(){
  memset(head, -1, sizeof(head));
  rd(n);
  rep(i, 0, n - 1){
	adde(i, (i + 1) % n, 1);
	adde(i, i * 10 % n, 0);
  }
  dijkstra();
  printf("%d\n", dis[0]);
  return 0;
}


Measured memory_bytes: 5236
using System;
using System.Linq;

namespace arc091_a
{
    class Program
    {
        static void Main(string[] args)
        {
            var HW = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
            Console.WriteLine(Math.Abs((HW[0] - 2) * (HW[1] - 2)));
        }
    }
}


Measured memory_bytes: 11348
# -*- coding: utf-8 -*-

n = int(input())

shop = []
for i in range(n):
    s, p = input().split()
    p = int(p)

    shop += [{'idx': i+1, 'val':s+f'{100-p:03}'}]

shop_sorted = sorted(shop, key=lambda x:x['val'])

for shop in shop_sorted:
    print(shop['idx'])


Measured memory_bytes: 9108
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)
#define cio ios::sync_with_stdio(false);

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    int n,x,y;
    scanf("%d %d %d",&n,&x,&y);
    vector<int> dis;
    int d;
    for (int i = 1;i <= n;i ++)
    {
        for (int j = i + 1;j <= n;j ++)
        {
            d = 0;
            if (i < x) {
                if (j <= x) d += j - i;
                else {
                    d += x - i;
                    if (j > x && j < y) d += min(j - x,y - j + 1);
                    else d += j - y + 1;
                }
            } else if (i >= x && i <= y) {
                if (j <= y) d += min(j - i,y - x + 1 - (j - i));
                else {
                    d += j - y;
                    d += min(y - i,i - x + 1);
                }
            } else {
                d += j - i;
            }
//            printf("%d %d: %d\n",i,j,d);
            dis.push_back(d);
        }
    }
    int k[2010] = {0};
    for (auto i = dis.begin();i != dis.end();i ++)
    {
        k[*i] ++;
    }
    for (int i = 1;i < n;i ++)
    {
        printf("%d\n",k[i]);
    }
    return 0;
}


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

int main() {
    ll N, T; cin >> N >> T;
    ll ans = 0;
    ll prev; cin >> prev;
    for (int i = 1; i < N; i++)
    {
        ll t; cin >> t;
        if(prev+T<t) ans += T;
        else ans += t-prev;
        prev = t;
    }
    ans += T;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
	#include<vector>
	using namespace std;
	int main(){
	 
	 for(int i=1;i<=9;i++){
	 	for(int j=1;j<=9;j++){
	 		cout <<i <<"x" << j << "=" << i*j <<endl;
	 	}
	 	
	 }

	  return 0;

	}


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

int main(){
	
  int A,B;
  cin >> A >> B;
  vector<string>N(A);
  
  for (int i=0; i<A; i++) {
  	cin >> N.at(i);
  }
  
  sort(N.begin(),N.end());
  string ans;
  for (int i = 0; i < A; i++){
    ans += N.at(i);
  }
  cout << ans << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  vector<LP> v[n];
  rep(i,n-1){
      ll uu,vv,ww;cin >> uu >> vv >> ww;
      uu--;
      vv--;
      v[uu].push_back(mp(vv,ww));
      v[vv].push_back(mp(uu,ww));
  }
  int col[n];
  rep(i,n){
      col[i] = 2;
  }
  col[0] = 0;
  queue<ll> q;
  q.push(0);
  while(q.size()){
      ll now = q.front();
      q.pop();
      rep(i,v[now].size()){
          ll to = v[now][i].first;
          ll dis = v[now][i].second;
          if(col[to]==2){
              if(dis%2){
                  col[to] = 1- col[now];
              }else{
                  col[to] = col[now];
              }
              q.push(to);
          }
      }
  }
  rep(i,n){
      cout << col[i] << endl;
  }
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n,m;
  cin >>n>>m;
  vector<vector<int>> p(n+1, vector<int>(0));
  rep(i,m){
    int x,y;
    cin >>x>>y;
    p[x].push_back(y);
  }
  //is duplicated?
  rep1(i,n){
    if(p[i].size() < 2) continue;
    rep(j,p[i].size()-1){
      if(p[i][j] != p[i][j+1]){
        cout << -1 << endl;
        return 0;
      }
    }
  }
  //is Top 0?
  if (p[1].size() > 0){
    if (p[1][0] == 0){
      if (n > 1){
        cout << -1 << endl;
        return 0;
      }
    }
  }else{
    if (n > 1){
      p[1].push_back(1);
    }else{
      p[1].push_back(0);
    }
  }
  //ans
  rep1(i,n){
    if(p[i].size() > 0) cout << p[i][0];
    else cout << 0;
  }
  cout << endl;
}


Measured memory_bytes: 256
import sys
from bisect import bisect_left

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    if len(A) != len(set(A)) or len(B) != len(set(B)):
        print(0)
        exit()
    A.sort()
    B.sort()
    As = set(A)
    Bs = set(B)
    res = 1
    for x in reversed(range(1, n * m + 1)):
        if x in As and x in Bs:
            continue
        elif x in As:
            res *= m - bisect_left(B, x)
        elif x in Bs:
            res *= n - bisect_left(A, x)
        else:
            s = m - bisect_left(B, x)
            t = n - bisect_left(A, x)
            res *= s * t - (n * m - x)
        res %= mod
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9288
#include <bits/stdc++.h>
using namespace std;
//A - Libra
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int left  = a + b;
  int right = c + d;
  
  if(left == right)
    cout << "Balanced" << endl;
  else if(left > right)
    cout << "Left" << endl;
  else if(left < right)
    cout << "Right" << endl;
  else
    cout << "error" << endl;
  
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	
	int N, A, B;
	cin >> N >> A >> B;
	
	int a[3] = {};
	
	for(int i = 0; i < N; i++){
		int P;
		cin >> P;
		if(P <= A){
			a[0] += 1;
		}else if(P <= B){
			a[1] += 1;
		}else{
			a[2] += 1;
		}
	}
	
	cout << min(min(a[0], a[1]), a[2]) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD = 1000000007;
ll cnt =0,ans=0;
const int MAX = 510000;

int main(){

    ll n;cin >> n;

   string s;
   
   while(n){
   n--;
   s += ('a' + (n%26));
   n/=26;
   }
   reverse(s.begin(),s.end());
   cout << s << endl;
}
       


Measured memory_bytes: 3632
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var NK = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = NK[0];
            var K = NK[1];
            var lList = Console.ReadLine().Split(' ').Select(int.Parse);

            var output = lList.OrderByDescending(x => x)
                .Take(K)
                .Sum();

            Console.WriteLine(output);
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 13396
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static int getFactorial( int x ){
        int ans = 1;
        for( int i = 1 ; i <= x ; i++ ){
            ans *= i;
        }
        return ans;
    }

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt( in.nextLine() );
        List<Integer> x = new ArrayList<>();
        List<Integer> y = new ArrayList<>();

        for( int i = 0 ; i < n ; i++ ){
            String[] params = in.nextLine().split(" ");
            x.add( Integer.parseInt( params[0]));
            y.add( Integer.parseInt( params[1]));
        }

        double ans = 0.0;

        for( int i = 0 ; i < n - 1 ; i++ ){
            for( int j = i + 1 ; j < n ; j++ ){
                int xi = x.get( i );
                int yi = y.get( i );
                int xj = x.get( j );
                int yj = y.get( j );
                int calc = (xi - xj )*(xi - xj) + (yi - yj ) * ( yi - yj );
                double distance = Math.sqrt( calc < 0 ? calc * -1 : calc );
                ans += distance * 2 * getFactorial(n-1);
            }
        }

        System.out.println( ans / getFactorial( n ) );

    }

}


Measured memory_bytes: 22868
#include<cstdio>
#include<cmath>
#include<iostream>
typedef long long ll;
using namespace std;

char a[100000];
int main()
{
	int N,K,X,Y,sum;
	scanf("%d%d%d%d",&N,&K,&X,&Y);
	if(N <= K)
	sum = N * X;
	else
	sum = K * X + (N - K) * Y;
	printf("%d\n",sum);
	return 0;
}


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

using namespace std;

typedef long long int ll;

const int N = 1e5 + 5;

vector < int > p (N), sz (N, 1);
vector < vector < int > > g (N);

int find (int u) {
  if (u == p[u]) return u;
  return p[u] = find (p[u]);
}

void merge (int u, int v) {
  u = find (u);
  v = find (v);
  if (u != v) {
    if (sz[u] > sz[v]) swap (u, v);
    p[u] = v;
    sz[v] += sz[u];
  }
}

void merge_array (int u, int v) {
  vector < int > tmp;
  int i = 0, j = 0;
  while (i < g[u].size() && j < g[v].size()) {
    if (g[u][i] < g[v][j]) {
      tmp.push_back (g[v][j]);
      j++;
    } else {
      tmp.push_back (g[u][i]);
      i++;
    }
  }
  while (i < g[u].size()) {
    tmp.push_back (g[u][i]);
    i++;
  }
  while (j < g[v].size()) {
    tmp.push_back (g[v][j]);
    j++;
  }
  g[u] = tmp;
  g[v].clear();
}

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

  int n, m;
  cin >> n >> m;
  vector < int > a (n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    p[i] = i;
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    merge (u, v);
  }

  for (int i = 0; i < n; i++) g[find (i)].push_back (a[i]);

  for (int i = 0; i < n; i++) sort (g[i].begin(), g[i].end(), greater < int > ());

  ll ans = 0;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (g[i].size() > 0) ans += g[i].back(), g[i].pop_back(), cnt++;
  }

  if (cnt == 1) {
    cout << 0 << '\n';
    return 0;
  }

  cnt -= 2;
  vector < int > v;
  for (int i = 0; i < n; i++) {
    for (auto to : g[i]) v.push_back(to);
  }
  sort (v.begin(), v.end());

  if (cnt > v.size()) {
    cout << "Impossible\n";
    return 0;
  }

  for (int i = 0; i < cnt; i++) ans += v[i];

  cout << ans << '\n';
}


Measured memory_bytes: 9864
#include <algorithm>
#include <cstdio>

const int N=100005;

int L[N],R[N],v[N],fst[N],tot,rt;
bool flag=1;
struct Edge{
	int to,nxt;
}e[N*2];

void addedge(int x,int y){
	e[++tot].to=y;e[tot].nxt=fst[x];fst[x]=tot;
}

void dfs(int x,int father,bool typ){
	if (L[x]==R[x] && (L[x]&1)!=typ){
		flag=0;return;
	}
	for (int i=fst[x];i && flag;i=e[i].nxt){
		int y=e[i].to;
		if (y!=father){
			dfs(y,x,typ^1);
			L[x]=std::max(L[x],L[y]-1);
			R[x]=std::min(R[x],R[y]+1);
			if (L[x]>R[x]) flag=0;
		}
	}
}

void dfs2(int x,int father){
	for (int i=fst[x];i;i=e[i].nxt){
		int y=e[i].to;
		if (y!=father){
			if (v[x]+1>=L[y] && v[x]+1<=R[y]) v[y]=v[x]+1;
				else v[y]=v[x]-1;
			dfs2(y,x);
		}
	}
}

int main(){
	int n,k;
	scanf("%d\n",&n);
	for (int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		addedge(x,y);
		addedge(y,x);
	}
	for (int i=1;i<=n;i++) L[i]=-(R[i]=100000000);
	scanf("%d\n",&k);
	for (int i=1;i<=k;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		L[rt=x]=R[x]=y;
	}
	dfs(rt,0,L[rt]&1);
	if (flag){
		v[rt]=L[rt];
		dfs2(rt,0);
		printf("Yes\n");
		for (int i=1;i<=n;i++) printf("%d\n",v[i]);
	}
	else printf("No\n");
}

Measured memory_bytes: 10240
#include <bits/stdc++.h>
#define ll long long
using namespace std;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if (a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r = a % b)) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  ll A, B, C, D;
  cin >> A >> B >> C >> D;
  ll ans;
  ans = B - A + 1;
  ans -= B / C;
  ans -= B / D;
  ans += B / ((C / euclidean_gcd(C, D)) * D);
  ans += (A - 1) / C;
  ans += (A - 1) / D;
  ans -= (A - 1) / ((C / euclidean_gcd(C, D)) * D);
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 100010
using namespace std;
struct poi{
int x,y,t;
}a[maxn];
int n;
int main()
{
	scanf("%d",&n);
	a[0].y=a[0].x=a[0].t=0;
	for(int i=1;i<=n;++i)
	scanf("%d%d%d",&a[i].t,&a[i].x,&a[i].y);
	for(int i=1;i<=n;++i)
	if(abs(a[i].x-a[i-1].x)+abs(a[i].y-a[i-1].y)-abs(a[i].t-a[i-1].t)>0||(abs(a[i].x-a[i-1].x)+abs(a[i].y-a[i-1].y)-abs(a[i].t-a[i-1].t))%2!=0) 
		{
			cout<<"No";
			return 0;
		}
		cout<<"Yes";
		return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
vector <int> a;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(10);
    cin >> n;
    a.resize(n);
    for(auto &i : a) cin >> i;
    double cur = 0;
    for(auto &i : a) cur += 1.0 / i;
    cur = 1 / cur;
    cout << cur << endl;
}


Measured memory_bytes: 256
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

typedef pair<pii,pii> tup;

int dat[505][505];
vector<tup> path;
vector<tup> res;

int generate_path(int h, int w){
    if(h==1 && w==1) return 0;
    path.clear();
    //
    vii lst; lst.clear();
    //do
    REP(i,1,h){
        if(i%2 == 0) REP(j,1,w) lst.pb(mp(i,j));
        if(i%2 == 1) REV(j,w,1) lst.pb(mp(i,j));
    }
    lst.pb(lst[0]);
    //generate path
    int sz = w*h;
    FOR(i,sz) path.pb(mp(lst[i], lst[i+1]));
    return 1;
}

int main(){
    int h,w; scanf("%d %d", &h, &w);
    REP(i,1,h) REP(j,1,w) scanf("%d", &dat[i][j]), dat[i][j] %= 2;
    generate_path(h,w);
    //
    deque<pii> lst; while(!lst.empty()) lst.pof();
    for(tup x: path) if(dat[x.fi.fi][x.fi.se]) lst.pb(x.fi);
    //remove unnecesary data
    if((int)lst.size()%2 == 1) lst.pob();
    if(!path.empty()) path.pob();
    //do
    int is_print = 0;
    res.clear();
    for(tup x: path){
        if(lst.empty()) break;
        if(x.fi==lst.front()) is_print ^= 1, lst.pof();
        if(is_print) res.pb(x);
    }
    //print
    printf("%d\n", (int)res.size());
    for(tup x: res) printf("%d %d %d %d\n", x.fi.fi, x.fi.se, x.se.fi, x.se.se);
    return 0;
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
#define vi vector<int>
using namespace std;
const int mod=998244353,i2=499122177;
int n,s;
vi a,b,ans;
int POW(int x,int y){
	int ret=1;
	while(y)y&1?ret=1ll*ret*x%mod:0,x=1ll*x*x%mod,y>>=1;
	return ret;
}
vi Solve(vi x,vi y){
	if(x.size()==1){
		vi ret(1);
		return ret[0]=(x[0]?1ll*y[0]*POW(x[0],mod-2)%mod:114514),ret;
	}
	vi t1(x.size()>>1),t2(y.size()>>1),a1,a2;
	for(int i=0;i<t1.size();++i)(t1[i]=x[i<<1]+x[i<<1|1])>=mod?t1[i]-=mod:0,(t2[i]=y[i<<1]+y[i<<1|1])>=mod?t2[i]-=mod:0;
	a1=Solve(t1,t2);
	for(int i=0;i<t1.size();++i)(t1[i]=x[i<<1]-x[i<<1|1])<0?t1[i]+=mod:0,(t2[i]=y[i<<1]-y[i<<1|1])<0?t2[i]+=mod:0;
	a2=Solve(t1,t2);
	for(int i=0;i<a1.size();++i)x[i<<1]=1ll*(a1[i]+a2[i])*i2%mod,x[i<<1|1]=1ll*(a1[i]-a2[i]+mod)*i2%mod;
	return x;
}
int main(){
	scanf("%d",&n),a.resize(1<<n),b.resize(1<<n);
	for(int i=0;i<(1<<n);++i)scanf("%d",&a[i]),s+=a[i];
	s=POW(s,mod-2);
	for(int i=0;i<(1<<n);++i)a[i]=1ll*a[i]*s%mod,b[i]=mod-1;
	--a[0],b[0]+=(1<<n)-mod;
	ans=Solve(a,b);
	for(int i=1;i<ans.size();++i)(ans[i]-=ans[0])<0?ans[i]+=mod:0;
	puts("0");
	for(int i=1;i<ans.size();++i)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 12528
#include <iostream>
#include <string>
#include <array>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <cctype>
#include <map>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <queue>

#include <iomanip>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

using namespace std;

bool is_integer( float x ){
    return floor(x)==x;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

//yakusuu rekkyo
vector<long long> enum_divisors(long long N) {
    vector<long long> res;
    for (long long i = 1; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            // push its partner
            if (N/i != i) res.push_back(N/i);
        }
    }

    sort(res.begin(), res.end());
    return res;
}


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // exponential

        // divide as much as you can
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // push the result
        res.push_back({a, ex});
    }

    // last num (if the lasting n is prime number and not 1)
    if (N != 1) res.push_back({N, 1});
    return res;
}



int main() {
    pair<long double,long double> pr[9];
    vector<int> h;
    int n; cin >> n;
    long double k = 1;
    long double tmpx,tmpy;
    long double ans = 0;

    rep(i,n){
        cin >> tmpx >> tmpy;
        pr[i] = make_pair(tmpx,tmpy);
        h.push_back(i);
        k *= i+1;
    }


    
    do {
        rep(i,n-1){
            ans += sqrtl(powl((pr[h[i]].first-pr[h[i+1]].first),2) + pow((pr[h[i]].second-pr[h[i+1]].second),2));
        }
    } while (next_permutation(h.begin(), h.end()));

    cout << fixed << setprecision(15) << ans/k << endl;

    return 0;
}











Measured memory_bytes: 3836
n,m = map(int,input().split())
if m == 0:
    print(1)
    import sys
    sys.exit()

u = []
graph = [[] for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a-=1
    b-=1
    graph[a].append(b)
    graph[b].append(a)

dist = [-1]*n
from collections import deque
q = deque([])

def bfs(vert,num):
    q.append(vert)
    dist[vert]=num
    while q:
        v = q.popleft()
        for i in graph[v]:
            if dist[i]!=-1:
                continue
            dist[i]=num
            q.append(i)

for j in range(n):
    if dist[j]==-1:
        bfs(j,j)

dist = list(dist)
from collections import Counter
e = Counter(dist)
print(e.most_common()[0][1])

Measured memory_bytes: 55612
#include <iostream>
#include <algorithm>
using namespace std;
int num[3], rem[3], res = 0;
int main(void){
    // Your code here!
    cin >> num[0] >> num[1] >> num[2];
    rem[0] = num[0] % 2;
    rem[1] = num[1] % 2;
    rem[2] = num[2] % 2;
    int sum = rem[0] + rem[1] + rem[2];
    
    if ((rem[0] == 1 && sum == 1) || (rem[0] == 0 && sum == 2)){
        num[1]++;
        num[2]++;
        res++;
    } if ((rem[1] == 1 && sum == 1) || (rem[1] == 0 && sum == 2)) {
        num[2]++;
        num[0]++;
        res++;
    } if ((rem[2] == 1 && sum == 1) || (rem[2] == 0 && sum == 2)) {
        num[0]++;
        num[1]++;
        res++;
    }
    sort(num, num + 3);
    cout << num[2] - (num[0] + num[1]) / 2 + res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];

    if(n == 1){
        cout << 1 << endl;
        return 0;
    }

    using P = pair<int, int>;
    map<P, int> m;
    rep(i, n){
        rep(j, n){
            if(i == j) continue;
            m[{x[i]-x[j], y[i]-y[j]}]++;
        }
    }
    int ans = 1e9;
    for(auto p: m){
        chmin(ans, n-p.second);
    }

    cout << ans << endl;
}

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

typedef long long ll;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = a; i < (b); ++i)
#define rep(i, n)     repd(i, 0, n)
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YesNo(x)      cout << ((x) ? "Yes" : "No") << endl
#define YESNO(x)      cout << ((x) ? "YES" : "NO") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )

ll cnt(string s) {
	bool flag = false;
	ll l = s.length();
	ll ret = 0;

	rep(i, l) {
		if(flag && (s[i] == 'B')) {
			++ret;
			flag = false;
		} else if(s[i] == 'A') {
			flag = true;
		} else {
			flag = false;
		}
	}

	return ret;
}

int main(int argc, const char* argv[]) {
	ll ret = 0;

	ll n;
	cin >> n;

	ll bx = 0;
	ll xa = 0;
	ll ba = 0;

	rep(i, n) {
		string s;
		cin >> s;
		ret += cnt(s);

		if(s[0] == 'B') {
			if(s[s.length() - 1] == 'A') {
				++ba;
			} else {
				++bx;
			}
		} else {
			if(s[s.length() - 1] == 'A') {
				++xa;
			}
		}
	}

	if(xa > 0) {
		if(bx > 0) {
			ret += ba + min(bx, xa);
		} else {
			ret += ba;
		}
	} else {
		if(bx > 0) {
			ret += ba;
		} else {
			if(ba != 0) {
				ret += ba - 1;
			}
		}
	}


	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <numeric>
#include <chrono>
#include <bitset>
#include <tuple>
#include <queue>
#include <map>
#include <cstring>
#include <cassert>
#include <math.h>
#define pi acos(-1)
using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;


int main() {
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int tc = 1; 
    // scanf("%d", &tc);
    for(int cn = 1; cn <= tc; cn++) {
        long long a, b, h, m; cin >> a >> b >> h >> m;
        long double an = abs((float) 30 * h + 0.5 * m - 6 * m);
        an = min(an, 360 - an);
        long double ans = (double)a * a + b * b - 2 * a * b * (double)cos((pi * an) / (double)180);
        printf("%.20lf\n", (double)sqrt(ans));
    }  
    return 0;
}

Measured memory_bytes: 4068
import java.util.*;

public class Main {
    static long MOD = 1000000007;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[3];
        
        long ans = 1;
        while (n-- > 0) {
            int num = sc.nextInt();
            
            long count = 0;
            for (int i = 0; i < 3; i++) {
                if (array[i] == num) count++;
            }
            
            if (count == 0) {
                System.out.println(0);
                return;
            }
            
            ans *= count;
            ans %= MOD;
            
            for (int i = 0; i < 3; i++) {
                if (array[i] == num) {
                    array[i]++;
                    break;
                }
            }
        }
        System.out.println(ans);
    }
}


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

using namespace std;

typedef long long ll;

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

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()


int main(){
    int N,W;
    cin>>N>>W;
    vector<int> v(N),w(N);
    rep(i,N)cin>>v[i]>>w[i];

    int dp[11000]={INF};
    dp[0]=0;

    for(int i=0;i<N;i++){
        for(int j=w[i];j<=W;j++){
            dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
        }
    }

    int ANS=0;
    rep(i,W+1)ANS=max(ANS,dp[i]);

    cout<<ANS<<endl;

    return 0;
}

//a=97,z=122


Measured memory_bytes: 3168
#include <stdio.h>
 
int main(){
  int n,k,x,y;
  int total=0;
    
  scanf("%d",&n);
  scanf("%d",&k);
  scanf("%d",&x);
  scanf("%d",&y);
  
  if(n<=k){
    total=n*x;
  } else {
    total=k*x;
    total+=((n-k)*y);
  }
  
  printf("%d",total);
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<tuple>
#include<utility>
#include<functional>
#include<algorithm>

#define LL long long

using namespace std;

LL h,w;

int main() {
	cin>>h>>w;
	if(h==1 || w==1)cout<<1<<endl;
	else if(h*w%2ll==1ll)cout<<(w+1ll)*(h+1ll)/4ll+(w-1ll)*(h-1ll)/4ll<<endl;
	else cout<<h*w/2ll<<endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
 using namespace std;
 int n,t=2,f=1;
 long long ans[100005];
 struct N{int data,num;}a[100005];
 bool comp(N x,N y){if(x.data==y.data) return x.num<y.num;else return x.data>y.data;}
 int main(){
    scanf("%d",&n);
     for(int i=1;i<=n;++i) scanf("%d",&a[i].data),a[i].num=i;
     sort(a+1,a+n+1,comp);
     while(t<=n){
        while(a[t].data==a[t-1].data) t++;
         ans[a[f].num]+=1ll*(a[f].data-a[t].data)*(t-1);
         if(a[t].num>a[f].num) a[f].data=a[t].data;
         else f=t;
     t++;
    }
    ans[a[f].num]+=1ll*a[f].data*n;
     for(int i=1;i<=n;++i) printf("%lld\n",ans[i]);
}

Measured memory_bytes: 2688
#include<cstring>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<utility>
#include<queue>
#include<cmath>
#include<functional>
#include<vector>
#define int long long
#define N 100005
#define K 100
#define INF 1e7
using namespace std;
int f[3001][3001],n,m,vis[3001][3001];
char s[3001],t[3001];
bool flag=false,a[26];
void print(int x,int y)
{
	if(!x||!y)return;
    if(!vis[x][y]){print(x-1,y-1);printf("%c",s[x-1]);}
    else if(vis[x][y]==1)print(x-1,y);
    else print(x,y-1);
}
signed main()
{
    scanf("%s %s",s,t);
    n=strlen(s),m=strlen(t);
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)
	{
		if(s[i-1]==t[j-1])f[i][j]=f[i-1][j-1]+1,vis[i][j]=0;
        else if(f[i-1][j]>=f[i][j-1])f[i][j]=f[i-1][j],vis[i][j]=1;
        else f[i][j]=f[i][j-1],vis[i][j]=2;
	}
    print(n,m);
    return 0;
}

Measured memory_bytes: 140928
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}
function Main(input) {
  input = myconv(input,4);
  var A = input[0];
  var B = input[1];
  var output = 0;
  for(var i = A; i <= B; i++){
    var tmp = myconv(i.toString(),6);
    if(tmp[0] == tmp[4] && tmp[1] == tmp[3]){
       output++;
    }
  }
  myout(output);
}
Main(myin());

Measured memory_bytes: 13188
import java .util.Scanner;
 
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int s = Integer.parseInt(sc.next());
    	int w = Integer.parseInt(sc.next());
    
 		if(w >= s){
     	 	System.out.println("unsafe");
    	}else{
      		System.out.println("safe");
    	}
    }
}

Measured memory_bytes: 35760
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define double long double
#define ll long long
#define INF LLONG_MAX/3
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int c[5],a,b;
signed main(){
	rep(i,3){
		cin>>a>>b;
		c[a]++;
		c[b]++;
	}
	int cnt=0;
	for(int i=1;i<=4;i++){
		if(c[i]%2)cnt++;
	}
	if(cnt==0||cnt==2)puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 256
! 2019.11.24
!
      program answer
      implicit none
      character(len=10000) :: S
      character(len=10000) :: res
      integer :: N
      integer :: i
      character,external :: ch
      intrinsic len_trim
!
      read(*,*) N
      read(*,*) S
!
      do i=1,len_trim(S)
        res(i:i) = ch(S(i:i),N)
      end do
      write(*,*) res(1:len_trim(S))
      end program answer
!
      function ch(S,N) result(res)
      implicit none
      integer :: N
      integer :: S_N
      character(len=1) :: S
      character(len=1) :: res
      intrinsic mod
!
      res = '1'
      select case(S)
        case('A')
          S_N = 0
        case('B')
          S_N = 1
        case('C')
          S_N = 2
        case('D')
          S_N = 3
        case('E')
          S_N = 4
        case('F')
          S_N = 5
        case('G')
          S_N = 6
        case('H')
          S_N = 7
        case('I')
          S_N = 8
        case('J')
          S_N = 9
        case('K')
          S_N = 10
        case('L')
          S_N = 11
        case('M')
          S_N = 12
        case('N')
          S_N = 13
        case('O')
          S_N = 14
        case('P')
          S_N = 15
        case('Q')
          S_N = 16
        case('R')
          S_N = 17
        case('S')
          S_N = 18
        case('T')
          S_N = 19
        case('U')
          S_N = 20
        case('V')
          S_N = 21
        case('W')
          S_N = 22
        case('X')
          S_N = 23
        case('Y')
          S_N = 24
        case('Z')
          S_N = 25
      end select
!
      S_N = mod(S_N+N,26)
!
      select case (S_N)
        case(0)
          res = 'A'
        case(1)
          res = 'B'
        case(2)
          res = 'C'
        case(3)
          res = 'D'
        case(4)
          res = 'E'
        case(5)
          res = 'F'
        case(6)
          res = 'G'
        case(7)
          res = 'H'
        case(8)
          res = 'I'
        case(9)
          res = 'J'
        case(10)
          res = 'K'
        case(11)
          res = 'L'
        case(12)
          res = 'M'
        case(13)
          res = 'N'
        case(14)
          res = 'O'
        case(15)
          res = 'P'
        case(16)
          res = 'Q'
        case(17)
          res = 'R'
        case(18)
          res = 'S'
        case(19)
          res = 'T'
        case(20)
          res = 'U'
        case(21)
          res = 'V'
        case(22)
          res = 'W'
        case(23)
          res = 'X'
        case(24)
          res = 'Y'
        case(25)
          res = 'Z'
      end select
      end function ch

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int a,b,c;

  scanf("%d %d %d",&a,&b,&c);
  
  if(a >= b && a >= c && c >= b){
    printf("%d %d %d\n",b,c,a);
  }
  else if(a >= b && a >= c && b >= c){
    printf("%d %d %d\n",c,b,a);
  }
  else if (b >= a && b >= c && a >= c){
    printf("%d %d %d\n",c,a,b);
  }
  else if (b >= a && b >= c && c >= a){
    printf("%d %d %d\n",a,c,b);
  }
  else if (c >= a && c >= b && a >= b){
    printf("%d %d %d\n",b,a,c);
  }
  else if(c >= a && c >= b && b >= a){
    printf("%d %d %d\n",a,b,c);
  }
  return 0;
}

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

int D,N;

int main()
{
	int i;
	scanf("%d%d",&D,&N);
	if(N<100)
	{
		printf("%d",N);
		for(i=1; i<=D; i++)
		printf("00");
		return 0;
	}
	else
	{
		printf("101");
		for(i=1; i<=D; i++)
		printf("00");
	}
}
//10100

Measured memory_bytes: 256
class Dice:
    def __init__(self,my_label):
        self.top,self.front,self.right,self.left,self.back,self.bottom = [int(x) for x in my_label]

    def Roll(self,i):
        if i == 0:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.right, self.front, self.bottom, self.top, self.back, self.left
        
        if i == 1:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.left, self.front, self.top, self.bottom, self.back, self.right
        
        if i == 2:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.back, self.top, self.right, self.left, self.bottom, self.front
            
        if i == 3:
            self.top, self.front, self.right, self.left, self.back, self.bottom = \
            self.front, self.bottom, self.right, self.left, self.top, self.back

    def Open(self):
        print(self.top)

def CheckData(data,top,front):
    for i in range(len(data)):
        if(data[i][0] == top and data[i][1] == front):
            print(data[i][2])
            break
            
def CheckDice(data1,data2):
    if(data1 == data2):
        print("Yes")
        
    else:
        print("No")

def MakeData(dice):
    num_data = 4 * 6 -1
    
    dataset = list()
    data = [dice.top, dice.front, dice.right]

    dataset.append(data)
    
    isOnly = True
    
    n = 0
    while 0 < num_data:
        n += 1
        if (n > 1000):break
        data = [dice.top, dice.front, dice.right]

        isOnly = True
        for i in range (len(dataset)):
            if(data == dataset[i]):
                isOnly = False
                break
        if isOnly == True:
            dataset.append(data)
            dataset.sort()
            num_data -= 1
        
        dice.Roll(int(random.random() * 4))
    return dataset

import random

my_label1 = [int(x) for x in input().split(" ")]
my_label2 = [int(x) for x in input().split(" ")]

dice1 = Dice(my_label1)
dice2 = Dice(my_label2)

data1 = MakeData(dice1)
data2 = MakeData(dice2)

CheckDice(data1,data2)


Measured memory_bytes: 8212
n, x = (int(i) for i in input().split()) 
a = sorted(list(set([int(i) for i in input().split()])))

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

import functools

if len(a) == 1:
    print(abs(a[0] - x))
    exit()

diff = []
for i in range(len(a)-1):
    diff.append(a[i+1] - a[i])

list_gcd = functools.reduce(gcd, diff)

import bisect

bi_index = bisect.bisect_left(a, x)
if bi_index == len(a):
    print(gcd(list_gcd, x-a[-1]))
    exit()

if a[bi_index] == x:
    print(list_gcd)
    exit()

if bi_index == 0:
    print(gcd(list_gcd, a[0]-x))
    exit()

print(functools.reduce(gcd, [list_gcd, x-a[bi_index-1], a[bi_index]-x ]))


Measured memory_bytes: 14480
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	ll x; double p;
  cin>>x>>p;
  if(x%2) printf("%.7lf\n", ((double)x+1)/2/p*100);
  else printf("%.7lf\n", ((double)x)/2/p*100);
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, n)
	for i := range p {
		fmt.Scan(&p[i])
	}

	cnt := 0
	for i := 1; i < n-1; i++ {
		if (p[i-1] < p[i] && p[i] < p[i+1]) || (p[i+1] < p[i] && p[i] < p[i-1]) {
			cnt++
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
sa=list(str(input()))
sb=list(str(input()))
sc=list(str(input()))

ans={"a":"A","b":"B","c":"C"}
card={"a":sa,"b":sb,"c":sc}

turn="a"

while True:
    if len(card[turn])==0:
        break

    next_turn=card[turn][0]

    card[turn]=card[turn][1:]

    turn=next_turn

print(ans[turn])


Measured memory_bytes: 3064
str = gets.chomp
a = str[0..1]
b = str[2..3]

if a[0] == "0" and a[1] != "0"
    flag_a = true
elsif a[0] == "1" and (a[1] == "0" or a[1] == "1" or a[1] == "2")
    flag_a = true
else
    flag_a = false
end

if b[0] == "0" and b[1] != "0"
    flag_b = true
elsif b[0] == "1" and (b[1] == "0" or b[1] == "1" or b[1] == "2")
    flag_b = true
else
    flag_b = false
end

if flag_a and flag_b
    puts "AMBIGUOUS"
elsif flag_a
    puts "MMYY"
elsif flag_b
    puts "YYMM"
else
    puts "NA"
end

Measured memory_bytes: 1788