akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {


	public static void main(String[] args) {
		Main ans = new Main();
		System.out.println(ans.solve());
	}

	private double solve() {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int [] array = new int[N+1];
		int one=0, two=0,three=0;
		for(int i=1;i<=N;i++){
			int val = sc.nextInt();
			if (val==1) one++;
			else if (val==2) two++;
			else three++;
		}
		double [][][] dp = new double[302][302][302];

		return solve(one,two,three,N, dp);
	}

	private double solve(int one, int two, int three, int N, double [][][] dp) {

		if (one==0 && two==0 && three==0) return 0;
		if (one<0 || two<0 || three<0) return 0;

		if (dp[one][two][three]!=0) return dp[one][two][three];

		double val = one * solve(one-1, two, three, N, dp)
		 				+ two * solve(one+1, two-1, three,N, dp)
		 				+ three * solve(one, two+1, three-1, N, dp)
		 				+ N;

		double answer = val/(one+two+three);

		dp[one][two][three] = answer;

		return answer;

 	}
}

Measured memory_bytes: 273620
#pragma GCC optimize("Ofast")
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long
#define ull unsigned long long

using namespace std;


int main() {
	ll X, K, D;
	cin >> X >> K >> D;

	ll cnt = abs(X) / D;
	ll val = abs(X) % D;

	if (K <= cnt){
		ll tmp = (X > 0) ? X - K * D : X + K * D;
		cout << abs(tmp) << "\n";
	} else {
		if ( (K - cnt) % 2 == 0 ){
			cout << val << "\n";
		} else {
			cout << abs(D - val) << "\n";			
		}
	}

	return 0;
}


Measured memory_bytes: 3632
#include<iostream>

using namespace std;
int A[20];

bool BorteForce(int t, int p, int n){
        if(p==A[t])return true;
        if(t==n-1)return false;

        else return BorteForce(t+1, p-A[t], n) | BorteForce(t+1, p, n);
    }


int main(){
    int n, q;
    int M[200];

    cin >>n;
    for(int i=0; i<=n-1;i++)cin >> A[i];
    cin >> q;
    for(int i=0; i<=q-1;i++)cin >> M[i];


    for(int i=0 ;i<=q-1;i++){
        if(BorteForce(0, M[i], n)){
            cout << "yes\n";
        }
        else cout << "no\n";
    }
}


Measured memory_bytes: 3104
N = int(input())
s =N+1
n = int(N**0.5) 
i = 1
while i<=n:
  if N % i != 0:
    i += 1
  elif N % i == 0 and N//i +i < s:
    s = N//i + i
    i += 1
  else:
    i += 1
print(s-2)

Measured memory_bytes: 40300
#問題文に連結と書いてあるのでどの部屋も互いに行き来できる
#自分がきたところを記録する幅優先探索をすればいい
n,m=list(map(int,input().split()))
#道を隣接リスト表現で表す
road=[[] for i in range(n)]
for i in range(m):
  a,b=list(map(int,input().split()))
  road[a-1].append(b)
  road[b-1].append(a)
#幅優先探索
from collections import deque
q=deque([1])
ans=[0 for i in range(n)]
check=[0 for i in range(n)]
check[0]=1
while len(q)>0: 
  p=q.popleft()
  for j in road[p-1]:
    if check[j-1]==0:
      q.append(j)
      check[j-1]=1
      ans[j-1]=p

print("Yes")
for i in range(1,n):
  print(ans[i])
  

  

Measured memory_bytes: 106884
class UnionFind:
  def __init__(self, n):
    self.tree = [-1] * n
  
  def union(self, a, b):
    a = self.root(a)
    b = self.root(b)
    if(a == b):
      return
    if(self.size(a) < self.size(b)):
      a, b = b, a
    self.tree[a] += self.tree[b]
    self.tree[b] = a
    
  def root(self, a):
    if(self.tree[a] < 0):
      return a
    res = self.root(self.tree[a])
    self.tree[a] = res
    return res
    
  def size(self, a):
    return -self.tree[self.root(a)]

N, M = map(int,input().split())
A, B = [], []
for _ in range(M):
  a, b = map(int,input().split())
  A.append(a-1)
  B.append(b-1)

uf = UnionFind(N)

res = N*(N-1)//2
result = [0] * M
for i in range(M-1, -1, -1):
  result[i] = res
  if(uf.root(A[i]) != uf.root(B[i])):
    res -= uf.size(A[i]) * uf.size(B[i])
    uf.union(A[i], B[i])

for r in result:
  print(r)


Measured memory_bytes: 17388
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <bitset>
#include <math.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
using namespace std;

typedef long long int ll;
const ll MOD = 1e9+7;
#define INF 10000000000000


inline ll Upstair(ll n){
	ll rt;
	if(n==1) return 1;
	return n*Upstair(n-1);
}

template<class T>
bool inline ChangeMinimum( T &a, T b )
{
	if( a > b ){
		a = b;
		return true;
	}
	return false;
}

class Tree
{
	public:
//		Tree(int _root);
		int root;
		vector<int> next;
		int value = 0;
};

template<class T>
class Vec3
{
	public:
		T act[3];
};

