akhauriyash/Code-Regression huggingface dataset:
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define s(v)       sort(v.begin(),v.end())
#define r(v)       reverse(v.begin(),v.end())
#define pf         printf
#define sf         scanf
#define GCD(x,y)   __gcd(x, y)
#define pb         push_back
#define ll         long long
#define vs         v.size()
#define ss         s.size()
using namespace std;
int main()
{
    int x;
    cin>>x;
    if(x==1) cout<<"0"<<endl;
    else cout<<"1"<<endl;
    return 0;
}



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

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            return Array().Select(int.Parse).ToArray();
        }
        public long[] LongArray()
        {
            return Array().Select(long.Parse).ToArray();
        }
    }

    class Program
    {
        private int A, B;
        private void Scan()
        {
            var sc = new Scanner();
            A = sc.NextInt();
            B = sc.NextInt();
        }

        public void Solve()
        {
            Scan();
            var ans = new char[100][];
            for (int i = 0; i < 100; i++)
            {
                ans[i] = new char[100];
                for (int j = 0; j < 100; j++)
                {
                    ans[i][j] = i < 50 ? '.' : '#';
                }
            }

            for (int i = 1; i < 50; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    if ((i + j) % 3 == 0)
                    {
                        if (B > 1)
                        {
                            ans[i][j] = '#';
                            B--;
                        }
                    }
                }
            }

            for (int i = 51; i < 100; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    if ((i + j) % 3 == 0)
                    {
                        if (A > 1)
                        {
                            ans[i][j] = '.';
                            A--;
                        }
                    }
                }
            }
            Console.WriteLine("100 100");
            for (int i = 0; i < 100; i++)
            {
                Console.WriteLine(new string(ans[i]));
            }
        }

        static void Main(string[] args)
        {
            new Program().Solve();
        }
    }
}

Measured memory_bytes: 13268
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

string s;
vector<char> vs;
vector<char> vc;
vector<int> vx;

