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

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextLine();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		for(int i = n - 1; i >= 0; i--) {
			if(i > 0)
			System.out.print(a[i] + " ");
			else
			System.out.print(a[i]);
		}		
		System.out.println();
		sc.close();
	}
}


Measured memory_bytes: 26376
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};



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

	cin >> a;
	
	int ans = 700;
	
	if (a[0] == 'o')
	{
		ans += 100;
	}

	if (a[1] == 'o')
	{
		ans += 100;
	}

	if (a[2] == 'o')
	{
		ans += 100;
	}
	
	cout << ans << endl;
	


}
	

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const long long INF = 1LL<<40;


int main()
{
    ll N, K; cin >> N >> K;
    vvll s(N);
    rep(i, N) {
        ll t, d; cin >> t >> d; --t;
        s[t].push_back(d);
    }

    for (auto &v : s) {
        sort(all(v), greater<ll>());
        if (v.empty()) v.push_back(-INF);
    }

    sort(all(s), [&](vll a, vll b){return a[0] > b[0];});

    ll cur = 0;
    priority_queue<ll> que;
    rep(i, K) {
        cur += s[i][0];
        for (int j = 1; j < s[i].size(); ++j) que.push(s[i][j]);
    }
    for (int i = K; i < N; i++) rep(j, s[i].size()) que.push(s[i][j]);

    ll res = cur + K * K;
    for (ll x = K - 1; x >= 1; --x) {
        ll v = s[x][0];
        ll w = que.top();
        if (v < w) {
            que.pop(); cur += w;
            que.push(v); cur -= v;
        }
        res = max(res, cur + x * x);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 8696
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = "123";
    String a = sc.next();
    String b = sc.next();
    String str1 = str.replace(a,"").replace(b,"");
    System.out.println(str1);
  }
}

Measured memory_bytes: 21204
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b): #最小公倍数
    return a/gcd(a,b)*b

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    n = input()
    ans = 0
    for i in range(4):
        if n[i] == '2':
            ans += 1
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38508
#include <iostream>
#include <cstdio>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;
int N,L[10],s=0;
int main(){
cin >> N;
for(int i=0;i<N;i++)cin >> L[i];
sort(L,L+10,greater<int>());
for(int i=1;i<N;i++){
s+=L[i];
}
if(L[0]<s)cout << "Yes" << endl;
else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <array>

using namespace std;
int main()
{
    int N;
    cin >> N;
    int A[N];

    for(int i = 0; i < N; i++){
      cin >> A[i];
    }

    int c = 0;
    int p = 0;

    while(true){
      p = 0;
      for(int i = 0; i < N; i++){
        if(A[i] % 2 == 0){
          p++;
          A[i] = A[i] / 2;
        }
      }
      if(p == N){
        c++;
      }else{
        break;
      }
    }

    cout << c << endl;
    return 0;
}


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

vector<vector<pair<int, int>>> g;
vector<int> color;
int Mx = 0;

void dfs(int v, int p, int c) {
  int nc = 1;
  for (auto nv : g[v]) {
    if (nv.first == p) continue;
    if (c == nc) nc++;
    color[nv.second] = nc;
    Mx = max(Mx, nc);
    dfs(nv.first, v, nc);
    nc++;
  }
}

int main() {
  int n; cin >> n;
  g.resize(n);
  color.resize(n-1);
  vector<int> a(n), b(n);
  rep(i, n-1) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  rep(i, n-1) {
    g[a[i]].push_back({b[i], i});
    g[b[i]].push_back({a[i], i});
  }
  dfs(0, -1, 0);
  cout << Mx << endl;
  for (auto u : color) cout << u << endl;
  return 0;
}


Measured memory_bytes: 8832
N, W = map(int, input().split())
w = [0]*N
v = [0]*N
for i in range(N):
    w[i],v[i] = map(int, input().split())

def solve(w,v):
    # print(W)
    dp = [[W+1]*(10**5+1) for i in range(N+1)]
    dp[0][0]=0
    for i in range(1,N+1):
        for j in range(10**5+1):
            if j < v[i-1]:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j],dp[i-1][j-v[i-1]]+w[i-1])
    for i in range(10**5,-1,-1):
        if dp[-1][i]<=W:
            ans = i
            break
    return ans
print(solve(w,v))

Measured memory_bytes: 118512
#include <stdio.h>
#include <stdlib.h>
#define INF 99999999
void init(int *c, int *s, int n)
{
	int i;
	c[0] = 0;
	for(i = 1; i < n; i++)
		c[i] = INF;

	for(i = 0; i < n; i++)
		s[i] = -1;
}

int min(int x, int y){return x<y?x:y;}

int main()
{
	int n, m, i, j, save;
	scanf("%d %d" ,&n ,&m);
	int *d = (int *)malloc(m*sizeof(int));
	int *c = (int *)malloc((n+1)*sizeof(int));
	int *s = (int *)malloc((n+1)*sizeof(int));
	for(i = 0; i < m; i++)
		scanf("%d" ,&d[i]);

	init(c, s, n+1);

	for(i = 0; i < m; i++)
	{
		for(j = d[i]; j <= n; j++)
		{
			save = c[j];
			c[j] = min(c[j], c[j-d[i]] + 1);
			if(c[j] != save) s[j] = d[i];
		}
	}		

	printf("%d\n" ,c[n]);
	return 0;
}