int Stair( int now, vector<ll> &H )
{
	if( H[now] >= H[now+1] ){}
	
}

int main(void) {
	
	string S;
	inp(S);
	string ans = "Yes";
	int N = int(S.length());
	rep(i,N){
		if(S[i] == 'U' || S[i] == 'D'){ continue;
		}else if(S[i] == 'R' && (i+1)%2==1){ continue;
		}else if(S[i] == 'L' && (i+1)%2==0){ continue;
		}else{ans = "No";break;}
	}
	out(ans);
	
		
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::*;

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
#[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

fn main() {
    println!("{}", solve(&stdin!()));
}
fn solve(src: &str) -> String {
    input! {
        source = src,
        k:isize,
        n:isize,
        a:[isize;n],
    }

    let mut prev = a.last().unwrap() - k;
    let mut m = 0;
    let mut ranges = Vec::with_capacity(a.len());
    let mut ri = 0;
    for (i, &v) in a.iter().enumerate() {
        let range = v - prev;
        prev = v;
        m = max(m, range);
        if m == range {
            ri = i;
        }
        ranges.push(range);
    }
    ranges.remove(ri);
    let sum = ranges.iter().fold(0, |s, v| s + v);
    (sum).to_string()
}
test! {
    include_str!("c1_in.txt") => "10",
    include_str!("c2_in.txt") => "10",
}


Measured memory_bytes: 6656
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main() {
	string s;
	cin >> s;
	cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
   char a[3][4];
   int i;

   for(i = 0; i < 3; i++){
      scanf("%s", a[i]);
   }

   for(i = 0; i < 3; i++){
      printf("%c", a[i][i]);
   }

   printf("\n");

   return 0;
}

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

bool vis[31622777];
int prime[2000000], tot;

long long exgcd(long long a, long long b, __int128 &x, __int128 &y) {
	if (!b) {
		x = 1, y = 0;
		return a;
	}
	long long g = exgcd(b, a % b, y, x);
	y -= a / b * x;
	return g;
}

void get_prime(int n) {
	for (int i = 2; i <= n; i++) {
		if (!vis[i]) prime[tot++] = i;
		for (int j = 0; j < tot && 1ll * i * prime[j] <= n; j++) {
			vis[i * prime[j]] = 1;
			if (i % prime[j] == 0) break;
		}
	}
}

int main () {
	get_prime(31622776);
	long long n; cin >> n; n *= 2;
	long long tmp = n;
	vector <long long> all;
	for (int i = 0; i < tot; i++) {
		long long pw = prime[i];
		while (n % pw == 0) pw *= prime[i];
		pw /= prime[i];
		if (pw != 1) all.push_back(pw), tmp /= pw;
	}
	if (tmp != 1) all.push_back(tmp);
	int m = all.size();
	__int128 ans = 900000000000000000;
	for (int mask = 0; mask < (1 << m); mask++) {
		long long x = 1, y = 1;
		__int128 k1, k2;
		for (int i = 0; i < m; i++) {
			if (mask >> i & 1) x *= all[i];
			else y *= all[i];
		}
		exgcd(x, y, k1, k2);
		assert(x * k1 + y * k2 == 1);
		k2 = -k2;
		__int128 tmp = max((max((__int128)0, 1 - k1) + y - 1) / y, (max((__int128)0, 1 - k2) + x - 1) / x);
		k1 += tmp * y, k2 += tmp * x;
		if (ans / k2 >= y) ans = min(ans, k2 * y);
		k1 = -k1, k2 = -k2;
		tmp = max((max((__int128)0, 1 - k1) + y - 1) / y, (max((__int128)0, 1 - k2) + x - 1) / x);
		k1 += tmp * y, k2 += tmp * x;
		if (ans / k1 >= x) ans = min(ans, k1 * x);
	}
	cout << (long long)ans << endl;
	return 0;
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  string s; cin>>s;
  int ans=0;
  for (int i=0; i<3; i++) {
    if (s[i]=='1') ans++;
  }
  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<string> dic;
    map<string,int> mp;
    for(int i = 0; i < N; i++){
        string s;
        cin >> s;
        mp[s] += 1;
    }
    int max_val = 0;
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        max_val = max(max_val,itr->second);
    }

    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        if(itr->second == max_val) dic.push_back(itr->first);
    }
    sort(dic.begin(),dic.end());
    for(int i = 0; i < dic.size(); i++){
        cout << dic.at(i) << endl;
    }
    return 0;
}

Measured memory_bytes: 26868
N,M = (int(x) for x in input().split())
AC = [False]*N
WA_count = [0]*N
AC_count = 0
for i in range(M):
  p,S = (y for y in input().split())
  if AC[int(p)-1] == False:
    if S == 'AC':
      AC[int(p)-1] = True
      AC_count += 1
    else:
      WA_count[int(p)-1] += 1
for i in range(N):
  if AC[i] == False:
    WA_count[i] = 0
print(AC_count,sum(WA_count))

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

typedef long long ll;

int F(int A, int B){
	// cout << A << " " << B << endl;
	int a = 0, b = 0;
	for(int i = 0; i <= 10; ++i) { A /= 10; a++; if(A == 0) break; }
	for(int i = 0; i <= 10; ++i) { B /= 10; b++; if(B == 0) break; }
		
	// cout << a << " " << b << endl;
	return max(a, b);
}