int main(){
  cin >> s;
  int n = s.size();
  REP(i,n){
    vs.push_back(s[i]);
    if(s[i]!='x')
      vc.push_back(s[i]);
  }
  int m = vc.size();
  REP(i,vc.size()){
    if(vc[i]!=vc[vc.size()-1-i]){
      cout << -1 << endl;
      return 0;
    } 
  }
  int cnt=0;
  REP(i,n){
    if(s[i]=='x')
      vx.push_back(cnt);
    else
      cnt++;
  }
  cnt=0;
  while(vx.size()){
    vector<int>::iterator it = lower_bound(vx.begin(),vx.end(),m-vx[0]);
    if(distance(vx.begin(),it) != vx.size()&& vx[0]==m-vx[distance(vx.begin(),it)]){
      if(m%2==1 || vx[0] != m/2){
	vx.erase(vx.begin());
	if(vx.size())
	  vx.erase(vx.begin()+distance(vx.begin(),it)-1);
      }else{
	vx.erase(vx.begin());
      }
    }else{
      vx.erase(vx.begin());
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int num;
    cin >> num;
    if(num%2==0){
      if(num%3==0 || num%5==0) continue;
      else{
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int n;cin>>n;
    int res = 0;
    vector<int>v;
    v.push_back(1);
    REP(i,2,n){
        int now = i;
        while(now<=n){
            now *= i;
            if(now>n)break;
            v.push_back(now);
        }
    }
    sort(ALL(v),greater<int>());
    cout<<v[0];
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())

cnt_ab = 0
cnt_ba = 0
cnt_last_a = 0
cnt_first_b = 0
for _ in range(n):
    s = input()
    cnt_ab += s.count("AB")

    b_flag, a_flag = False, False
    if s[0] == 'B':
        b_flag = True
    if s[-1] == 'A':
        a_flag = True

    if a_flag and b_flag:
        cnt_ba += 1
    elif b_flag:
        cnt_first_b += 1
    elif a_flag:
        cnt_last_a += 1

if cnt_ba >= 2:
    cnt_ab += cnt_ba - 1
    cnt_ba = 1

if cnt_ba == 1 and cnt_first_b >= 1 and cnt_last_a >= 1:
    cnt_ab += 2
    cnt_first_b -= 1
    cnt_last_a -= 1
elif cnt_ba == 1:
    if max(cnt_first_b, cnt_last_a) > 0:
        cnt_ab += 1

print(cnt_ab + min(cnt_first_b, cnt_last_a))


Measured memory_bytes: 3064
s = input()
sl = len(s)
div = ['dream', 'dreamer', 'erase', 'eraser']

s = s[::-1]
ans = ""
for i in range(4): div[i] = div[i][::-1]

for i in range(sl):
    ans += s[i]
    if ans in div:
        ans = ""

if len(ans) == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9180
h, w = map(int, input().split())

diffs = []
for y in range(h):
    row = map(int, input().split())
    diffs.append(list(row))

for y in range(h):
    row = map(int, input().split())
    for x, b in zip(range(w), row):
        diffs[y][x] = abs(diffs[y][x] - b)

m = 80 * (h + w)
dp = [[0 for j in range(w)] for k in range(h)]
d = m - diffs[0][0]
dp[0][0] = 1 << d

for y in range(h):
    for x in range(w):
        if x == y == 0:
            continue
        diff = diffs[y][x]
        if y != 0:
            dp[y][x] |= dp[y-1][x] << diff
            dp[y][x] |= dp[y-1][x] >> diff
        if x != 0:
            dp[y][x] |= dp[y][x-1] << diff
            dp[y][x] |= dp[y][x-1] >> diff

end = bin(dp[-1][-1])[2:][::-1]  # reverse

candidates = [abs(i-m) for i, b in enumerate(end) if b == '1']
ans = min(candidates)
print(ans)


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

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12

int main(void)
{
	//変数の宣言
	int n;
	static llong a[200010];
	static llong ruiseki[200010];
	llong int p,q,r,s;
	int left,right;
	int m;
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	llong int ans=0;
	int count=0;
	int temp,temp1,temp2;
	llong int max,min;
	int len;
	int sum=0;
	//データの読み込み
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=0;i<n;i++){
		if(i==0){
			ruiseki[0]=a[0];
		}else{
			ruiseki[i]=ruiseki[i-1]+a[i];
		}
	}
	
	ans=INF;
	for(i=1;i<n-2;i++){
		m=i;
		
		flag=0;
		left=0;right=m;
		while(flag==0){
			if(right-left<=1){
				if(r==m){
					p=ruiseki[left];
					q=ruiseki[m]-ruiseki[left];
					flag=1;
				}else if(llabs(ruiseki[m]-2*ruiseki[left])<llabs(ruiseki[m]-2*ruiseki[right])){
					p=ruiseki[left];
					q=ruiseki[m]-ruiseki[left];
					flag=1;
				}else{
					p=ruiseki[right];
					q=ruiseki[m]-ruiseki[right];
					flag=1;
				}
			}else{
				temp=(left+right)/2;
				if(ruiseki[m]<2*ruiseki[temp]){
					right=temp;
				}else{
					left=temp;
				}
			}
		}
		
		flag=0;
		left=m+1;right=n-1;
		while(flag==0){
			if(right-left<=1){
				if(r==n-1){
					r=ruiseki[left]-ruiseki[m];
					s=ruiseki[n-1]-ruiseki[left];
					flag=1;
				}else if(llabs(ruiseki[n-1]+ruiseki[m]-2*ruiseki[left])<llabs(ruiseki[n-1]+ruiseki[m]-2*ruiseki[right])){
					r=ruiseki[left]-ruiseki[m];
					s=ruiseki[n-1]-ruiseki[left];
					flag=1;
				}else{
					r=ruiseki[right]-ruiseki[m];
					s=ruiseki[n-1]-ruiseki[right];
					flag=1;
				}
			}else{
				temp=(left+right)/2;
				if(ruiseki[n-1]+ruiseki[m]<2*ruiseki[temp]){
					right=temp;
				}else{
					left=temp;
				}
			}
		}
		
		min=min(min(p,q),min(r,s));
		max=max(max(p,q),max(r,s));
		
		ans=min(ans,max-min);
	}
//	printf("計算部分終了\n");
	//出力
	
	printf("%lld",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



Measured memory_bytes: 3328
N,A=map(int,input().split())
x=list(map(int,input().split()))
X=max(max(x),A)
y=[x[i]-A for i in range(N)]
dp=[[0 for i in range(2*N*X+1)] for j in range(N+1)]
dp[0][N*X]=1
for j in range(1,N+1):
  for k in range(2*N*X+1):
    dp[j][k]=dp[j-1][k]
    if 0<= k-y[j-1] and k-y[j-1]<=2*N*X:
      dp[j][k]+=dp[j-1][k-y[j-1]]
print(dp[N][N*X]-1)

Measured memory_bytes: 5740
/**
*
* Author: MARS
* Lang: GNU C++14
*
**/

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

#define F first
#define S second
#define ii pair<int,int>

typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl pi = acos(-1);
const ll inf = 1LL<<30;
const dbl eps = 1e-9;
const ll mod = 1e9+7;

/** /////////// ** Code ** /////////// **/

const int N=200200;
vector<int>adj[N];
bool vis[N];
int cnt=0;

void DFS(int u){
    cnt++;
    vis[u]=1;
    for(auto v:adj[u])
        if(!vis[v])
            DFS(v);
}

int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0 ; i<m ; i++){
        int u,v;
        scanf("%d%d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    int ans=0;
    for(int i=1 ; i<=n ; i++){
        if(vis[i]) continue;
        cnt=0;
        DFS(i);
        ans=max(ans, cnt);
    }


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


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

#define Mset(s, n)      memset(s, n, sizeof(s))
#define Rp0(i, m)       for(int i = 0; i < m; ++i)
#define Rpd(i, m, l)    for(int i = l; i >= m; --i)
#define Rp1(i ,m)       for(int i = 1; i <= m; i++)
#define All(a)          (a).begin(), (a).end()
#define Lwb             lower_bound
#define Upb             upper_bound
#define Sz(a)           int((a).size())
#define u_map           unordered_map
#define fi              first
#define se              second
#define pb              push_back
#define pf              push_front
#define is              insert
#define ooi             INT_MAX
#define ool             LLONG_MAX
#define ll              long long
#define ull             unsigned ll
#define ld              long double
#define pii             pair<int, int>
#define vi              vector<int>
#define vpii            vector<pii>

const ll MOD = (ll) 1e9 + 7;
const ld PI = acos((ld) -1);
inline int Get_bit(int x, int k){return (x >> (k - 1)) & 1;}
inline ll Gcd(ll a, ll b) {ll r; while(b){ r = a % b; a = b; b = r;} return a;}
inline ll Lcm(ll a, ll b) {return a / Gcd(a, b) * b;}
inline ll Pow(ll n, ll k) {ll r = 1; for(; k; k >>= 1, n = n * n % MOD){if(k & 1) r = r * n % MOD;} return r;}
const int base = 311;


const int N = 2e5 + 10;


ll n, m, k, ans, a[N];

void Solve(){
    string s, t;
    cin >> s >> t;
    int res = 0;
    for(int i = 0; i < 3; i++) res += (s[i] == t[i]);
    cout << res;
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    Solve();
    return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        TA: [(i64,i64); N],
    }
    let mut t = 1;
    let mut a = 1;
    for i in 0..N{
        let r = max(1+(t-1)/TA[i].0, 1+(a-1)/TA[i].1);
        t = TA[i].0*r;
        a = TA[i].1*r;
    }
    println!("{}", t+a);
}

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

#define    ll    long long int

const int N = 200005;
int ara[N];
int cnt[N];
vector<int> v;

ll func(ll x)
{
    return ((x * (x - 1)) / 2);
}

int main( )
{
    ll s = 0;
    ll i, j, k, n;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> ara[i];
        cnt[ara[i]]++;
        if (cnt[ara[i]] == 1) {
            v.push_back(ara[i]);
        }
    }
    for (i = 0; i < (int) v.size(); i++) {
        s += func(cnt[v[i]]);
    }
    for (i = 1; i <= n; i++) {
        j = ara[i];
        s -= func(cnt[j]);
        s += func(cnt[j] - 1);
        cout << s << '\n';
        s += (cnt[j] - 1);
    }
    return 0;
}


Measured memory_bytes: 3832
def func():
    pass


def main():
    n, m = map(int, input().split())

    l = [0] * m
    for i in range(n):
        a = [int(i) for i in input().split()]
        for i, ai in enumerate(a):
            if i == 0:
                continue
            l[ai - 1] += 1

    print(l.count(n))


if __name__ == '__main__':
    main()


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

using namespace std;
using ll =long long;
using db = double;

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; }

#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(v) SORT(v);(v).erase(unique((v).begin(),(v).end()),(v).end())
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める
ll dp[110][100100] = {0};
int main()
{
	cout << setprecision(10);
	int n,w;
	cin >> n >> w;

	int	weight[110] , value[110];
	rep(i,n) cin >> weight[i] >> value[i];

	rep(i,n){
		for(int sum_w = 0 ; sum_w <= w; ++sum_w){

			//i番目の品物を選ぶ場合
			if( sum_w - weight[i] >= 0 ){
				chmax(dp[i+1][sum_w],dp[i][sum_w - weight[i]]+value[i]);
			}
			chmax(dp[i+1][sum_w],dp[i][sum_w]);
		}
	}

	cout << dp[n][w] << endl;
}


Measured memory_bytes: 79360
import sys

import numpy as np
MOD = 10 ** 9 + 7
def cumprod(a, p):
  l = len(a); sql = int(np.sqrt(l) + 1)
  a = np.resize(a, sql ** 2).reshape(sql, sql)
  for i in range(sql - 1): a[:, i+1] *= a[:, i]; a[:, i+1] %= p
  for i in range(sql - 1): a[i+1] *= a[i, -1]; a[i+1] %= p
  return np.ravel(a)[:l]

def make_tables(n=10 ** 9, r=5 * 10 ** 6, p=MOD):
  fac = np.arange(r + 1); fac[0] = 1; fac = cumprod(fac, p)
  ifac = np.arange(r + 1, 0, -1); ifac[0] = pow(int(fac[-1]), p - 2, p)
  ifac = cumprod(ifac, p)[n::-1]
  n_choose = np.arange(n + 1, n - r, -1); n_choose[0] = 1;
  n_choose[1:] = cumprod(n_choose[1:], p) * ifac[1:r+1] % p
  return fac, ifac, n_choose

fac, ifac, n_choose = make_tables()

def choose(n, r, p=MOD):
  # if r > n or r < 0: return 0
  return fac[n] * ifac[r] % p * ifac[n-r] % p

n, k = map(int, sys.stdin.readline().split())
a = np.array(sys.stdin.readline().split(), dtype=np.int64)
a.sort()

def main():
  res = (a[k-1:] * choose(np.arange(k-1, n), k - 1) % MOD).sum() % MOD
  res -= (a[:n-(k-1)] * choose(np.arange(n-1, k-2, -1), k-1) % MOD).sum() % MOD
  res %= MOD
  print(res)
    
if __name__ == '__main__':
  main()


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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int get(int x) {
  return (x * (x - 1)) / 2;
}

bool isok(string s) {
  string p = s;
  reverse(p.begin(), p.end());
  return p == s;
}

int main() {
  double n; cin >> n;
  double ans = (n / 3.0) * (n / 3.0) * (n / 3.0);
  printf("%0.8lf\n", ans);
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		String str=s.next();
		
		long sum=0;
		
		for(int i=0;i<str.length();i++)
		{
			sum=sum+Integer.valueOf(str.charAt(i)+"");
		}
		
		if(sum%9==0)
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}
		
	}
	
}

Measured memory_bytes: 52052
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    string s, t; cin >> s >> t;
    int ans = 0;
    rep(i,3) {
        if (s[i]==t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector
#define pb push_back

pair<int, int> dfs(vec<vec<int> > t, int s)
{
  queue<int> q;
  q.push(s);
  vec<int> dp(t.size(), 0);
  while(q.size()) {
    int p = q.front();
    q.pop();
    rep(i, t[p].size()) {
      if (dp[t[p][i]]) continue;
      dp[t[p][i]] = dp[p] + 1;
      q.push(t[p][i]);
    }
  }
  int m = 0;
  rep(i, dp.size()) {
    if (dp[i] > dp[m]) m = i;
  }
  return make_pair(m, dp[m]);
}

int tree_diameter(vec<vec<int> > tree)
{
  pair<int, int> p = dfs(tree, 0);
  pair<int, int> q = dfs(tree, p.first);
  return q.second;
}

int main(void)
{
  int n;
  cin >> n;
  vec<vec<int> > tree(n);
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree[a].pb(b);
    tree[b].pb(a);
  }
  int get = tree_diameter(tree);
  if (get % 3 == 1) cout << "Second" << endl;
  else cout << "First" << endl;
  return 0;
}



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

const int N = (int)2e5;
const long long MOD = (long long)1e9 + 7;

long long fast(long long a, long long p) {
    if (p == 0) return 1;
    long long res = fast(a, p >> 1);
    res = (res * res) % MOD;
    if (p & 1) res = (res * a) % MOD;
    return res;
}

char s[N+5];

int main() {
    scanf("%s", s);
    int n = strlen(s);
    int summ = 0;

    long long res = 0;
    for (int i=0; s[i]; i++) if (s[i] == '1') {
        res = (res + fast(2, summ) * fast(3, n-i-1)) % MOD;
        summ += 1;
    }
    res = (res + fast(2, summ)) % MOD;

    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 384
S = list(map(int,list(str(input()))))

data = [0]*2019
pre = 0
for i in range(len(S)):
    x = pow(10,i,2019)
    x *= S[-i-1]
    x %= 2019
    data[(pre+x)%2019] += 1
    pre += x

#print(data)
ans = data[0]
for i in range(2019):
    ans += data[i]*(data[i]-1)//2

print(ans)

Measured memory_bytes: 12104
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back

using namespace std;
using ll=long long;
// using ll=int;

const ll mod = (ll)(1e9+7);

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

int main(){

    /*
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("myoutput.txt", "w", stdout);
    #endif
    */

    fast;
    ll t = 1;
    // cin >> t;
    while(t--){
        ll n; cin >> n;
        vi x(n);
        for(ll i = 0; i < n; cin >> x[i++]);
        // for(auto i : x) cerr << i <<  ' '; cerr << endl;
        ll sum1 = ceil(accumulate(all(x), 0)*1.0/n);
        ll sum2 = accumulate(all(x), 0)/n;
        ll stamina1 = 0, stamina2 = 0;
        for(auto i : x){
            stamina1 += pow(sum1-i, 2);
            stamina2 += pow(sum2-i, 2);
        }

        // cerr << sum << endl;
        cout << min(stamina1, stamina2) << endl;
    }
    // cerr << (double)clock()/CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check
const ll INF = 1LL << 60;


void solve(std::string s){
    ll N = s.length();
    vll posBC;
    REP(i, N-1){
        if(s[i]=='B' && s[i+1]=='C')
            posBC.push_back(i);
    }
    ll nrBC = posBC.size();
    vll conBC(nrBC);
    ll ps=0, pt;
    pt = ps;
    while(ps < nrBC){
        while(pt < nrBC-1){ //* [ps, pt] are connected
            if( posBC[pt+1]==posBC[pt]+2 ){
                pt++;
            }
            else{
                bool isGood=true;
                for(ll i= posBC[pt]+2; i < posBC[pt+1]; i++){
                    if(s[i] != 'A'){
                        isGood = false;
                        break;
                    }
                }
                if(isGood)
                    pt++;
                else
                    break;
            }
        }
        if(pt == ps){
            conBC[ps] = 1;
            ps++;
            pt = ps;
            continue;
        }
        //* pt > ps
        ll len = pt-ps+1;
        for(ll i= ps; i<= pt; i++){
            conBC[i] = len - (i-ps);
        }
        ps = pt+1;
        pt = ps;
    }
    /*
    cout << "display conBC \n";
    for(auto x: conBC){
        cout << x <<" " ;
    }
    cout << endl;
    */
    vll posA;
    REP(iBC, nrBC){
        if(posBC[iBC]>0){
            ll tmp=0;
            for(ll p = posBC[iBC]-1; p >=0; p--){
                if(s[p]!='A')
                    break;
                tmp++;
            }
            posA.push_back(tmp);
        }
        else{
            posA.push_back(0);
        }
    }
    /*
    for(auto x: posA){
        cout << x <<" " ;
    }
    cout << endl;
    */
    ll ans = 0;
    REP(iBC, nrBC){
        ans += posA[iBC]*conBC[iBC];
    }
    cout << ans << endl;
}

int main(){
    std::string s;
    std::cin >> s;
    solve(s);
    return 0;
}


Measured memory_bytes: 3192
#include <cmath>
#include <functional>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>>g(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector <tuple <int, int, int> > e;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int v, d, c;
    cin >> v >> d >> c;
    v--;
    e.push_back(tuple<int, int, int>{v, d, c});
  }
  reverse(e.begin(), e.end());
  vector <vector <bool> > u(n, vector <bool> (11));
  vector <int> ans(n);
  function<void(int,int,int)>dfs=[&](int v, int d,int col) {
    if (u[v][d]) return;
    u[v][d] = true;
    if (d == 0) {
      ans[v]=col;
    }else{
      dfs(v,d-1,col);
      for(int j:g[v]){
        dfs(j,d-1,col);
      }
    }
  };
  for (auto c : e) {
    dfs(get<0>(c),get<1>(c),get<2>(c));
  }
  for (int i = 0; i < n; i++) cout << ans[i] << '\n';
}


Measured memory_bytes: 15088
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int N; cin >> N;
  int num[100005]; CLR(num);
  FOR(i,0,N) {
    int in; cin >> in;
    num[in]++;
    if(in > 0) num[in-1]++;
    num[in+1]++;
  }
  int ans = 0, mx = 0;
  FOR(i,0,100005) {
    if(mx < num[i]) {
      mx = num[i];
      ans = i;
    }
  }
  cout << num[ans] << endl;
  return 0;
}

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

typedef long long ll;

int main() {
	int H, W, N;
	cin >> H >> W >> N;
	vector<int> a(N), t;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		for (int j = 0; j < a[i]; j++) {
			t.push_back(i+1);
		}
	}

	bool f = true;
	int k=0;
	vector<list<int> > ans(H);
	for (int i = 0; i < H; i++) {
		if (f) {
			for (int j = 0; j < W; j++) {
				ans[i].push_back(t[k++]);
			}
			f = false;
		}
		else {
			for (int j = 0; j < W; j++) {
				ans[i].push_front(t[k++]);
			}
			f = true;
		}
		
	}

	for (int i = 0; i < H; i++) {
		for (auto itr = ans[i].begin(); itr != ans[i].end(); itr++) {
			cout << *itr <<" ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 640
N, Y = map(int, input().split())
flag = 0
for num_so in range(N+1):
    if flag == 1:
        break
    for num_fs in range(N+1):
        num_ts = N - num_so - num_fs
        sum = num_ts * 10000 + num_fs * 5000 + num_so * 1000
        if flag == 1:
            break
        elif sum == Y and num_ts >= 0:
            print(num_ts, num_fs, num_so)
            flag = 1
            break

if flag == 0:
    print("-1 -1 -1")


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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);
	int n ; cin >> n;
	vector<string> S(n);
	rep(i,n) cin >>S[i];

	int num[26];
	rep(i,26) num[i] = 50 ;

	rep(i,n){
		for(int c = 'a' ; c <= 'z' ; c++){
			int count = 0;
			for(int j = 0 ; j <= S[i].size() ; j ++){
				if(S[i][j]==c){
					count ++;
				}
			}
			chmin(num[c-'a'],count);
		}
	}
	int ans = 0;
	rep(i,26){
		char c = 'a'+i;
		rep(j,num[i]){
			cout <<c;
		}
	}
	cout << endl;
}


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

using namespace std;

int main()
{
    char s[100005];
    scanf("%s",s);
    int n=strlen(s);
    if(s[0]==s[n-1])
        n--;
    if(n&1)
        printf("First\n");
    else
        printf("Second\n");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    long a, min, max;
    long long sum = 0;
    min = 1000000;
    max = -1000000;

    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> a;
        if(a < min) min = a;
        if(a > max) max = a;
        sum += a;
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}

Measured memory_bytes: 3084
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a < b){
            if(b < c){
                System.out.printf("%d %d %d\n", a, b, c);
            }else if(a < c){
                System.out.printf("%d %d %d\n", a, c, b);
            }else{
                System.out.printf("%d %d %d\n", c, a, b);
            }
        }else{
            if(a < c){
                System.out.printf("%d %d %d\n", b, a, c);
            }else if(c < b){
                System.out.printf("%d %d %d\n", c, b, a);
            }else{
                System.out.printf("%d %d %d\n", b, c, a);
            }
        }
        }
    }


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

