akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

bool f[405][405][2];
int d[405][405];
int H,W,M,Q,h,w;
int ax[100],ay[100],bx[100],by[100];
map<int,int> X,Y;

int solve(int sx,int sy,int tx,int ty){
  memset(d,1,sizeof(d));
  deque<int> qx,qy;
  qx.push_front(sx);
  qy.push_front(sy);
  d[sx][sy]=0;
  while(!qx.empty()){
    int px=qx.front();qx.pop_front();
    int py=qy.front();qy.pop_front();
    //cout<<px<<' '<<py<<endl;
    if(px==tx&&py==ty)return d[px][py];
    for(int i=0;i<4;i++){
      int nx=px+dx[i];
      int ny=py+dy[i];
      if(nx<=0||ny<=0)continue;
      if(w<=nx||h<=ny)continue;
      int flg=0;
      if(i<2){
        if(f[px][py][i])flg=1;
      }else{
        if(f[nx][ny][i-2])flg=1;
      }
      if(d[px][py]+flg<d[nx][ny]){
        d[nx][ny]=d[px][py]+flg;
        if(flg){
          qx.push_back(nx);
          qy.push_back(ny);
        }else{
          qx.push_front(nx);
          qy.push_front(ny);
        }
      }
    }
  }
  return -1;
}

void func(map<int,int> &X){  
  map<int,int>::iterator it;  
  int C=0;
  for(it=X.begin();it!=X.end();++it)
    X[it->first]=++C;
}

int sx[105],sy[105];
int tx[105],ty[105];

int main(){
  scanf("%d %d %d",&W,&H,&M);
  for(int i=0;i<M;i++){
    scanf("%d %d %d %d",&ax[i],&ay[i],&bx[i],&by[i]);
    if(ax[i]>bx[i])swap(ax[i],bx[i]);
    if(ay[i]>by[i])swap(ay[i],by[i]);
    X[ax[i]]=Y[ay[i]]=i;
    X[bx[i]]=Y[by[i]]=i;
  }
  X[0]=Y[0]=1;
  X[W]=Y[H]=M;
  scanf("%d",&Q);
  for(int i=0;i<Q;i++){
    scanf("%d %d %d %d",&sx[i],&sy[i],&tx[i],&ty[i]);
    X[sx[i]]=Y[sy[i]]=i;
    X[tx[i]]=Y[ty[i]]=i;
  }  
  func(X);
  func(Y);
  w=X[W],h=Y[H];
  for(int i=0;i<M;i++){
    int AX=X[ax[i]],AY=Y[ay[i]];
    int BX=X[bx[i]],BY=Y[by[i]];
    if(AX==BX){
      for(int y=AY;y<BY;y++)f[AX][y][0]=true;      
    }else{
      for(int x=AX;x<BX;x++)f[x][AY][1]=true;      
    }    
  }
  for(int i=0;i<Q;i++){
    sx[i]=X[sx[i]];
    sy[i]=Y[sy[i]];
    tx[i]=X[tx[i]];
    ty[i]=Y[ty[i]];
    printf("%d\n",solve(sx[i],sy[i],tx[i],ty[i]));
  }
  return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */
int n;
vector<int> to;
vector<int> v;
bool used[MAX];

int dfs(int s=0){
    used[s] = true;
    v.push_back(s);
    int t = to[s];
    if(used[t]){
        return t;
    }
    return dfs(t);
}

int main(){
    lint k; cin>>n>>k;
    rep(i,n){
        int a; cin>>a; a--;
        to.push_back(a);
    }
    int r = dfs(); int x,y;
    rep(i, v.size()){
        if(v[i]==r){
            x = i; break;
        }
    }
    y = v.size()-x;
    if(k<x) out(v[k]+1);
    else out(v[(k-x)%y+x]+1);
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = a; i >= (b); --i)
#define trav(a, x) for(auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;


int N = 1e6 + 5;
vector<int> factor(N);

void Factor() {
  for (int i = 1; i < N; i++)
    factor[i] = i;
  for (ll i = 2; i * i <= N; i++) {
    if (factor[i] == i) {
      for (int j = i * i; j < N; j += i) 
        if (factor[j] == j)
          factor[j] = i;
    }
  }
}

int count(int n) {
  if (n == 1) return 1;
  
  ll res = 1, c = 0;
  int p = -1;
  while (n != 1) {
    if (factor[n] == p) {
      n /= p;
      c++;
    } else {
      res *= (c + 1);
      c = 0;
      p = factor[n];
    }
  }
  return res * (c + 1);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  
  int n; cin >> n;
  Factor();
  ll res = 0;
  for (int i = 1; i < n; i++) {
    res += count(i);
    
  }
  cout << res;
}


Measured memory_bytes: 7080
import java.util.*;

public class Main{
    static int N;
    static int A;
    static int B;
    static int C;
    static int[] l;
    static int MP;
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        l = new int[N];
        for(int i = 0; i < N; i++){
            l[i] = sc.nextInt();
        }
        sc.close();
        MP = 1000000000;
        dps(0, 0, 0, 0, 0);
        System.out.println(MP);
    }

    static void dps(int cur, int a, int b, int c, int count){
        if(cur == N){
            if((Math.abs(A-a) + Math.abs(B-b) + Math.abs(C-c) - 30 + 10*count) < MP &&
                (a>0&&b>0&&c>0)){
                    MP = Math.abs(A-a) + Math.abs(B-b) + Math.abs(C-c) - 30 + 10*count;
                }
        } else if(cur < N) {
            dps(cur+1, a, b, c, count);
            dps(cur+1, a+l[cur], b, c, count+1);
            dps(cur+1, a, b+l[cur], c, count+1);
            dps(cur+1, a, b, c+l[cur], count+1);
        }
    }
}


