akhauriyash/Code-Regression huggingface dataset:
use std::io;
use std::cmp::Ordering;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    loop {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).ok();
    
        let mut vec: Vec<String> = s.trim().split_whitespace().map(|x| x.to_string()).collect();

        let val: i32 = match vec[1].chars().next().unwrap() {
            '+' => vec[0].parse::<i32>().unwrap() + vec[2].parse::<i32>().unwrap(),
            '-' => vec[0].parse::<i32>().unwrap() - vec[2].parse::<i32>().unwrap(),
            '*' => vec[0].parse::<i32>().unwrap() * vec[2].parse::<i32>().unwrap(),
            '/' => vec[0].parse::<i32>().unwrap() / vec[2].parse::<i32>().unwrap(),
            _ => -127,
        };
        
        if val == -127 {
            break;
        }
        else
        {
            println!("{}", val);
        }
    }
}



Measured memory_bytes: 5028
#include<cstdio>
int c[500 + 5], s[500 + 5], f[500 + 5];
int n;

int main() {
	scanf("%d", &n);
	for (int i = 1;i < n;i++)scanf("%d%d%d", &c[i], &s[i], &f[i]);
	for (int i = 1;i < n;i++) {
		int a = s[i] + c[i];
		for (int j = i + 1;j < n;j++) {
			if (a <= s[j])a = s[j] + c[j];
			else {
				int b = (a - s[j] - 1) / f[j] + 1;
				a = s[j] + b*f[j] + c[j];
			}
		}
		printf("%d\n", a);
	}
	printf("0\n");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<math.h>
using namespace std;
main()
{
	long long int a,b;
	cin>>a>>b;
	if(a%2 != b%2)
	{
		cout<<"IMPOSSIBLE"<<endl;
	}
	else
	{
		cout<<(a+b)/2<<endl;
	}
}


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


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


class E{
public:
  int to,dist,value;
  E(int to,int dist,int value):to(to),dist(dist),value(value){}
};

const int N = 111;

int n,m,r;
vector<E> edge[N];

bool input(){
  cin>>n>>m>>r;
  if(n==0)return false;

  rep(i,N)edge[i].clear();

  rep(i,m){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    edge[a].push_back(E(b,c,d));
    edge[b].push_back(E(a,c,d));
  }

  
  return true;
}



class Q{
public:
  int pos;
  int life;
  int val;
  Q(int a,int b,int c):pos(a),life(b),val(c){}
  bool operator<(const Q& a)const{
    if(val!=a.val) return val>a.val;
    return life<a.life;
  }
};

int visit[N][N];

int solve(){
  rep(i,N)rep(j,N)visit[i][j]=0;
  //puts("hello");

  priority_queue<Q> que;
  que.push(Q(1,r,0));

  int ans = -1;
  while(!que.empty()){
    priority_queue<Q> cp = que;


    Q u = que.top();
    que.pop();

    //printf("@@ %d %d %d   %d\n",u.pos,u.life,u.val, que.size());

    if(visit[u.pos][u.life]==1)continue;
    visit[u.pos][u.life]=1;

    //printf("** %d %d %d\n",u.pos,u.life,u.val);

    if(u.pos==n){
      if(ans==-1 || ans>u.val)ans=u.val;
      return u.val;
    }

    rep(i,edge[u.pos].size()){
      E e = edge[u.pos][i];
      if(u.life-e.dist>=0)que.push(Q(e.to, u.life-e.dist, u.val));
      que.push(Q(e.to, u.life, u.val+e.value));
    }
  }
  return ans;
}

int main(){
  while(input())cout<<solve()<<endl;
}

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

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

int main() {
	int H, W, N;
	map<int, map<int, int>>mp;
	long long cnt[10] = {};
	cin >> H >> W >> N;
	cnt[0] = (long long)(H - 2) * (W - 2);
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		for (int j = 0; j < 9; j++) mp[a + dy[j]][b + dx[j]]++;
	}
	for (auto& rows : mp) {
		int y = rows.first;
		if (y < 2 || H - 1 < y) continue;
		for (auto& col : rows.second) {
			int x = col.first;
			if (x < 2 || W - 1 < x) continue;
			cnt[col.second]++;
			cnt[0]--;
		}
	}
	for (int i = 0; i < 10; i++) cout << cnt[i] << endl;
	
	return 0;
}

