akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;

int P[81][81][12801] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W;
    cin >> H >> W;
    vvec<int> A(H,vec<int>(W)),B(H,vec<int>(W));
    for(int i=0;i<H;i++) for(int j=0;j<W;j++) cin >> A[i][j];
    for(int i=0;i<H;i++) for(int j=0;j<W;j++) cin >> B[i][j];

//    vvec<unordered_map<int,int>> P(H,vec<unordered_map<int,int>>(W,unordered_map<int,int>()));
    struct state{
        int x,y,val;
    };

    const int offset = 6400;
    queue<state> Q;
    Q.push((state){0,0,A[0][0]-B[0][0]});
    Q.push((state){0,0,-A[0][0]+B[0][0]});
    while(!Q.empty()){
        state now = Q.front(); Q.pop();
        if(now.x+1<H){
            int nx = now.x+1,ny = now.y;
            if(!P[nx][ny][offset+now.val+A[nx][ny]-B[nx][ny]]){
                Q.push((state){nx,ny,now.val+A[nx][ny]-B[nx][ny]});
                P[nx][ny][offset+now.val+A[nx][ny]-B[nx][ny]] = 1;
            }
            if(!P[nx][ny][offset+now.val-A[nx][ny]+B[nx][ny]]){
                Q.push((state){nx,ny,now.val-A[nx][ny]+B[nx][ny]});
                P[nx][ny][offset+now.val-A[nx][ny]+B[nx][ny]] = 1;
            }
        }
        if(now.y+1<W){
            int nx = now.x,ny = now.y+1;
            if(!P[nx][ny][offset+now.val+A[nx][ny]-B[nx][ny]]){
                Q.push((state){nx,ny,now.val+A[nx][ny]-B[nx][ny]});
                P[nx][ny][offset+now.val+A[nx][ny]-B[nx][ny]] = 1;
            }
            if(!P[nx][ny][offset+now.val-A[nx][ny]+B[nx][ny]]){
                Q.push((state){nx,ny,now.val-A[nx][ny]+B[nx][ny]});
                P[nx][ny][offset+now.val-A[nx][ny]+B[nx][ny]] = 1;
            }
        }
    }
    int ans = 1e9;
    for(int k=0;k<=12800;k++) if(P[H-1][W-1][k]) ans = min(ans,abs(k-offset));
    cout << ans << endl;
}

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

#define For(i,x,y) for (int i=x;i<y;i++)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

const int oo=(1<<30)-1;
const int N=100000+19;

struct seg{
	int l,r;
	bool operator < (const seg &B) const{
		return l<B.l;
	}
} A[N],stk[N];
int R,C,n,x,y,X1,Y1,X2,Y2,c,top;

int getid(int x,int y){
	if (y==0) return x;
	if (x==R) return y+R;
	if (y==C) return R+C+(R-x);
	if (x==0) return R+C+R+(C-y);
	return -1;
}

int main(){
	R=IN(),C=IN(),n=IN();
	For(i,1,n+1){
		X1=IN(),Y1=IN(),X2=IN(),Y2=IN();
		x=getid(X1,Y1);
		y=getid(X2,Y2);
		if (x==-1||y==-1) continue;
		if (x>y) swap(x,y);
		A[++c]=(seg){x,y};
	}
	sort(A+1,A+c+1);
	For(i,1,c+1){
		while (top>0&&A[i].l>stk[top].r) top--;
		if (top>0&&A[i].r>stk[top].r){
			puts("NO");
			return 0;
		}
		stk[++top]=A[i];
	}
	puts("YES");
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
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(){
  long n,k;
  cin >> n >> k;
  vl a(n);
  long t = 1;
  rep(i,n) cin >> a.at(i);
  rep(i,k) t = a.at(i);
  REP(i,k,n){
    if(a.at(i) > a.at(i-k)) YES;
    else NO;
  }
}

Measured memory_bytes: 4800
using System;

namespace _7_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var nml = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            var n = nml[0];
            var m = nml[1];
            var l = nml[2];
            var matA = new long[n, m];
            var matB = new long[m, l];
            var matC = new long[n, l];
            for (var i = 0; i < n; i++)
            {
                var s = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
                for (var j = 0; j < m; j++)
                {
                    matA[i, j] = s[j];
                }
            }
            for (var i = 0; i < m; i++)
            {
                var s = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
                for (var j = 0; j < l; j++)
                {
                    matB[i, j] = s[j];
                }
            }
            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < l; j++)
                {
                    for (var k = 0; k < m; k++)
                    {
                        matC[i, j] += matA[i, k] * matB[k, j];
                    }
                }
            }
            for (var i = 0; i < n; i++)
            {
                for (var j = 0; j < l; j++)
                {
                    if (j == 0) Console.Write(matC[i, j]);
                    else Console.Write(" " + matC[i, j]);
                }
                Console.WriteLine();
            }
        }
    }
}



Measured memory_bytes: 18028
// -*- coding:utf-8-unix -*-

use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};

use itertools::Itertools;
use proconio::input;

#[allow(dead_code)]
fn map2d<InnerIt: IntoIterator, It: Iterator<Item = InnerIt>, B>(
    it: It,
    f: fn(InnerIt::Item) -> B,
) -> Vec<Vec<B>> {
    it.map(|row| row.into_iter().map(f).collect::<Vec<_>>())
        .collect::<Vec<_>>()
}