Measured memory_bytes: 23764
class ReversePopHeap
  attr_accessor :nodes, :size
  def initialize(n)
    @nodes = Array.new(n)
    @size = 0
  end

  def push(x)
    current_index = @size
    @size += 1
    while current_index > 0 do
      parent_index = (current_index - 1)>>1
      parent_value = @nodes[parent_index]
      break if parent_value >= x
      @nodes[current_index] = parent_value
      current_index = parent_index
    end
    @nodes[current_index] = x
  end

  def pop
    top = @nodes[0]
    current_node_index = 0
    current_node_value = @nodes[0] = @nodes[@size - 1]
    @nodes[@size - 1] = nil
    @size -= 1

    while
      child_node_index_r = (current_node_index + 1) << 1
      child_node_index_l = child_node_index_r - 1
      return top unless child_node_index_l < @size
      child_node_value_l = @nodes[child_node_index_l]
      child_node_value_r = @nodes[child_node_index_r]
      if child_node_value_r&.>child_node_value_l
        max_child_value = child_node_value_r
        max_child_index = child_node_index_r
      else
        max_child_value = child_node_value_l
        max_child_index = child_node_index_l
      end
      return top unless max_child_value > current_node_value
      change(current_node_index, max_child_index)
      current_node_index = max_child_index
    end
  end

  private

  def change(index_i, index_j)
    @nodes[index_i], @nodes[index_j] = @nodes[index_j], @nodes[index_i]
  end
end

n, m = gets.split.map(&:to_i)
rph = ReversePopHeap.new(n)
gets.split.map {|s| rph.push s.to_i}
sum = 0
m.times do |i|
  top = rph.pop
  rph.push(top/2)
  sum +- top
end
sum += rph.nodes[0...rph.size].inject(:+)
puts sum

Measured memory_bytes: 11916
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use std::cmp::*;
use std::collections::*;
use std::mem::*;

fn main() {
    let (r, w, e) = (std::io::stdin(), std::io::stdout(), std::io::stderr());
    let mut io = IO::new(r.lock(), w.lock(), e.lock());

    let n = io.read::<usize>();
    let mut a = io.readn::<i64>(n);
    let mut b = a
        .iter()
        .cloned()
        .enumerate()
        .map(|(i, x)| (x, i + 1))
        .collect::<Vec<_>>();
    b.sort();
    let mn = b[0];
    let mx = b[n - 1];

    println!("{}", 2 * n - 1);
    if mx.0.abs() >= mn.0.abs() {
        for i in 1..n + 1 {
            println!("{} {}", mx.1, i);
        }
        for i in 1..n {
            println!("{} {}", i, i + 1);
        }
    } else {
        for i in 1..n + 1 {
            println!("{} {}", mn.1, i);
        }
        for i in (2..n + 1).rev() {
            println!("{} {}", i, i - 1);
        }
    }
}