int main(){
	ll N; cin >> N;
	vector<ll> x;

	for(int i = 1; i <= (ll)sqrt(N); ++i){
		if(N%i == 0) x.push_back(i);
	}

	int fmin = 10000;
	for(int i = 0; i < x.size(); ++i){
		int f = F(x[i], N/x[i]);
		if(fmin > f) fmin = f;
	}	

	cout << fmin << endl;

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  int a, n2 = 0, n1 = 0, n0 = 0;
  for (int i = 0; i < N; i++) {
    cin >> a;
    if (a % 4 == 0) n2++;
    else if (a % 2 == 0) n1++;
    else n0++;
  }
  if (n1 == 0) n0--;
  cout << (n0 <= n2 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define M 100005
using namespace std;
const int mod=1000000007;
int n,K,h[M],tt;
struct edge{
	int nxt,to;
}G[M<<1];
void Add(int a,int b){
	G[++tt]=(edge){h[a],b};
	h[a]=tt;
}
LL ans=1;
void dfs(int x,int f){
	LL hav=K-2;
	if(x==1)hav++; 
	for(int i=h[x];i;i=G[i].nxt){
		int u=G[i].to;
		if(u==f)continue;
		dfs(u,x);
		ans=ans*hav%mod;
		hav--;
	}
}
int main(){
	scanf("%d%d",&n,&K);
	for(int i=1,a,b;i<n;i++){
		scanf("%d%d",&a,&b);
		Add(a,b);Add(b,a);
	}
	dfs(1,0);
	printf("%lld\n",ans*K%mod);
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>

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

using namespace std;

int gcd(int x,int y){
    if (x < y) {
        int tmp = x;
        x = y;
        y = tmp;
    }
    while (y > 0) {
        int tmp = x;
        x = y;
        y = tmp % y;
    }
    return x;
}

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

    int a, b;
    cin >> a >> b;
    int ans = a * b / gcd(a, b);
    cout << (long) a * b / gcd(a, b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int a,b,n,m,x,y,z,i=0,ans=0,c=0,r;
    string s;
    cin >> n >> m;
    cout << (n*(n-1)/2)+(m*(m-1)/2) << endl;
    return 0;
}


Measured memory_bytes: 3640
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    N,=pin()
    s=set()
    prev=""
    for i in range(N):
        temp=input()
        if temp in s:
            print("No")
            return
        if i>0 and temp[0]!=prev[-1]:
            print("No")
            return
        s.add(temp)
        prev=temp
    print("Yes")
#%%submit!
resolve()

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

using namespace std;

const int Maxn = 1e3+7;
const int MOD = 1e9+7;

int H, W;
int m[Maxn][Maxn];

int main()
{
    char c;
    cin >> H >> W;
    for(int i = 1; i <= H; ++i)
        for(int j = 1; j <= W; ++j)
        {
            cin >> c;
            if(c == '.') m[i][j] = (m[i-1][j]+m[i][j-1])%MOD;
            if(i == 1 && j == 1) m[i][j] = 1;
        }
    cout << m[H][W] << endl;
    return 0;
}

Measured memory_bytes: 4224
def kagamiMochi():
	N = int(input())
	d = []
	for _ in range(0, N):
		d.append(int(input()))
	d.sort()
	count = 1
	for j in range(1, N):
		if d[j] != d[j-1]:
			count += 1
	print(count)

kagamiMochi()

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

int main(){
    int n;
    cin>>n;
    if(n%10!=7&&(n/10)%10!=7&&(n/100)%10!=7){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N=1e6+9;
int cnt[N];
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    int y[x];
    for (int i=0;i<x;i++){
        cin>>y[i];
        cnt[y[i]]++;
    }
    int ans=0;
    for (int i=0;i<x;i++){
        if (cnt[y[i]]>1)
            continue;
        vector<int>d;
        for (int j=1;j<=sqrtl(y[i]);j++){
            if (y[i]%j==0)
            {
                d.push_back(j);
                if (j*j!=y[i])
                    d.push_back(y[i]/j);
            }
        }
        bool valid=1;
        for (int j=0;j<d.size();j++){
            if (d[j]==y[i])
                continue;
            if (cnt[d[j]]){
                valid=0;
                break;
            }
        }
        if (valid)
            ans++;
    }
    cout<<ans;
    return 0;
}

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

#define SWAP(a,b) {int temp;temp=a;a=b;b=temp;}

void quicksort(int *seq,int size);
void sub_quicksort(int *seq,int left,int right);


int main(void){

  int size;
  int *seq;
  double value=0.0;

  scanf("%d",&size);

  if((seq=malloc(size*sizeof(int)))==NULL){
    printf("error");
    exit(1);
  }

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

  quicksort(seq,size);
  value=seq[0];
  for(int i=1;i<size;i++){
    value=(value+seq[i])/2.0;
  }

  printf("%f\n",value);

  free((void *)seq);

}

void quicksort(int *seq,int size){

  sub_quicksort(seq,0,size-1);

}


void sub_quicksort(int *seq,int left,int right){
  int pivot=seq[(left+right)/2];
  int left_index=left;
  int right_index=right;

  while(left_index<=right_index){
    for(;seq[left_index]<pivot;left_index++);
    for(;seq[right_index]>pivot;right_index--);

    if(left_index<=right_index){
      SWAP(seq[left_index],seq[right_index]);
      left_index++;
      right_index--;
    }
  }
  if(right_index>left){
    sub_quicksort(seq,left,right_index);
  }
  if(left_index<right){
    sub_quicksort(seq,left_index,right);
  }
}


Measured memory_bytes: 128
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#include <string>
#include <stack>
#include <cctype>
#include <vector>
#include <queue>
#include <set>
using namespace std;

int a[100500];

void init()
{

    return;
}

int main()
{
    int n;
    scanf("%d",&n);
    int MOD=1e9+7;
    long long ans;
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    int s,k;
    s=1;k=1;ans=1;
    for (int i=1;i<n;i++)
    {
        if ((a[i]<s)&& (i!=n)) {ans=ans*k % MOD;continue;}
        s=s+2;k=k+1;
    }
    //printf("%d %d\n",s,k);
    for (int i=1;i<=k;i++)
    {
        ans=ans*i % MOD;
    }
    printf("%d\n",(int) ans);
    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 200000 + 100;
int N, ans, A[maxn];

void Init()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; ++i)
		scanf("%d", &A[i]);
}

void Solve()
{
	sort(A+1, A+N+1);
	printf("%d ", A[N]);
	int mid = A[N] >> 1;
	ans = A[1];
	for(int i = 2; i < N; ++i)
		if(abs(A[i]-mid) <= abs(ans-mid))
			ans = A[i];
	printf("%d\n", ans);
}

int main()
{
	Init(), Solve();
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<pair<int, int>>>;
vector<int> color;
/////black: 1, white: 0, undecided: -1

void dfs(const Graph &G, int u, int this_color){
    color[u] = this_color;
    for (auto next: G[u]){
        int w = next.second;
        int next_u = next.first;
        if (color[next_u] != -1) continue;
        int next_color = this_color;
        if (w % 2 == 1) {next_color = 1 - this_color;}
        dfs(G, next_u, next_color);
        // if (w % 2 == 1) dfs(G, next_u, 1 - this_color);
        // else dfs(G, next_u, this_color);
        // color[next_u] = this_color;
        // dfs(G, next_u, u, this_color);
    }
}

int main() {
    int N;
    cin >> N;
    Graph G;
    G.assign(N, vector<pair<int, int>>());
    for (int i = 1; i < N; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--;v--;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }
    color.assign(N, -1);
    dfs(G, 0, 1);
    for (auto c: color) cout << c << endl;
    return 0;
}

Measured memory_bytes: 10744
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
wa=0
data=[0]*(n+1)
AC=[0]*(n+1)
for i in range(m):
    p,s=input().split()
    p=int(p)
    if s=="WA":
        data[p]+=1
    else:
        AC[p]=1
        wa+=max(0,data[p])
        data[p]=-inf
# print(data)
print(sum(AC),wa)

        
    

Measured memory_bytes: 45932
program hi;
var 
    k, n, i, j, ans: integer;
    p: array[1..1000] of integer;

procedure swap(var x: integer; var y: integer);
var tmp: integer;
begin
    tmp := x;
    x := y;
    y := tmp;
end;

begin
    readln(n, k);
    for i := 1 to n do 
        read(p[i]);
    for i := 1 to n - 1 do
        for j := 1 to n - 1 do 
            if p[j] > p[j + 1] then
                swap(p[j], p[j + 1]);
    ans := 0;
    for i := 1 to k do
        ans := ans + p[i];
    writeln(ans);
end.

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

int main() {
	
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++)
	{
	    cin>>arr[i];
	}
	
	int dp[n];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);
	
	for(int i=2;i<n;i++)
	{
	     dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]) , dp[i-2]+abs(arr[i]-arr[i-2]) );
	 
	}
	
	cout<<dp[n-1];
	
	return 0;
}


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



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a, b;
    cin >> a >> b;
    if (a >= 13)
    {
        cout << b << endl;
    }
    else if (a >= 6)
    {
        cout << b / 2 << endl;
    }
    else cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 2e5+5;