Measured memory_bytes: 988
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct help{
 ll weight,value;
};
ll maxValue(help arr[],ll n,ll w){
 ll dp[n+1][w+1]={0};
 for(ll i=0;i<=n;i++){
    for(ll j=0;j<=w;j++){
      if(i==0 || j==0){
        dp[i][j] = 0;
      }
      else{
         if(j-arr[i].weight>=0){
            dp[i][j] = max(dp[i][j],arr[i].value + dp[i-1][j-arr[i].weight]);
         }
         dp[i][j] = max(dp[i][j],dp[i-1][j]);
      }
   }
 }
 return dp[n][w];
}
int main(){
 ll n,w;
 cin>>n>>w;
 help arr[n+1];
 for(ll i=1;i<=n;i++){
    cin>>arr[i].weight>>arr[i].value;
 }
 cout<<maxValue(arr,n,w);
}


Measured memory_bytes: 79104
N = int(input())
balls = []
for i in range(N):
    x, y = map(int, input().split(' '))
    balls.append((x,y))

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

dic = {}
for i in range(N):
    for j in range(i+1,N):
        dx = balls[j][0] - balls[i][0]
        dy = balls[j][1] - balls[i][1]
        if (dx,dy) not in dic.keys():
            dic[(dx,dy)] = 1
        else:
            dic[(dx,dy)] += 1
        dx *= -1
        dy *= -1
        if (dx,dy) not in dic.keys():
            dic[(dx,dy)] = 1
        else:
            dic[(dx,dy)] += 1

d_max = max(dic.values())
print(N - d_max)


Measured memory_bytes: 3444
#include<stdio.h>
#include<algorithm>
#define pii pair<int,int>
using namespace std;
int n, chk[101000], res;
pii w[101000];
int main(){
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&w[i].first);
        w[i].second = i;
    }
    sort(w+1,w+n+1);
    for(i=1;i<=n;i++){
        if(w[i].second%2 != i%2)res++;
    }
    printf("%d\n",res/2);
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
const int maxn=0x3f3f3f3f;
typedef long long ll;
char a[100005];
int b[100005];
int main()
{
    scanf("%s",a);
    memset(b, 0, sizeof b);
    int t=0;
    int n=strlen(a);
    int left=0;
    for(int i=0;i<n;i++){
        t++;
        if(a[i]=='R')
            left=i;
        if(a[i]=='L'){
            if((i-left)%2){
                b[left]+=t/2;
                b[left+1]+=(t+1)/2;
            }
            else {
                b[left+1]+=t/2;
                b[left]+=(t+1)/2;
            }
            t=0;
        }
    }
    for(int i=0;i<n-1;i++){
        printf("%d ",b[i]);
    }
    printf("%d\n",b[n-1]);
    return 0;
}


Measured memory_bytes: 896
l=int(input())
d=l.bit_length()
g=[]
for i in range(d-1):
  g.append((i+1,i+2,0))
  g.append((i+1,i+2,2**(d-i-2)))
s=1<<(d-1)
for i in range(d-1)[::-1]:
  if (1<<i)&l:
    g.append((1,d-i,s))
    s+=1<<i
print(d,len(g))
for u,v,c in g:
  print(u,v,c)

Measured memory_bytes: 3064
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 10;

int main() {
	int n, m, s, g1, g2;
	while (cin >> n >> m >> s >> g1 >> g2, n) {
		s--; g1--; g2--;

		vvi dist(n, vi(n, INF));
		REP(i, n) {
			dist[i][i] = 0;
		}

		int b1, b2, c;
		REP(i, m) {
			cin >> b1 >> b2 >> c;
			dist[b1 - 1][b2 - 1] = c;
		}

		REP(i, n) {
			REP(j, n) {
				REP(k, n) {
					dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
				}
			}
		}

		int ans = INF;
		REP(i, n) {
			ans = min(ans, dist[s][i] + dist[i][g1] + dist[i][g2]);
		}
		cout << ans << endl;
	}
}

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

int main(){
  int n,k;
  char s[100006];
  int i,ans;

  scanf("%d %d", &n, &k);
  scanf("%s", s);

  int cnt = 0;
  for(i = 0;i < n - 1;i++){
    if(s[i] != s[i + 1]) cnt++;
  }

  int init;
  init = n - cnt - 1;
  init += 2*k;

  ans = min(n - 1,init);

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

  return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> unit;
  unit.push_back(1);
  int six = 6;
  for (; six <= N; six *= 6)
    unit.push_back(six);
  int nine = 9;
  for (; nine <= N; nine *= 9)
    unit.push_back(nine);
  vector<int> dp(N + 1);
  for (int i = 1; i <= N; ++i)
  {
    vector<int> cnt(unit.size(), 100001);
    for (int j = 0; j < cnt.size(); ++j)
      if (0 <= i - unit[j])
        cnt[j] = dp[i - unit[j]] + 1;
    dp[i] = *min_element(cnt.begin(), cnt.end());
  }
  cout << dp[N];
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
set<int> S;
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		int val;
		scanf("%d", &val);
		S.insert(val);
	}
	if(S.size() == n) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 9600
