akhauriyash/Code-Regression huggingface dataset:
// use std::cmp;
// use std::collections::HashMap;
// use std::collections::HashSet;
// use std::collections::VecDeque;


// const INF: i64 = 1_000_000_000;


fn color(mut d1: i64, mut d2: i64, mut x: i64, mut y: i64) -> i64 {
    while d1 % 4 == 0 && d2 % 4 == 0 {
        d1 /= 4;
        d2 /= 4;
        x /= 2;
        y /= 2;
    }
    if d1 % 4 != 0 && d2 % 4 != 0 {
        return (x % 2) + 2 * (y % 2);
    }
    let (mut d1, d2) = if d2 % 4 == 0 {
        (d2, d1)
    } else {
        (d1, d2)
    };
    let tmp = match d2 % 4 {
        1 => (x + y) % 2,
        2 => x % 2,
        _ => panic!(),
    };
    while d1 % 4 == 0 {
        d1 /= 4;
        x /= 2;
        y /= 2;
    }
    tmp + 2 * match d1 % 4 {
        1 => (x + y) % 2,
        2 => x % 2,
        _ => panic!(),
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: i64 = sc.read();
    let d1: i64 = sc.read();
    let d2: i64 = sc.read();
    let grid_size = 2 * n as usize;
    let mut grid = vec![vec![0; grid_size]; grid_size];
    let mut cnt = vec![0; 4];
    for i in 0..grid_size {
        for j in 0..grid_size {
            let k = color(d1, d2, i as i64, j as i64) as usize;
            grid[i][j] = k;
            cnt[k] += 1;
        }
    }
    let mut k = 0;
    loop {
        if cnt[k] >= n * n {
            break;
        }
        k += 1;
    }
    let mut count = 0;
    for i in 0..grid_size {
        for j in 0..grid_size {
            if grid[i][j] == k {
                println!("{} {}", i, j);
                count += 1;
                if count == n * n {
                    return;
                }
            }
        }
    }
}

// thanks, ir5
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


Measured memory_bytes: 7036
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;

int main()
{
    cout<<fixed<<setprecision(12);
    ll n,i,j,l,o;
    cin>>n;
    ld a[200],k;
    rep(i,0,n-1)cin>>a[i];
    sort(a,a+n);
    ld s=(a[0]+a[1])/2;
    rep(i,2,n-1)
    {
        s=(s+a[i])/2;
    }cout<<s;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<complex>
#include<algorithm>
#define EPS 1e-10
using namespace std;

typedef complex<double> P;

int n,m;
P p[100][4];

double cross(P a,P b){return imag(conj(a)*b);}
double dot(P a,P b){return real(conj(a)*b);}

/*
bool interp(int q,P x){
  P tmp = P(10000,x.imag());
  bool res = false;
  for(int i=0;i<4;i++)if(is_cp(p[q][i],p[q][(i+1)%4],x,tmp))res=!res;
  return res;
}
*/
int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;
  if (cross(b,c)<-EPS) return -1;
  if (dot(b, c)<-EPS) return 2;
  if (abs(b)<abs(c)) return -2;
  return 0;
}

bool is_cp(P a1, P a2, P b1, P b2){
    return ( ccw(a1, a2, b1) * ccw(a1, a2, b2) <= 0 &&
     ccw(b1, b2, a1) * ccw(b1, b2, a2) <= 0 );
}

bool interp(int q, P x){
  for(int i=0;i<4;i++){
    if ( ccw(p[q][i], p[q][(i+1)%4], x ) == 1 ) return false;
  }
  return true;
}
bool inter(int q1,int q2){
  for(int i=0;i<4;i++)
    for(int j=0;j<4;j++)
      if(is_cp(p[q1][i],p[q1][(i+1)%4],p[q2][j],p[q2][(j+1)%4]))return true;
  for(int i=0;i<4;i++)if(interp(q1,p[q2][i]))return true;
  for(int i=0;i<4;i++)if(interp(q2,p[q1][i]))return true;
  return false;
}

int par[100];
int rank[100];

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

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

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

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

int main(){
  while(cin >> n && n){
    for(int i=0;i<n;i++){
      cin >> m;
      for(int j=0;j<m;j++)
	for(int k=0;k<4;k++)cin >> p[j][k].real() >> p[j][k].imag();

      init(m);

      for(int j=0;j<m;j++)
	for(int k=0;k<j;k++)
	  for(int l=0;l<4;l++)
	    if(inter(j,k))unite(j,k);

      int ans = 0;
      for(int j=0;j<m;j++){
	find(j);
	if(par[j]==j)ans++;
      }
      cout << ans << endl;
    }
  }
}

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

int main(){
    int time;
    cin>>time;
    
    int h,m,s;
    h=time/3600;
    m=(time%3600)/60;
    s=time%60;
    
    cout<<h<<':'<<m<<':'<<s<<endl;
}


Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define rep(i, a, b) for(long long i=(a) ; i<=(b) ; ++i)
#define Task ""
using namespace std;
const long long N=1002;
long long n, a[N], cnt, dd[N*N], k, ans, c[N*N], mark[N*N];
long long b[N*N];
vector <long long > v[45];

bool cmp(long long i, int j) {
    return dd[i]>dd[j];
}

//#define TEST

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef TEST
        srand(time(NULL));
        freopen(Task".inp", "w", stdout);
        long long n=rand()%1000+1;
        long long k=rand()%n+1;
        cout << n << ' ' << k << '\n';
        rep(i, 1, n) cout << rand()%10000 << ' ';

    #else
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    cin >> n >> k;
    rep(i, 1, n) { cin >> a[i]; a[i]+=a[i-1]; }
    rep(i, 1, n)
        rep(j, i, n) {
            b[++cnt]=a[j]-a[i-1];
        }
    rep(i, 0, 42) {
        rep(j, 1, cnt) {
            if((b[j]>>i)&1ll) v[i].push_back(j);
        }
    }

    long long fl=0;
    bool ok=0;
    for(long long i=42 ; i>=0 ; --i) {
        if(v[i].size()<k) continue;
        ok=1;
        long long dem=0;
        for(long long x:v[i]) if(mark[x]==fl) ++dem;
        if(dem<k) continue;
        for(long long x:v[i]) if(mark[x]==fl) {
                mark[x]=fl+1;
                ++dd[x];
        }
        ++fl;
    }
    if(ok==false) return cout << 0, 0;
    rep(i, 1, cnt) c[i]=i;
    sort(c+1, c+cnt+1, cmp);
    long long ans=b[c[1]];
    rep(i, 2, k) ans&=b[c[i]];
    cout << ans;
    #endif // TEST
    return 0;
}


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