static MX: usize = 1010101;
static MOD: i64 = 1000000007;
static INF: i64 = std::i64::MAX >> 1;
// IO
use std::io::*;
struct IO<R: Read, W: Write, E: Write> {
    Read: R,
    Write: BufWriter<W>,
    Error: BufWriter<E>,
}
impl<R: Read, W: Write, E: Write> IO<R, W, E> {
    fn new(r: R, w: W, e: E) -> IO<R, W, E> {
        IO {
            Read: r,
            Write: BufWriter::new(w),
            Error: BufWriter::new(e),
        }
    }
    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let next: String = self
            .Read
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect();
        next.parse().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    fn chari(&mut self) -> Vec<i64> {
        self.chars()
            .iter()
            .map(|&c| (c as u8 - b'0') as i64)
            .collect::<Vec<i64>>()
    }
    fn readn<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect::<Vec<_>>()
    }
    fn readmat<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n).map(|_| self.readn(m)).collect()
    }
    fn write<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
    }
    fn writeln<S: ToString>(&mut self, val: S) {
        self.Write.write(val.to_string().as_bytes());
        self.Write.write(b"\n");
    }
    fn debug<S: std::fmt::Debug>(&mut self, val: S) {
        writeln!(self.Error, "(debug) {:?}", &val);
    }
    fn debug2<S: std::fmt::Debug, T: std::fmt::Debug>(&mut self, val1: S, val2: T) {
        writeln!(self.Error, "(debug2) {:?} -> {:?}", val1, val2);
    }
    fn debug3<S: std::fmt::Debug, T: std::fmt::Debug, U: std::fmt::Debug>(
        &mut self,
        val1: S,
        val2: T,
        val3: U,
    ) {
        writeln!(
            self.Error,
            "(debug3) {:?} -> {:?} -> {:?}",
            val1, val2, val3
        );
    }
}


Measured memory_bytes: 2152
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b != c) {
		cout << "Yes";
	}else if (c == b && a != c) {
		cout << "Yes";
	}else if (a == c&& b != c) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

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

string f[10010][11] = {};

string getmax(string f[10010][11], int d, int m) {
	string max = f[d][0];
	for (int i = 1; i < m; i++) {
		int l1 = max.length();
		int l2 = f[d][i].length();

		if ((l1 < l2) || ((l1 == l2) && max.compare(f[d][i]) < 0)) {
			max = f[d][i];
		}
	}

	return max;
}

int main() {
	int n, m;
	int da[] = { 0,2,5,5,4,5,6,3,7,6 };
	int a[9] = {};

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < m; i++) {
		f[0][i] = "0";
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < m; j++) {
			if (i - da[a[j]] >= 0) {
				f[i][j] = getmax(f, i - da[a[j]], m);
				if (f[i][j].compare("") != 0) 
					f[i][j] = f[i][j].append(to_string(a[j]));
			}
			else {
				f[i][j] = "";
			}
		}
	}

	string result = getmax(f, n, m);
	if (result.at(0)=='0') {
		result = result.substr(1, result.length() - 1);
	}
	cout << result;


	getchar(); getchar();
	return 0;
}

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

    using namespace std;
    #define ll long long
    #define ld long double
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define pb push_back
    #define deb(x) cout<<#x<<" : "<<x<<endl;
    #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
    #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
   
   
    const int mod=998244353;
    const int N=1e6+5; 
    const ll inf=1e18+5;
   
    bool sortbysec(const pair<pair<ll,ll>,ll> &a, 
                      const pair<pair<ll,ll>,ll> &b) 
        { 
            return (a.second > b.second); 
        } 
        ll powermod(ll x, ll y, ll p)
        {
            ll res = 1;
            x = x % p;
            while (y > 0)
            {
                if (y & 1) res = (res*x) % p;
                y = y>>1;
                x = (x*x) % p;
            }
            return res;
        }
       
        bool isprime(int n) 
        { 
            if (n <= 1)  return false; 
            if (n <= 3)  return true; 
            if (n%2 == 0 || n%3 == 0) return false; 
            for (int i=5; i*i<=n; i=i+6) 
                if (n%i == 0 || n%(i+2) == 0) 
                   return false; 
           return true; 
        }
        
    int main()
    {
        FAST;
        ll x,y,a,b,c;
        cin>>x>>y>>a>>b>>c;
        vll red(a);
        vll green(b);
        vll colorless(c);
        for(ll i=0;i<a;i++)
        cin>>red[i];
        for(ll i=0;i<b;i++)
        cin>>green[i];
        for(ll i=0;i<c;i++)
        cin>>colorless[i];
        sort(red.rbegin(),red.rend());
         sort(green.rbegin(),green.rend());
          sort(colorless.rbegin(),colorless.rend());
          ll sum=0;
         vll ans;
         for(ll i=0;i<min(x,a);i++)
         ans.pb(red[i]);
         for(ll i=0;i<min(y,b);i++)
         ans.pb(green[i]);
         for(ll i=0;i<min(x+y,c);i++)
         ans.pb(colorless[i]);
         sort(ans.rbegin(),ans.rend());
         for(ll i=0;i<x+y;i++)
         sum+=ans[i];
          cout<<sum;
        return 0;
    }