use std::io::{self, Read};

fn gcd(a: i64, b: i64) -> i64 {
    if a % b == 0 {
        b
    } else {
        gcd(b, a % b)
    }
}

fn main() {
    let mut k = String::new();
    io::stdin().read_to_string(&mut k).unwrap();

    let k: i64 = k.trim().parse().unwrap();

    let mut result: i64 = 0;

    for a in 1..=k {
        for b in 1..=k {
            for c in 1..=k {
                result += gcd(gcd(a, b), c);
            }
        }
    }

    println!("{}", result);
}


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

#define T 36
 
int main(){
 
  int A[T],B[T],n,a1,b2,flag=0;
  char c3,C[T],D[T];
 
  scanf("%d",&n);
  
  int i,j;
 
  for(i=1;i<=n;i++){
    
    scanf(" %c%d",&C[i],&A[i]);
    
    B[i]=A[i];
    D[i]=C[i];
  }
 
 
 
  
  for(i=0;i<n;i++){
    
    for(j=n;j > i+1;j--){
      
      if(A[j]<A[j-1]){
	
        c3=C[j];
        C[j]=C[j-1];
        C[j-1]=c3;
        a1=A[j];
        A[j]=A[j-1];
        A[j-1]=a1;
    }
    }
  }

  
  for(i=1;i<=n;i++){
    
    printf("%c%d",C[i],A[i]);
    
    if(i!=n)printf(" ");
  }
    printf("\nStable\n");


  for(i=1;i<=n;i++){
    
    b2=i;
    
    for(j=i;j<=n;j++){
      
      if(B[j]<B[b2]){
	
        b2=j;
      }
    }
     c3=D[i];
      D[i]=D[b2];
      D[b2]=c3;
      a1=B[i];
      B[i]=B[b2];
      B[b2]=a1;
  }
  for(i=1;i<=n;i++){
    
    printf("%c%d",D[i],B[i]);
    
    if(i!=n)printf(" ");
    
  }
  
  printf("\n");
  
flag=0;
 
  for(i=1;i<=n;i++){
    
    if(B[i]!=A[i]||D[i]!=C[i]){
      
      flag=1;
      
      printf("Not stable\n");
      
      break;
    }
  }
     if(flag==0) printf("Stable\n");
   return 0;
}




Measured memory_bytes: 2140
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
using namespace std;

int main()
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  string s;
  cin >> s;

  int n = s.size();
  int i = 0, j = n-1;

  for(i; i < n; i++)
  	if(s[i] == 'A')
  		break;

  for(j; j > i; j--)
  	if(s[j] == 'Z')
  		break;

  cout << j-i+1 << endl;
  return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int m[111] = {};
  for (int i = 1; i <= n; ++i) {
    string s = to_string(i);
    int a = s.front() - '0';
    int b = s.back() - '0';
    int k = a * 10 + b;
    m[k]++;
  }
  long long ans = 0;
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      int x = i * 10 + j;
      int y = j * 10 + i;
      ans += m[x] * m[y];
    }
  }
  cout << ans << endl;
  return 0;
}



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

const int INF = 1e9+7;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p.at(i);
	int now=p.at(0);
	int ans=0;
	rep(i, n){
		if(p.at(i) <= now){
			ans++;
			now=p.at(i);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#define DBG 1 //submit 0
#define ll long long
#if DBG
    #include <algorithm>
    #include <array>
    #include <ctime>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <unordered_map>
    #include <iostream>
    #include <cmath>
    #include <queue>
    #include <numeric>
#else
    #include <bits/stdc++.h>
#endif
 
using namespace std;
 
 
int main(){
    int n,k,m,x,sum=0,ok=0,ng=0;
    int ans=0;
    char s[10005][5];
    char c='a';
    //char alp[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    bool flag[100005];
    int p[100005];
    //char s[100];
    //for(int i=0;i<n;i++)
   
    cin >> c;
    c++;
   

    
   
    //cout << (flag ? "Yes" : "No");
    cout << c;
    //for(int i=0;i<m;i++) cout << s[i];
    //printf("%.10f",ans_d);
    cout << endl;
}


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int a;
  set<int> s;
  rep(i, 0, n) {
    cin >> a;
    if (Find(s, a)) {
      s.erase(a);
    } else {
      s.insert(a);
    }
  }

  cout << (int)s.size() << endl;

  return 0;
};


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
    long long x;
public:
    mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
    mint operator-() const {
        return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream& operator<<(ostream& os, const mint& m) {
        os << m.x;
        return os;
    }
};

///////////////////////////


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

    vector<pair<ll, ll>> a(N+1);

    repn(i, N) {
        cin >> a[i].first;
        a[i].second = i;
    }

    sort(++a.begin(), a.end());

    ll ans = N;
    repn(i, N) {
        if ((a[i].second - i) % 2 == 0) { ans--; }
    }

    cout << ans / 2;
   
	
	system("PAUSE");
}


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

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