int main() {
  int N;

    cin >> N ;
  vector<int> count(N);
  
 for(int i=0;i<N;i++){
  count.at(i)=0;
 }
  int aa;
  for(int i=1; i<N;i++){
   cin >> aa;
    count.at(aa-1)=count.at(aa-1)+1;
  }
    for(int i=0;i<N;i++){
    cout << count.at(i) << endl;
    }
  return 0;
  
}


Measured memory_bytes: 4052
n,m = map(int,input().split())

G,C = [],[]

for i in range(n):
    a,b = map(int,input().split())
    G.append((a,b))

for i in range(m):
    a,b = map(int,input().split())
    C.append((a,b))

ans_L = []
for i in range(n):
    ans = float("inf")
    a,b = G[i]
    idx = 0
    for j in range(m):
        c,d = C[j]
        ten = abs(a-c) + abs(b-d)
        if ans != min(ans,ten):
            ans = ten
            idx = j+1

    ans_L.append(idx)

for i in ans_L:
    print(i)


Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using Int = long long;
const char newl = '\n';

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n,k;
  cin>>n>>k;
  vector<int> cnt(n,0);
  for(int i=0;i<k;i++){
    int d;
    cin>>d;
    for(int j=0;j<d;j++){
      int a;
      cin>>a;
      a--;
      cnt[a]++;
    }
  }
  int ans=0;
  for(int c:cnt) ans+=c==0;
  cout<<ans<<newl;
  return 0;
}


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

int main() {
	int N;
  	cin>>N;
  	int a[N];
  	rep(i,N) cin>>a[i];
  	int sum=0;
  
  	rep(i,N) sum=sum^a[i];
  	
  	rep(i,N) {
  		cout<<(sum^a[i])<<endl;
    }
}


Measured memory_bytes: 4308
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    N, M = map(int, input().split())
    A = []
    B = []

    for i in range(N):
        A.append(input())
    for i in range(M):
        B.append(input())

    for i in range(N - M + 1):
        for j in range(N - M + 1):
            for k in range(M):
                s1 = A[i + k][j:j + M]
                s2 = B[k]
                if s1 != s2:
                    break
            else:
                print('Yes')
                return None

    print('No')


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
import java.util.Scanner;
 
class Main {
	public static void main(String[] args) {
 
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int M = sc.nextInt();
	    int A = 0;
	    for (int i = 0; i < M; i++) {
	      int temp = sc.nextInt();
	      A += temp;
	    }
	    
	    if (N < A) {
	      System.out.println(-1);
	    } else {
	      System.out.println(N - A);
	    }
	    
	  }
}

Measured memory_bytes: 39248
#include <bits/stdc++.h>
#define N 1010
using namespace std;
int n;

int a[N];