int a[MAXN];
long long ans;
int main(){
	int n,t;
	scanf("%d%d",&n,&t);
	for(int i = 1; i <= n; i++)
		scanf("%d",&a[i]);
	for(int i = 1; i < n; i++)
		ans += min(a[i+1]-a[i] ,t);
	printf("%lld\n",ans+t);
}

Measured memory_bytes: 896
from functools import reduce

# 入力
N = int(input())
P = [int(input()) for _ in range(N)]

INF = 10**15

# Pの逆写像
Q = {p: i for i, p in enumerate(P, 1)}

# j以上の整数を末尾に移動する場合に、先頭に移動すべき整数の個数を求める
ans, _ = reduce(
    lambda acc, j: (
        min(
            acc[0],
            acc[1] + N - j + 1
        ),
        acc[1] if j > N or Q[j - 1] < Q[j] else
        j - 1
    ),
    range(2, N + 2),
    (INF, 0)
)

# 出力
print(ans)


Measured memory_bytes: 35468
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <limits>
#include <map>
#include <set>
#include <iomanip>
#include <cmath>

using namespace std;

typedef long long int ll;
typedef std::numeric_limits<double> dbl;
const long long int LL_INF=1LL<<60;

vector<string> split(const string& input, char delimiter)
{
    stringstream stream(input);
    
    string field;
    vector<string> result;
    while (getline(stream, field, delimiter)) {
        result.push_back(field);
    }
    return result;
}