int a[200005];
int ceiling(int atas,int bawah){
	return (atas-1)/bawah+1;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n,k;
	cin >> n >> k;
	for(int i=1;i<=n;i++)cin >> a[i];
	int ki=1,ka=1e9,res;
	while(ki<=ka){
		int mid=(ki+ka)/2,byk=0;
		for(int i=1;i<=n;i++){
			byk+=ceiling(a[i],mid)-1;
		}
		if(byk<=k){
			res=mid;
			ka=mid-1;
		}
		else ki=mid+1;
	}
	cout << res << '\n';
	return 0;
}



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

long dp[110][100010];
int main() {
	int N, W; cin >> N >> W;
	int w[110], v[110];
	for(int i=1; i<=N; ++i) cin >> w[i] >> v[i];
	for(int i=1; i<=N; ++i){
	    for(int j=0; j<=W; ++j){
	        if(w[i]>j) dp[i][j]=dp[i-1][j];
	        else dp[i][j]=max(dp[i-1][j-w[i]]+v[i], dp[i-1][j]);
	    }
	}
	cout << dp[N][W] << endl;
	return 0;
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
typedef long long ll;
ll exp(int a, int x){
    if (x == 0) return 1;
    ll p = exp(a,x/2);
    p *= p;
    p %= mod;
    if (x & 1){ p += a; p %= mod; }
    return p;
}
int ct[1000005];
int main(){
    ll n;
    scanf("%lld",&n);
    ll cur = n-1;
    ll ans = 1;
    for (ll i = 2; i*i <= n; i++){
        if (cur%i == 0) {
            while (cur%i == 0){
                cur /= i;
                ct[i]++;
            }
            ans *= (ct[i]+1);
        }
    }
    if (cur != 1) ans *= 2;
    ll sum = 0;
    for (ll i = 2; i*i <= n; i++){
        if (n % i == 0){
            ll P = 1;
            while (n%(P*i) == 0) P *= i;
            if ((n/P) % i == 1) {
                //printf("%lld %lld can\n",P,i);
                sum++;
            }
        }
    }
    printf("%lld\n",ans+sum);
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;

public class Main {
	public static void main(String[] args) {
		var sc = new java.util.Scanner(System.in);
		var n = sc.nextInt();
		var a = new Integer[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a,Collections.reverseOrder());

		var cal = new Boolean[a[0]+1];
		for(int i=0;i<cal.length;i++) {
			cal[i]=false;
		}
		var work = -1;
		for(int i=0;i<a.length;i++) {
			if(work==a[i]) {
				cal[a[i]]=false;
			}else {
				cal[a[i]]=true;
				for(int k=a[i]*2;k<cal.length;k+=a[i]) {
					cal[k]=false;
				}
			}
			work=a[i];
		}
		System.out.println(Arrays.stream(cal).filter(v->v).count());
	}
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

#define NIL NULL

Node root;

Node treeMinimum(Node x){

  while(x->left != NIL){
    x = x->left;
  }
  return x;

}

Node treeSearch(Node u, int k){

  if(u == NIL || k == u->key){
    return u;
  }

  if(k < u->key){
    return treeSearch(u->left, k);
  }
  else{
    return treeSearch(u->right,k);
  }

}

Node treeSuccessor(Node x){

  Node y;

  if(x->right != NIL){
    return treeMinimum(x->right);
  }

  y = x->parent;

  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  //
  if(z->left == NIL || z->right == NIL){
    y = z;
  }
  else{
    y = treeSuccessor(z);
  }

  if(y->left != NIL){
    x = y->left;
  }
  else{
    x = y->right;
  }

  if(x != NIL){
    x->parent = y->parent;
  }

  if(y->parent == NIL){
    root = x;
  }
  else if(y == y->parent->left){
    y->parent->left = x;
  }
  else{
    y->parent->right = x;
  }


}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  //

  while(x != NIL){
    y = x;

    if(k < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }

  z->parent = y;
  
  if(y == NIL){
    root = z;
  }
  else if(k < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }
  
}

void inorder(Node u){

  if(u->left != NIL ){
    inorder(u->left);
    printf(" %d", u->key);
  }
  else{
    printf(" %d", u->key);
  }

  if(u->right != NIL){ 
    inorder(u->right);
  }
  
}
 
void preorder(Node u){
  
  printf(" %d", u->key);
  
  if(u->left != NIL){
    preorder(u->left);
  }
  
  if(u->right != NIL){
    preorder(u->right);
  }
  
}


int main(){
  int n, i, x;
  char com[20];
  
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      
      Node t = treeSearch(root, x);
      
      if ( t != NIL ){
	printf("yes\n");
      }
      else{
	printf("no\n");
      }
      
    }
    
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      
      preorder(root);
      printf("\n");
    }
    
    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
    
  }
  
  return 0;
}