fn argmax_list<It: Iterator<Item = Item>, Item, F>(it: It, mut compare: F) -> Vec<It::Item>
where
    Item: Copy,
    F: FnMut(&It::Item, &It::Item) -> Ordering,
{
    let mut max: Option<Item> = None;
    let mut argmax = Vec::new();
    for item in it {
        let comp = match max {
            None => Ordering::Greater,
            Some(max) => compare(&item, &max),
        };
        match comp {
            Ordering::Equal => argmax.push(item),
            Ordering::Greater => {
                max = Some(item);
                argmax.clear();
                argmax.push(item);
            }
            Ordering::Less => {}
        }
    }
    return argmax;
}

#[allow(dead_code)]
fn compare_key<K, V>(t1: &(K, V), t2: &(K, V)) -> Ordering
where
    K: Ord,
{
    t1.0.cmp(&t2.0)
}

fn compare_val<K, V>(t1: &(K, V), t2: &(K, V)) -> Ordering
where
    V: Ord,
{
    t1.1.cmp(&t2.1)
}

#[allow(non_snake_case)]
fn main() {
    input! {
        _: i32,
        _: i32,
        M: i32,
        bombs: [(i32, i32); M],
    }
    // count_y[y] = #{ x | (x, y) is bomb }
    let mut count_y = HashMap::new();
    let mut count_x = HashMap::new();
    for bomb in &bombs {
        let (y, x) = *bomb;
        *count_y.entry(y).or_insert(0) += 1;
        *count_x.entry(x).or_insert(0) += 1;
    }
    let count_y = count_y;
    let count_x = count_x;
    let max_y = argmax_list(count_y.into_iter(), compare_val);
    let max_x = argmax_list(count_x.into_iter(), compare_val);
    let max = max_y[0].1 + max_x[0].1;
    let bomb_set = bombs.iter().map(|bomb| *bomb).collect::<HashSet<_>>();
    for (&(y, _), &(x, _)) in max_y.iter().cartesian_product(max_x.iter()) {
        if !bomb_set.contains(&(y, x)) {
            println!("{}", max);
            return;
        }
    }
    println!("{}", max - 1);
}


Measured memory_bytes: 21912
#include<iostream>
#include<algorithm>
#define f first
#define s second
#define DIM 100005
using namespace std;
int n, i, minim, maxim, sol;
int smin[DIM];
pair<int, int> v[DIM];
int interv(int x, int y){
    if(x > y){
        return 0;
    }
    return y - x + 1;
}
int main(){
    cin>> n;
    for(i = 1; i <= n; i++){
        cin>> v[i].f >> v[i].s;
    }
    sort(v + 1, v + n + 1);
    smin[n] = v[n].s;
    for(i = n - 1; i >= 1; i--){
        smin[i] = min(smin[i + 1], v[i].s);
    }
    minim = 1000000000;
    maxim = 0;
    for(i = 1; i < n; i++){
        minim = min(minim, v[i].s);
        maxim = max(maxim, v[i].s);
        sol = max(sol, interv(v[i].f, minim) + interv(v[n].f, smin[i + 1]) );
        sol = max(sol, interv(v[i].f, maxim) + interv(v[n].f, min(smin[i + 1], minim) ) );
    }
    cout<< sol;
}


Measured memory_bytes: 1408
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int n,a[N],k;
int p[N];
int vis[N];
vector<int>res;
void dfs(int x){
  vis[x]=1;
  res.pb(x);
  if(!vis[p[x]])dfs(p[x]);
}
LL su[N];
int main() {
  ios::sync_with_stdio(false);
  cin>>n>>k;
  for(int i=1;i<=n;i++)cin>>p[i];
  for(int i=1;i<=n;i++)cin>>a[i];
  LL ans=LLONG_MIN;
  for(int i=1;i<=n;i++){
    if(!vis[i]){
      res.clear();
      dfs(i);
      LL s=0;
      for(auto k:res){
        s+=a[k];
      }
      int sz=res.size();
      for(int i=1;i<=sz;i++){
        su[i]=su[i-1]+a[res[i-1]];
      }
      for(int j=0;j<sz;j++){
        res.pb(res[j]);
      }
      for(int j=sz+1;j<=2*sz;j++){
        su[j]=su[j-1]+a[res[j-1]];
      }
      if(su[sz]<0){
        LL tot=LLONG_MIN;
        for(int i=1;i<=min(sz,k);i++){
          for(int j=0;j+i<=2*sz;j++){
            tot=max(tot,su[j+i]-su[j]);
          }
        }
        ans=max(ans,tot);
      }else{
//        cout<<"this"<<endl;
        LL tot=LLONG_MIN;
        for(int j=0;j<2*sz;j++){
          for(int f=1;f<=min(sz,k)&&j+f<=2*sz;f++){
            tot=max(tot,su[sz]*((k-f)/sz)+su[j+f]-su[j]);
//            cout<<j<<' '<<f<<' '<<su[sz]*(k-f)/sz+su[j+f]-su[j]<<endl;
          }
        }
        ans=max(ans,tot);
      }
//      cout<<i<<' '<<ans<<endl;
    }
  }
  cout<<ans<<'\n';
  return 0;
}