bool check(int pro) {
	static int bit[12];
	int len;
	for (len = 1; pro; ++len) {
		bit[len] = pro % 10;
		pro /= 10;
	}
	len--;
	for (int i = 1; i <= len; ++i) {
		if (bit[1] - bit[i] != i - 1) return false;
	}
	return true;	
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
	}
	int ans = -1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j < i; ++j) {
			if (check(a[i] * a[j])) {
				ans = max(ans, a[i] * a[j]);
			}
		}
	}
	printf("%d\n", ans);
}

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    ll ans = 0;
    rep(bit, 1<<(n-1)) {
        ll tmp = 0;
        rep(i,n-1) {
            tmp *= 10;
            tmp += s[i] - '0';
            if (bit & 1<<i) {
                ans  += tmp;
                tmp = 0;
            }
        }
        tmp *= 10;
        tmp += s.back() - '0';
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;


int cumsum_A_S[100001];
int cumsum_B_S[100001];
int cumsum_A_T[100001];
int cumsum_B_T[100001];
int main(){
   string S;
   string T;
   cin >> S;
   cin >> T;
   for(int i = 1; i <= S.size(); i++){
     cumsum_A_S[i] = cumsum_A_S[i - 1];
     cumsum_B_S[i] = cumsum_B_S[i - 1];
     if(S[i - 1] == 'A'){
       cumsum_A_S[i] ++;
     }
     if(S[i - 1] == 'B'){
       cumsum_B_S[i] ++;
     }
   }

   for(int i = 1; i <= T.size(); i++){
     cumsum_A_T[i] = cumsum_A_T[i - 1];
     cumsum_B_T[i] = cumsum_B_T[i - 1];
     if(T[i - 1] == 'A'){
       cumsum_A_T[i] ++;
     }
     if(T[i - 1] == 'B'){
       cumsum_B_T[i] ++;
     }
   }

   int q;
   cin >> q;
   for(int i = 0; i < q; i++){
     int a;
     int b;
     int c;
     int d;
     cin >> a >> b >> c >> d;

     int s_a_num = cumsum_A_S[b] - cumsum_A_S[a - 1];
     int s_b_num = cumsum_B_S[b] - cumsum_B_S[a - 1];
     int t_a_num = cumsum_A_T[d] - cumsum_A_T[c - 1];
     int t_b_num = cumsum_B_T[d] - cumsum_B_T[c - 1];
     if(((s_a_num - s_b_num) % 3 + 3) % 3 == ((t_a_num - t_b_num) % 3 + 3) % 3){
       cout << "YES" << endl;
     } else {
       cout << "NO" << endl;
     }
   }
   return 0;
}

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

#define endl '\n'

void solvetask(){
    int n;
    string s; // 0 -> W
    cin >> n >> s;
    int l = 0, r = n-1, ans = 0;
    while(l < r){
        while(l < n && s[l] != 'W') l++;
        while(r >=0 && s[r] != 'R') r--;
        if (l > r) break;
        ans++;
        s[l] = 'R';
        s[r] = 'W';
    }
    cout << ans << endl;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1; //cin >> t;
    while(t--) solvetask();
}

Measured memory_bytes: 3708
def gcd(a, b):
    if a % b == 0:
        return b
    else:
        return gcd(b, a % b)


def main():
    N = int(input())
    A = [int(i) for i in input().split()]

    g = A[0]
    for i in range(1, N):
        g = gcd(g, A[i])

    if not g == 1:
        print('not coprime')
        return


    limit = int(10 ** 3)
    F = [0] * (10 ** 6 + 1)
    M = [0] * (10 ** 6 + 1)
    for i in range(2, limit + 1):
        if F[i] > 0:
            continue
        v = 2 * i
        while v <= 10 ** 6:
            if F[v] == 0:
                F[v] = i
            v += i

    pc = True
    for v in A:
        S = set()
        x = v
        while True:
            if F[x] > 0:
                S.add(F[x])
                x //= F[x]
            else:
                S.add(x)
                break

        for s in S:
            if s == 1:
                continue
            if M[s] == 1:
                pc = False
                break
            M[s] += 1

        if not pc:
            break

    if pc:
        print('pairwise coprime')
    else:
        print('setwise coprime')


if __name__ == '__main__':
    main()


Measured memory_bytes: 189084
/*
Submitted With (^^) by -> Hossam ^_^
 _____________________
|     ___     ___     |
|    (^_^)   (^_^)    |
|   /( | )\_/( | )\   |
|_____|_|_____|_|_____|
*/

#include <bits/stdc++.h>

using namespace std;

inline void prep()
{
    cin.tie(0);
    cin.sync_with_stdio(0);
}

#define X first
#define Y second
#define ll long long
#define inf (0x7fffffffffffffff)
#define all(x) x.begin(), x.end()
#define ZXC cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl;

const int mod = (int)1e9 + 7;
const int MX = (int)2e5 + 5;

const int MAX_NODES = 5000 * 1000;

int n, k;
string res;

int main()
{
    prep();

    string s;

    cin >> s >> k;
    n = s.size();

    // for(int i = 0; i < n; ++i){
    //     string cur = s.substr(i);
    //     // cerr << cur << endl;
    //     trie.insert(cur);
    // }

    // trie.find(0);

    vector<string> vv;
    for(int i = 0; i < n; ++i){
        for(int len = 1; len <= k && i + len <= n; ++len){
            vv.push_back(s.substr(i, len));
        }
    }

    sort(all(vv));
    auto it = unique(all(vv));
    // for(auto x : vv){
    //     cout << x << endl;
    // }
    cout << vv[k - 1] << endl;
    
    // ZXC
    return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
template<class T = int> using V = vector<T>;

using P = complex<double>;
double dot(const P& p, const P& q) { return real(conj(p) * q); }

P proj(P p1, P p2, P p) {
    p2 -= p1, p -= p1;
    return p1 + dot(p2, p) / norm(p2) * p2;
}

constexpr double pi = acos(-1.0);

int main() {
    int n; cin >> n;
    V<P> p(n);
    for (int i = 0; i < n; ++i) {
        int x, y; cin >> x >> y;
        p[i] = P(x, y);
    }
    int l, r;
    double mxl = -1e12, mxr = -1e12;
    P vl = polar(1.0, arg(p[1] - p[0]) + pi / 6.0);
    P vr = polar(1.0, arg(p[1] - p[0]) + 5.0 * pi / 6);
    for (int i = 0; i < n; ++i) {
        double cl = dot(p[i], vl);
        double cr = dot(p[i], vr);
        if (cl > mxl) {
            mxl = cl;
            l = i;
        }
        if (cr > mxr) {
            mxr = cr;
            r = i;
        }
    }
    P pl = proj(p[0], p[1], p[l]);
    P pr = proj(p[0], p[1], p[r]);
    double res = abs(pl - pr) + (abs(pl - p[l]) + abs(pr - p[r])) / sqrt(3);
    for (int i = 1; i < n; ++i) {
        vl = polar(1.0, arg(p[(i + 1) % n] - p[i]) + pi / 6.0);
        vr = polar(1.0, arg(p[(i + 1) % n] - p[i]) + 5.0 * pi / 6);
        while (dot(p[r], vr) < dot(p[(r + 1) % n], vr)) {
            r = (r + 1) % n;
        }
        while (dot(p[l], vl) < dot(p[(l + 1) % n], vl)) {
            l = (l + 1) % n;
        }
        pl = proj(p[i], p[(i + 1) % n], p[l]);
        pr = proj(p[i], p[(i + 1) % n], p[r]);
        double curr = abs(pl - pr) + (abs(pl - p[l]) + abs(pr - p[r])) / sqrt(3);
        res = min(res, curr);
    }
    cout << setprecision(15) << res << '\n';
}


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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)
#define REP(i, n, m) for (long long i = (long long)(n); i < (long long)(m); i++)

namespace solver {
  using namespace std;
  typedef long long ll;

  static const ll MAX = 100010LL;
  ll N, M, indeg[MAX], dp[MAX], ans;
  bool visited[MAX];
  vector<ll> G[MAX], RG[MAX];

  void init() {
    scanf("%lld %lld", &N, &M);
    ll x, y;
    rep(i, M) {
      scanf("%lld %lld", &x, &y);
      x--; y--;
      indeg[y]++;
      G[x].push_back(y);
      RG[y].push_back(x);
    }
  }

  void bfs(ll u) {
    queue<ll> que;
    que.push(u);
    while(!que.empty()) {
      ll s = que.front(); que.pop();
      if(visited[s]) continue;
      visited[s] = true;
      for(const ll& t : RG[s]) {
        dp[s] = max(dp[s], dp[t]+1);
        ans = max(ans, dp[s]);
      }
      for(const ll& t : G[s]) {
        indeg[t]--;
        if(indeg[t] <= 0 && !visited[t]) {
          que.push(t);
        }
      }
    }
  }

  void solve() {
    rep(i, N) if(indeg[i] <= 0 && !visited[i]) bfs(i);
    cout << ans << endl;
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

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

int main() {
  int n,a,b;
  int i,j,total,sum;
  string s;
  
  cin >> n >> a >> b;
  
  total=0;
  for (i=0;i<=n;++i)
  {
    s = to_string(i);
    sum=0;
    for (j=0;j<s.length();++j)
    {
      sum += (s[j] - '0');
    }
    if (sum>=a && sum<=b)
      total += atoi(s.c_str());
  }
  
  	cout << total << endl;
}

Measured memory_bytes: 256
s = list(input())

ans = 0
for i in range(len(s)-1):
    if int(s[i]) == int(s[i+1]) == 0:
        s[i+1] = 1
        ans += 1
    elif int(s[i]) == int(s[i+1]) == 1:
        s[i+1] = 0
        ans += 1
print(ans)



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


int main() {
  int n, k;
  int ans = 0, num = 0;
  cin >> n >> k;
  rep(i ,n) {
    cin >> num;
    if(num >= k) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
a=0
w=0
t=0
r=0
for _ in range(n):
    s=input()
    if s[0]=="A":
        a+=1
    elif s[0]=="W":
        w+=1
    elif s[0]=="T":
        t+=1
    elif s[0]=="R":
        r+=1
print("AC x",a)
print("WA x",w)
print("TLE x",t)
print("RE x",r)

Measured memory_bytes: 9220
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <typeinfo>
#include <list>
#include <queue>
#include <stack>
#include <limits.h>
#include <unordered_set>
#include <map>
#include <cstring>

using namespace std;

typedef long long ll;

int mod = 1e9 + 7;

ll Solve(int K, vector<pair<ll, int> > cake, int N) {
    sort(cake.begin(), cake.end());
    priority_queue<ll, vector<ll>, greater<ll> > q;
    unordered_set<int> m;
    ll res = 0;
    for (int i = N - 1; i >= N - K; i--) {
        res += cake[i].first;
        if (m.count(cake[i].second)) {
            q.push(cake[i].first);
        }
        else {
            m.insert(cake[i].second);
        }
    }
    ll ret = res + m.size() * m.size();
    for (int i = N - K - 1; i >= 0; i--) {
        if (q.empty()) {
            return ret;
        }
        if (!m.count(cake[i].second)) {
            res -= q.top() - cake[i].first;
            q.pop();
            m.insert(cake[i].second);
            ll tmp = m.size();
            ret = max(ret, res + tmp * tmp);
        }
    }
    return ret;
}


int main() {
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<pair<ll, int> > cake(N);
    for (int i = 0; i < N; i++) {
        int t;
        ll d;
        cin >> t >> d;
        cake[i] = {d, t};
    }
    cout << Solve(K, cake, N);
    return 0;
}


Measured memory_bytes: 7052
n,i;
ea[2<<17],eb[2<<17],next[2<<17],first[1<<17];
long M,dp1[1<<17],dp2[1<<17],L[2<<17],R[2<<17]={1};
dfs1(u,p,id)
{
	dp1[u]=1;
	id=first[u];
	while(id)
	{
		if(eb[id]!=p)
		{
			dfs1(eb[id],u);
			dp1[u]=dp1[u]*-~dp1[eb[id]]%M;
		}
		id=next[id];
	}
}
make();
dfs2(u,p,x,id)
{
	dp2[u]=dp1[u]*x%M;
	make(first[u],p,x);
	id=first[u];
	while(id)
	{
		if(eb[id]!=p)
		{
			dfs2(eb[id],u,L[id]*R[next[id]]%M+1);
		}
		id=next[id];
	}
}
make(i,p,x,t)
{
	if(i)
	{
		L[i]=x;
		t=eb[i]!=p?-~dp1[eb[i]]:1;
		make(next[i],p,t%M*x%M);
		R[i]=R[next[i]]*t%M;
	}
}
main(u,v)
{
	/*for(scanf("%d%d",&n,&M);~scanf("%d%d",&u,&v);)
	{
		i++;
		ea[i]=u;
		eb[i]=v;
		i++;
		ea[i]=v;
		eb[i]=u;
	}*/
	//for(;~scanf("%d%d",&u,&v);)i++?ea[i]=eb[i+1]=u,ea[i+1]=eb[i]=v,i++:(n=u,M=v);
	for(;~scanf("%d%d",&u,&v);i++)i++?ea[i-1]=eb[i]=u,ea[i]=eb[i-1]=v:(n=u,M=v);
	for(;i--;)
	{
		next[i]=first[ea[i]];
		first[ea[i]]=i;
	}
	dfs1(1,0);
	dfs2(1,0,1);
	for(i=1;i<=n;i++)printf("%d\n",dp2[i]);
}

Measured memory_bytes: 13056
/*  よろしくお願いします

    LEARNING DP:    LCS

    CONSTRAINT:
        +1 <= |S|, |T| <= 3000
    QUESTION:
        WHICH INDEX and CHOOSE OR NOT
        THE SUBSTR on THE PREVIOUS
        should we TRACKING
    IF WE KNOW:
        THE LENGTH OF THE PREVIOUS SUBSTR:
        we can try to add more character to get longer.
    PRE DP:
        ALL equal 0;
    TIME COMPLEXITY:
        O(|S|*|T|)
*/
#include <bits/stdc++.h>
using namespace std;

#define DB(_x)      cout << #_x << " is " << (_x) << "\n";
#define FOR(_a,_b)  for (_a = 0; _a < _b; ++_a)
#define fs          first
#define sc          second
#define pb          push_back
//#define IOFILE

using LL = long long;
using LD = long double;
using VI = vector<int>;
using PI = pair<int,int>;

void Excalibur(){
    string s, t, ans;
    int i, j, n ,m;

    while (cin >> s >> t){
        vector<VI> dp(3001,VI(3001,0));
        n = s.size(); m = t.size();
        FOR (i, n+1){
            FOR (j, m+1){
                if (i == 0 || j == 0) continue;
                dp[i][j] = max(dp[i-1][j-1] + (s[i-1] == t[j-1]), dp[i][j]);
                dp[i][j] = max({dp[i][j], dp[i-1][j], dp[i][j-1]});
            }
        }
        i = n; j = m; ans = "";
        while (i > 0 && j > 0){
            if (s[i-1] == t[j-1]){
                ans = s[i-1] + ans;
                --i;
                --j;
            } else if (dp[i-1][j] > dp[i][j-1]) --i;
            else --j;
        }

        cout << ans << "\n";
    }
}

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

#ifdef  IOFILE
    freopen("INPUT.in", "r", stdin);
    freopen("OUTPUT.out", "w", stdout);
#endif

Excalibur();
return 0;}


Measured memory_bytes: 35584
#include<stdio.h>
#include<stdlib.h>
#define MAX 100
int main(void){
  int num=0,stack_m[MAX];
  char stack[MAX];
  while(scanf("%s",stack)!=EOF){
    switch(stack[0]){
    case '+':
      stack_m[num-2]=stack_m[num-2]+stack_m[num-1];
      num--;
      break;
    case '-':
      stack_m[num-2]=stack_m[num-2]-stack_m[num-1];
      num--;
      break;
    case '*':
      stack_m[num-2]=stack_m[num-2]*stack_m[num-1];
      num--;
      break;
    default:
      stack_m[num] = atoi(stack);
      num++;
      break;
    }
  }
  printf("%d\n",stack_m[0]);
  return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using ll = unsigned long long int;
using namespace std;

int main() {
    fastIO;
    int x, y, z;
    cin >> x >> y >> z;
    x -= z;
    cout << x / (z + y) << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
typedef long long ll;
long long a[2100],b[2100],c[2100];
ll p(ll a,ll b,ll mod)
{
    ll ans=0;
    for(;b;b>>=1)
    {
        if(b&1)
        {
            ans=ans+a%mod;
        }
        a=a*2%mod;
    }
    return ans%mod;
}
int main(){
	long long n,m;long long ans=0,s=0,ss=0;
	cin>>n>>m;
	for(long long i=0;i<n;i++) cin>>a[i];
	for(long long i=0;i<n-1;i++) {
		for(long long j=i+1;j<n;j++) {
			if(a[i]>a[j]) s++; 
		}
	}
	for(long long i=0;i<n;i++) {
		for(long long j=0;j<n;j++) {
			if(a[i]>a[j]) ss++;
		}
	}
	ans=p(s,m,mod);
	ans=(ans+p(m*(m-1)/2,ss,mod))%mod;
	cout<<ans%mod<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define fastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cout<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define pb push_back
#define ff first
#define ss second
#define all(v) (v).begin(), (v).end()

using namespace std;

int gcd(int a, int b){
    return b == 0 ? a : gcd(b, a%b);
}
int lcm(int a, int b){
    return (a*b)/gcd(a,b);
}
int ncr(int n, int k){
    int res = 1;
    if ( k > n - k )
        k = n - k;

    for (int i = 0; i < k; ++i){
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

int fibonacci(int n){
    double phi = (1LL + sqrt(5))/(double)2;
    int nth_fib = round(pow(phi,n)/sqrt(5));
    return nth_fib;
}
bool checkYear(int year)  
{  

    if (year % 400 == 0)  
        return true;  
  
    if (year % 100 == 0)  
        return false;  

    if (year % 4 == 0)  
        return true;
        
    return false;  
}
signed main(){

    fastIO

    string s;
    cin >> s;
    
    int count = 0,ans = 0;
    for(int i =0; i < s.length(); i++){
        if(s[i] == 'A' || s[i] =='C' || s[i] == 'G' || s[i] == 'T'){
            count++;
        }else{
            ans = max(ans, count);
            count = 0;
        }
    }
    ans = max(ans, count);
    cout << ans;
    // int n;
    // cin >> n;
    // int ar[n];
    // for(int i =0; i<n; i++) cin >> ar[i];
    // sort(ar, ar+n);
    // int pre[n], suf[n];
    // pre[0] = ar[0]; suf[n-1] = ar[n-1];
    // bool same = false;
    // for(int i = 1; i < n; i++){
    //     pre[i] = gcd(pre[i-1], ar[i]);
    //     suf[n-1-i] = gcd(suf[n-i], ar[n-1-i]);
    // }
    // int maxgcd = gcd(ar[0], ar[n-1]);
    // for(int i = 1; i < n-1; i++){
    //     maxgcd = max(maxgcd, gcd(pre[i-1],suf[i+1]));
    //     // trace1(gcd(pre[i-1],suf[i+1]));
    // }
    // cout << maxgcd << endl;
    
    
    return 0;
}


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

#define ENDL '\n'
#define sayy cout<<"YES"<<ENDL;
#define sayn cout<<"NO"<<ENDL;

int main(){

    int n;
    cin >> n;

    vector<int> v(n);
    for(int i(0); i<n; i++){
        cin >> v.at(i);
    }

    int max(0);
    for(int i(v.size()-1); i>=1; i--){
        int temp(0);
        while(v[i] <= v[i-1]){
            temp++;
            i--;
        }
        if(temp > max) max = temp;
    }
    cout << max << ENDL;

    return 0;
}

Measured memory_bytes: 3788
/*
  Author: Alokit Kumar
  */
 #include<bits/stdc++.h>
 using namespace std;
 #define int long long
 int32_t main()
 {
   int t,n,i,j,k,l,s=0,q,b,c;
  cin>>n;
  map<int,int> m;
  for(i=1;i<=n;i++)
  {
    cin>>l;s+=l;
    m[l]++;
  }
  cin>>q;
  while(q--){
    cin>>b>>c;
    if(m.count(b))
    {
      j=m[b];
      s=s-b*j;
      s=s+c*j;
      m.erase(b);
      m[c]+=j;
      cout<<s<<"\n";
    }
    else
     cout<<s<<"\n";
  }
 }

Measured memory_bytes: 7576
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 50;
int n, avg, a[MAXN+5];
long long memo[MAXN+5][MAXN*MAXN+5];
int main()
{
	scanf("%d%d", &n, &avg);  
	for(int i=1; i<=n; i++)
		scanf("%d", &a[i]);
	memo[0][0] = 1;
	for(int i=1; i<=n; i++)
		for(int j=i-1; j>=0; j--)
			for(int k=0; k<=j*MAXN; k++)
				memo[j+1][k+a[i]] += memo[j][k];
	long long ans = 0;
	for(int i=1; i<=n; i++)
		ans += memo[i][i*avg];
	printf("%lld", ans);
}

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

int main () {

	string s, t;
	cin >> s >> t;

	int ans = 0;
	for (int i = 0; i < 3; ++i)
		if (s[i] == t[i]) ++ans;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
h, w = gets.chomp.split(' ').map(&:to_i)
list = h.times.map { gets.chomp.chars }

after_h = list.reject do |line|
  line.all? { |c| c == '.' }
end
i_list = 0.upto(w - 1).reject do |i|
  after_h.all? { |line| line[i] == '.' }
end

after_h.each do |line|
  row = i_list.map { |i| line[i] }.join
  puts row
end



Measured memory_bytes: 2556
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back

map<int,int> mp;
int n,m,k;

void dfs(int t, int sum){
    if(t==0){
        mp[max<int>(1,sum-k)]++;
        return ;
    }
    for(int i=1;i<=m;i++){
        dfs(t-1,sum+i);
    }
}

signed main(){
    while(cin>>n>>m>>k&&(n||m||k)){
        mp.clear();
        dfs(n,0);
        
        int ans = 0;
        for(auto elm:mp){
//            cout<<elm.first<<" "<<elm.second<<endl;
            ans += elm.first*elm.second;
        }
        printf("%.20lf\n",(double)ans/pow(m,n));
    }
}

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

int main() {
    int n;
    cin >> n;
    double b = 0;
    rep(i, n) {
        double a;
        cin >> a;
        b += 1 / a;
    }
    cout << 1 / b << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] T = new long[N];
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            T[i] = scan.nextLong();
        }
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextLong();
        }
        long[][] range = new long[N][2];
        for (int i = 0; i < N; i++) {
            range[i][0] = 0;
            range[i][1] = Long.MAX_VALUE;
        }
        range[0][0] = T[0];
        range[0][1] = T[0];
        if (A[0] < T[0]) {
            System.out.println(0);
            return;
        }
        range[N-1][0] = A[N-1];
        range[N-1][1] = A[N-1];
        if (T[N-1] < A[N-1]) {
            System.out.println(0);
            return;
        }
        for (int i = 1; i < N; i++) {
            if (T[i - 1] >= T[i]) {
                continue;
            }
            if (A[i] < T[i]) {
                System.out.println(0);
                return;
            }
            range[i][0] = T[i];
            range[i][1] = T[i];
        }
        for (int i = N-2; 0 <= i; i--) {
            if (A[i] <= A[i + 1]) {
                continue;
            }
            if (T[i] < A[i]) {
                System.out.println(0);
                return;
            }
            if (range[i][0] == range[i][1] && range[i][0] != A[i]) {
                System.out.println(0);
                return;
            }
            range[i][0] = A[i];
            range[i][1] = A[i];
        }
        for (int i = 0; i < N; i++) {
            if (range[i][0] == range[i][1]) {
                continue;
            }
            range[i][1] = Math.min(T[i], A[i]);
        }
        long ans = 1;
        for (int i = 0; i < N; i++) {
            if (range[i][0] == range[i][1]) {
                continue;
            }
            ans *= (range[i][1]-range[i][0]);
            ans %= 1000000007;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 90700
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

  int minv = a[0];
  int tmp_diff = 0;
  int ans = 0;
  for (int i = 1; i < n; i ++) {
    if (a[i] < minv) {
      minv = a[i];
      continue;
    }
    if (tmp_diff < a[i] - minv) {
      tmp_diff = a[i] - minv;
      ans = 1;
    } else if (tmp_diff == a[i] - minv) {
      ans ++;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

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

    ll money=1000;
    ll stock=0;
    ll temp=0;
    for(int i=1; i<n; i++){
        if(a[i]>a[temp]){
            //temp時点で買えるだけ株を買う
            stock = money/a[temp];
            money -= stock*a[temp];
            //a[i]時点で全株売る
            money += stock*a[i];
            stock =0;
        }
        temp=i;
    }
    cout << money << endl;
}

Measured memory_bytes: 3584
import math

def main():
    a, b, h, m = map(int, input().split())
    hr = 360 / 12 * (h + m / 60)
    mr = 360 / 60 * m
    if hr == 0:
        hr = 360
    if mr == 0:
        mr = 360
    diff = min(abs(hr - mr), abs(hr - mr))
    # c2=a2+b2−2abcosA
    print('{:.10f}'.format(math.sqrt(a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(diff)))))
if __name__ == '__main__':
    main()

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

int main(void) {
	while (1) {
		int n, m;
		cin >> n >> m;
		if (n == 0) return 0;
		int p[100] = { 0 }, p_sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> p[i];
			p_sum += p[i];
		}
		int q[100] = { 0 }, q_sum = 0;
		for (int i = 0; i < m; i++) {
			cin >> q[i];
			q_sum += q[i];
		}
		int pq_dif = p_sum - q_sum;
		int ans_p = 101, ans_q = 101;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m;j++) {
				if (2*(p[i] - q[j]) == pq_dif&&p[i]<ans_p) {
					ans_p = p[i];
					ans_q = q[j];
				}
			}
		}
		if (ans_p == 101) {
			cout << "-1" << endl;
		}
		else {
			cout << ans_p <<" "<< ans_q << endl;
		}
	}
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define PI 3.14159265359
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define tr(con, it) \
    for (auto it = con.begin(); it != con.end(); it++)
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define present(con, ele) (con.find(ele) != con.end())
#define cpresent(con, ele) (find(all(con), ele) != con.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double lf;
typedef unsigned long long lu;
const ll mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    unordered_map<string, int> M;
    int n;
    cin >> n;
    fr(i, 0, n)
    {
        string s;
        cin >> s;
        M[s]++;
    }
    cout << sz(M) << "\n";
    return 0;
}

Measured memory_bytes: 17728
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main()
{
	vector<int> a(3);
	int sum=0;
	rep(i,3) cin >> a[i];
	sort(a.begin(), a.end());
	rep(i,2){
		sum += (a[i+1] - a[i]);
	}
	cout << sum <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

const int MAXN = 1e3 + 10;
int N;
int A[MAXN];
int ap[MAXN];

int main() {
	register int i;
	scanf("%d", &N);
	for(i = 1; i <= N; ++i)
		scanf("%d", A + i), ++ap[A[i]];
	sort(A + 1, A + N + 1);
	for(i = A[1] + 1; i <= A[N]; ++i)
		if(ap[i] < 2)
			return puts("Impossible"), 0;
	if(ap[A[1]] > 2) return puts("Impossible"), 0;
	if(!(A[N] & 1) && (A[1] == A[2] || A[1] != A[N] / 2)) return puts("Impossible"), 0;
	if((A[N] & 1) && (A[1] != A[2] || A[1] != (A[N] + 1) / 2)) return puts("Impossible"), 0;
	puts("Possible");
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n,m;
	int s[200];
	while(scanf("%d %d",&n,&m),n) {
		int sum_t=0,sum_h=0;
		for(int i=0;i<n;i++) {
			scanf("%d",&s[i]);
			sum_t+=s[i];
		}
		for(int i=0;i<m;i++) {
			scanf("%d",&s[i+n]);
			sum_h+=s[i+n];
		}
		int sum=1<<30,a,b;
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				if(sum_h-sum_t==2*(s[j+n]-s[i])) {
					if(sum>(s[j+n]+s[i])) {
						sum=s[j+n]+s[i];
						a=i,b=j;
					}
				}
			}
		}
		if(sum==1<<30) {
			printf("-1\n");
		}else {
			printf("%d %d\n",s[a],s[b+n]);
		}
	}
}

Measured memory_bytes: 1040
#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int > Pi;
typedef pair< int , Pi > Pii;
#define fr first
#define sc second
#define INF 1e300

int main()
{
  int n;
  int num[15], dist[15], box[15];
  double dp[1 << 15][15];
  int prev[1 << 15][15];
  long double speed[1 << 15];
  fill_n( *prev, 15 * (1 << 15), -1);
  fill_n( *dp, 15 * (1 << 15), INF);

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> num[i] >> dist[i] >> box[i];
  }
  
  for(int i = 0; i < 1 << n; i++){
    int ret = 0;
    for(int j = 0; j < n; j++){
      if(i >> j & 1) continue;
      ret += box[j];
    }
    //speed[i] = 200.0 / ( 7.0 + ret);
    speed[i] = (7.0 + 2 * ret) / 200.0; //逆っぽい
  }
  for(int i = 0; i < n; i++){
    dp[1 << i][i] = 0;
  }
           
  for(int bit = 0; bit < 1 << n; bit++){
    for(int i = 0; i < n; i++){
      if(!((bit >> i) & 1)) continue;
      for(int k = 0; k < n; k++){
        double power = abs( dist[i] - dist[k]) * speed[bit];
        if((bit >> k) & 1) continue;

        int nxbit = bit|(1 << k);
        if(dp[nxbit][k] > dp[bit][i] + power){
          dp[nxbit][k] = dp[bit][i] + power;
          prev[nxbit][k] = i;
        }
      }
    }
  }
  
  int pos = 0;
  int bit = (1 << n) - 1;
  for(int i = 1; i < n; i++){
    if( dp[bit][pos] > dp[bit][i]) pos = i;
  }
  queue< int > st;
  while(pos != -1){
    st.push(num[pos]);
    int foo = prev[bit][pos];
    bit ^= 1 << pos;
    pos = foo;
  }
  while(st.size() > 1){
    cout << st.front() << " ";
    st.pop();
  }
  cout << st.front() << endl;
  return(0);
}

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

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	string s;
	cin >> s;
	map<char,int> m;

	if(s.length()==1){
		cout << 0 << endl;
		return 0;
	}

	REP(i,s.length()-1){
		m[s[i]]++;
	}
	char maxChar[m.size()];
	int max=0;
	int cnt=0;
	for(auto i=m.begin();i!=m.end();i++){
		maxChar[cnt] = i->first;
		if(i->second>max){
			max = i->second;
		}
		cnt++;
	}
	int ansg=1000;

	string s_init = s;
	REP(j,m.size()){
		s = s_init;
		int ans=0;
		while(true){
			bool flag=false;
			REP(i,s.length()){
				if(s[i]!=maxChar[j]) break;
				if(i==s.length()-1){
					ansg = min(ansg,ans);
					flag = true;
					break;
				}
			}
			if(flag) break;
			ans++;
			string s_new;
			REP(i,s.length()-1){
				if(s[i+1]==maxChar[j]){
					s_new.push_back(maxChar[j]);
				}
				else s_new.push_back(s[i]);
			}
			
			s = s_new;
		}
	}
	
	cout << ansg << endl;
	
	
}

Measured memory_bytes: 256
"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

!function () {
  function splitNum(line) {
    return (Array.isArray(line) ? line : line.split(/\s+/)).map(function (n) {
      return parseInt(n);
    });
  }

  function* range(start, end) {
    for (var i = start; i < end; i++) {
      yield i;
    }
  }

  !function (input) {
    var lines = input.split("\n");

    var _splitNum = splitNum(lines[0]),
        _splitNum2 = _slicedToArray(_splitNum, 2),
        N = _splitNum2[0],
        K = _splitNum2[1];

    var sum = 0;
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = range(1, N + 1)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var start = _step.value;
        sum += Math.pow(.5, Math.max(0, Math.ceil(Math.log(K / start) / Math.log(2))));
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return != null) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }

    console.log(sum / N);
  }(require("fs").readFileSync("/dev/stdin", "utf8"));
}();


Measured memory_bytes: 21956
// 2014/06/26 Tazoe

#include <iostream>
using namespace std;

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

	for(int i=0; i<N; i++){
		int x, y, b, p;
		cin >> x >> y >> b >> p;

		int f1 = x*b+y*p;		// 割引なし

		if(b<5){
			b = 5;
		}
		if(p<2){
			p = 2;
		}
		int f2 = (x*b+y*p)*4/5;		// 割引あり

		if(f1<f2){
			cout << f1 << endl;
		}
		else{
			cout << f2 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
input = gets.split

stack = []
input.each do |inp|
	if ["+", "-", "*"].include?(inp)
		val1 = stack.pop.to_i
		val2 = stack.pop.to_i
		val3 = val2.send(inp, val1)
		stack.push(val3)
	else
		stack.push(inp.to_i)
	end
end

puts stack.pop

Measured memory_bytes: 8672
bingocard = []
bingo = False
for _ in range(3):
    bingocard += input().split()

punch_data = [0]*9
n = int(input())

for _ in range(n):
    num = input()
    if num in bingocard:
        punch_data[bingocard.index(num)] = 1

for i in range(3):
    if not 0 in punch_data[3*i: 3*(i+1)]:
        bingo = True
        break
    
    if punch_data[i] == punch_data[i+3] == punch_data[i+6] == 1:
        bingo = True
        break

if punch_data[0] == punch_data[4] == punch_data[8] == 1:
    bingo = True

if punch_data[2] == punch_data[4] == punch_data[6] == 1:
    bingo = True

if bingo:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <list>
#include <stack>
#include <limits.h>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <memory>
#include <regex>
#include <functional>
using namespace std;
bool canSolve(int N, int A)
{
    if (N == 0) return true;
    if (A == 0) return false;
    int percent5 = N % 5;
    if (percent5 == 0) return true;
    return percent5 <= A;
}
int main() {
    int N, A;
    cin >> N >> A;
    cout << ((N % 500 <= A) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
w, h, x, y = list(map(int, input().split()))
ans = 0
s = w * h / 2

if ((x, y) == (w / 2, h / 2)):
    print("{s} {mul}".format(s=s, mul=1))
else:
    print("{s} {mul}".format(s=s, mul=0))


Measured memory_bytes: 38256
def koch(d,p0,p1):
    #終了条件
    if d == n:
        return
    
    #内分点：s,t
    s=[(2*p0[0]+p1[0])/3,(2*p0[1]+p1[1])/3]
    t=[(2*p1[0]+p0[0])/3,(2*p1[1]+p0[1])/3]
    
    #正三角形の頂点:u
    u=[(p0[0]+p1[0])/2-(p1[1]-p0[1])*(3**(1/2)/6),(p1[1]+p0[1])/2+(p1[0]-p0[0])*(3**(1/2)/6)]
    
    koch(d+1,p0,s)
    print(*s)
    # point.append(s)
    koch(d+1,s,u)
    print(*u)
    # point.append(u)
    koch(d+1,u,t)
    print(*t)
    # point.append(t)
    koch(d+1,t,p1)
    
p0=[0,0]
p1=[100,0]


n=int(input())

print(*p0)
koch(0,p0,p1)
print(*p1)



Measured memory_bytes: 5708
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>

using namespace std;

int n, m, q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int> A)
{
    if (A.size() == n + 1)
    {
        int point = 0;
        for (int i = 0; i < q; i++)
        {
            if (A.at(b.at(i)) - A.at(a.at(i)) == c.at(i))
            {
                point += d.at(i);
            }
        }
        ans = max(ans, point);
        return;
    }

    A.push_back(A.back());
    while (A.back() <= m)
    {
        dfs(A);
        A.back()++;
    }
}

int main()
{
    cin >> n >> m >> q;
    a = b = c = d = vector<int> (q);

    for (int i = 0; i < q; i++)
    {
        cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    }
    
    dfs(vector<int>(1, 1));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>

int main() {
 
  int N;
  std::cin >> N;
  
  int count_ac = 0, count_wa = 0;
  int count_sa = 0, count_tle = 0;

  for(int i = 0; i < N; i++){
     std::string judge;
     std::cin >> judge;
     if(judge == "AC") {
        count_ac ++;
     }else if(judge == "WA") {
        count_wa ++;
     }else if(judge == "RE") {
        count_sa ++;
     }else {
        count_tle ++;
     }
  }
  
    std::cout << "AC x " << count_ac << "\n"
              << "WA x " << count_wa << "\n"
              << "TLE x " << count_tle << "\n"
              << "RE x " << count_sa << "\n" << std::endl;
  
  return 0;
}

Measured memory_bytes: 3600
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

lst = inputs[1]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
  p lst
end

ll = []
lst.each do |a_i|
  cnt = 0
  tmp = a_i
  while tmp % 2 == 0 and tmp > 0
    tmp /= 2
    cnt += 1
  end
  ll << cnt
end

puts ll.min


Measured memory_bytes: 1788