int main()
{
  int N {0};
  std::cin >> N;
  int a[N+1][3] {0};
  for (int i = 1; i <= N; i++) {
    std::cin >> a[i][0] >> a[i][1] >> a[i][2];
  }

  long long dp[N+1][3] {0};
  for ( int i = 0; i <= N; i++ ) {
    for ( int j = 0; j < 3; j++ ) {
      for ( int k = 0; k < 3; k++ ) {
        if ( j == k ) continue;
        chmax(dp[i+1][j], dp[i][k] + a[i+1][j]);
      }
    }
  }
  long long ans {0};
  for ( int i = 0; i < 3; i++ ) {
    if ( ans < dp[N][i] ) ans = dp[N][i];
  }
  std::cout << ans << std::endl;
  return 0;
}


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

#define debug(x) cerr << #x << ": " << x << endl;

#define iosbase ios_base::sync_with_stdio(false)
#define tie cin.tie();cout.tie();

#define endl '\n'

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

#define mod 1000000007

long long fat(long long int x){
  long long res = 1;
  for(int i = 1; i <= x; i++){
    res = (res * i)%mod;
  }

  return res;
}

long long fast_expo(long long int b, long long int e){
  if(e == 0) return 1LL;
  if(e == 1) return b;
  long long res = 1;
  if(e & 1) res = (res*b)%mod;
  return (res*fast_expo((b*b)%mod, e/2))%mod;
}