Measured memory_bytes: 8688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll a, b, c, k;
  scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
  /*
      係数が1,0,0と0,1,1から始まり、sとoとするとs_(n+1)=2o_(n),
     o_(n+2)=2o_(n)+o_(n+1) s_0=1,o_0=0,s_1=0,o_1=1 (x-2)(x+1)=0
      o_n2-2o_n1=-(o_n1-2o_n) -> n+1 - 2n = (-1)^n
      o_n2+o_n1=2(o_n1+o_n) -> n+1 + n = 2^n
      o_n = (2^n - (-1)^n) / 3
      s_n = (2^n - 2(-1)^(n-1)) / 3

      a_n = s_n*a + o_n*(b+c)
      b_n = s_n*b + o_n*(a+c)
      a_n - b_n = s_n * (a - b) + o_n * (b - a)
  */
  ll ab = a - b;
  ll ba = b - a;
  if (k % 2 == 0) {
    // o_k = (2^k - 1) / 3, s_k = (2^k + 2) / 3
    // (2ab - ba) / 3
    ll y = (2 * ab - ba) / 3;
    printf("%lld\n", y);
  } else {
    // o_k = (2^k + 1) / 3, s_k = (2^k - 2) / 3
    // (ab - 2ba) / 3
    ll y = (ba - 2 * ab) / 3;
    printf("%lld\n", y);
  }
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
lst = list(map(int,input().split()))
s = 0
t = 0
for x in lst:
  s += x
  t += (x ** 2) % (10**9+7)

w = (s**2-t) % (10**9+7)
if w % 2 == 0:
  print(w//2)
else:
  print((w+10**9+7)//2)
  

Measured memory_bytes: 49884
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, p[200000];
pair<int,int> tree[1 << 19][2];
priority_queue<pair<pair<int, int>, pair<int, int>>, vector<pair<pair<int, int>, pair<int, int>>>, greater<pair<pair<int, int>, pair<int, int>>>>q;
queue<int>res;

pair<int, int> calc(int l, int r, int p, int q, int k) {
	if (r < p || q < l)return mkp(0xE869120, -1);
	if (p <= l&&r <= q)return tree[k][p & 1];
	return min(calc(l, (l + r) / 2, p, q, k * 2), calc((l + r) / 2 + 1, r, p, q, k * 2 + 1));
}

void dfs(int l, int r) {
	if (l > r)return;
	int L = calc(0, (1 << 18) - 1, l, r, 1).second;
	int R = calc(0, (1 << 18) - 1, L + 1, r, 1).second;
	q.push(mkp(mkp(p[L], p[R]), mkp(L + 1, R - 1)));
	dfs(l, L - 1);
	dfs(R + 1, r);
}

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> p[i];
		tree[(1 << 18) + i][i & 1] = mkp(p[i], i);
		tree[(1 << 18) + i][!(i & 1)] = mkp(0xE869120, -1);
	}
	for (int i = (1 << 18) - 1; i; --i) {
		tree[i][0] = min(tree[i * 2][0], tree[i * 2 + 1][0]);
		tree[i][1] = min(tree[i * 2][1], tree[i * 2 + 1][1]);
	}
	q.push(mkp(mkp(-1, -1), mkp(0, N - 1)));
	while (!q.empty()) {
		res.push(q.top().first.first);
		res.push(q.top().first.second);
		int l = q.top().second.first;
		int r = q.top().second.second;
		q.pop();
		dfs(l, r);
	}
	res.pop();
	res.pop();
	while (!res.empty()) {
		cout << res.front() << sp;
		res.pop();
	}
	cout << endl;
}

Measured memory_bytes: 19056
use proconio::input;

fn main() {
    input! {
        a: [[usize; 3]; 3],
        n: usize,
        b: [usize; n],
    }

    let mut card = [[0; 3]; 3];

    for x in 0..n {
        for i in 0..3 {
            for j in 0..3 {
                if a[i][j] == b[x] {
                    card[i][j] = 1;
                    break;
                }
            }
        }
    }

    if card[0][0] == 1 && card[0][1] == 1 && card[0][2] == 1
        || card[1][0] == 1 && card[1][1] == 1 && card[1][2] == 1
        || card[2][0] == 1 && card[2][1] == 1 && card[2][2] == 1
        || card[0][0] == 1 && card[1][0] == 1 && card[2][0] == 1
        || card[0][1] == 1 && card[1][1] == 1 && card[2][1] == 1
        || card[0][2] == 1 && card[1][2] == 1 && card[2][2] == 1
        || card[0][0] == 1 && card[1][1] == 1 && card[2][2] == 1
        || card[0][2] == 1 && card[1][1] == 1 && card[2][0] == 1 {
            println!("Yes")
        } else {
            println!("No")
        }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> H(N);
    REP(i, N) cin >> H[i];

    ll res = -1;
    ll tmp = 0;
    REP(i, N-1){
    	if(H[i+1]<=H[i]) tmp++;
    	else{
    		res = max(res, tmp);
    		tmp = 0;
    	}
    	//dump(tmp)
    }
    res = max(res, tmp);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N,T,cnt=0,match=0;
	cin >>N;
	queue<int> Q;
	for (size_t i = 0; i < N; i++)
	{
		cin >> T;
		T--;
		Q.push(T);
	}
	for (size_t i = 0; i < N; i++)
	{
		while (Q.size() != 0 &&Q.front()!=i)
		{

			//cout << i << "で" << Q.front()<<"を粉砕";
			Q.pop();
			cnt++;
		}
		if (Q.size() == 0) {
			break;
		}
		match++;
		Q.pop();
	}
	if (match!=0)
	{

		cout << cnt;
	}
	else {
		cout << -1;
	}
}