//#define DEBUG

ll A, B, M, N, D, K, Q, W, H, T, X, Y;

int main()
{
    cin >> N;
    ll power = 1;
    for (int i = 1; i <= N; ++i) {
        power *= i;
        if (power > 1000000007)
            power %= 1000000007;
    }
    cout << power << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    n=int(input())
    a=[int(input()) for _ in [0]*n]
    a=sorted([[a[i],i] for i in range(n)])
    for i in range(n):
        a[i][0]=abs(i-a[i][1])%2
    a=[i[0] for i in a]
    print(sum(a)//2)
main()

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/
/****** define variable start ******/
ll n;
vl a;
/******* define variable end *******/
ll solve() {
	cin >> n;
	a.resize(n);
	bool flag = true;
	REP(i, n){
		cin >> a[i];
		flag = flag && a[i] % 2 == 0;
	}
	if(flag){
		cout << "second" << endl;
	}else{
		cout << "first" << endl;
	}

	return 0;
}
int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return (int)end_solve;
}


Measured memory_bytes: 1024
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Ringo's Favorite Numbers
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  if (n == 100) n++;
  printf("%d", n);
  for (int i = 0; i < d; i++) printf("00");
  putchar('\n');
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

int main() {
	set<PII> s;
	int n;
	scanf( "%d", &n );
	for ( int i = 0; i < n; i++ ) {
		int a, b;
		scanf( "%d %d", &a, &b );
		s.insert( PII( a, b ) );
	}
	scanf( "%d", &n );
	for ( int i = 0; i < n; i++ ) {
		int a, b;
		scanf( "%d %d", &a, &b );
		s.insert( PII( a, b ) );
	}
	vector<PII> vp( s.begin(), s.end() );
	for ( int i = 0; i < vp.size() - 1; i++ ) {
		printf( "%d:%02d ", vp[ i ].first, vp[i].second );
	}
	printf( "%d:%02d\n", vp.back().first, vp.back().second );
	return 0;
}

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

using namespace std;

const int INF = 100000;

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

    vector<pair<int, int>> red;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        red.emplace_back(make_pair(a, b));
    }

    vector<pair<int, int>> blue;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        blue.emplace_back(make_pair(b, a));//x座標とy座標を逆に入れる
    }

    sort(red.begin(), red.end(), greater<>());//x座標が大きい順
    sort(blue.begin(), blue.end());//y座標が小さい順

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (red[i].first < INF && blue[j].first < INF &&
                red[i].first < blue[j].second &&
                red[i].second < blue[j].first) {
                ans++;
                red[i].first = INF;
                blue[j].first = INF;
            }
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D,L,R;
  cin >> A >> B >> C >> D;
  L = A+B;
  R = C+D;
  
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (L < R) {
    cout << "Right" << endl;
  }
  else if (L == R){
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M){
	if (N==M) cout << YES << "\n";
	else cout << NO << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


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

int main()
{
    int a, ara[1000], even[1000], j = 0;
    cin>>a;
    for(int i = 0; i < a; i++){
        cin>>ara[i];
        if(ara[i] % 2 == 0){
            even[j] = ara[i];
            j++;
        }
    }
    int count = 0;
    for(int i = 0; i < j; i++){
        if(even[i] % 3 == 0 || even[i] % 5 == 0){
            count++;
        }
    }
    if(count == j) cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;

    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(M)]

G = [[] for _ in range(N)]
for x, y in L:
  x, y = x-1, y-1
  G[x].append(y)
  G[y].append(x)

for v in G[0]:
  if N-1 in G[v]:
    print("POSSIBLE")
    exit()
print("IMPOSSIBLE")

Measured memory_bytes: 79512
n, k = map(int, input().split())
x0 = list(map(int, input().split()))

x1 = [i for i in x0 if i >= 0]
x2 = list(reversed([i for i in x0 if i < 0]))
count0 = len(x1)
count1 = len(x2)
ans = float('inf')

if count1 == 0:
    print(x1[k-1])
elif count0 == 0:
    print(-x2[k-1])
else:
    if 0 in x1:
        x1.remove(0)
        k -= 1
        count0 -= 1
    for i in range(min(count0, k)):
        if count1 >= k-i-1:
            ans = min(ans, x1[i]*2-x2[k-i-2])
    for i in range(min(count1, k)):
        if count0 >= k-i-1:
            ans = min(ans, -x2[i]*2+x1[k-i-2])
    print(ans)


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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

int n, ans;

int main() {
	read(n);
	for (int i = 1; i <= n; ++i)
		if (i & 1) ++ans;
	printf("%.10lf\n", ans * 1.0 / n);
	return 0;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++)
        cin >> A[i];
    vector<int> res(n);
    for(int i=0;i<n;i++)
        res[ A[i] - 1] = i + 1;
    for(int i=0;i<n;i++)
        cout << res[i] << ' ';
}

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