Measured memory_bytes: 4024
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;
using ll = long long;
#define out(S) cout<<(S)<<endl;

int getGroup(int x) {
	if (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) return 1;
	if (x == 2) return 3;
	return 2;
}

int main()
{
	int H, W;
	vector<string> o;
	cin >> H >> W;
	for (size_t i = 0; i < H; i++)
	{
		string a,push;
		cin >>a;
		push = "#" + a + "#";
		o.push_back(push);
	}
	string head = "";
	for (size_t i = 0; i < W+2; i++)
	{
		head += "#";
	}
	out(head);
	for (auto s : o) {
		out(s);
	}
	out(head);

    return 0;
}



Measured memory_bytes: 256
n,k = gets.split.map(&:to_i)
sushis = []
n.times do
  sushis << gets.split.map(&:to_i)
end

sushis.sort!{|a,b| a[1] <=> b[1]}.reverse!

used = Hash.new(false)
fixed = []
sw = []
sushis[0...k].each do |sushi|
  if used[sushi[0]]
    sw << sushi
  else
    fixed << sushi
    used[sushi[0]] = true
  end
end

sw.sort_by!{|s| s[1]}

cands = []
sushis[k..-1].each do |sushi|
  break if cands.size == sw.size
  if !used[sushi[0]]
    cands << sushi
    used[sushi[0]] = true
  end
end
cands.sort_by!{|s| s[1]}.reverse!

fixed_size = fixed.size
fixed_point = fixed.reduce(0){|a,e|a+=e[1]}
sw_point = sw.reduce(0){|a,e| a+=e[1]}
cands_point = 0
ans = fixed_point + fixed_size**2 + sw_point

cands.size.times do |i|
  cands_point += cands[i][1]
  sw_point -= sw[i][1]
  tmp = fixed_point + cands_point + sw_point
  tmp += (fixed_size + i+1)**2
  ans = [ans, tmp].max
end

puts ans

Measured memory_bytes: 15748
s = raw_input()

replaced = s.replace('x', '')
l = len(replaced)
halfl = int(l / 2)

if l > 1 and replaced[:halfl] != replaced[-halfl:][::-1]:
  print "-1"
  exit()

xset = {}
i = 0
for c in s:
  if c == 'x':
    d = min(i, l-i)
    if i != l-i:
      xset[d] = xset.get(d, 0) + [-1, 1][i < l-i]
  else:
    i += 1

ans = 0
for v in xset.itervalues():
  ans += abs(v)
print ans

Measured memory_bytes: 7104
# ABC051 D
INF = 10**6
n, m = gets.chomp.split(" ").map(&:to_i)
cost = Array.new(n + 1){Array.new(n + 1, INF)}
(n+1).times do |i|
  cost[i][i] = 0
end
m.times do
  a, b, c = gets.chomp.split(" ").map(&:to_i)
  cost[a][b] = c
  cost[b][a] = c
end

edges = Array.new(n + 1){Array.new(n + 1, 0)}

1.upto(n) do |s|
  # dijkstra: from s to each node
  d = Array.new(n+1, INF)
  used = Array.new(n+1, false)
  prev = Array.new(n+1, -1)
  d[s] = 0

  while true
    v = -1
    1.upto(n) do |u|
      if !used[u] && (v == -1 || d[u] < d[v])
        v = u
      end
    end
    break if v == -1
    used[v] = true
    1.upto(n) do |u|
      if d[u] > d[v] + cost[v][u]
        d[u] = d[v] + cost[v][u]
        prev[u] = v
      end
    end
  end

  # get path: from s to each node
  1.upto(n) do |to|
    path = []
    next if to == s
    t_ = to
    loop do
      break if t_ == -1
      path << t_
      t_ = prev[t_]
    end
    path.each_cons(2) do |a, b|
      edges[a][b] = 1
      edges[b][a] = 1
    end
  end
end

puts m - edges.map{|row| row.inject(:+)}.inject(:+) / 2

Measured memory_bytes: 2428
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPL(i,f,n) for(int i=f, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

int func(int x) {
	if (x % 2 != 0)return 0;
	return 1 + func(x / 2);
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N,a,ans = 0;
	cin >> N;
	REP(i, N) {
		cin >> a;
		ans += func(a);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1e17
#define int long long

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() {
  cerr << "]\n";
}
template<typename T, typename ...Args> void DBG(T first, Args... args) {
  cerr << first; if (sizeof...(args))cerr<<", "; DBG(args...);
}

/////////////////////////// GLOBAL ///////////////////////////

/////////////////////////// GLOBAL ///////////////////////////
void solve() {
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++){
    cin>>arr[i];
  }
  int count = 0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
        if(i!= j && j!=k && i!= k){
          if(arr[i] + arr[j] > arr[k] && arr[i]+arr[k] > arr[j] && arr[j]+arr[k] > arr[i]){
            if(arr[i] != arr[j] && arr[i] != arr[k] && arr[j] != arr[k]) {
              count++;
            // deb(i+1, j+1, k+1);
            }
          }
        }
      }
    }
  }
  cout<<count/6<<"\n";
}