long long mydiv(long long int a, long long int b){
  return (a * fast_expo(b, mod-2))%mod;
}
int main(){

int n, m;
  iosbase;
  tie;

  int x, y;
  cin >> x >> y;
  if( y > x) swap(y, x);
  int cont = 0;
  for(int i = 0; i <= x; i++){
    // debug(i);
    if( (x-i)%2 != 0 ) continue;
    int num2 = (x - i)/2;
    // debug(y - (i*2) - num2);
    if( (y - (i*2) - num2) == 0 ){
      // cout << "entrou aqui" << endl;
      long long p1 = fat(i+num2);
      // debug(p1);
      long long p2 = (fat(i) * fat(num2))%mod;
      // debug(p2);
      cout << mydiv(p1, p2) << endl;
      return 0;
    }
  }

  cout << "0" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int h[] = new int[N];
		for (int i=0;i<N;i++) {
			h[i]= sc.nextInt();
		}
		int result[]= new int[N];
		for (int i=0;i<M;i++) {
			int a= sc.nextInt();
			int b = sc.nextInt();
			if (h[a-1]<h[b-1]) {
				result[a-1]++;
			} else if (h[a-1]==h[b-1]) {
				result[a-1]++;
				result[b-1]++;
			} else {
				result[b-1]++;
			}
		}
		int count=0;
		for (int i=0;i<N;i++) {
			if (result[i] ==0) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 59840
n = int(input())
xy = []
idx = [None]*n
ys = [None]*n
ans = [None]*n
accumx = [None]*n
accumn = [None]*n
for i in range(n):
    x, y = map(int, input().split())
    idx[x-1] = i
    ys[x-1] = y-1
accumx[-1] = ys[-1]
for i in range(n-2, -1, -1):
    accumx[i] = max(accumx[i+1], ys[i])
accumn[0] = ys[0]
for i in range(1, n):
    accumn[i] = min(accumn[i-1], ys[i])

def bisect(x):
    ok = 0
    ng = n
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if accumx[mid]>x:
            ok = mid
        else:
            ng = mid
    return ok

nowx = 0
while nowx<n:
    nxtx = nowx
    tmp = bisect(ys[nowx])
    while tmp>nxtx:
        nxtx = tmp
        tmp = bisect(accumn[nxtx])
    if nxtx<nowx:
        nxtx = nowx
    for i in range(nowx, nxtx+1):
        ans[idx[i]] = nxtx-nowx+1
    nowx = nxtx + 1
print(*ans, sep='\n')

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll a, b;

	cin >> a >> b;

	ll d = b - a;
	ll sum = 0;

	REP(i, d) {
		sum += i + 1;
	}

	cout << sum - b << endl;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 2e5;
int n, a[nsz + 5], rt, lst, ans;
int ql, qr, q[2 * nsz + 5];

struct treap {
	int sz, ls[nsz + 5], rs[nsz + 5], pri[nsz + 5];
	int key[nsz + 5], mn[nsz + 5], mx[nsz + 5];
	
	int inline node(int w) {
		int u = ++sz;
		key[u] = mn[u] = mx[u] = w, pri[u] = rand();
		return u;
	}
	
	void inline up(int u) {
		mn[u] = ls[u] ? mn[ls[u]] : key[u];
		mx[u] = rs[u] ? mx[rs[u]] : key[u];
	}
	
	int merge(int v1, int v2) {
		if (!v1 || !v2)  return v1 | v2;
		return pri[v1] < pri[v2] ? (rs[v1] = merge(rs[v1], v2), up(v1), v1) : (ls[v2] = merge(v1, ls[v2]), up(v2), v2);
	}
	
	void split(int u, int w, int &v1, int &v2) {
		if (!u) { v1 = v2 = 0; return; }
		key[u] <= w ? (v1 = u, split(rs[u], w, rs[u], v2), up(u)) : (v2 = u, split(ls[u], w, v1, ls[u]), up(u));
	}
	
	void inline push_back(int &rt, int w) { rt = merge(rt, node(w)); }
	
	void inline pop_back(int &rt, int w) { int v; split(rt, w - 1, rt, v); }
};
treap tr;

void inline init() {
	cont (i, n) {
		if (i == 1 || a[i] < a[i - 1])  ++qr;
		tr.push_back(q[qr - 1], a[i]);
	}
	
	for (lst = n; tr.mx[q[qr - 1]] == lst && lst; tr.pop_back(q[qr - 1], lst--));
}

void inline deal() {
	for (++ans; !q[ql] && ql != qr; ++ql);
	
	int u = q[ql++], mx = tr.mx[u], v1, v2;
	for (int k = ql; k != qr && mx != lst; ++k) {
		if (!q[k] || tr.mx[q[k]] < mx)  continue;
		
		tr.split(q[k], mx, v1, v2);
		q[k] = v1, u = tr.merge(u, v2), mx = tr.mx[u];
		
		int &r1 = q[k - 1], &r2 = q[k];
		if (r1 && tr.mx[r1] < tr.mn[r2])  r2 = tr.merge(r1, r2), r1 = 0;
	}
	
	int &r1 = q[qr - 1], &r2 = u;
	if (r1 && tr.mx[r1] < tr.mn[r2])  r2 = tr.merge(r1, r2), r1 = 0;
	for (; tr.mx[u] == lst && lst; tr.pop_back(u, lst--));
	
	q[qr++] = u;
}

int main() {
	scanf("%d", &n);
	cont (i, n) {
		scanf("%d", &a[i]);
	}
	for (init(); lst; deal());
	printf("%d\n", ans);
}

Measured memory_bytes: 7168
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>

#define CK(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long  LLINF = 1e18;

using namespace std;

/*===========================================*/

ll gcd( ll m, ll n )
{
	if ( ( 0 == m ) || ( 0 == n ) ) return 0;
  if(m < n){
    ll tmp = n;
    n = m;
    m = tmp;
  }
	while(n > 0){
    ll r = m % n;
    m = n;
    n = r;
  }

	return m;
}

ll lcm( ll m, ll n )
{
	if ( ( 0 == m ) || ( 0 == n ) ) return 0;
	return ((m / gcd(m, n)) * n);
}

/*===========================================*/

int N;
ll T[105];

int main(){
  cin>>N;
  REP(i,0,N){
    cin>>T[i];
  }

  ll ans = T[0];
  REP(i,1,N){
    ans = lcm(ans, T[i]);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
    //データ定義
    int card_cnt; //カードの数
    int i;
    //カードの情報
    string player_1_card;
    string player_2_card;
    //プレイヤーの得点
    int player_1_score = 0;
    int player_2_score = 0;
    
    //カードの数を取得
    cin >> card_cnt;
    
    //データ取得
    for(i = 0; i < card_cnt; i++){
        //カードの情報を取得
        cin >> player_1_card >> player_2_card;
        
        //カード比較
        if(player_1_card == player_2_card){
            player_1_score++;
            player_2_score++;
        }else if(player_1_card > player_2_card){
            player_1_score += 3;
        }else{
            player_2_score += 3;
        }
    }
    
    //結果出力
    cout << player_1_score << " " << player_2_score << endl;
    
    return 0;
}


Measured memory_bytes: 3224
//package _0136;



import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);

	void run(){

		int[] dp = new int[6];

		int n = sc.nextInt();

		for(int i = 0 ; i < n;i++){

			double value = sc.nextDouble();

			int grade = (int)(value-160)/5;

			grade = Math.max(0, grade);

			grade = Math.min(grade,5);

			dp[grade]++;

		}

		for(int i=0; i < 6; i++){

			System.out.print((i+1)+":");

			for(int j = 0; j < dp[i]; j++){

				System.out.print("*");

			}

			System.out.println();

		}

	}

	public static void main(String[] args){

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 12000
#include <cstdio>
#include <cstring>
using namespace std;
int x, a[12];
int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    for(int i=1;i<=k;i++) scanf("%d", &x),a[x]=1;
    while(1) {
        int tmp = n;
        bool flag = 0;
        while(tmp) {
            int t = tmp%10;
            if(a[t]) {
                flag = 1;
                break;
            }
            else  tmp/=10;
        }
        if(!flag) {
            printf("%d\n", n);
            return 0;
        }
        n++;
    }
}

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

const ll INF = 1LL << 60;

int main(int argc, char const *argv[])
{
  // 入力
  ll N;
  cin >> N;
  vector<vector<ll>> abc(N, vector<ll>(3, 0));  // N*() の 2d array
  for(ll i=0; i<N; ++i) cin >> abc[i][0] >> abc[i][1] >> abc[i][2];

  // 添字付きのDPテーブル. 添字はその日行った行動を表す
  /*
    行動の表し方は {0: A, 1: B, 2: C} で表す.
    日目は 0を0日目とする.(初期状態)
  */
  vector<vector<ll>> dp(N+1, vector<ll>(3, -INF));  // N日*(Aをした時の幸福度, B 以下略, C 以下略)
  dp[0][0] = 0;  dp[0][1] = 0;  dp[0][2] = 0;  // 0日目. 幸福度の初期値は0
  for (ll i=0; i<N; ++i){  // N日
    rep(j, 3){  // 今日の行動
      rep(k, 3){  // 明日の行動
        if (j == k) continue;  // 今日と明日が同じ行動
        dp[i+1][k] = max(dp[i+1][k], dp[i][j]+abc[i][k]);
      }
    }
  }

  ll ans = 0;
  // 3つの中から最大の値を取り出す
  rep(i, 3) ans = max(ans, dp[N][i]);  // dpは0日目から始まるのでdp[N]
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
int n, x, y;
pair<int, int> ratios[40];
int costs[40];
bool memoo[40][500][500];
int memo[40][500][500];
int func(int ind, int a, int b){
    if (ind >= n){
        int gcdd = __gcd(a, b);
        if (gcdd == 0){
            return 1000000000;
        }
        if (a/gcdd == x && y ==  b/gcdd){
            return 0;
        }
        return 1000000000;
    }
    if (memoo[ind][a][b]){
        return memo[ind][a][b];
    }
    int res = 0;
    // add it
    int newa = a+ratios[ind].first;
    int newb = b+ratios[ind].second;
    
    res = costs[ind]+func(ind+1, newa, newb);
    // don't
    res = min(res, func(ind+1, a, b));
    memoo[ind][a][b] = true;
    memo[ind][a][b] = res;
    return res;
}
int main(){
  prep();
  cin >> n >> x >> y;
  for (int i=0; i<n; i++){
      int a, b, c;
      cin >> a>> b >> c;
      ratios[i] = {a, b};
      costs[i] = c;
  }
  int res = func(0, 0, 0);
  if (res >= 1000000000){
      cout << -1;
  }else{
      cout << res;
  }
  return 0; 
}

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

int main(void)
{
  int x, y;
  while(true) {
    cin >> x >> y;
    if(x == 0 && y ==0) break;
    if(x <= y) {
      cout << x << " " << y << endl;
    }
    else {
      cout << y << " " << x << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()
/* --- */
int main() {
map <string,int> votes;
string s;
int n;
cin>>n;
for(int i=0; i<n;i++)
{
	cin>>s;
	votes[s]++;
}
int max=0;
for(auto i= votes.begin(); i!=votes.end(); i++)
{
	if(i->second>max)max=i->second;
}
for(auto i= votes.begin(); i!=votes.end(); i++)
{
	if(i->second == max) cout<< i->first<< endl;
}
}



Measured memory_bytes: 25216
#include <iostream>
#include <string>
using namespace std;
string N, W[3] = {"Sunny", "Cloudy", "Rainy"};
int main() {
    cin >> N;
    for(int i = 0; i < 3; ++i) {
        if(W[i] == N) {
            cout << W[(i+1)%3];
            break;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    string s; cin >> s;
    int mixi = 1000;
    rep(i, s.length() - 2){
        string temp  = s.substr(i, 3);
        mixi = min(abs(753 - stoi(temp)), mixi);
    }
    cout << mixi << endl;
}

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

double calc(double d){
  double res = 2 * d / sqrt(2);
  double y = (int)d;
  if(sqrt(y*y+1)>=d)res=max(res,y+1);
  return res;
}

int main(){
  double d;
  cin>>d;
  double ans = calc(d);
  printf("%.10f\n",ans);		 
  return 0;
}

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

int n, a[100000];
int l[100000];
int r[100000];

signed main() {
  cin >> n;
  rep(i,n) cin >> a[i];

  l[0] = a[0];
  r[n-1] = a[n-1];

  for(int i=1;   i<n;  i++) l[i] = gcd(a[i], l[i-1]);
  for(int i=n-2; i>=0; i--) r[i] = gcd(a[i], r[i+1]);

  int ans = 0;
  rep(i,n) {
    int g;
    if(i==0) g = r[1];
    else if(i==n-1) g = l[n-2];
    else g = gcd(l[i-1], r[i+1]); 
    ans = max(ans,g);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4800
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll n, a, b; cin >> n >> a >> b;
    vi cnt(3);
    rep(i, n){
        ll p; cin >> p;
        if(p <= a) cnt[0]++;
        else if(p >= b+1) cnt[2]++;
        else cnt[1]++;
    }
    sort(all(cnt));
    cout << cnt[0] << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int& a : A) cin >> a;
  if (n == 1) {
    cout << A[0] << endl;
    return 0;
  }
  for (int i = n - 1; 0 <= i; i -= 2) {
    cout << A[i] << ' ';
  }
  for (int i = n % 2; i < n; i+= 2) {
    if (n-2 <= i) cout << A[i] << endl;
    else cout << A[i] << ' ';
  }
}

Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {
	int n, m;
	int[][] e;

	int calc(int k, boolean[] f) {
		if (check(f)) {
			return 1;
		}
		int ret = 0;
		for (int i = 0; i < n; i++) {
			if (e[k][i] == 1 && !f[i]) {
				f[i] = true;
				ret += calc(i, f);
				f[i] = false;
			}
		}
		return ret;
	}

	boolean check(boolean[] f) {
		for (int i = 0; i < n; i++) {
			if (!f[i]) {
				return false;
			}
		}
		return true;
	}

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

		n = sc.nextInt();
		m = sc.nextInt();
		e = new int[n][n];
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			e[a][b] = e[b][a] = 1;
		}
		boolean[] f = new boolean[n];
		f[0] = true;
		System.out.println(calc(0, f));
	}

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


Measured memory_bytes: 21460
//58
#include<iostream>
#include<vector>
#include<set>

using namespace std;

struct E{
  int x,y,c;
};

int n,m;
int p[100];

int find(int x){
  return p[x]==x?x:p[x]=find(p[x]);
}

void unite(int a,int b){
  p[find(a)]=find(b);
}

int ds(vector<E> v){
  for(int i=0;i<n;i++){
    p[i]=i;
  }
  for(int i=0;i<v.size();i++){
    unite(v[i].x,v[i].y);
  }
  set<int> r;
  for(int i=0;i<n;i++){
    r.insert(find(i));
  }
  return r.size();
}

int rec(vector<E> v,int d,int c){
  if(d>2){
    return 1<<30;
  }else{
    if(ds(v)>1){
      return c;
    }else{
      int m=1<<30;
      for(int i=0;i<v.size();i++){
	vector<E> nv=v;
	int nc=c+nv[i].c;
	nv.erase(nv.begin()+i);
	m=min(m,rec(nv,d+1,nc));
      }
      return m;
    }
  }
}
	      
int main(){
  while(cin>>n>>m,n|m){
    int s=0;
    vector<E> v;
    while(m--){
      int x,y,c;
      cin>>x>>y>>c;
      if(c>0){
	E e={x,y,c};
	v.push_back(e);
      }else{
	s+=c;
      }
    }
    cout<<rec(v,0,s)<<endl;
  }
  return 0;
}


      
      

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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)

#define int long long

signed main(){
	int n;
	cin>>n;
	int p[101],m[101][101];
	for(int i=1;i<=n;i++){
		cin>>p[i-1]>>p[i];
	}
	for(int i=1;i<=n;i++){
		m[i][i]=0;
	}
	for(int l=2;l<=n;l++){
		for(int i=1;i<=n-l+1;i++){
			int j=i+l-1;
			m[i][j]=INF;
			for(int k=i;k<=j-1;k++){
				m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
			}
		}
	}
	cout<<m[1][n]<<endl;
	return 0;
}



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

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, p1, p2, x;
            var word = Console.ReadLine().Split(' ');
            n = int.Parse(word[0]);
            a = int.Parse(word[1]);
            b = int.Parse(word[2]);
            p1 = n * a;
            p2 = b;
            if (p1 < p2)
                x = p1;
            else
                x = p2;            
            Console.WriteLine(x);
            Console.ReadKey(); 
        }
    }
}


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

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

ll digit_sum(ll A){
    ll ret = 0;
    while (A != 0){
        ret += A % 10;
        A /= 10;
    }
    return ret;
}

int main() {
    ll N;
    cin >> N;
    ll sum_min{numeric_limits<ll>::max()};
    for (auto &&i: irange(1LL, N)) {
        ll sum = 0;
        sum += digit_sum(i);
        sum += digit_sum(N - i);
        sum_min = min(sum_min, sum);
    }
    cout << sum_min;

    return 0;
}

Measured memory_bytes: 256
#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 CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

int numofbits(long bits)
{
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

void solve()
{
  int n; cin >> n;
  vector<char> c = {'M', 'A', 'R', 'C', 'H'};
  vector<ll> cnt(5,0);
  for (int i=0; i<n; i++) {
    string s; cin >> s;
    for (int j=0; j<5; j++) {
      if (s[0] == c[j]) cnt[j]++;
    }
  }

  ll ans=0;
  for (int i=0; i<(1<<5); i++) {
    if(numofbits(i)!=3) continue;
    ll tmp=1;
    for (int j=0; j<5; j++) {
      if (((i>>j)&1) == 1) {
        tmp*=cnt[j];
      }
    }
    ans+=tmp;
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <climits>
using namespace std;
 
#define MOD 1000000009LL
 
typedef long long LL;
typedef pair<LL,LL> pLL;
typedef vector<LL> vLL;
typedef vector<vLL> vvLL;
 
vvLL make(int n){
	return vvLL(n, vLL(n));
}
 
void mulmm(vvLL &x, const vvLL &y){
	int n = x.size();
	vvLL z = make(n);
	for(int i = 0; i < n; ++i)
	for(int j = 0; j < n; ++j)
	for(int k = 0; k < n; ++k){
		z[i][j] = (z[i][j] + x[i][k] * y[k][j]) % MOD;
	}
	x.swap(z);
}

void mulvm(vLL &x, const vvLL &y){
	int n = x.size();
	vLL z(n);
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			z[i] = (z[i] + x[j] * y[j][i]) % MOD;
		}
	}
	x.swap(z);
}

void powm(vvLL &x, LL y){
	int n = x.size();
	vvLL z = make(n);
	for(int i = 0; i < n; ++i){
		z[i][i] = 1;
	}
	while(y){
		if(y & 1){ mulmm(z, x); }
		mulmm(x, x);
		y >>= 1;
	}
	z.swap(x);
}
 
int main(){
	LL w, h, n;
	int T = 0;
	while(scanf("%lld%lld%lld", &w, &h, &n), w){
		vector<pLL> v(n + 1);
		vLL ys;
		LL x, y;
		for(int i = 0; i < n; ++i){
			scanf("%lld%lld", &x, &y);
			v[i] = pLL(y, x);
			if(y > 1 && y < h){
				ys.push_back(y);
			}
		}
		v[n] = pLL(LLONG_MAX, LLONG_MAX);
		sort(v.begin(), v.end());
		ys.push_back(1);
		ys.push_back(h);
		sort(ys.begin(), ys.end());
		ys.erase(unique(ys.begin(), ys.end()), ys.end());
		vvLL s = make(w);
		for(int i = 0; i < w; ++i){
			s[i][i] = 1;
			if(i != 0){ s[i][i - 1] = 1; }
			if(i != w - 1){ s[i][i + 1] = 1; }
		}
		vLL a(w);
		a[0] = 1;

		int k = 0;
		while(v[k].first <= 1){ ++k; }
		for(int i = 1; i < ys.size(); ++i){
			vvLL b = s;
			powm(b, ys[i] - ys[i - 1]);
			mulvm(a, b);

			while(v[k].first == ys[i]){
				x = v[k].second - 1;
				if(x >= 0 && x < w){
					a[x] = 0;
				}
				++k;
			}
		}
		 
		printf("Case %d: %lld\n", ++T, a[w - 1]);
	}
}

Measured memory_bytes: 1236
# coding: utf-8
N, K, S = map(int, input().split())
L = []
for i in range(N):
    if i < K:
        L.append(S)
    else:
        if S == 79865413:
            L.append(99999989)
        else:
            L.append(79865413)
print(*L)

Measured memory_bytes: 6560
#include <iostream>
#include <algorithm>
using namespace std;
int a[1000006];
int main(){
	int n;
	cin >> n;
	int x;
	cin >> x;
	for (int i = 1; i <= n; ++ i)
		cin >> a[i];
	sort(a + 1, a + 1 + n);
	int ans = 0;
	for (int i = 1; i < n; ++ i)
		if (x >= a[i]){
			++ ans;
			x -= a[i];
		}
		else
			break;
	if (x == a[n])
		++ ans;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> x(M);
  vector<int> y(M-1);

  rep(i, M){
    cin >> x[i];
  }

  // コマの方が多いときは移動する必要がないので0を返す
  if (N >= M) {
    cout << 0 << endl;
    return 0;
  }

  sort(x.begin(), x.end());// 順番に並べる

  // 道の間の距離を求める
  rep(i, M-1){
    y[i] = x[i+1] - x[i];
  }
  sort(y.begin(), y.end());
  ll ans = 0;
  rep(i, M - N){
    ans += y[i];
  }

  cout << ans << endl;

}


Measured memory_bytes: 1024
//define DEBUG for debug
//#define DEBUG

#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair 
#define pb push_back
#define MAX 3000
#define MOD 1000000007
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int dp[MAX+10][MAX+10];
string cevap;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef DEBUG
	freopen("i.txt","r",stdin);
	freopen("o.txt","w",stdout);
#endif
	string a,b;cin >> a >> b;
	int x = a.size(),y = b.size();
	for(int i = 1;i <= x;i++)
		for(int j = 1;j <= y;j++){
			if(a[i-1] == b[j-1]){
				dp[i][j] = dp[i-1][j-1]+1;
			}else
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	int index = dp[x][y];
	while(x > 0 || y > 0){
		if(x > 0 && dp[x-1][y] == dp[x][y]){
			x--;
		}else if(y > 0 && dp[x][y-1] == dp[x][y]){
			y--;
		}else{
			cevap += a[x-1];
			x--;
			y--;
		}
	}
	for(int i = index-1;i >= 0;i--)
		cout << cevap[i];	
	return 0;
}

Measured memory_bytes: 35584
#include<iostream>
#include <string>
#include<vector>
typedef long long ll;

using namespace std;
int main()
{
	vector < vector<int>> cs;
	for (int i = 0; i < 3; i++) {
		int temp1, temp2, temp3;
		cin>> temp1>> temp2>> temp3;
		vector<int> temp{ temp1, temp2, temp3 };
		cs.push_back(temp);
	}
	string kotae = "Yes";

	for (int i = 0; i < 2;i++) {
		int d;
		d = cs[i][0] - cs[i+1][0];
		if (d != cs[i][1] - cs[i+1][1]) {
			kotae = "No";
		}
		if (d != cs[i][2] - cs[i + 1][2]) {
			kotae = "No";
		}
	}

	for (int i = 0; i < 2; i++) {
		int d;
		d = cs[0][i] - cs[0][i + 1];
		if (d != cs[1][i] - cs[1][i + 1]) {
			kotae = "No";
		}
		if (d != cs[2][i] - cs[2][i + 1]) {
			kotae = "No";
		}
	}

	cout << kotae;

	return 0;
}

Measured memory_bytes: 256