Measured memory_bytes: 1152
/* AtCoder 星には四種類の塩基 A, C, G, T が存在し、A と T、C と G がそれぞれ対になります。
文字 
b
b
が入力されます。これは A, C, G, T のいずれかです。塩基 
b
b
と対になる塩基を表す文字を出力するプログラムを書いてください。 */

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

int main(){
    char b;
    cin>>b;
    if(b=='A')cout<<'T'<<endl;
    else if(b=='T')cout<<'A'<<endl;
    else if(b=='C')cout<<'G'<<endl;
    else if(b=='G')cout<<'C'<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int x;
    cin >> x;
    cout << 48 - x << endl;
    return 0;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
var N;
var mo=1000000007;
// 標準入力がくると発生するイベント
process.stdin.on('data', function (chunk) {
    chunk.trim().split('\n').forEach(function(line) {
        //console.log('>' + line);
		N=parseInt(line);
    });
});
// EOFがくると発生するイベント
process.stdin.on('end', function () {
	var power=1;
	for(var i=1;i<N+1;i++){
		power*=i;
		power%=mo;
	}
	console.log(power);
});

Measured memory_bytes: 21320
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 
#define debugP(vec) for(auto v : vec) cout << "(" << v.first << "," << v.second << ") "; cout << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << "(" << v.first << "," << v.second << ") "; cout << endl; } 

typedef long long ll;

const ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

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

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

  string s; cin >> s;

	int r = 0, ans = 0, man = 0;
	while(s[r] == '1') r++;
	rep(l, n) {
	  while (r < l) r++;
		while ( r < n && man < k) {
		  if(r == n - 1 || s[r] == '1' && s[r + 1] == '0') man++;
			r++;
		}
		//cout << l << " " << r-1 << endl; 
		chmax(ans, r - l);
		while (l + 1 < n && !(s[l] == '0' && s[l + 1] == '1')) l++;
		man--;
	}
	cout << ans << endl;
}


Measured memory_bytes: 512
#include<cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<set>
#include<cstring>
using namespace std;
int main()
{
    int n,i,j,k,num[200005],num1[200005];
    cin>>n;
    for(i=1;i<=n;i++)scanf("%d",&num[i]);
    memcpy(num1,num,sizeof(num));sort(num+1,num+1+n);
    for(i=1;i<=n;i++){
        int pos=lower_bound(num+1,num+1+n,num1[i])-num;
        if(pos<=n/2)cout<<num[n/2+1]<<endl;
        else cout<<num[n/2]<<endl;
    }

    return 0;
}

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

using namespace std;
typedef long long ll;
//ループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//コンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    int s, w;
    cin >> s >> w;
    if(s<=w) {cout << "unsafe" << endl;}
    else {cout << "safe" << endl;}
}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

bool Rectangle(int a, int b, int c)
{
	return a * a + b * b == c * c;
}

bool Diamond(int a, int b, int c)
{
	return a == b;
}