using namespace std;

int main() {
    string s; cin >> s;
    int ans = s.size();
    int n = s.size();
    int tmp = 0;
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n - i - 1]) tmp++;
    }

    ans = min(ans, tmp);
    reverse(s.begin(), s.end());
    tmp = 0;
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n - i - 1]) tmp++;
    }
    ans = min(ans, tmp);
    cout << ans << endl;
}

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

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  double L;
  cin >> L;
  double S = L*L*L/27;
  printf("%lf\n" ,S);


return 0;
}




Measured memory_bytes: 256
N = int(input())
p = list(map(int,input().split()))
inc = []
for i in range(1,N+1):
    if p[i - 1] == i:
        continue
    else:
        inc.append(p[i-1])
if len(inc) <= 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3060
n,a,b,c=map(int,input().split())
ans='NO'
if n==1 or a==1 or b==1 or c==1:
    if n==9 or a==9 or b==9 or c==9:
        if n==7 or a==7 or b==7 or c==7:
            if n==4 or a==4 or b==4 or c==4:
                ans='YES'
print(ans)                


Measured memory_bytes: 2940
main = getContents >>= putOut.formatOut.calc.formatIn
  where putOut s | null s || last s == '\n' = putStr s
                 | otherwise                = putStrLn s
  
formatIn :: String -> ([[Int]],[Int])
formatIn s =  (fst (g s), concat (snd (g s)))
  where f m = map (map (read :: String -> Int).words) (lines m)
        g n = splitAt ((head.head) (f n)) $tail (f n)

formatOut :: [Int] -> String
formatOut = unlines.map show

calc :: ([[Int]],[Int]) -> [Int]
calc (a,b) = map (sum.(zipWith (*) b)) a

Measured memory_bytes: 7520
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n, m = map(int, input().split())
yama = [1]*n
h = []
for i in input().split():
    h.append(int(i))
ab = []
for i in range(m):
    ab.append([int(i) for i in input().split()])

for i in ab:
    if h[i[0] - 1] > h[i[1] - 1]:
        yama[i[1] - 1] = 0
    elif h[i[0] - 1] < h[i[1] - 1]:
        yama[i[0] - 1] = 0
    else:
        if i[0] != i[1]:
            yama[i[0] - 1] = 0
            yama[i[1] - 1] = 0

sum = 0
for i in yama:
    sum += i
print(sum)

Measured memory_bytes: 30404
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



signed main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N,C;
	cin >> N >> C;
	VI X(N+2),V(N+2);
	eFOR(i,1, N) cin >> X[i] >> V[i];
	X[0] = 0;
	X[N + 1] = C;

	int cal = 0;
	vector<VI> dp(2, VI(100010, 0));

	eFOR(i, 1, N) {
		cal -= X[i] - X[i - 1];
		cal += V[i];
		dp[0][i] = max(dp[0][i - 1], cal);
	}
	cal = 0;
	for (int i = N; i >= 0; i--) {
		cal -= X[i + 1] - X[i];
		cal += V[i];
		dp[1][i] = max(dp[1][i + 1], cal);
	}
	int maxcal = 0;
	eREP(i, N) {
		cal = dp[0][i] + dp[1][i + 1] - X[i];
		maxcal = max(maxcal, cal);

		cal = dp[0][i] + dp[1][i + 1] - C + X[i + 1];
		maxcal = max(maxcal, cal);
	}


	cout << maxcal << endl;


	return 0;
}



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

int main() {
  int N; cin >> N;
  double x[N]; string u[N]; for (int i = 0; i < N; ++i) cin >> x[i] >> u[i];
  double res = 0;
  for (int i = 0; i < N; ++i) {
    if (u[i] == "JPY") res += x[i];
    else res += (x[i] * 380000.0);
  }
  cout << res << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		char[] col = new char[S.length()];
		
		for(int i = 0; i < S.length(); i++) {
			col[i] = S.charAt(i);
		}
			
		int count1 = 0;
		int count2 = 0;
		
		for(int i = 1; i < S.length(); i++) {
			if(col[i] == col[i - 1] && col[i] == '0') {
				col[i] = '1';
				count1++;
			} else if(col[i] == col[i - 1] && col[i] == '1') {
				col[i] = '0';
				count1++;
			} 
		}
		
		for(int i = 1; i < S.length(); i++) {
			if(col[i] == col[i - 1] && col[i] == '0') {
				col[i - 1] = '1';
				count2++;
			} else if(col[i] == col[i - 1] && col[i] == '1') {
				col[i - 1] = '0';
				count2++;
			} 
		}
	
		System.out.println(Math.max(count1, count2));
		
	}
}


Measured memory_bytes: 26724
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    int N, M;
    readf("%d %d\n", &N, &M);
    bool[] first = new bool[N];
    bool[] last = new bool[N];
    foreach (i; 0..M) {
        int a, b;
        readf("%d %d\n", &a, &b);
        if (a == 1) first[b-1] = true;
        if (b == N) last[a-1] = true;
    }
    writeln(N.iota.any!(i => first[i] && last[i]) ? "POSSIBLE" : "IMPOSSIBLE");
}