Measured memory_bytes: 24040
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val array = Array(n, {0})
    var count = 0
    for(i in 0..n-1){
        array[i] = scanner.nextInt()
        if(array[i] !== i+1) count++
    }
    if(count === 0 || count === 2) println("YES")
    else println("NO")
}

Measured memory_bytes: 31144
def div_count(n, k, l)
  (n / k) + (n / l) - (n / k.lcm(l))
end

def main(argv)
  (a, b, c, d) = gets.chomp.split(' ').map(&:to_i)
  
  m = b - a + 1
  x = div_count(a - 1, c, d)
  y = div_count(b, c, d)
  p (m - (y - x))
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 1788
#include<stdio.h>
int main()
{
    int a,p,i,q,max,z,j,k,x;
    scanf("%d",&a);
    int ara[a];
    z=0;
    for(i=0;i<a;i++){
            scanf("%d",&ara[i]);
    }
    max=ara[0];
    for(j=0;j<a;j++){

        if(ara[j]>=max){
            max=ara[j];
            x=j;
        }
    }

    for(k=0;k<a;k++){
        if(ara[k]==max && k==x){
            p=ara[k]/2;
        }
        else{
            p=ara[k];
        }
        z=z+p;
    }

    printf("%d",z);
    return 0;
}


Measured memory_bytes: 1732
# 2019/12/7