int main()
{
	int a, b, c, sum1 = 0, sum2 = 0; char ch;

	while (cin >> a >> ch >> b >> ch >> c)
	{
		if (Rectangle(a, b, c)) sum1++;

		if (Diamond(a, b, c)) sum2++;
	}

	cout << sum1 << endl << sum2 << endl;

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

int main(){
	int N;
    string S;
    cin>>N>>S;
    string mae=S.substr(0,N),ushi=S.substr(N,N);

    map<pair<string,string>,ll> ma;
    for(int bit=0;bit<(1<<N);bit++){
        string a="",b="";
        for(int i=0;i<N;i++){
            if(bit & (1<<i)) a+=ushi[i];
            else b+=ushi[i];
        }
        reverse(all(a));
        reverse(all(b));
        auto p=make_pair(a,b);
        ma[p]++;
    }

    ll res=0;
    for(int bit=0;bit<(1<<N);bit++){
        string a="",b="";
        for(int i=0;i<N;i++){
            if(bit & (1<<i)) a+=mae[i];
            else b+=mae[i];
        }
        auto p=make_pair(a,b);
        res+=ma[p];
    }
    cout<<res<<endl;
}

Measured memory_bytes: 87040
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007 ;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	llint i,n,ans=0,t=-inf;cin>>n;
	vector<pair<llint,llint>>a(n);
	for(i=0;i<n;i++){
		int x,L;cin>>x>>L;
		a[i]=mp(x,L);
	}
	SO(a);
	for(i=0;i<n;i++){
		if(t<=a[i].fir-a[i].sec){ans++;t=a[i].fir+a[i].sec;}
		else{chmin(t,a[i].fir+a[i].sec);}
	}
	cout<<ans<<endl;
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  long long res = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 and i % 5) {
      res += i;
    }
  }
  cout << res << '\n';
}


Measured memory_bytes: 3648
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

a = list(input())
b = list(input())
c = list(input())

def solve(tar):
  if len(eval(tar))==0:
    print(tar.upper())
    exit()
  if tar=="a":
    x = a[0]
    del a[0]
    solve(x)
  elif tar=="b":
    x = b[0]
    del b[0]
    solve(x)
  else:
    x = c[0]
    del c[0]
    solve(x)
solve("a")

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

using namespace std;