Measured memory_bytes: 2684
#include <bits/stdc++.h>
using namespace std;
  
#define rep(i,b) for(int i = 0 ; i < b; i++)
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(a) (int)a.size()
#define mod 1000000007
#define dbg(a) cout<<#a<<" = "<<a<<endl
#define dbg2(a,b) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<endl
#define dbg3(a,b,c) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<endl
#define dbg4(a,b,c,d) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<", "<<#d<<" = "<<d<<endl
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>

vi adj[200004];
int ans[200004],v[200004],an;

void dfs(int x,int p, int an){
    ans[x] = an+v[x];
    for(int y:adj[x]){
        if(y!=p) dfs(y,x,ans[x]);
    }
}



void solve()
{
    int n,q,x,y;cin>>n>>q;
    rep(i,n-1){
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    while(q--){
        cin>>x>>y;
        v[x]+=y;
    }
    dfs(1,1,0);
    rep(i,n) cout<<ans[i+1]<<" ";
}
 
int main()
{   
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(11);
    clock_t beg=clock();
    int t=1, n;
    // cin>>t;
    // n = t;
    while(t--){
        // cout << "Case #" << n-t << ": ";
        solve();
    }
    //
    clock_t end=clock();
    fprintf(stderr, "%lf sec\n", (double)(end-beg)/(CLOCKS_PER_SEC));
    return 0;
}

Measured memory_bytes: 24064
#include<bits/stdc++.h>
using namespace std;
#define pfi(a) printf("%d",a);
#define pfl(a) printf("%lld",a);
#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pb push_back
#define f(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define endl "\n"
const int MAXN=3e5+5;
const int M= 1e9;

int main(){	
	
	int n;
	sfi(n)

	int freq[n+1]={0};

	for(int i=2;i<=n;i++){
		int temp;sfi(temp)

		freq[temp]++;
	}

	for(int i=1;i<=n;i++){
		cout<<freq[i]<<endl;
	}
	
	return 0;	
}

Measured memory_bytes: 4472
#include<stdio.h>
#define rep(i,n) for(int i=0; (i)<(n); (i)++)
typedef struct{
    int num;
    int h;
}Position;
Position pos[200][200];
const int dice[7][7]={{0,0,0,0,0,0,0},{0,0,4,2,5,3,0},{0,3,0,6,1,0,4},{0,5,1,0,0,6,2},
    {0,2,6,0,0,1,5},{0,4,0,1,6,0,3},{0,0,3,5,2,4,0}};
void init(){
    rep(i,200) rep(j,200) pos[i][j].num=-1,pos[i][j].h=0;
}
int left(int top,int front){
    if(dice[top][front]==0) printf("エラー\n");
    return dice[top][front];
}
const int dx[4]={0,-1,1,0};
const int dy[4]={-1,0,0,1};
int main(void){
    while(1){
        int n;
        scanf("%d",&n);
        if(n==0) break;
        init();
        rep(i,n){
            int t, f;
            int starty=100,startx=100;
            scanf("%d%d", &t, &f);
            while(1){
                int dir[4];
                int direction=4;
                int max=3;
                dir[0]=7-f,dir[1]=left(t,f),dir[2]=7-dir[1],dir[3]=f;
                rep(j,4){
                    int tmpy=starty+dy[j],tmpx=startx+dx[j];
                    if((pos[starty][startx].h>pos[tmpy][tmpx].h)
                       && (dir[j]>max)){
                        direction=j;
                        max=dir[j];
                    }
                }
                //printf("%d:direction=%d t=%d f=%d\n",i,direction,t,f);
                if(max==3) break;
                else {
                    starty+=dy[direction],startx+=dx[direction];
                    switch (direction) {
                        case 0:f=7-t;break;
                        case 1:break;
                        case 2:break;
                        case 3:f=t;break;
                        default:break;
                    }
                    t=7-dir[direction];
                }
            }
            //if(starty==99&&startx==101)printf("clear\n");
            pos[starty][startx].h++;
            pos[starty][startx].num=t;
        }
        int a[6]={0};
        rep(i,200) rep(j,200) if(pos[i][j].num>0)a[pos[i][j].num-1]++;
        rep(i,6) printf("%d%c",a[i],i==5?'\n':' ');
    }
}



Measured memory_bytes: 2104
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;
const double PI=3.1415926;

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	double n;

	cin>>n;

	cout<<2*n*PI<<endl;

	return 0;

}

Measured memory_bytes: 3784
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>
using namespace std;
#define INF 1<<20


struct edge{
	int to;
	int cost;
	edge() {};
	edge(int a, int b) {
		to = a;
		cost = b;
	}
};

struct Node {
	int pos;
	int cost;
	Node() {};
	Node(int a, int b) {
		pos = a;
		cost = b;
	}
	bool operator <(const Node& rhs) const {
		return cost > rhs.cost;
	}
};