# DPver

x=int(input())

dp=[0]*(x+1)
c=[100,
   101,
   102,
   103,
   104,
   105]

dp[0]=1
for i in range(len(c)):
    for j in range(1,x+1):
        if c[i]>j:continue
        if dp[j-c[i]]:dp[j]=1
print(1 if dp[-1] else 0)

Measured memory_bytes: 3828
M, D = input().split()
count = 0

for m in range(4, int(M)+1):
  for d in range(22, int(D)+1):
    d10 = int(str(d)[0])
    d1 = int(str(d)[1])
    if d10>=2 and d1>=2 and d10*d1==m:
      count+=1
      
print(count)
    

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)


int nCr(int n , int r ) {
	int p = 1, k = 1;

	if (n - r < r ) {
		r = n - r;
	}
	if (r != 0) {
		while (r != 0) {
			p *= n ;
			k *= r ;
			int m = __gcd(p, k);
			p /= m;
			k /= m;
			n--;
			r--;
		}
	}
	else {
		p = 1;
	}
	return p ;
}

void aryan_p() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return;
}


int32_t main() {


	int n ;
	cin >> n;
	string s;
	cin >> s;

	for (int i = 0 ; i < s.length() ; i++) {
		int idx = s[i] - 'A';
		if (idx + n > 25) {
			s[i] = 'A';
			s[i] += (n - 26 + idx);
		}
		else {
			s[i] += n;
		}
	}
	cout << s;






	return 0;
}