#ifdef NeverBeRed
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef TurnRed
		//freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	int ans = 0;
	for (auto &i : a)
	{
		cin >> i;
		ans += i >= k;
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 640
k =int(input())
a , b=map(int,input().split())
flag = False
if b-a >= k:
  flag=True
else:
  for i in range(a,b+1):
    if i%k==0:
      flag=True
      
if flag :
  print("OK")
else:
  print("NG")
  
  

Measured memory_bytes: 9104
#include <stdio.h>
#include <iostream>
using namespace std;
#pragma warning(disable:4996)

int main(void){

	int n, x, z;
	char s, y;
	int card[4][13] = { 0 };

	scanf("%d", &n);

	for (int i = 0; i < n; i++){
		cin >> y >> x;

		switch (y){
		case 'S':
			z = 0;
			break;
		case'H':
			z = 1;
			break;
		case'C':
			z = 2;
			break;
		case'D':
			z = 3;
			break;
		}

		card[z][x - 1] = 1;
	}

	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 13; j++){
			if (card[i][j] == '\0'){
				switch (i){
				case 0:
					s = 'S';
					break;
				case 1:
					s = 'H';
					break;
				case 2:
					s = 'C';
					break;
				case 3:
					s = 'D';
					break;
				}
				printf("%c %d\n", s, j + 1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll Max(ll a,ll b,ll c){
    return max(max(a,b),c);
}

int main(){
    string s;cin>>s;
    ll a[3];rep(i,0,2)a[i]=0;
    rep(i,0,s.size()-1){
        if(s[i]=='a'){
            a[0]++;
        }else if(s[i]=='b'){
            a[1]++;
        }else{
            a[2]++;
        }
    }
    if(Max(abs(a[0]-a[1]),abs(a[1]-a[2]),abs(a[2]-a[0]))<=1){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 512
def main():
    n = int(input())
    X,Y,H = [],[],[]
    xyh = [list(map(int, input().split())) for _ in range(n)]
    xyh = sorted(xyh, key=lambda x:x[2], reverse=True)
    for i in range(n):
        X.append(xyh[i][0])
        Y.append(xyh[i][1])
        H.append(xyh[i][2])

    for cx in range(101):
        for cy in range(101):
            judge = True
            h = H[0]+abs(X[0]-cx)+abs(Y[0]-cy)
            for i in range(n):
                if H[i] != max(h-abs(X[i]-cx)-abs(Y[i]-cy),0):
                    judge = False
                    break
            if judge:
                print(cx,cy,h)
                return


if __name__ == '__main__':
    main()


Measured memory_bytes: 41328
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, price_excluding_tax, tax_included_price;
    cin >> n;
    
    price_excluding_tax = ceil(n / 1.08);
    tax_included_price  = floor(price_excluding_tax * 1.08);
    
    if (n == tax_included_price) {
        cout << price_excluding_tax << endl;
    } else {
        cout << ":(" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>

using namespace std;

int ans=0;
long long N;
void dfs(long long s, bool a, bool b, bool c){
    if(s>N) return;
    if(a && b && c) ans++;
    dfs(s*10+3,true,b,c);
    dfs(s*10+5,a,true,c);
    dfs(s*10+7,a,b,true);
}
int main(){
    cin >> N;
    dfs(0,false,false,false);
    cout << ans <<endl;

}


Measured memory_bytes: 256
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

LL dp[SIZE][13];

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

    dp[0][0] = 1;
    
    for( int i = 0; i < s.size(); ++i ) {
        int dig;
        if( s[i] == '?' ) dig = -1;
        else dig = s[i] - '0';

        for( int j = 0; j < 10; ++j ) {
            if( dig != -1 && dig != j ) continue;

            for( int k = 0; k < 13; ++k ) {
                dp[i + 1][( k * 10 + j ) % 13] = ( dp[i + 1][( k * 10 + j) % 13] + dp[i][k] ) % MOD;

            }
        }
    }

    cout << dp[s.size()][5] << endl;
    
    return 0;
}


Measured memory_bytes: 10604
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<int> ans(n, -1);
    queue<int> que;
    que.push(0);
    while(!que.empty())
    {
        int v = que.front();
        que.pop();
        for(int nx : g[v])
        {
            if(nx == 0 || ans[nx] != -1) continue;
            ans[nx] = v;
            que.push(nx);
        }
    }
    cout << "Yes" << endl;
    for(int i = 1; i < n; i++) cout << ans[i] + 1 << endl;
}


Measured memory_bytes: 10224
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
int main() {
  string s;
  cin>>s;
  int n=s.size();
  vector<int>ans(n);
  int odd=0,even=0;
  for(int i=0;i<n;i++){
    if(s[i]=='R'){
      if(i%2==0){even++;}
      else{odd++;}
    }
    else{
      if(i%2==0){ans[i]+=even;ans[i-1]+=odd;even=0;odd=0;}
      else{ans[i]+=odd;ans[i-1]+=even;odd=0;even=0;}
    }
  }
  for(int i=n-1;i>=0;i--){
    if(s[i]=='L'){
      if(i%2==0){even++;}
      else{odd++;}
    }
    else{
      if(i%2==0){ans[i]+=even;ans[i+1]+=odd;even=0;odd=0;}
      else{ans[i]+=odd;ans[i+1]+=even;odd=0;even=0;}
    }
  }
  for(int i=0;i<n;i++){
    cout<<ans[i];
    if(i<n-1){cout<<" ";}
  }cout<<endl;
  return 0;  
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define  rep(i,a,b)for(int i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const int INF=1000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;

int k;
int n;
int main() {

	string s;
	cin>>s;
	ll ans=0,b=0;
	for(int i=0;i<s.size();++i){
		if(s[i]=='B')++b;
		else ans+=b;
	}
	cout<<ans<<endl;
}


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

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

	int sum = 0;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}

	int cnt=0;
	for (int i = 0; i < n; i++) {
		if (a[i] >= ((double)sum / (4 * m))) {
			cnt++;
		}
	}

	if (cnt >= m) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;

}

Measured memory_bytes: 3592
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

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

    ans = 0
    for i in range(N-1):
        for j in range(i+1,N):
            d = A[i][j]
            flag = True
            for k in range(N):
                if k == i or k == j:
                    continue
                
                tmp = A[i][k] + A[k][j]
                if tmp < d:
                    print(-1)
                    exit()
                
                elif tmp == d:
                    flag = False
                    break
            if flag:
                ans += d
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 42588
// C - Slimes
#include <stdio.h>

int main(void){
    int i, j, n, cnt=1;
    char s[100010]={'\0'}, c;
    scanf("%d%s", &n, s);
    for(i=0; i<n-1; i++){
        if(s[i]!=s[i+1]){cnt++;}
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <climits>

using namespace std;


int main() {
	int a,b;
	cin >> a >> b;

	if (a <= 8 && b <= 8)cout << "Yay!" << endl;
	else cout << ":(" << endl;

	return 0;
}

Measured memory_bytes: 3620
import java.io.*;
import java.util.*;

public class Main {
	static int n;
	static int w;
	static int[] val;
	static int[] wei;
	static Long[][] memo;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		n = sc.nextInt();
		w = sc.nextInt();
		val = new int[n];
		wei = new int[n];
		memo = new Long[n][w + 1];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < w + 1; j++) {
				memo[i][j] = -1l;
			}
		}

		for (int i = 0; i < n; i++) {
			wei[i] = sc.nextInt();
			val[i] = sc.nextInt();
		}
		out.println(dp(0, 0));

		out.flush();
	}

	public static Long dp(int idx, int totW) {

		if (totW > w) {
			return -999999999l;
		}
		if (idx == n) {
			return 0l;
		}
		if (totW == w) {
			return 0l;
		}
		if (memo[idx][totW] != -1l) {
			return memo[idx][totW];
		}

		if (totW + wei[idx] > w) {
			return memo[idx][totW] = dp(idx + 1, totW);

		} else {
			Long take = val[idx] + dp(idx + 1, totW + wei[idx]);
			Long leave = dp(idx + 1, totW);
			return memo[idx][totW] = Math.max(take, leave);
		}

	}

	/*
	 * 
	 * public static Long dp(int idx, int totW) {
	 * 
	 * if (totW > w) { return -999999999l; } if (idx == n) { return 0l; } if (totW
	 * == w) { return 0l; } if(memo[idx][totW]!=-1) { return memo[idx][totW]; }
	 * 
	 * 
	 * Long take = val[idx] + dp(idx + 1, totW + wei[idx]); Long leave = dp(idx + 1,
	 * totW); return memo[idx][totW]=Math.max(take, leave); }
	 */
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 342968
#include <iostream>
#include <algorithm>
using  namespace std;
int a[105];
int main() {
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int x=0,y=k;
    int s=0;
    for(int i=1;i<=n;i++)
        if(a[i]>y-a[i])
            s+=2*(y-a[i]);
        else
            s+=2*(a[i]);
    cout<<s<<endl;
    //std::cout << "Hello, World!" << std::endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class E
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var rs = Enumerable.Range(0, h[1]).Select(i => read()).Select(r => new R { A = r[0], B = r[1], C = r[2] - h[2] }).ToArray();
		map = rs.GroupBy(r => r.A).ToDictionary(g => g.Key, g => g.ToArray());

		var cs = Enumerable.Repeat(long.MinValue, h[0] + 1).ToArray();
		cs[1] = 0;
		long c;
		for (var i = 0; i < h[0]; i++)
			foreach (var r in rs)
				if (cs[r.A] != long.MinValue && cs[r.B] < (c = cs[r.A] + r.C)) cs[r.B] = c;

		foreach (var r in rs)
		{
			if (outs.Contains(r.B)) continue;
			if (cs[r.A] == long.MinValue || cs[r.B] >= cs[r.A] + r.C) continue;

			FindPath(r.B);
			if (outs.Contains(h[0])) { Console.WriteLine(-1); return; }
		}
		Console.WriteLine(Math.Max(cs[h[0]], 0));
	}

	static Dictionary<int, R[]> map;
	static HashSet<int> outs = new HashSet<int>();

	static void FindPath(int p)
	{
		if (!outs.Add(p)) return;
		if (!map.ContainsKey(p)) return;
		foreach (var r in map[p]) FindPath(r.B);
	}
}

struct R
{
	public int A, B, C;
}


Measured memory_bytes: 16596
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}


ll solve(ll n){
  if (n % 2 == 1){
    return 0;
  }
  ll res = 0;
  n /= 2;
  while (n){
    res += n / 5;
    n /= 5;
  }
  return res;
}

int main() {
 ll n;
 cin >> n;
 cout << solve(n) << endl;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

/*************** using variables ***************/
int a, d, n;
vector<LL> sosuu_list;
/**********************************************/
bool isprime(LL x){
    if(x == 2) return true;
    if(x < 2 || x % 2 == 0) return false;
    LL i = 3;
    LL sqrtx = sqrt(x);
    while(i <= sqrtx){
        if(x % i == 0) return false;
        i += 2;
    }
    return true;
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    while(cin >> a >> d >> n, a != 0 && d != 0 && n != 0){
        int cnt = 0;
        while(1){
            if(isprime(a+d*cnt)) n--;
            if(n == 0) break;
            cnt++;
        }
        cout << a+d*cnt << endl;
    }
}



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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

void solve() {
  int N;
  cin >> N;
  vector<int> A(N);
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  if (sum % 10 == 0) {
    sort(all(A));
    for (int i = 0; i < N; i++) {
      if (A[i] % 10 != 0) {
        cout << sum - A[i] << endl;
        return;
      }
    }
    cout << 0 << endl;
  } else {
    cout << sum << endl;
  }
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

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

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans = 0;
  for (int i = a; i < b + 1; i++) {
    if (c % i == 0) ans++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3088
using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var ssQuery =
            from i in Enumerable.Range(1, n)
            select (
                from c in Console.ReadLine()
                group c by c into g
                select new { c = g.Key, len = g.Count() }
            );

        var lss = ssQuery.Aggregate(
            (xs, ys) => 
                from x in xs
                join y in ys on x.c equals y.c
                let len = Math.Min(x.len, y.len)
                where len > 0
                select new { x.c, len }
        );
        var s = string.Join("", lss.OrderBy(x => x.c).SelectMany(x => Enumerable.Repeat(x.c, x.len)));
        Console.WriteLine(s);
    }
}


Measured memory_bytes: 13908