void dijkistra(int st, int TO,int V,vector<vector<edge> > graph) {
	priority_queue<Node> q;
	vector<int> d(V);
	for (int i = 0;i < V;i++) {
		d[i] = INF;
	}
	d[st] = 0;
	q.push(Node(st, 0));
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int pos = s.pos;
for (int i = 0;i < graph[pos].size();i++) {
	int to = graph[pos][i].to;
	int cost = graph[pos][i].cost;
	if (d[pos] + cost < d[to]) {
		d[to] = d[pos] + cost;
		q.push(Node(to, d[to]));
	}

}
	}
	cout << d[TO] << endl;
}
int partition(int A[], int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q - 1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[], int n, int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >= 0) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n, int* v, int* ww) {
	int W[101][10001];
	for (int j = 0;j <= w;j++) {
		W[0][j] = 0;
	}
	for (int i = 0;i < n;i++) {
		for (int k = 0;k < n;k++) {
			for (int j = 0;j <= w;j++) {
				if (j - ww[k] < 0) {
					W[i + 1][j] = W[i][j];
				}
				if (j - ww[i] >= 0) {
					W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]);

				}
			}
		}
	}
	return W[n][w];
}
int fib(int n) {
	vector<int> v(n + 1);
	v[0] = 1;
	v[1] = 1;
	for (int i = 2;i < n + 1;i++) {
		v[i] = v[i - 2] + v[i - 1];
	}
	return v[n];
}
int isPrime(int x) {
	if (x <= 1) return false;
	if (x > 2 && x % 2 == 0) return false;
	for (int i = 2;i <= sqrt(x);i++) {
		if (x%i == 0) {
			return false;
		}
	}
	if (x == 2) return true;
	return true;
}
int gnc(int a, int b) {
	while (b%a != 0) {
		if (a > b) swap(a, b);
		else {
			b = b%a;
		}
	}
	return a;
}
int calc(int a, long long int b, long long int m) {
	if (b == 0) return 1;
	else if (b % 2 == 0) {
		long long int d = calc(a, b / 2, m);
		return (d*d) % m;
	}
	else {
		long long int d = calc(a, b -1, m);
		return (d*a) % m;
	}
}


int main() {
	int N;
	int num;
	cin >> N;
	vector<int> A(N);
	for (int i = 0;i < N;i++) {
		cin>>A[i];
	}
	sort(A.begin(), A.end());
	A.erase(unique(A.begin(), A.end()), A.end());
	num = A.size();
	if (num % 2) {
		cout << num << endl;
	}
	else cout << num - 1 << endl;
	return 0;
	}




Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <iostream>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    vector<pair<int, int>> v;
    for (int i = 1; i <= 150; ++i) {
        for (int j = i + 1; j <= 150; ++j) {
            assert(i < j);
            v.emplace_back(i, j);
        }
    }
    sort(begin(v), end(v),
         [](const pair<int, int>& a, const pair<int, int>& b) {
             int ah = a.first;
             int aw = a.second;
             int bh = b.first;
             int bw = b.second;
             auto aa = ah * ah + aw * aw;
             auto bb = bh * bh + bw * bw;
             if (aa < bb) {
                 return true;
             }
             else if (aa == bb) {
                 return ah < bh;
             }
             return false;
         });
    while (true) {
        int h, w;
        cin >> h >> w;
        if (h == 0 && w == 0) {
            return 0;
        }

        auto it = find(begin(v), end(v), make_pair(h, w));
        ++it;
        cout << it->first << ' ' << it->second << endl;
    }
}


Measured memory_bytes: 3220
S = [["0" for i in range(101)] for j in range(101)]

while True:
    check = [[False for i in range(101)] for j in range(101)]
    x = 0
    y = 0
    LOOP = False
    
    H, W = map(int, raw_input().split())
    
    if (H == 0 and W == 0):
        break
    
    for i in range(H):
        S[i] = raw_input()
    
    while (S[y][x] != "."):
        if (check[y][x] == True):
            LOOP = True
            print "LOOP"
            break
        
        check[y][x] = True
        
        if (S[y][x] == "^"):
            y -= 1
        elif (S[y][x] == ">"):
            x += 1
        elif (S[y][x] == "v"):
            y += 1
        else:
            x -= 1

    if (LOOP == False):
        print x, y

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const int N = 100010;

inline int in() {int x; scanf("%d",&x); return x;}
inline ll lin() {ll x; scanf("%lld",&x); return x;}

int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

bool f_prime[N];
int prime[N], sz;

void Sieve(){
    for(int i = 4; i < N; i += 2) f_prime[i] = 1;
    for(int i = 3; i * i <= N; i += 2){
        if(f_prime[i] == 0){
            for(int j = i * i; j < N; j += i){
                f_prime[j] = 1;
            }
        }
    }
    prime[++sz] = 2;
    for(int i = 3; i <= 55555; i += 2){
        if(f_prime[i] == 0){
            prime[++sz] = i;
        }
    }
}

int main(){
    Sieve();
    int n = in();
    for(int i = 1; i <= sz && n > 0; i++){
        if(prime[i] % 10 == 3){
            printf("%d ", prime[i]);
            n--;
        }
    }
    puts("");
}


Measured memory_bytes: 384