Measured memory_bytes: 3604
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc;

	static final int INF=1<<28;
	static final double EPS=1e-9;

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

		double[] xs=new double[1000];
		double[] ys=new double[1000];
		xs[0]=1;
		ys[0]=0;
		for(int i=1; i<1000; i++){
			double rad=atan2(ys[i-1], xs[i-1])+PI/2;
			xs[i]=xs[i-1]+cos(rad);
			ys[i]=ys[i-1]+sin(rad);
			// println(xs[i]+", "+ys[i]);
		}

		for(;;){
			int n=sc.nextInt();
			if(n==-1)
				break;
			println(xs[n-1]+"");
			println(ys[n-1]+"");
		}
		sc.close();
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 11000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//
ll H,W;
bool can=false;
vvc<bool> used;
void dfs(ll h,ll w, ll lpre, ll upre, ll now, vc<string>& S){
    used[h][w] = true;
    if(h==H-1&&w==W-1){
        can = true;
        return;
    }

    if(h+1<H&&!used[h+1][w]&&S[h+1][w]=='0'+7-upre){
        dfs(h + 1, w, lpre, now, 7 - upre, S);
    }
    if(h-1>=0&&!used[h-1][w]&&S[h-1][w]=='0'+upre){
        dfs(h - 1, w, lpre, 7 - now, upre, S);
    }
    if(w+1<W&&!used[h][w+1]&&S[h][w+1]=='0'+7-lpre){
        dfs(h, w + 1, now, upre, 7 - lpre, S);
    }
    if(w-1>=0&&!used[h][w-1]&&S[h][w-1]=='0'+lpre){
        dfs(h, w - 1, 7 - now, upre, lpre, S);
    }

}
int main() {
    init();
    cin >> H >> W;
    vc<string> S(H);
    rep(i, H) cin >> S[i];
    if(H%2==0&&W%2==0){
        cout << "NO" << endl;
        return 0;
    }
    used.resize(H);
    rep(i, H) used[i].resize(W);

    dfs(0, 0, 4, 5, 6, S);
    cout << (can ? "YES" : "NO") << endl;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 = 998244353;
const ll LINF = 1e18;

class UnionFind{
private:
  vector<ll> Parent; 
 public:
  UnionFind(ll N){
    Parent = vector<ll>(N, -1);
  }
  
  ll root(ll A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  ll size(ll A){
    return -Parent[root(A)]; 
  }
  
  bool connect(ll A, ll B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(ll A, ll B){
    return root(A) == root(B);
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  
  vll cnt(n,1);
  vb flg(n);
  flg[0]=true;
  rep(i,m){
    ll a,b; cin>>a>>b;
    a--,b--;
    if(flg[a]){
      cnt[b]++;
      cnt[a]--;
      flg[b]=true;
      if(cnt[a]==0) flg[a]=false;
    }else{
      cnt[b]++;
      cnt[a]--;
    }
  }
  
  ll ans=0;
  rep(i,n){
    if(flg[i]) ans++;
  }
  
  cout<<ans<<endl;
}

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

int main(){
    int N;
    cin >> N;
    // vector<int> vec(N);
	// for (int i = 0; i < N; i++) {
    //     cin >> vec.at(i);
    //     }
    if(N%2==1){
        cout << "No" << endl;
    }
    else{
        char a[N];
        for(int i=0;i<N;i++){
            cin >> a[i];
        }
        // for(int i=0;i<N;i++){
        //     cout << a[i] <<endl;
        // }
        int count = 0;
        for(int j=0;j<N/2;j++){
            if(a[j]==a[j+(N/2)]){
                count++;
            }
        }
        if(count == N/2){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int * c,k;
int cost(int i,int n,int h[]){
	if(i==n){return 0;}
	int a=999999999,t;
	for(int j=1;j<=k&&i+j<=n;j++)
	{
		
	if(c[i+j]==-1)
		{
			c[i+j]=cost(i+j,n,h);
			t=abs(h[i+j]-h[i])+c[i+j];
			if(t<a)a=t;
		}	
	else{
			t=abs(h[i+j]-h[i])+c[i+j];
			if(t<a)a=t;
		}
	
	}
	return a;
}
int main(){
	int n;
	cin>>n>>k;
	int h[n+1];
	c=new int[n+1];
	for(int i=0;i<=n;i++)c[i]=-1;
	for(int i=1;i<=n;i++)cin>>h[i];
	cout<<cost(1,n,h);
	return 0;
}

Measured memory_bytes: 8832
import math
N = int(input())
xi = []
yi = []

for i in range(N):
  x, y = map(int, input(). split())
  xi.append(x)
  yi.append(y)

L=0

for j in range(N):
  for k in range(N):
    if j >= k:
      continue
    L += math.sqrt((xi[j]-xi[k])**2 + (yi[j]-yi[k])**2)
    
print(2*L/N)

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

int main()
{
    int n;cin>>n;
    vector<int> a(n);
    int i;
    for(i=0;i<n;i++)cin>>a.at(i);
    sort(a.begin(),a.end());
    long long lenlong=0;
    long long lenmin=0;
    int now=a.at(n-1);
    for(i=n-2;i>=0;i--)
    {
        if(now==a.at(i))
        {
            if(lenmin!=0)break;
            else if(lenlong!=0)lenmin=now;
            else lenlong=now;
            now=-1;
        }
        else now=a.at(i);
    }
    cout<<lenlong*lenmin<<endl;
}


Measured memory_bytes: 640
n,m = map(int,input().split())
h = list(map(int,input().split()))
ans = 0
arr = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    arr[a-1].append(b-1)
    arr[b-1].append(a-1)

for i in range(len(h)):
    tmph = h[i]
    flg = 1
    if arr[i]:
        for j in arr[i]:
            if tmph <= h[j]:
                flg = 0
                break
    if flg == 1:
        ans +=1
print(ans)

Measured memory_bytes: 29348