int32_t main() {
  #ifndef ONLINE_JUDGE
  clock_t tStart = clock();
  freopen("in.txt", "r", stdin);
  //freopen("output.txt","w",stdout);
  #endif 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  //cin >> t;
  for (int tt=1;tt<=t;tt++) {
    //cout << "Case #"<<tt<<": ";
    solve();
  }
  #ifndef ONLINE_JUDGE
    cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
  #endif
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>

#ifndef ULLONG
typedef unsigned long long ULLONG;
#endif
#ifndef LLONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void A_task();

int main()
{
	A_task();
	fflush(stdout);
	return 0;
}

static void A_task()
{
	int A, B, C;
	get3int(A, B, C);

	int ans = tp_max(C - (A - B), 0);
	printf("%d\n", ans);
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;

int		main(void)
{
	int X;
	cin >> X;
	int a = X / 500;
	X %= 500;
	int b = X / 5;
	cout << a * 1000 + b * 5 << endl;
}


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

#define FOR(i,a,b) for(i=a;i<=b;i++)
#define FOD(i,b,a) for(i=a;i>=b;i--)
#define pa pair<long long , long long >
#define fi first
#define se second
#define task "x"


typedef long long ll;
const ll M=1e2+1;
const ll N=1e4+1;
using namespace std;

ll i, j, n, ans = 0, x, y, z;
pa a[M][M];
ll b[M],t[M];

void input()
{
    cin >> n;
    FOR(i,1,n)
    {
        cin >> b[i];
        FOR(j,1,b[i])
        {
            cin >> a[i][j].fi >> a[i][j].se;
        }
    }
}

void xuat()
{
    ll kt = 0,s = 0;
        FOR(i,1,n)
        if(t[i]==1)
        {
            FOR(j,1,b[i])
            if(t[a[i][j].fi]!=a[i][j].se) kt = 1;
            s += 1;
        }
        if(kt==0) ans = max( ans , s);
}

void Try(int i)
{
   int j;
   FOR(j,0,1)
   {
       t[i] = j;
       if(i>=n) {xuat();}
       else {
        Try(i+1);
       }
   }
}
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);
    input();
    Try(1);
    cout << ans;
	return 0;
}


Measured memory_bytes: 3648
import java.util.*;

class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int x = sc.nextInt();
      	int y = sc.nextInt();
      	System.out.println(y%2 == 1 || y > 4*x || y < 2*x ? "No" : "Yes");
    }
}

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

int main()
{
	int i, N, X[16], Y[16], P[16];
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d %d %d", &(X[i]), &(Y[i]), &(P[i]));
	
	int j, k, dist[2][32768][16], num[32768] = {};
	const int bit[16] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768};
	for (i = 0; i < bit[N]; i++) {
		for (k = 0; k < N; k++) if ((i & bit[k]) != 0) num[i]++;
		for (j = 0; j < N; j++) {
			dist[0][i][j] = abs(X[j]);
			dist[1][i][j] = abs(Y[j]);
			for (k = 0; k < N; k++) {
				if ((i & bit[k]) == 0) continue;
				if (abs(X[j] - X[k]) < dist[0][i][j]) dist[0][i][j] = abs(X[j] - X[k]);
				if (abs(Y[j] - Y[k]) < dist[1][i][j]) dist[1][i][j] = abs(Y[j] - Y[k]);
			}
		}
	}
	
	const long long sup = (long long)1 << 60;
	long long ans[16], tmp;
	for (i = 0, ans[N] = 0; i < N; i++) ans[i] = sup;
	for (i = 0; i < bit[N]; i++) {
		for (j = 0; j < bit[N]; j++) {
			if (num[i] + num[j] >= N - 4) continue;
			for (k = 0, tmp = 0; k < N; k++) tmp += (long long)P[k] * ((dist[0][i][k] < dist[1][j][k])? dist[0][i][k]: dist[1][j][k]);
			if (tmp < ans[num[i] + num[j]]) ans[num[i] + num[j]] = tmp;
		}
	}
	
	int l;
	long long min, max[16];
	for (k = 0; k < N; k++) max[k] = (long long)P[k] * ((abs(X[k]) < abs(Y[k]))? abs(X[k]): abs(Y[k]));
	for (i = 0; i < bit[N]; i++) {
		if (num[i] < N - 4) continue;
		for (j = 0; j < bit[N]; j++) {
			if ((i & j) != j) continue;
			for (k = 0, tmp = 0; k < N; k++) {
				if ((i & bit[k]) != 0) continue;
				for (l = 0, min = max[k]; l < N; l++) {
					if ((i & bit[l]) == 0) continue;
					if ((j & bit[l]) == 0 && (long long)P[k] * abs(X[k] - X[l]) < min) min = (long long)P[k] * abs(X[k] - X[l]);
					if ((j & bit[l]) != 0 && (long long)P[k] * abs(Y[k] - Y[l]) < min) min = (long long)P[k] * abs(Y[k] - Y[l]);
				}
				tmp += min;
			}
			if (tmp < ans[num[i]]) ans[num[i]] = tmp;
		}
	}
	
	for (i = 0; i <= N; i++) printf("%lld\n", ans[i]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 5956
n,*a= map(int,open(0).read().split())
"""
b=[]

for i in range(1,n+1):
    b.append(a.index(i)+1)
"""
b=[[a[i],i+1] for i in range(n)]
b.sort(key=lambda x: x[0])
for bb in b:
    print(bb[1],end =" ")
print("")


Measured memory_bytes: 22592
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key = lambda x: x[1]) #締め切りが早い順位ソート