Measured memory_bytes: 70528
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main() {
  string s;
  cin >> s;
  for (int i = 0; 2 * i < s.size(); i++) {
    cout << s[2 * i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define float long double 

int32_t main()
{
  IOS;
  int n;
  cin>>n;
  int arr[n];
  for(int i=0; i<n; i++)
  {
    cin>>arr[i];
  }
  int freq[100006]={0};
  int s= 0 ;
  for(int i=0;i<n; i++)
  {
    freq[arr[i]]++;
    s+=arr[i];
  }

  int q;
  cin>>q;
  while(q--)
  {
    int a,b;
    cin>>a>>b;

    int no = freq[a];
    freq[a] = 0;
    s-=(a*no);
    s+=(no*b);
    freq[b]+=no;
    cout<<s<<endl;
  }
  return 0;
}

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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

int main(int argc, char const* argv[])
{
  int n;
  cin>>n;

  map<string,int> m;
  int max_count = 0;
  REP(i,n) {
    string s;
    cin>>s;
    m[s]++;
    if(max_count<m[s]) max_count = m[s];
  }

  vector<string> ans;
  for(auto p: m) {
    if(p.second==max_count) ans.push_back(p.first);
  }

  sort(ALL(ans));

  for(auto s: ans) {
    cout << s << endl;
  }

  return 0;
}

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

int main() {
	string s;
	cin >> s;
	
	rep(i, s.size()) cout << "x";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
namespace ABC173
{

  class C_HAndV
  {
  public:
    C_HAndV() = default;
    ~C_HAndV() = default;

    static constexpr int H_MAX = 6;
    static constexpr int W_MAX = 6;

    int H = {};
    int W = {};
    int K = {};
    std::string masu[H_MAX];

    void Run()
    {

      std::cin >> H;
      std::cin >> W;
      std::cin >> K;

      for (int i = 0; i < H; ++i)
      {
        std::cin >> masu[i];
      }

    
      int answer = 0;
      int hparam_max = 1;
      int wparam_max = 1;
      for (int i = 0; i < H; ++i) hparam_max *= 2;
      for (int i = 0; i < W; ++i) wparam_max *= 2;


      for (int i = 0; i < hparam_max; ++i)
      {
        for (int j = 0; j < wparam_max; ++j)
        {
          if (Solve(i, j)) answer++;
        }
      }

      std::cout << answer << std::endl;
    }

    bool Solve(int hparam, int wparam)
    {
      std::string m[H_MAX];
      for (int i = 0; i < H; ++i) m[i] = masu[i];

      for (int i = 0; i < H; ++i)
      {
        if ((hparam & (1 << i)) > 0)
        {
          for (int j = 0; j < W; ++j) m[i].at(j) = 'r';
        }
      }

      for (int i = 0; i < W; ++i)
      {
        if ((wparam & (1 << i)) > 0)
        {
          for (int j = 0; j < H; ++j) m[j].at(i) = 'r';
        }
      }

      int s_count = 0;
      for (int i = 0; i < H; ++i)
      {
        for (int j = 0; j < W; ++j)
        {
          if (m[i].at(j) == '#') s_count++;
        }
      }

      return s_count == K;
    }
  };

}

int main()
{

  ABC173::C_HAndV prob;
  prob.Run();

  return 0;
}



Measured memory_bytes: 3088
//#define DEBUG
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define MAX_T 202
#define MAX_N 100

int N;
int a[1000000];

int main() {
#ifdef DEBUG

#endif
	scanf("%d", &N);
	int i;
	for (i = 0; i < N; i++)scanf("%d", &a[i]);

	int max = 0;
	int tmp;
	int flag = 0;
	int idx;
	for (i = 0; i < N; i++) {
		tmp = abs(a[i]);
		if (max < tmp) {
			max = tmp;
			idx = i;
			if(a[i]>0) {
				flag = 1;
			}else{
				flag = -1;
			}
		}
	}
	int cnt=0;
	int ans[100][2];
	int ansIdx = 0;
	if (flag == 1) {
		for (i = 0; i < N; i++) {
			if (a[i] < 0) {
				a[i] += a[idx];
				ans[ansIdx][0] = idx + 1;
				ans[ansIdx++][1] = i + 1;
				cnt++;
			}
		}
		for (i = 0; i < N-1; i++) {
			if (a[i] > a[i + 1]) {
				a[i + 1] += a[i];
				ans[ansIdx][0] = i + 1;
				ans[ansIdx++][1] = i + 2;
				cnt++;
			}
		}
	}
	else{
		for (i = 0; i < N; i++) {
			if (a[i] > 0) {
				a[i] += a[idx];
				ans[ansIdx][0] = idx + 1;
				ans[ansIdx++][1] = i + 1;
				cnt++;
			}
		}
		for (i = N-1; i > 0; i--) {
			if (a[i] < a[i - 1]) {
				a[i - 1] += a[i];
				ans[ansIdx][0] = i+1;
				ans[ansIdx++][1] = i;
				cnt++;
			}
		}
	}

	printf("%d\n", cnt);
	for (i = 0; i < cnt; i++) {
		printf("%d %d\n", ans[i][0], ans[i][1]);
	}
}

Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<functional>
#include<math.h>
#include<algorithm>
typedef long long ll;
using namespace std;

#define divider 1000000007
string s;
map<char, ll> miria;
map<char, bool> rika;
vector<int> aho;

int main(){
  ll N;
  cin >> N;
  cin >> s;
  for(int i=0;i<N;i++){
    miria[s[i]]++;
    rika[s[i]]=false;
  }

  ll ans = 1;
  for(int i=0;i<N;i++){
    if(rika[s[i]]==false){
      aho.push_back(miria[s[i]]);
      rika[s[i]]=true;
    }
  }
  for(int i=0;i<aho.size();i++){
    ans = (ans*(aho[i]+1))%divider;
  }
  cout << (ans-1)%divider << endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
 #define all(v) (v).begin(),(v).end()
 using ll = long long;
using Graph = vector<vector<int>>;

int main(){
ll a;
  cin>>a;
  map<ll, ll>kuku;
  rep(i,10){
  rep(j,10){
  ll g=10*i+j;
    kuku[g]=0;
  
  }
  
  }
  for(ll i=1;i<=a;i++){
  ll x;
    ll k=i;
 x=k%10;   
    while(k>=10)
    {
    k=k/10;
    
    } 
    ll z=10*x+k;
  ll p=kuku[z];
    p++;
    kuku[z]=p;
  }

  ll ans=0;
    rep(i,10){
  for(ll j=0;j<10;j++){
  ll g=10*i+j;
ll h=10*j+i; 
  ans=ans+kuku[g]*kuku[h];
    
  }
  
  }
  cout<<ans;
  }
 





Measured memory_bytes: 384
import java.util.*;
     
    public class Main {
      public static void main(String[] args) {
     
        Scanner scan = new Scanner(System.in);
     
        String[] param = scan.nextLine().split(" ");
     
        long n = Long.parseLong(param[0]);
        long k = Long.parseLong(param[1]);
     
        ArrayList<Element> e = new ArrayList<Element>();
     
        for (int i = 0; i < n ; i++){
            String[] elem = scan.nextLine().split(" ");
            e.add(new Element(Long.parseLong(elem[0]), Long.parseLong(elem[1]) ) );
        }
     
        Collections.sort(e);
     
        long minNum = 0;
        long m = 0;
     
        for (Element el : e) {
            if (m < k && m + el.b >= k){
              minNum = el.a;
            }
            m += el.b;
        }
     
        System.out.println(minNum);
      }
     
    }
     
     class Element implements Comparable<Element> {
        public long a;
        public long b;
     
        public Element (long a, long b){
          this.a = a;
          this.b = b;
        }
     
        public int compareTo (Element e) {
          return this.a > e.a ? +1 : this.a < e.a ? -1 : 0;
        }
      }

Measured memory_bytes: 113872
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define rep(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)

using namespace std;
typedef long long int ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef priority_queue<int> PQI;
typedef priority_queue<int,vector<int>,greater<int> > PQSI;
typedef priority_queue<ll> PQL;
typedef priority_queue<ll,vector<ll>,greater<ll> > PQSL;

const int MOD = 1000000007;
struct mint { int n; mint(int n_ = 0) : n(n_) {} };
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};
void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

template<typename T>
T gcd(T x, T y){
    if (y == 0) return x;
    else return gcd(y, x % y);
}

template<typename T>
T lcm(T x, T y){
    return (x / gcd(x, y)) * y;
}

ll A, B;
int main(void){
    cin >> A >> B;
    if ((A+B)%2 != 0){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << (A+B) / 2 << endl;
    }

    return 0;
}



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

bool isprime (int x){
  if (x<=1) return 0;
  for (int i=2; i*i<=x; i++)
    if (x%i==0) return 0;
  return 1;
}

int main(){
  int x;
  cin>>x;
  while(1){
    if(isprime(x)){
      cout<<x<<endl;
      return 0;
    }
    x++;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def cmb(n, k, p):
    x, y = 1, 1
    for i in range(k):
        x = x * (n-i) % p
        y = y * (k-i) % p
    return x * pow(y, p-2, p) % p
def main():
    n, a, b = map(int, input().split())
    p = 10 ** 9 + 7
    ans = pow(2, n, p) - 1
    ans -= cmb(n, a, p) + cmb(n, b, p)
    print(ans%p)
if __name__ == "__main__":
    main()

Measured memory_bytes: 38640
A,B = map(int,input().split())
A,B = A-1,B-1
print(100,100)

for n in range(50):
  print(50*"."+50*"#")
  a = min(24,A)
  b = min(24,B)
  print(b*".#"+(50-2*b)*"."+a*"#."+(50-2*a)*"#")
  A-=a
  B-=b

Measured memory_bytes: 9136
<?php
  list($n,$a,$b) = explode(" ", trim(fgets(STDIN)));

  $ans=0;
  for ($i=1; $i<=$n; $i++) {
    $x=intdiv($i,10000);
    $x+=intdiv($i%10000,1000);
    $x+=intdiv($i%1000, 100);
    $x+=intdiv($i%100, 10);
    $x+=$i%10;
    
    if($a<=$x && $x<=$b){
//    echo $i." ".$x.PHP_EOL;
      $ans+=$i;
    }
  }

  echo $ans.PHP_EOL;
  

Measured memory_bytes: 16136
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

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

    sort(A.begin(),A.end(),greater<int>());

    long long ans = A[0];
    for (int i = 2; i < N; i++){
        ans += A[i/2];
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4044
N=int(input())
W=input().split()
W_lis=[int(s) for s in W]
aaa=1000000000
for i in range(len(W_lis)):
    a,b=0,0
    a=sum(W_lis[:i+1])
    b=sum(W_lis[i+1:])
    temp = abs(a-b)
    if temp < aaa:
        aaa=temp

print(aaa)

Measured memory_bytes: 3060
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


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

class BJudgeStatusSummary {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
	    in >> n;
        vector<string> s(n);
        map<string,int> m;
        rep(i,n){
            in >> s[i];
            m[s[i]]++;
        }
        vector<string> v = {"AC","WA","TLE","RE"};
        rep(i,4){
            out << v[i] << " x " << m[v[i]] << endl;
        }
	}
};


int main() {
	BJudgeStatusSummary solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 6392
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v):
    print(["Yes", "No"][not v])


# エントリーポイント
def main():
    N, A, B = input([int, 3])
    ans = 0
    ans += N // (A + B) * A
    temp = N % (A + B)
    ans += A if A <= temp else temp
    print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(ll i=0;i<(n);++i)
#define Fr(i,n) for(long long i=1;i<=(n);++i)
#define ifr(i,n) for(long long i=(n)-1;i>=0;--i)
#define iFr(i,n) for(long long i=(n);i>0;--i)

int main() {
  cin.tie(nullptr);
  ll n,a,b,c,ans;
  cin>>a>>b;
  string s;
  int arr[a+2][b+2]{};
  fr(i,a){cin>>s;
    fr(l,b){

    
    if(s[l]=='#'){
      arr[i+1][l+1]+=10;
      ++arr[i][l+1];
      ++arr[i+1][l];
      ++arr[i+2][l+1];
      ++arr[i+1][l+2];
      ++arr[i][l];
      ++arr[i][l+2];
      ++arr[i+2][l];
      ++arr[i+
      2][l+2];
      
    }
    }
  }
  fr(i,a){
    fr(l,b){
      if(arr[i+1][l+1]<9){cout<<arr[i+1][l+1];}
      else{cout<<"#";}
    }
    cout<<"\n";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main(){
	int n, p;
	while (1){
		cin >> n >> p;
		vi d(55);
		if (n == 0 && p == 0) break;
		int ans = 0, now = 0, np = p;
		for (int i = 0;; i++){
			if (np){
				d[now]++;
				np--;
				if (np == 0 && d[now] == p){
					ans = now; break;
				}
			}
			else{
				np = d[now];
				d[now] = 0;
			}
			now++;
			if (now == n) now = 0;
		}
		o(ans);
	}
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define UNIQUE(c) sort(ALL(c)), c.erase(unique(ALL(c)), c.end())

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  vector<int> A(3), B(3);
  REP(i, 3) cin >> A[i];
  REP(i, 3) cin >> B[i];

  vector<int> dp(N+1);
  REP(i, 3) {
    if (B[i] - A[i] <= 0) continue;
    REP(w, N+1) {
      if (w >= A[i]) {
        dp[w] = max(dp[w], dp[w-A[i]] + B[i] - A[i]);
      }
    }
  }

  int M = *max_element(ALL(dp)) + N;
  vector<ll> dp2(M+1);
  REP(i, 3) {
    if (A[i] - B[i] <= 0) continue;
    REP(w, M+1) {
      if (w >= B[i]) {
        dp2[w] = max(dp2[w], dp2[w-B[i]] + A[i] - B[i]);
      }
    }
  }

  cout << *max_element(ALL(dp2)) + M << endl;

  return 0;
}


Measured memory_bytes: 195584
#include <stdio.h>

#define INFTY 1000000001

void merge(int *,int,int,int);

void mergesort(int *,int,int);

int Count;

int main()
{
  int n,i;

  scanf("%d",&n);

  int A[n];

  for(i=0;i<n;i++)scanf("%d",&A[i]);

  mergesort(A,0,n);

  for(i=0;i<n-1;i++)printf("%d ",A[i]);
  printf("%d\n%d\n",A[n-1],Count);
  return 0;
}

void mergesort(int *A,int L,int R)
{
  int M;
  
  if(L+1<R)
    {
      M=(L+R)/2;
      mergesort(A,L,M);
      mergesort(A,M,R);
      merge(A,L,M,R);
    }
}

void merge(int *A,int L,int M,int R)
{
  int n1,n2,i,j,k;

  n1=M-L;
  n2=R-M;

  int l[n1+1],r[n2+1];

  for(i=0;i<n1;i++) l[i]=A[L+i];
  for(i=0;i<n2;i++) r[i]=A[M+i];

  l[n1]=INFTY;
  r[n2]=INFTY;

  i=0;
  j=0;

  for(k=L;k<R;k++)
    {
      if(l[i]<=r[j])
	{
	  A[k]=l[i];
	  i=i+1;
	}
      else
	{
	  A[k]=r[j];
	  j=j+1;
	}
      Count++;
    }
}



Measured memory_bytes: 5612
S = input()

flag = 1
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] != "R" and S[i] != "U" and S[i] != "D":
            flag = 0
    else:
        if S[i] != "L" and S[i] != "U" and S[i] != "D":
            flag = 0
    if flag == 0:
        break
if flag == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef queue<P> Q;

#define _CRT_SECURE_NO_WARNINGS

int N = 0;
char s[1000][1051];
int main() {
	while (scanf("%d", &N), N != 0) {
		int start[1051] = {};
		for (int i = 0; i<N; i++) {
			scanf("%s", s[i]);
			if (s[i][0] == '.') {
				for (int j = 0; j<1050; j++) {
					if (s[i][j + 1] != '.') {
						s[i][j] = '+';
						if (start[j] != 0) {
							for (int k = start[j]+1; k < i;k++) {
								s[k][j] = '|';
							}
							
						}
						start[j] = i;
						for (int k = j+1; k < 1000; k++) {
							start[k] = 0;
						}
						break;
					}
					else {
						s[i][j] = ' ';
					}
				}
			}
		}
		for (int i = 0; i < N; i++) {
			printf("%s\n", s[i]);
		}
	}
	return 0;
}





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

#define ll long long

const int mxN=50, M=1e9+7;
int n;
ll a[16][16], d1[1<<16], d2[1<<16];

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

	cin >> n;
	for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
			cin >> a[i][j];
	for(int i=0; i<1<<n; ++i)
		for(int j=0; j<n; ++j)
			if(i>>j&1)
				for(int k=j+1; k<n; ++k)
					if(i>>k&1)
						d1[i]+=a[j][k];
	for(int i=0; i<1<<n; ++i)
		for(int j=i; j; j=(j-1)&i)
			d2[i]=max(d2[i], d2[i^j]+d1[j]);
	cout << d2[(1<<n)-1];
}


Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>

using namespace std;

int main() {
	vector<int>x, y;
	int n, m, xx, yy, i, j;

	cin >> n >> m >> xx >> yy;

	for (i = 0; i < n; i++) {
		cin >> j;
		x.push_back(j);
	}
	for (i = 0; i < m; i++) {
		cin >> j;
		y.push_back(j);
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());

	i = x[n - 1];
	j = y[0];

	if (xx > yy) {
		cout << "War";
		return 0;
	}

	if (i < j && i<yy && j>xx)
		cout << "No War";
	else
		cout << "War";

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
    int main()
    {
        int A,B;
        scanf("%d",&A);
        scanf("%d",&B);

        if ((A==2&&B==3)||(A==3&&B==2))
            printf("1\n");
        else if ((A==1&&B==2)||(A==2&&B==1))
            printf("3\n");
        else printf("2\n");


        return 0;
    }

Measured memory_bytes: 128
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<vector>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define pb push_back

using namespace std;
typedef long long LL;
const int N=100005;
int n,m,t1[N],t2[N],tot;
vector <int> vt[N];

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;	
	return x;
}

void ins(int t[],int x)
{
	for(int i=x+1; i<=m+1; i+=i&-i) ++t[i];
}

int query(int t[],int x)
{
	if(x<0) return 0;
	int rt=0;
	for(int i=x+1; i; i-=i&-i) rt+=t[i];
	return rt;
}

int query(int t[],int l,int r)
{
	r=min(r,m);
	return query(t,r)-query(t,l-1);
}

int solve(int p)
{
	LL ans=0;
	int sz=vt[p].size();
	rep(i,0,sz-1) ins(t1,vt[p][i]),ins(t2,vt[p][i]+p-1),++tot;
	rep(i,0,m/p)
	{
		int l=i*p,r=(i+1)*p-1;
		ans+=(LL)(query(t2,l,r)-query(t1,l,r))*i;
	}
	return ans+n-tot;
}

int main()
{
	n=getint(),m=getint();
	rep(i,1,n)
	{
		int l=getint(),r=getint();
		vt[r-l+2].pb(l-1);
	}
	rep(i,1,m) printf("%d\n",solve(i));
	return 0;
}

Measured memory_bytes: 7168
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define PI          3.14159265358979323846
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ld          long double
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
const ll M = 1e9 + 7;
ll dp[N];
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int x;
        cin >> x;
        dp[x] = -1;
    }
    dp[0] = 1;
    if(dp[1] != -1){
        dp[1] = 1;
    }
    for(int i = 2; i <= n; i++){
        if(dp[i] == -1) continue;
        else if(dp[i - 1] == -1 && dp[i - 2] == -1){
            continue;
        }else if(dp[i - 1] == -1){
            dp[i] += dp[i - 2];
        }else if(dp[i - 2] == -1){
            dp[i] += dp[i - 1];
        }else{
            dp[i] = dp[i - 1] + dp[i - 2];
        }
        if(dp[i] >= M){
            dp[i] -= M;
        }
    }
    cout << dp[n];
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<string, int> m1, m2;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        m1[s]++;
    }

    int m;
    cin >> m;
    for (int i = 0; i < m; i++) {
        string t;
        cin >> t;
        m2[t]++;
    }

    int ans = 0;
    for (auto& p : m1) {
        ans = max(ans, p.second - m2[p.first]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt(),k=sc.nextInt();
    int m=-1;
    for(int i=0;i<n;i++)if(sc.nextInt()==1)m=i;
    System.out.println((n-2)/(k-1)+1);
  }
}

Measured memory_bytes: 48640
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int[] h=new int[n];
    for(int i=0;i<n;i++){
      h[i]=sc.nextInt();
    }
    Arrays.sort(h);
    long ans=0;
    for(int i=0;i<n-k;i++){
      ans+=h[i];
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 64672
S = str(input())

T = len(S)
K = T//5+1

for i in range (0, K+1):
	T = len(S)
	if S[-5::] == 'dream':
		S = S[0:T-5]
	elif S[-5::] == 'erase':
		S = S[0:T-5]
	elif S[-7::] == 'dreamer':
		S = S[0:T-7]
	elif S[-6::] == 'eraser':
		S = S[0:T-6]

if len(S) == 0:
	print('YES')
else:
	print('NO')

Measured memory_bytes: 8976
#include <algorithm>
#include <array>
#include <assert.h>
#include <chrono>
#include <bitset>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <random>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;

typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<ld>> vvld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<pll> vpll;

#ifdef OLBOEB
mt19937 rnd(228 + 1488 + 239 + 24111997 % 322 + std::hash<std::string>()("Tsypkokokokoko is gay"));
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

void print_time() {
#ifdef OLBOEB
  cout.flush();
  cerr << "\ntime: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}


#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sz(x) ((ll)(x).size())
#define popcnt(x) (__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

template <typename T>
void update_max(T& x, T y) { x = max(x, y); }
template <typename T>
void update_min(T& x, T y) { x = min(x, y); }
template <typename T>
T min(T x, T y, T z) { return min(x, min(y, z)); }
template <typename T>
T max(T x, T y, T z) { return max(x, max(y, z)); }

ll get_bit(ll m, ll i) {
  return (m >> i) & 1;
}

void set_bit(ll& m, ll i) {
  m |= (1LL << i);
}

template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
template<class L, class R> ostream& operator<<(ostream& out, map<L, R> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }


pll get(ll x) {
  ll y = x;
  while (y > 9) {
    y /= 10;
  }
  return {x % 10, y};
}


int main() {
  cout << fixed << setprecision(20);
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  ll n;
  cin >> n;

  map<pll, ll> cnt;
  for (ll i = 1; i <= n; ++i) {
    ++cnt[get(i)];
  }

  ll ans = 0;
  for (auto& x : cnt) {
    pll p = x.fi;
    ll c = x.se;
    ans += c * (cnt[{p.se, p.fi}]);
  }
  cout << ans;

  print_time();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

int main(){
    ll n;
    cin>>n;
    int maxi = 0;
    rep(i,n) {
        int h;
        cin >> h;
        if(h >= maxi) maxi = h;
        else if(h < maxi-1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

int main(){
	string a, b;
	cin >> a >> b;
	bool flag = true;
	if(a.size() + 1 == b.size()){
		for(int i = 0; i < a.size(); i++){
			if(a[i] != b[i]){
				flag = false;
				break;
			}
		}
	}
	else{
		flag = false;
	}
	if(flag){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
} 

Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		long max = Integer.MIN_VALUE;
		long min = Integer.MAX_VALUE;
		long sum = 0;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(br.readLine());
		String[] inputArray = br.readLine().split(" ");

		long input = 0;
		for (int i=0; i<N; i++) {
			input = Long.parseLong(inputArray[i]);
			if (max < input) {
				max = input;
			}

			if (min > input) {
				min = input;
			}

			sum += input;
		}

		System.out.println(min +" "+ max +" "+ sum);
	}
}

Measured memory_bytes: 28440
N=int(input())
A=[]
for _ in range(N):
  A.append(int(input()))
  
B=sorted(A)
M1=B[-1]
M2=B[-2]

if B.count(M1)>1:
    for i in range(N):
        print(M1)
else:
    for i in range(N):
        if A[i] == M1:
            print(M2)
        else:
            print(M1)

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN =2e5 + 5;

set<int> vals[MAXN];

void solve(){
	int h, w, n;
	scanf("%d%d%d", &h, &w, &n);
	REP(i, 0, n) {
		int a, b;
		scanf("%d%d", &a, &b);
		vals[a].insert(b);
	}
	int l = 1, r = 1;
	REPN(i, 2, h) {
		int cur = w + 1;
		if (vals[i].lower_bound(l) != vals[i].end()) {
			cur = *vals[i].lower_bound(l);
		}
		if (cur <= r) {
			printf("%d\n", i - 1);
			return;
		}
		if (cur != r + 1) {
			r++;
		}
	}
	printf("%d\n", h);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

int x, y;

void cmp(int a, int b){
    if(a < b){
        int z = a;
        a = b;
        b = z;
    }
}

int main(){
    int r=1;

    cin >> x >> y;
    cmp(x, y);

    while(r!=0){
        r = x % y;
        x = y;
        y = r;
    }

    cout << x << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <vector>
#include <stack>

using namespace std;

template <typename C>
void PrintAll(const C& c) {
    for(auto it = c.cbegin(); it != c.cend();) {
        cout << *it++;
        if(it != c.cend()) {
            cout << ' ';
        }
    }
}

int main() {
    string str;
    cin >> str;

    //?¨????????????°?????°??????

    stack<int> s1;
    stack<pair<int, int>> s2 {};
    int sum {};

    //for(int i = 0; i < str.size(); ++i) {
    //    if(str[i] == '\\') {
    //        s1.push(i);
    //    }
    //    else if(str[i] == '/' && s1.size() > 0) {
    //        int j = s1.top();
    //        s1.pop();
    //        sum += i - j;
    //        int current = i - j;
    //        while(s2.size() > 0 && s2.top().first > j) {
    //            current += s2.top().second;
    //            s2.pop();
    //        }
    //        s2.push(make_pair(j, current));
    //    }
    //}

    for(int i = str.size() - 1; i >= 0; --i) {
        if(str[i] == '/') {
            s1.push(i);
        }
        else if(str[i] == '\\' && s1.size() > 0){
            int j = s1.top();
            s1.pop();
            sum += j - i;
            int current = j - i;
            while(s2.size() > 0 && s2.top().first < j) {
                current += s2.top().second;
                s2.pop();
            }
            s2.push(make_pair(j, current));
        }
    }

    vector<int> v;
    int num {};

    while(s2.size() > 0) {
        v.emplace_back(s2.top().second);
        s2.pop();
        ++num;
    }

    cout << sum << '\n' << num << (v.size() != 0 ? " " : "");
    PrintAll(v);
    cout << endl;
    
    return 0;
} 

Measured memory_bytes: 3300
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<deque>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define MAX 100

int n, s[MAX] = {}, d[MAX], f[MAX], t = 0;
bool M[MAX][MAX] = {};

void dfs(int u) {
	int v;
	s[u] = 1;
	d[u] = ++t;
	for (int v = 0; v < n; v++) {
		if (M[u][v] == false)continue;
		if (s[v] == 0) {
			dfs(v);
		}
	}
	s[u] = 2;
	f[u] = ++t;
}

int main() {
	cin >> n;

	for (int i = 0; i < n; i++) {
		int u, k; cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++) {
			int v; cin >> v;
			v--;
			M[u][v] = true;
		}
	}

	for (int u = 0; u < n; u++) {
		if (s[u] == 0)dfs(u);
	}
	for (int u = 0; u < n; u++) {
		printf("%d %d %d\n", u + 1, d[u], f[u]);
	}
	return 0;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.LoopSimulation
{
    class ABC_060_B
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);

            for (int i = 0; i < b; i++)
            {
                if ((a * i) % b == c)
                {
                    Console.WriteLine("YES");
                    return;
                }
            }
            Console.WriteLine("NO");
        }
    }
}

Measured memory_bytes: 11092
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

nlist = list(range(1, n+1))
nmlist = []

for val in itertools.permutations(nlist, n):
    nmlist.append(val)

print(abs(nmlist.index(p)-nmlist.index(q)))

Measured memory_bytes: 8052
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <unordered_map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

//#include<bits/stdc++.h>

#define lli long long int
#define mp make_pair
#define pb push_back
using namespace std;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<lli> vli;

//static bool comp(){
//    if(){
//        return true;
//    }
//    return false;
//}


void solve(){
    lli a, b, c, k;
    cin >> a >> b >> c >> k;
    
    lli sum = 0;
    if(k >= a){
        k = k - a;
        sum += a;
    }
    else{
        cout<<k;
        return;
    }

    if(k >= b){
        k = k - b;
        
    }
    else{
        cout<<sum;
        return;
    }

    if(k >= c){
        k = k - c;
        sum -= c;
    }
    else{
        cout<< sum - k;
        return;
    }

    cout<< sum;

}


int main(){
    
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif


    int t = 1;
    while(t--){
        solve();
        cout<<endl;
    }

}

Measured memory_bytes: 3628
n,k=map(int,input().split())
p=list(map(int,input().split()))
for i in range(n):
    p[i]=(p[i]+1)/2
q=[0]*(n-k+1)
q[0]=sum(p[0:k])
for i in range(1,n-k+1):
    q[i]=q[i-1]-p[i-1]+p[k+i-1]
print(max(q))

Measured memory_bytes: 98956
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

using Edge = pair<ll, ll>;
using Graph = vector<vector<Edge> >;

Graph G;
vector<ll> res;

// v を c で塗る。pはvの親
void dfs(ll v, ll p, ll c)
{
    res[v] = c;
    for (auto e : G[v])
    {
        if(e.first==p)
            continue;
        if (e.second & 1)
            dfs(e.first, v, 1 - c);
        else
            dfs(e.first, v, c);
    }
}

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    G.assign(n, vector<Edge>());
    for (ll i = 0; i < n - 1; i++)
    {
        ll u, v, w;
        cin >> u >> v >> w;
        --u;
        --v;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }
    res.assign(n, 0);
    dfs(0, -1, 1);
    for (auto v : res)
        cout << v << endl;
}

Measured memory_bytes: 10752
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int total = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int ashikiri = a + b;
        String s = sc.next();
        char list[] = s.toCharArray();
        int total_pass = 0;
        int foreigner_rank = 0;
        for (int i = 0; i < total; i++) {
            if (list[i] == 'a') {
                if (total_pass < ashikiri) {
                    total_pass++;
                    System.out.println("Yes");
                } else {
                    System.out.println("No");
                }
            } else if (list[i] == 'b') {
                foreigner_rank++;
                if ((total_pass < ashikiri) && (foreigner_rank <= b)) {
                    total_pass++;
                    System.out.println("Yes");
                } else {
                    System.out.println("No");
                }
            } else {
                System.out.println("No");
            }
        }
        sc.close();
    }

}

Measured memory_bytes: 50016
#include "bits/stdc++.h"
using namespace std;


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

	int min_health = 1000000;
	for (int point = 1; point <= 100; point++) {
		int sum = 0;
		for (int i = 0; i < n; i++) {
			sum += pow((x.at(i) - point), 2);
		}
		min_health = min(min_health, sum);
	}

	cout << min_health << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pr(x) cerr<<#x<<"="<<(x)<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (ll ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define inf 1000000000000ll
#define N 1000100
#include<queue>
ll n,a[N],b[N],dis,ans;
int main()
{
	scanf("%lld",&n);
	ll f=1,minn=inf;
	for (ll i=1;i<=n;i++)
	{
		scanf("%lld %lld",&a[i],&b[i]);ans+=a[i];
		if (a[i]!=b[i]) f=0;
		if (a[i]<=b[i]) {a[i]=0,b[i]-=a[i];}
		if (a[i]>b[i]) minn=min(minn,b[i]);
	}
	if (f) {printf("0\n");return 0;}
	printf("%lld\n",ans-minn);
}

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

#define READ                freopen("in.txt", "r", stdin)
#define WRITE               freopen("out.txt", "w", stdout)

#define si(a)               scanf("%d", &a)
#define sii(a,b)            scanf("%d %d", &a, &b)
#define siii(a,b,c)         scanf("%d %d %d", &a, &b, &c)

#define CLR(a)              memset(a, 0, sizeof(a))
#define SET(a)              memset(a, -1, sizeof(a))

#define PI                  acos(-1.0)

#define pb                  push_back
#define mp                  make_pair
#define SORT(v)             sort(v.begin(), v.end())
#define REV(v)              reverse(v.begin(), v.end())
#define FOR(i, n)           for(int i=0; i<n; i++)
#define FOR1(i, n)          for(int i=1; i<=n; i++)
#define ROF(i, n)           for(int i=n-1; i>=0; i--)
#define ROF1(i, n)          for(int i=n; i>=1; i--)
#define LOOP(i, x, y)       for(int i=x; i<=y; i++)
#define fastIO()            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


typedef long long              LL;
typedef unsigned long long     ULL;
typedef vector<int>            VI;
typedef pair<int, int>         PII;
typedef pair<string, int>      PSI;
typedef pair<char, int>        PCI;

const int MAX = 100005;
const LL LMAX = 12158598925;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;

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

int dp[MAX], arr[MAX];


int main()
{
//    READ;
//    WRITE;

    int n; si(n);
    FOR1(i, n) si(arr[i]);

    dp[1] = 0;
    dp[2] = abs(arr[2] - arr[1]);

    for(int i=3; i<=n; i++){
        int p = abs(arr[i] - arr[i-1]) + dp[i-1];
        int q = abs(arr[i] - arr[i-2]) + dp[i-2];
        dp[i] = min(p, q);
    }

    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1024