tmp = 0
for a, b in AB:
    if tmp + a <= b:
        tmp += a
    else:
        print ('No')
        exit()

print ('Yes')

Measured memory_bytes: 31836
/*
Though leaves are many , the root is one.
Through all the lying days of my youth
I swayed my leaves and flowers in the sun.
Now I may wither into the truth.
*/
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
inline string getstr(string &s,int l,int r){string ret="";for(int i=l;i<=r;i++)ret.push_back(s[i]);return ret;}
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n;
int a[100005];
int b[100005];
signed main(){
	cin>>n;
	for(int i=1;i<=n+1;i++)cin>>b[i];
	for(int i=1;i<=n;i++)cin>>a[i];
	int ans=0;
	for(int i=1;i<=n;i++){
		if(a[i]<b[i]){
			b[i]-=a[i];
			ans+=a[i];
			a[i]=0;
		}else{
			a[i]-=b[i];
			ans+=b[i];
			b[i]=0;
		}
		if(a[i]>b[i+1]){
			ans+=b[i+1];
			a[i]-=b[i+1];
			b[i+1]=0;
		}else{
			ans+=a[i];
			b[i+1]-=a[i];
			a[i]=0;
		}
//		cerr<<a[i]<<" "<<b[i]<<" "<<b[i+1]<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int A[200010];
    rep(i, n) cin >> A[i];
    int right = 0;    
    int sum1 = 0, sum2 = 0;
    int res = 0;
    for (int left = 0; left < n; ++left) {
        while (right < n && (sum1 ^ A[right]) == sum2 + A[right]) {
            //cout << sum1 << " " << sum2 << endl;
            sum1 ^= A[right];
            sum2 += A[right];
            ++right;
        }

        res += (right - left);

        if (right == left) ++right;
        else {
            sum1 ^= A[left];
            sum2 -= A[left];
        }
        //cout << left << " " << right << " " << res << endl;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>

#define int long long

using namespace std;

const int N = 2e5 + 10;

int32_t main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);    
    int n;
    cin >> n;
    string ans;
    while (n)
    {
        --n;
        bool b = 0;
        ans += char((n % 26) + 'a');
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ll mod2 = 998244353;
const ld eps = 1e-10;
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;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m; cin >> n >> m;
  if(m / 2 <= n) {
    cout << m / 2 << endk;
  } else {
    cout << n + (m - 2 * n) / 4 << endk;
  }
  return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a<b){
            System.out.println("a < b");
        }else if(a>b){
            System.out.println("a > b");
        }else{
            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26292
import sys;input=lambda:sys.stdin.readline().rstrip();ints=lambda:list(map(int,input().split()))
 
def main():
    a,b,c,k = ints()
    if k<=a:
        print(k)
    elif k<=a+b:
        print(a)
    elif k<=a+b+c:
        print(2*a+b-k)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9128
#include<stdio.h>
int main(void){
  int N=0,i;
  long count=0;
  scanf("%d",&N);
  for(i=0;i<=N;i++){
    if(i%3!=0&&i%5!=0)count=count+i;
  }
  printf("%ld",count);
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

map< int, int > prime_factor(int n) {
	map<int, int> ret;
	for(int i = 2; i * i <= n; i++) {
		while(n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if(n != 1) {
		ret[n] = 1;
	}
	return ret;
}

signed main()
{
	int A, B; cin >> A >> B;
	auto p1 = prime_factor(A);
	auto p2 = prime_factor(B);

	int ans = 1;

	for (auto a : p1) {
		ans += !!p2.count(a.first);
	}

	cout << ans << endl;
}




Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdio>
#define mod 1000000007
using namespace std;
const int N = 100000 + 5;
char s1[N],s2[N];
int n,type=0; long long ans=1;
int main(){
	scanf("%d", &n);
	scanf("%s", s1+1); scanf("%s", s2+1);
	for( int i = 1; i <= n; i++ ){
		if( s1[i] == s2[i] ){
			if( type == 0 ) ans *= 3;
			if( type == 1 ) ans *= 2;
			if( type == 2 ) ans *= 1;
			type = 1; ans %= mod;
		}if( s1[i] == s1[i+1] ){
			if( type == 0 ) ans *= 6;
			if( type == 1 ) ans *= 2;
			if( type == 2 ) ans *= 3;
			type = 2; ans %= mod; i++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int ll;
typedef  long double ld;
#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; i++)
#define forl(i, n) for(long long i=0;i<n;++i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pi>
#define vpl vector<pl>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define mp make_pair
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m > 0){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}

int main()
{
    fast;
    int x1,x2,x3,x4,x5;
    cin>>x1>>x2>>x3>>x4>>x5;
    if(x1==0)
        cout<<1;
    if(x2==0)
        cout<<2;
    if(x3==0)
        cout<<3;
    if(x4==0)
        cout<<4;
    if(x5==0)
        cout<<5;
    return 0;
}   

Measured memory_bytes: 3524
r, c = [int(_) for _ in input().split()]
sum_row = [0 for _ in range(c + 1)]
for i in range(r):
    row = [int(_) for _ in input().split()]
    row.append(sum(row))
    print(*row)
    for j in range(c + 1):
        sum_row[j] += row[j]
print(*sum_row)


Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  int n, a;
  map<int, int> p;
  vector<int> l;
  for(int i = 0; i < 2; i++) l.push_back(0);
  cin >> n;
  for(int i = 0; i != n; i++){
    cin >> a;
    if(p[a] == 1) l.push_back(a);
    if(p[a] == 3) l.push_back(a);
    p[a]++;
  }
  sort(l.begin(), l.end(), greater<int>());
  cout << (long)l[0] * (long)l[1] << endl;
  return 0;
}

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

void main_()
{
    int64_t X, Y;
    cin >> X >> Y;

    int ans = 0;
    while (X <= Y) {
        X *= 2;
        ans++;
    }
    cout << ans << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  while(cin>>s){
    char c='d';
    if(s[0]=='o'&&s[1]=='o'&&s[2]=='o') c='o';
    if(s[3]=='o'&&s[4]=='o'&&s[5]=='o') c='o';
    if(s[6]=='o'&&s[7]=='o'&&s[8]=='o') c='o';
    if(s[0]=='o'&&s[3]=='o'&&s[6]=='o') c='o';
    if(s[1]=='o'&&s[4]=='o'&&s[7]=='o') c='o';
    if(s[2]=='o'&&s[5]=='o'&&s[8]=='o') c='o';
    if(s[0]=='o'&&s[4]=='o'&&s[8]=='o') c='o';
    if(s[2]=='o'&&s[4]=='o'&&s[6]=='o') c='o';
     
    if(s[0]=='x'&&s[1]=='x'&&s[2]=='x') c='x';
    if(s[3]=='x'&&s[4]=='x'&&s[5]=='x') c='x';
    if(s[6]=='x'&&s[7]=='x'&&s[8]=='x') c='x';
    if(s[0]=='x'&&s[3]=='x'&&s[6]=='x') c='x';
    if(s[1]=='x'&&s[4]=='x'&&s[7]=='x') c='x';
    if(s[2]=='x'&&s[5]=='x'&&s[8]=='x') c='x';
    if(s[0]=='x'&&s[4]=='x'&&s[8]=='x') c='x';
    if(s[2]=='x'&&s[4]=='x'&&s[6]=='x') c='x';
     
    cout << c << endl;
  }
  return 0;
}


Measured memory_bytes: 3180
s = input()
t = input()
lenS = len(s)
lenT = len(t)

dp = [[0]*(lenT+1)for _ in range(lenS+1)]

for i in range(1,lenS+1):
  for j in range(1,lenT+1):
    if s[i-1]==t[j-1]:
      dp[i][j]=dp[i-1][j-1]+1
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j-1])
      
m = lenS
n = lenT
ans = ""
while m and n:
  if dp[m][n] == dp[m-1][n]:
    m -= 1
    continue
  elif dp[m][n] == dp[m][n-1]:
    n -= 1
    continue
  else:
    m -= 1
    n -= 1
    ans = "".join([s[m],ans])
    continue
print(ans)    

Measured memory_bytes: 112348
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {  
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a * b, c * d) << endl;
}




Measured memory_bytes: 3636
#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, MOD = 1e9 + 7;
    cin >> N;
    vector<vector<ll>> dp(N + 1, vector<ll>(64, 0));
    dp[0][63] = 1;
    rep(i, N) {
        rep(j, 64) {
            rep(k, 4) {
                if (j == 33 || j == 6 || j == 9) continue;
                int last4 = j + k * 64;
                if (last4 / 64 == 0 && last4 % 16 == 9) continue;
                if (last4 / 16 == 2 && last4 % 4 == 1) continue;
                dp[i + 1][j] += dp[i][k * 16 + j / 4];
                dp[i + 1][j] %= MOD;
            }
        }
    }
    ll ans = 0;
    rep(i, 64) ans = (ans + dp[N][i]) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
n=int(input())
x=[float(k) for k in input().split()]
y=[float(k) for k in input().split()]
for i in range(1,4):
    print((sum([math.fabs(x[k]-y[k])**i for k in range(n)]))**(1/i))
m=-1000000
for k in range(n):
    v=math.fabs(x[k]-y[k])
    if v>m:
        m=v
print(m)



Measured memory_bytes: 5724
import java.util.Scanner;
public class Main {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       while (true) {int count = 0, upStatus = 0, times = sc.nextInt();
           if (times == 0) {break;}
           for (int i = 0; i < times; i++) {String legAction=sc.next();
               upStatus = (legAction.equals("lu") || legAction.equals("ru")) ? upStatus + 1 : upStatus - 1;
               if ((count % 2 == 0 && upStatus == 2)|| (count % 2 == 1 && upStatus == 0)) {count++;}}
           System.out.println(count);}}}

Measured memory_bytes: 38368
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;

struct AdjItem
{
    int v;
	AdjItem* next;
};

bool DFS_Visit(AdjItem **AdjTable, int i, int *Vertices)
{
	Vertices[i] = 1;
	AdjItem *p = AdjTable[i];
	while(p != NULL)
	{
		if(Vertices[p->v] == 1)
			return true;
		if(Vertices[p->v] == 0)
		{
			if(DFS_Visit(AdjTable, p->v, Vertices) == true)
				return true;
		}
		p = p->next;
	}
	Vertices[i] = 2;
	return false;
}

bool findCycle(int **Edges, int numEdge, int numVert)
{
	int *Vertices = (int*)malloc(sizeof(int) * numVert);
	memset(Vertices, 0, sizeof(int) * numVert);   //ys: 0 means white, 1 means gray, 2 means black

	AdjItem **AdjTable = (AdjItem**)malloc(sizeof(AdjItem) * numVert);
	AdjItem *LastItem;
	for(int i = 0; i < numVert; i++)
	{
		AdjTable[i] = NULL;

		for(int j = 0; j < numEdge; j++)
		{
			if(Edges[j][0] == i)
			{
				if(AdjTable[i] == NULL) //ys:first one
				{
					AdjTable[i] = (AdjItem*)malloc(sizeof(AdjItem));
					AdjTable[i]->v = Edges[j][1];
					AdjTable[i]->next = NULL;
					LastItem = AdjTable[i];
				}
				else
				{
					LastItem->next = (AdjItem*)malloc(sizeof(AdjItem));
					LastItem->next->v = Edges[j][1];
					LastItem->next->next = NULL;

					LastItem = LastItem->next;
				}
			}
		}
	}

	for(int i = 0; i < numVert; i++)
	{
		if(Vertices[i] == 0)
		{
			if(DFS_Visit(AdjTable, i, Vertices) == true)
				return 1;
		}
	}
	
	return 0;
}

int main()
{
	int numVert,numEdge;
	
	cin>>numVert>>numEdge;

	int **Edges = (int**)malloc(sizeof(int*) * numEdge);
	Edges[0] = (int*)malloc(sizeof(int) * numEdge * 2);
	for(int i = 0; i < numEdge; i++)
	{
		Edges[i] = &Edges[0][i*2];
		cin>>Edges[i][0]>>Edges[i][1];
	}

	cout<<findCycle(Edges, numEdge, numVert)<<endl;
	return 0;
}

Measured memory_bytes: 1248
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    s=chomp(readline())
    x=[false for i in 1:26]
    y=[false for i in 1:26]
    ans=0
    for i in 1:n-1
        for j in 1:i
            x[s[j]-'a'+1]=true
        end
        for j in i+1:n
            y[s[j]-'a'+1]=true
        end
        res=0
        for j in 1:26
            if x[j] && y[j]
                res+=1
            end
        end
        ans=max(ans,res)
        x=[false for i in 1:26]
        y=[false for i in 1:26]
    end
    println(ans)
end
main()

Measured memory_bytes: 113964
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define ll long long

void solve()
{
    ll r;
    cin >> r;
    cout << r * r << endl;

    return;
}

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


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



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

	int X,A;
	cin >> X>>A;
	if (X < A) {
		cout << 0 << endl;
	}
	else {
		cout << 10 << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int S[13]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
		H[13]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
		C[13]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
		D[13]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
int sn=13, hn=13, cn=13, dn=13;

void del(char c, int x)
{
		int i, j;
		switch (c)
		{
				case 'S':
						for (i=0; i<13; i++) {
								if (S[i]==x) {
										for (j=i; j<=12; j++) S[j] = S[j+1];
								}
						}
						sn--;
						S[sn] = '\0';
						break;
				case 'H':
						for (i=0; i<13; i++) {
								if (H[i]==x) {
										for (j=i; j<=12; j++) H[j] = H[j+1];
								}
						}
						hn--;
						H[hn] = '\0';
						break;
				case 'C':
						for (i=0; i<13; i++) {
								if (C[i]==x) {
										for (j=i; j<=12; j++) C[j] = C[j+1];
								}
						}
						cn--;
						C[cn] = '\0';
						break;
				case 'D':
						for (i=0; i<13; i++) {
								if (D[i]==x) {
										for (j=i; j<=12; j++) D[j] = D[j+1];
								}
						}
						dn--;
						D[dn] = '\0';
						break;
		}
}

int main()
{
		int n, i, x;
		cin >> n;
		char c; 

		for (i=0; i<n; i++) {
				cin >> c >> x;
				del(c, x);
		}

		for (i=0; i<sn; i++) cout << "S " << S[i] << "\n";
		for (i=0; i<hn; i++) cout << "H " << H[i] << "\n";
		for (i=0; i<cn; i++) cout << "C " << C[i] << "\n";
		for (i=0; i<dn; i++) cout << "D " << D[i] << "\n";
}

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

const int N = 100 + 5;
const int M = 1e5 + 5;
int n, we;
ll w[N], v[N];
ll dp[N][M];


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> we;
    for (int i = 0; i < n; i++)
        cin >> w[i] >> v[i];
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= we; j++) {
            dp[i][j] = dp[i - 1][j];
            if (j - w[i - 1] >= 0)
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
        }
    }
    cout << dp[n][we];
    return 0;
}


Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int W,H;
vector<vector<int> > c;

void dfs(int h, int w){
    c[h][w] = 0;

    for(int i=-1;i<=1;++i){
        for(int j=-1;j<=1;++j){
            int nh = h + i, nw = w + j;

            if(nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if(c[nh][nw] == 0) continue;

            dfs(nh, nw);
        }
    }
}

int main(){
    while(cin >> W >> H){
        if(H == 0 || W == 0) break;
        c.assign(H, vector<int>(W, 0));
        for(int i=0;i<H;++i){
            for(int j=0;j<W;++j){
                cin >> c[i][j];
            }
        }

        int count = 0;
        for(int i=0;i<H;++i){
            for(int j=0;j<W;++j){
                if(c[i][j] == 0) continue;
                dfs(i, j);
                count ++;
            }
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const double pi=acos(-1);
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<MOD>;

mint calc(long long N, long long K) {
    mint res = 1;
    for (long long n = 0; n < K; ++n) {
        res *= (N - n);
        res /= (n + 1);
    }
    return res;
}
int main() {
//cout << fixed << setprecision(12);
ll n;
cin>>n;
ll r;
ll a[n+1]={};
ll b[n+1]={};
repl(i,1,n+1){
cin>>a[i];}
for(ll i=n; i>0; i--){
r = 0;
ll g = i;
while(g<=n){
r+=b[g];
g+=i;}
if(a[i]!=r%2){
b[i]++;}
}
r = 0;
repl(i,1,n+1){
r+=b[i];}
cout << r << endl;
rep(i,n+1){
if(b[i]==1){
cout << i << " ";}}
cout << endl;}


Measured memory_bytes: 6696
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Point {
  int x;
  int y;
  int cost;
  Point() {;}
  Point(int x, int y, int cost) : x(x), y(y), cost(cost) {;}
  bool operator<(const Point &rhs) const {
    return cost > rhs.cost;
  }
};

int sx, sy;
int h, w, n;
char seq[1000010];
int dir[1000010];
int ndir[4][1000010];
char field[1010][1010];
bool visit[1010][1010];
int dist[1010][1010];
const int dx[4] = { 0, 1, 0, -1 };
const int dy[4] = { -1, 0, 1, 0 };

int main() {
  while (scanf("%d %d %d", &h, &w, &n), h|w|n) {
    MEMSET(dir, 0x0f);
    MEMSET(ndir, 0x0f);
    MEMSET(visit, false);
    MEMSET(dist, 0x0a);
    scanf("%s", seq);
    dir[0] = 0;
    REP(i, n) {
      dir[i + 1] = (dir[i] + (seq[i] == 'R' ? 1 : 3)) % 4;
    }
    for (int i = n; i >= 0; i--) {
      REP(d, 4) {
        ndir[d][i] = ndir[d][i + 1];
      }
      ndir[dir[i]][i] = i;
    }

    REP(y, h) {
      scanf("%s", field[y]);
      REP(x, w) {
        if (field[y][x] == 'S') { sx = x; sy = y; }
      }
    }
    priority_queue<Point> que;
    que.push(Point(sx, sy, 0));
    while (!que.empty()) {
      Point p = que.top();
      que.pop();
      if (visit[p.y][p.x]) { continue; }
      visit[p.y][p.x] = true;
      if (field[p.y][p.x] == 'G') {
        puts("Yes");
        goto next;
      }
      REP(d, 4) {
        int nx = p.x + dx[d];
        int ny = p.y + dy[d];
        int ncost = ndir[d][p.cost];
        if (nx < 0 || nx >= w || ny < 0 || ny >= h || field[ny][nx] == '#') { continue; }
        if (dist[ny][nx] <= ncost) { continue; }
        dist[ny][nx] = ncost;
        que.push(Point(nx, ny, ncost));
      }
    }
    puts("No");
next:;
  }
}

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

int main() {
    int n, q;
    cin >> n >> q;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    for (int i = 0; i < q; i++) {
        long long x;
        cin >> x;

        long long ans = 0;
        long long sum = 0;
        long long right = 0;
        for (int left = 0; left < n; left++) {

            while (right < n && sum + a[right] <= x) {
                sum += a[right];
                right++;
            }

            ans += right - left;

            if (right == left) right++;
            else sum -= a[left];
        }

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


Measured memory_bytes: 3548
//
//  main.cpp
//  aojTest1
//
//  Created by yusuke okui on 2013/03/22.
//  Copyright (c) 2013年 yusuke okui. All rights reserved.
//

#include <iostream>

int main(void)
{
	for(int i=1; i<10; i++){
		for(int j=1; j<10; j++){
			std::cout << i << 'x' << j << '=' << i*j << std::endl;
		}
	}
	
	return 0;
	
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    vi a(26, 0);
    vector<char> c(n);
    REP(i, n) cin >> c[i];
    REP(i, n) {
      a[c[i]-'A']++;
      P p = P(-1, -1);
      REP(j, 26) {
        bool conf = true;
        REP(k, 26) {
          if(j == k) continue;
          if(a[j] <= a[k] + n-1-i) {
            conf = false;
            break;
          }
        }
        if(conf) {
          p.fi = j;
          p.se = i;
          break;
        }
      }
      if(p.fi != -1) {
        cout << (char)(p.fi + 'A') << " " << p.se+1 << endl;
        break;
      }
      if(i == n-1) cout << "TIE" << endl;
    }
  }
}



Measured memory_bytes: 3068