akhauriyash/Code-Regression huggingface dataset:
#include<queue>
#include<cstdio>
#include<vector>

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

using namespace std;

const int INF=1<<29;

template<class T>
struct AdjMatrix:public vector< vector<T> >{
	AdjMatrix(int n,const vector<T> &v=vector<T>()):vector< vector<T> >(n,v){}
};

template<class T>
T augment(const AdjMatrix<T> &capa,int src,int snk,AdjMatrix<T> &flow){
	int n=capa.size();
	vector<int> parent(n,-1); parent[src]=-2;

	T water=0;
	queue< pair<T,int> > qu; qu.push(make_pair(INF,src));
	while(!qu.empty()){
		pair<T,int> a=qu.front(); qu.pop();
		int u=a.second;
		T w=a.first;
		if(u==snk){ water=w; break; }
		rep(v,n) if(parent[v]==-1 && capa[u][v]-flow[u][v]>0) {
			qu.push(make_pair(min(w,capa[u][v]-flow[u][v]),v));
			parent[v]=u;
		}
	}

	if(water==0) return 0;

	for(int v=snk,u=parent[snk];v!=src;v=u,u=parent[u]){
		flow[u][v]+=water;
		flow[v][u]-=water;
	}

	return water;
}

template<class T>
T FordFulkerson(const AdjMatrix<T> &capa,int src,int snk,AdjMatrix<T> &flow){
	int n=capa.size();

	T ans=0;
	while(1){
		T water=augment(capa,src,snk,flow);
		if(water==0) break;
		// if(water<EPS) break;
		ans+=water;
	}
	return ans;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	static pair<bool,int> adj[300][300];
	AdjMatrix<int> capa(n,vector<int>(n));
	rep(i,m){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		adj[u][v]=make_pair(true,i);
		capa[u][v]=capa[v][u]=1;
	}
	int s,t; scanf("%d%d",&s,&t); s--; t--;

	int cnt=0;
	AdjMatrix<int> flow(n,vector<int>(n));
	int amount=FordFulkerson(capa,s,t,flow);
	rep(u,n) rep(v,n) {
		if(adj[u][v].first && flow[v][u]>0) cnt++;
	}
	printf("%d\n%d\n",amount,cnt);
	rep(u,n) rep(v,n) {
		if(adj[u][v].first && flow[v][u]>0) printf("%d\n",adj[u][v].second+1);
	}

	return 0;
}

Measured memory_bytes: 0
#![allow(unused_imports)]
use std::cmp;
use std::collections::*;
use std::io::*;
use std::mem::swap;
#[allow(dead_code)]
struct Io<'a> {
    r: BufReader<StdinLock<'a>>,
    w: BufWriter<StdoutLock<'a>>,
    buf: VecDeque<String>,
    buf_str: String,
}
#[allow(dead_code)]
impl<'a> Io<'a> {
    fn r<T: std::str::FromStr>(&mut self) -> T {
        if self.buf.len() == 0 {
            self.r.read_line(&mut self.buf_str).unwrap();
            for w in self.buf_str.split_whitespace() {
                self.buf.push_back(w.to_owned());
            }
            self.buf_str.clear();
        }
        self.buf
            .pop_front()
            .unwrap()
            .parse()
            .unwrap_or_else(|_| panic!())
    }
    fn r_s(&mut self) -> String {
        if self.buf.len() == 0 {
            self.r.read_line(&mut self.buf_str).unwrap();
            for w in self.buf_str.split_whitespace() {
                self.buf.push_back(w.to_owned());
            }
            self.buf_str.clear();
        }
        self.buf.pop_front().unwrap()
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        write!(self.w, "{}", v).unwrap();
    }
    fn wl<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.w, "{}", v).unwrap();
    }
    fn iter<'b, T: std::str::FromStr>(&'b mut self) -> IoIter<'a, 'b, T> {
        IoIter {
            io: self,
            p: std::marker::PhantomData,
        }
    }
}
#[allow(dead_code)]
struct IoIter<'a: 'b, 'b, T: std::str::FromStr> {
    io: &'b mut Io<'a>,
    p: std::marker::PhantomData<T>,
}
#[allow(dead_code)]
impl<'a, 'b, T: std::str::FromStr> Iterator for IoIter<'a, 'b, T> {
    type Item = T;
    fn next(&mut self) -> Option<T> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let r = BufReader::new(stdin.lock());
    let w = BufWriter::new(stdout.lock());
    let io = Io {
        r,
        w,
        buf: VecDeque::new(),
        buf_str: String::new(),
    };
    unsafe {
        problem(io);
    }
}

unsafe fn problem(mut io: Io) {
    let n: usize = io.r();
    let s: Vec<usize> = io.iter().take(n).collect();
    let q: usize = io.r();
    let t: Vec<usize> = io.iter().take(q).collect();

    let mut count = 0;
    'a: for ti in t {
        let mut start = 0;
        let mut end = s.len();

        while start != end {
            let mid = (start + end) / 2;
            if s[mid] == ti {
                count += 1;
                continue 'a;
            } else if s[mid] > ti {
                end = mid;
            } else {
                start = mid + 1;
            }
        }
    }
    io.wl(count);
}



Measured memory_bytes: 11060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int N = 5e5+5;
const dd eps = 1e-5;
const ll mod = 1e9+7;

int a,b,c;

int main(){
  // freopen("input.txt","r",stdin);
  cin>>a>>b>>c;  
  if(a == b && b == c && a == c) cout<<"No"<<endl;
  else if(a != b && b != c && a != c) cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}


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

const int N = 4e5;

int n, sf[N], pr[N];

main() {
    string s;
    cin >> n;
    cin >> s;
    s = ' ' + s;
    rep(i, 1, n + 1) pr[i] = pr[i - 1] + (s[i] == 'W');
    for (int i = n; i > 0; --i) sf[i] = sf[i + 1] + (s[i] == 'E');
    int mn = N;
    rep(i, 1, n + 1) {
        mn = min(mn, pr[i - 1] + sf[i + 1]);
    }
    cout << mn << '\n';
}

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

int main()
{
    int h,n;
    cin >> h >> n;
    
    int a[n] = {};
    int b[n] = {};
    int ma = 0;
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
        ma = max(ma,a[i]);
    }
    
    int h2 = h+ma;
    vector<int> dp(h2+1, 1e9);
    dp[0] = 0;
    for(int i=0; i<n; i++){
        int k = h2/a[i];
        for(int j =1; j<=k; j++){
            dp[j*a[i]] = min(dp[(j-1)*a[i]] + b[i], dp[j*a[i]]);
        }
        for(int w=0; w<=h2; w++){
            if(w >= a[i]){
                dp[w] = min(dp[w-a[i]] + b[i], dp[w]);
            }
            //cout << i << " ," << w << " : "<< dp[w]<<endl;
        }
    }
    auto ans = min_element(&dp[h], &dp[h2]);
    cout << *ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
using namespace std;
 
signed main() {
  int N;
  cin >> N;
  
  vector<int> X(N);
  vector<int> Y(N);
  vector<int> H(N);
  for( int i = 0; i < N; i++ ) cin >> X.at(i) >> Y.at(i) >> H.at(i);
  
  for( int i = 0; i <= 100; i++ ){
    for( int j = 0; j <= 100; j++ ){
      int zanteiH = -1;
      for( int k = 0; k < N; k++ ){
        if( H.at(k) > 0 ){ //ピラミッド内部のとき
          int tmp = H.at(k) + abs(j-Y.at(k)) + abs(i-X.at(k));
          if( zanteiH == -1 ) zanteiH = tmp;
          else if( zanteiH != -1 && zanteiH != tmp ) zanteiH = -2;
        }
      }
      if( zanteiH == -2 ) continue;
      
      //h.at(k)が0のときについて
      for( int k = 0; k < N; k++ ){
        int dist = abs(j-Y.at(k)) + abs(i-X.at(k));
        if( H.at(k) == 0 && zanteiH > dist ){
          zanteiH = -2;
          break;
        }
      }
      if( zanteiH == -2 ) continue;
      cout << i << " " << j << " " << zanteiH << endl;
    }
  }
}

Measured memory_bytes: 256
K, N = gets.split.map(&:to_i)
a = []
a = gets.split.map(&:to_i)

dist = []
(N-1).times do |i|
  # dist[i] : a[i+1]とa[i]との距離
  dist[i] = a[i+1] - a[i]
end
dist[N-1] = a[0]+K - a[N-1]
# puts "#{dist}"

puts K - dist.max

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

#define REP(i,n)    for(int i = 0; i < (int)n; i++)
#define MAX_N   100000
#define MAX_M   100000

int x;
void solve(){
    int cnt = x / 100;
    x -= cnt * 100;
    if(x <= 5 * cnt)
        cout << 1 << endl;
    else
        cout << 0 << endl;
}

int main(){
    cin >> x;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<set>
#include<list>
#include<queue>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    int x,a;
    cin>>x>>a;
    if(x<a) cout<<0;
    if(x>=a) cout<<10;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(0);

int main()
{
  Hello;
  
  long long int a, b, c=0, d;
  cin>>a>>b;
  
  for(int i=0; i<b; i++)
  {
    cin>>d;
    c+=d;
  }
  
  if(c>=a)  cout<<"Yes";
  else  cout<<"No";
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <stack>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;

void printarray(int n, int a[])
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i];
        if (i != n - 1)
            cout << " ";
    }
    cout << endl;
}

void printpairaraay(int n, pair<int,int> a[])
{
    int x, y;
    for (int i = 0; i < n; i++)
    {
        x = a[i].first;
        y = a[i].second;
        cout << x << " " << y << "\n";
    }
}
void swaprange(int b, int t, int e, int a[])
{
    for (int i = 0; i < e - b; i++)
    {
        swap(a[b + i], a[i + t]);
    }
}

int main()
{
    int n, x, y;
  	cin >> n;
    pair<int,int> a[n];
    for (int i = 0; i < n; i++){
        cin >> x >> y;
        a[i] = make_pair(x,y);
    }
    sort(a,a+n);
    printpairaraay(n,a);
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3904
# -*- coding: utf-8 -*-

def ans() :
    n, k, q  = map(int, input().split())
    ans = [k - q for i in range(n)]
    for i in range(q) :
        a = int(input())
        ans[a - 1] += 1

    for i in range(n):
        if ans[i] > 0:
            print("Yes")
        else:
            print("No")

if __name__ == '__main__':
    ans()

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

int main(){
    int x, y, A;
    cin >> x >> y;

    A = x*2 - y/2;

    if(y%2 == 1){
        cout << "No" << endl;
    }
    else if(0 <= A and A <= x){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

}


Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif
#define FILE_IO freopen("input.txt","r",stdin);
#define f first
#define int long long
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
void solve(){
   int k,a,b;
   cin>>k>>a>>b;
   if(abs(a-k)<abs(k-b))cout<<"A";
   else cout<<"B";
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
    IOS;
    solve();
    #ifdef LOCAL_DEFINE
    cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
    #endif
}


Measured memory_bytes: 256
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int sum=0;
int main(){
    int n,m,a[1005];
    int u,q;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    cin>>m;
    while(m--){
        cin>>u>>q;
        cout<<sum-a[u]+q<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
from itertools import permutations

n=int(input())
plst=list(map(int,input().split()))
qlst=list(map(int,input().split()))

token=0
for x in permutations(range(1,n+1)):
    if list(x)==plst : p=token
    if list(x)==qlst : q=token
    token+=1
print(abs(p-q))

Measured memory_bytes: 9188
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
    float n;
   long long int i;
    //double n,i,j,k,sum=0;
    double ans;
//    string s;
//    getline(cin,s);
    cin>>n;
        i=n/2;
        ans=(n-i)/n;

    printf("%.10f",ans);
    return 0;
}


Measured memory_bytes: 384
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

	private void solve() {
		// 入力
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Set<Integer> d = new HashSet<Integer>();
		for (int i = 0; i < N; i++) {
			d.add(sc.nextInt());
		}
		sc.close();

		// 出力
		System.out.println(d.size());

		return;
	}
}

Measured memory_bytes: 22612
X, N = map(int, input().split())
if N == 0:
  print(X)
  exit()
P = list(map(int, input().split()))
 
for i in range(X+1):
  for d in [-1, +1]:
    if not (X+i*d) in P:
      print(X + i*d)
      exit()


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

int main() {
    string s;
    cin >> s;
    int len = s.size();
    for (int i = len - 2; i >= 0; i -= 2) {
        if (s.substr(0, i / 2) == s.substr(i / 2, i / 2)) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define INF 100000000
using namespace std;
const int mod = 1000000007;

int main() {

  int N,K,cnt=0;
  cin>>N>>K;
  while(true){
   N/=K;//cout<<N<<endl;
    cnt++;
    if(N<1)break;
  }
  //vector<int> A(N);
  //for(int i=0; i<N; i++){cin>>A[i];}
  //vector<vector<int>> A(N,vector<int>(M));
  //for(int i=0; i<N; i++){for(int j=0; j<M; j++){cin>>A[i][j];}}
  //sort(A.begin(),A.end());
  //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
  //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<queue>
#include<vector>
using namespace std;
#define maxn 10000
vector<int> G[maxn+10],ans;
queue<int> q;
int biao[maxn+10];
int color[maxn+10];
void bfs(int s)
{
    q.push(s);
    color[s]=true;
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        ans.push_back(u);
        for (int i=0;i<G[u].size();i++)
        {
            int v=G[u][i];
            biao[v]--;
            if(!color[v]&&biao[v]==0)
            {
                color[v]=true;
                q.push(v);
            }
        }
    }
}
int main()
{
    int u,v;
    scanf("%d%d",&u,&v);
    int x,y;
    for (int i=0;i<v;i++)
    {
        scanf("%d%d",&x,&y);
        G[x].push_back(y);
    }
    for(int i=0;i<u;i++)
    {
        for (int j=0;j<G[i].size();j++)
            biao[G[i][j]]++;
    }
    for (int i=0;i<u;i++)
    {
        if(biao[i]==0&&!color[i])
            bfs(i);
    }
    for (int i=0;i<ans.size();i++)
        printf("%d\n",ans[i]);
    return 0;
}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);


int main(void)
{
    ll n,ans;
    string s,t;
    cin>>n>>s>>t;
    ans=n;
    rep(i,n){
        if(s.substr(i) == t.substr(0,n-i)) break;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(L[int(input())-1])

Measured memory_bytes: 9192
#include<stdio.h>
#define N 100
#define W 0
#define G 1
#define B 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u){
  int v;
  color[u] = G;
  d[u] = ++tt;
  for(v=0; v<n; v++){
    if(M[u][v] == 0) continue;
    if(color[v] == W){
      dfs_visit(v);
    }
  }
  color[u] = B;
  f[u] = ++tt;
}

void dfs(){
  int u;
  for(u=0; u<n; u++) color[u] = W;
  tt = 0;

  for(u=0; u<n; u++){
    if(color[u] == W) dfs_visit(u);
  }
  for(u=0; u<n; u++){
    printf("%d %d %d\n",u+1, d[u], f[u]);
  }
}

int main(){
  int u, v, k, i, j;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++) M[i][j]=0;
  }

  for(i=0; i<n; i++){
    scanf("%d%d",&u, &k);
    u--;
    for(j=0; j<k; j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  dfs();

  return 0;
}

Measured memory_bytes: 636
#include <iostream>
typedef long long ll;
#include <cmath>

int main() {
  int n,i,ans;
  int b[100];
  std::cin >> n;
  for (i = 0; i < n-1; ++i) {std::cin >> b[i];}
  ans=b[0]+b[n-2];
  for (i = 0; i < n-2; ++i) {
    ans+=std::min(b[i],b[i+1]);
  }
  std::cout <<ans << '\n';
}


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

using namespace std;

char c[100010];
int n, k;

int main(){
	scanf("%d%d", &n, &k);

	scanf(" %s", c + 1);

	if(c[k] == 'A') c[k] = 'a';
	if(c[k] == 'B') c[k] = 'b';
	if(c[k] == 'C') c[k] = 'c';

	for(int i = 1; c[i] != '\0'; i++){
		printf("%c", c[i]);
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 256
$<.gets.to_i.times do
	point = 0
	out = 0
	runner = 0

	while out < 3
		case $<.gets.chomp
		when 'HIT'
			runner == 3 ? point += 1 : runner += 1
		when 'OUT'
			out += 1
		when 'HOMERUN'
			point += runner + 1
			runner = 0
		end
	end

	p point
end

Measured memory_bytes: 6092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll a,b;cin>>a>>b;
  print((a<10&&b<10)?a*b:-1);
  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <math.h>
#include <list>
#define mod 1000000007
#define ms0(x) memset(x, 0, sizeof(x))
#define ms_1(x) memset(x, -1, sizeof(x))
using namespace std;
using ll = long long int;
using ull = unsigned long long int;

int main(){
    int n, k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++) cin>>h[i];
    ll x[n];
    x[0] = 0;
    for(int i=1;i<n;i++){
        ll temp = 1000000000;
        for(int j=1;j<=k && i-j>=0;j++){
            temp = min(x[i-j]+abs(h[i]-h[i-j]), temp);
        }
        x[i] = temp;
    }
    cout<<x[n-1];
    return 0;
}


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

const int INF = 1 << 30;

void solve(int N) {
    int cnt[4];
    for (int i = 0; i < 4; i++) {
        cin >> cnt[i];
    }
    int cnt_sum = INF;
    int ans[4] = {INF, INF, INF, INF};
    for (int i = 0; i <= cnt[0]; i++) {
        for (int j = 0; j <= cnt[1]; j++) {
            for (int k = 0; k <= cnt[2]; k++) {
                for (int l = 0; l <= cnt[3]; l++) {
                    int now_sum = 10 * i + 50 * j + 100 * k + 500 * l;
                    if (now_sum >= N) {
                        int now_rest = now_sum - N;
                        int now_cnt = 0;
                        now_cnt += cnt[0] - i;
                        now_cnt += cnt[1] - j;
                        now_cnt += cnt[2] - k;
                        now_cnt += cnt[3] - l;
                        if (now_rest / 500 && l) continue;
                        now_cnt += now_rest / 500;
                        now_rest %= 500;
                        if (now_rest / 100 && k) continue;
                        now_cnt += now_rest / 100;
                        now_rest %= 100;
                        if (now_rest / 50 && j) continue;
                        now_cnt += now_rest / 50;
                        now_rest %= 50;
                        if (now_rest / 10 && i) continue;
                        now_cnt += now_rest / 10;
                        if (now_cnt <= cnt_sum) {
                            cnt_sum = now_cnt;
                            ans[0] = i;
                            ans[1] = j;
                            ans[2] = k;
                            ans[3] = l;
                        }
                    }
                }
            }
        }
    }
    if (ans[0] > 0) cout << 10 << ' ' << ans[0] << endl;
    if (ans[1] > 0) cout << 50 << ' ' << ans[1] << endl;
    if (ans[2] > 0) cout << 100 << ' ' << ans[2] << endl;
    if (ans[3] > 0) cout << 500 << ' ' << ans[3] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    bool outputed = false;
    while (true) {
        cin >> N;
        if (N == 0) break;
        if (outputed) cout << '\n';
        solve(N);
        outputed = true;
    }
    return 0;
}


Measured memory_bytes: 3136
//package atcoder;
 
import java.util.*;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String A[] = new String[N];
		
		for(int i=0;i<N;i++) {
			A[i] = sc.next();
			//System.out.println(A[i]);
		}
		
		HashMap<String,Integer>map = new HashMap<String,Integer>();
		for(int i=0;i<N;i++) {
			if(map.containsKey(A[i])) {
				map.put(A[i],map.get(A[i])+1);
				//System.out.println(map.get(A[i]));
			}else {
				map.put(A[i],1);
				//System.out.println(map.get(A[i]));
			}
		}
		int ans = 0;
		for(String key : map.keySet()) {
			int temp = map.get(key);
			//System.out.println(temp);
				ans ++;
				//System.out.println(ans);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 73968
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define ll long long
#define ull unsigned long long
#define REP(i, n) for(int i=0; i<n; i++)

int main(){
    int a,b;
    cin >> a >> b;
    cout << (a - b + 1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define el '\n'
typedef long long ll;
const int MAXN = 4e3+2;
int N, psa[4][MAXN];
string S;
map<char, int>m;
int main() {
	cin >> N >> S;
	m['R']=1; m['G'] = 2; m['B'] = 3;
	for(int i = 1;i<=N;i++){
		psa[1][i]+=psa[1][i-1];
		psa[2][i]+=psa[2][i-1];
		psa[3][i]+=psa[3][i-1];
		psa[m[S[i-1]]][i]++;
	}
	ll ans = 0;
	for(int i = 1;i<=N;i++){
		int cur = m[S[i-1]];
		for(int j = i+1;j<=N;j++){
			int cur2 = m[S[j-1]];
			if(cur==cur2)continue;
			int cur3, diff = j-i;
			if((cur==1&&cur2==2)||(cur==2&&cur2==1))cur3 = 3;
			else if((cur==2&&cur2==3)||(cur==3&&cur2==2))cur3 = 1;
			else if((cur==1&&cur2==3)||(cur==3&&cur2==1))cur3 = 2;
			int k = diff+j;
			if(k<=N&&m[S[k-1]]==cur3){
				ans-=1;
			}
			ans+=(psa[cur3][N]-psa[cur3][j]);
		}
	}
	cout << ans << el;
	return 0;
}

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

int main()
{
	int n, max = -1000000000, min;
	cin >> n;
	cin >> min;
	int x;

	for (int i = 1; i < n; i++) {
		cin >> x;
		if ((x - min) > max) max = x - min;
		if (min > x) min = x;
	}

	cout << max << "\n";
	return 0;
}

Measured memory_bytes: 1168
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

int A[10][10000];
int cnt[10000]; // ???????????????????????°

signed main()
{
    int R, C;
    while (cin >> R >> C, R || C) {
        rep(i, R) rep(j, C) {
            cin >> A[i][j];
        }

        int ma = 0;

        rep(i, 1 << R) {
            memset(cnt, 0, sizeof(cnt));

            rep(j, C) rep(k, R) {
                if (i & 1 << k) {
                    cnt[j] += A[k][j] ^ 1;
                } else {
                    cnt[j] += A[k][j];
                }
            }

            int t = 0;

            rep(j, C) {
                t += max(cnt[j], R - cnt[j]);
            }

            chmax(ma, t);
        }

        cout << ma << endl;
    }
}

Measured memory_bytes: 1596
import Control.Applicative
import Control.Monad
import Data.Char

sumC :: String -> Int
sumC [] = 0
sumC (x:xs) = (ord x - ord '0') + sumC xs

main = do
    s <- getLine
    if s == "0" then return()
    else do 
      putStrLn $ show(sumC s)
      main
    

Measured memory_bytes: 3948
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define pii pair<int,int>
#define maxn 100005
using namespace std;
priority_queue<pii> q;
vector<int> v[maxn];
int n,k,A,B,a[maxn];
bool used[maxn],has[maxn];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n-1;i++)
	{
		scanf("%d%d",&A,&B);
		v[A].push_back(B);
		v[B].push_back(A);
	}
	scanf("%d",&k);
	for(int i=0;i<k;i++)
	{
		scanf("%d%d",&A,&B);
		a[A]=B;has[A]=1;
		q.push(pii(-B,A));
	}
	//memset(a,-0x3f,sizeof(a));
	while(!q.empty())
	{
		B=-q.top().first,A=q.top().second;q.pop();
		used[A]=1;
		for(int i=0;i<v[A].size();i++)
		if(!used[v[A][i]]&&has[v[A][i]]&&a[v[A][i]]!=B+1)
		{
			//printf("A:%d v[A][i]:%d a[v[A][i]]:%d B:%d\n",A,v[A][i],a[v[A][i]],B);
			puts("No");
			return 0;
		}
		else if(!used[v[A][i]])
		used[v[A][i]]=1,a[v[A][i]]=B+1,q.push(pii(-B-1,v[A][i])),has[v[A][i]]=1;
	}
	puts("Yes");
	for(int i=1;i<=n;i++)printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 8308
import sys
n, y = (int(i) for i in input().split())

for i_10000 in range(0, n + 1):
  for i_5000 in range(0, n + 1):
    i_1000 = n - i_10000 - i_5000
    if (i_10000 * 10000 + i_5000 * 5000 + i_1000 * 1000 == y) and i_10000 + i_5000 + i_1000 == n and i_10000 >= 0 and i_5000 >= 0 and i_1000 >= 0:
      print(i_10000, i_5000, i_1000)
      sys.exit()
      
print(-1, -1, -1)
  

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    vec hand;
    int pos = n;
    while (pos != 0) {
        int ne = 0;
        Forr(i, m, 1) {
            if (pos - i >= 0 and s[pos - i] == '0') {
                ne = i;
                break;
            }
        }
        if (ne == 0) {
            print(-1);
            return 0;
        }
        hand.pb(ne);
        pos -= ne;
    }
    reverse(all(hand));
    print(hand);

    return 0;
}


Measured memory_bytes: 2244
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int a,b;
cin >> a >> b;
if(a<=8&&b<=8) {
  cout << "Yay!" << endl;
} else {
  cout << ":(" << endl;
}
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	string s;
	cin >> s;
	if (s[1] == 'B') {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
	
	static int compute_maxprofit(int n, int[] R) {
		int max_profit = -999999999;
		int minValue = R[0];

		for (int i = 1; i < n; i++) {
			max_profit = Math.max(max_profit, R[i] - minValue);
			minValue = Math.min(minValue, R[i]);
		}
		return max_profit;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] R = new int[n];
		
		for(int i = 0; i < n; i++) {
			R[i] = in.nextInt();
		}
		System.out.println(compute_maxprofit(n, R));
		in.close();
	}
}


Measured memory_bytes: 101696
package main

import "fmt"

func main() {
	var n, x, y, a, minx, maxx, miny, maxy int
	fmt.Scan(&maxx, &maxy, &n)
	minx = 0
	miny = 0
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &y, &a)
		switch a {
		case 1:
			if minx < x {
				minx = x
			}
		case 2:
			if maxx > x {
				maxx = x
			}
		case 3:
			if miny < y {
				miny = y
			}
		case 4:
			if maxy > y {
				maxy = y
			}
		}
	}
	if minx >= maxx || miny >= maxy {
		fmt.Println("0")
		return
	}
	fmt.Println((maxx - minx) * (maxy - miny))
}


Measured memory_bytes: 512
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

const int N = 19;

char s[N][N];
int p[N];
long long x[N];
long long rx[N];
bool used[N];

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  for (int mask = 0; mask < (1 << n); ++mask) {
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      if (mask >> i & 1) {
        ++cnt;
      }
    }
    if (cnt != (n + 1) / 2) {
      continue;
    }
    vector<int> a, b;
    for (int i = 0; i < n; ++i) {
      if (mask >> i & 1) {
        a.push_back(i);
      } else {
        b.push_back(i);
      }
    }
    for (int i = 0; i < (n + 1) / 2; ++i) {
      p[i] = i;
    }
    do {
      for (int j = 0; j < m; ++j) {
        x[j] = 0;
        rx[j] = 0;
        used[j] = false;
        long long z = 1;
        for (int i = 0; i < n / 2; ++i) {
          x[j] += (s[a[p[i]]][j] - 'a') * z;
          x[j] += (s[b[i]][j] - 'a') * z * 26;
          rx[j] += (s[b[i]][j] - 'a') * z;
          rx[j] += (s[a[p[i]]][j] - 'a') * z * 26;
          z *= 26 * 26;
        }
        if (n % 2 == 1) {
          x[j] += (s[a[p[n / 2]]][j] - 'a') * z;
          rx[j] += (s[a[p[n / 2]]][j] - 'a') * z;
        }
        for (int i = 0; i < j; ++i) {
          if (!used[i] && rx[i] == x[j]) {
            used[i] = true;
            used[j] = true;
            break;
          }
        }
      }
      int rem = 0;
      for (int i = 0; i < m; ++i) {
        if (!used[i]) {
          ++rem;
        }
      }
      if (rem == m % 2) {
        puts("YES");
        return 0;
      }
    } while (next_permutation(p, p + (n + 1) / 2));
  }
  puts("NO");
}


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

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (argc == 2 && atoi(argv[1]) == 123456789)
        freopen("d:\\code\\cpp\\stdin", "r", stdin);

   vector<string> words;
   set<string> cache;

   int N;
   cin >> N;
   bool ok = true;
   for(int i=0; ok && i<N; i++){
       string s;
       cin >> s;
       if (cache.find(s)!=cache.end())
           ok = false;
       if (i && words[i-1].back() != s[0])
           ok = false;
       words.push_back(s);
       cache.insert(s);
   }

   if (ok)
       cout << "Yes";
   else
       cout << "No";

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void)
{
	int i, n;
	int m, h;
	double mDeg, hDeg, deg;
	
	scanf("%d", &n);
	for(i=0; i<n; i++)
	{
		scanf("%d:%d", &h, &m);
		mDeg=6*m;
		hDeg=30*h +mDeg/12;
		deg =fabs(mDeg-hDeg);
		
		if(deg>180)deg = 360-deg;

		     if(deg <30)printf("alert");
		else if(deg <90)printf("warning");
		else printf("safe");
		puts("");
		//printf("(%f)\n", deg);
	}
	return 0;
}

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

const int maxn = 1e5 + 100;

vector<int>graph[maxn];

int dp[maxn];

int dfs(int u)
{
    int &ans = dp[u];
    if(ans != -1)
        return ans;
    ans = 0;
    for(auto &v : graph[u])
    {
        ans = max(ans, dfs(v) + 1);
    }
    return ans;
}

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    for(int i = 1; i <= m; i++)
    {
        int u,v;
        scanf("%d %d",&u,&v);
        graph[u].push_back(v);
    }
    memset(dp,-1,sizeof(dp));
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        ans = max(ans, dfs(i));
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 7424
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int r = scan.nextInt();
		if(r == (-1)*h) {
			System.out.println(0);
		}else if(r < (-1)*h) {
			System.out.println(-1);
		}else {
			System.out.println(1);
		}
	}
}


Measured memory_bytes: 26272
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000009
using namespace std;
using ll = long long;
int main()
{
    int n, nc;
    cin >> n >> nc;
    vector<int> s(n), t(n), c(n);
    rep(i,n){
        cin >> s[i] >> t[i] >> c[i];
        c[i]--;
    }
    vector<vector<int>> dp(nc, vector<int>(200002));
    rep(i,n){
        for (int j = s[i]*2-1; j <= t[i]*2;j++){
            dp[c[i]][j] = 1;
        }   
    }
    int ans = 0;
    rep(i,200002){
        int cnt = 0;
        rep(j,nc){
            if(dp[j][i])
                cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 25728
#include <bits/stdc++.h>
using namespace std;
const int MAXN=10010;
int n,x,y,cnt[MAXN];
int main () {
	scanf("%d%d%d",&n,&x,&y);
	for (int i=1;i<=n;i++) {
		for (int j=i+1;j<=n;j++) {
			int dis=min(j-i,min(abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j)));
			cnt[dis]++;
		}
	}
	for (int i=1;i<=n-1;i++) {printf("%d\n",cnt[i]);}
	return 0;
}

Measured memory_bytes: 256
const fs = require('fs')
const reader = (s: string) => (s.split("\n"))[1].split(" ")
 
function Main(input: string) {
  let min = 100
  let max = -100
  let minCost = Number.MAX_VALUE

  const nums = reader(input).map(i => parseInt(i));

  nums.forEach(num =>{
    min = min > num ? num : min;
    max = max < num ? num : max;
  })

  for( let i= min ;i <= max ; i++)
  {
    let cost = 0
    nums.forEach(num =>{
      cost += Math.pow((i - num),2)
    })
    minCost = minCost > cost ? cost : minCost;
  }
  console.log(minCost);

}
 
Main(fs.readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 9420
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    sc.close();
    System.out.println(a * b);
    // String[] array = str.split(" ");
    // int sum = 0;
    // for(int i=0; i<array.length; i++) {
    // int num = Integer.parseInt(array[i]);
    // sum += num;
    // }
    // System.out.println(15-sum);
  }
}

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

int main(){
    string s,t;
    cin >> s >> t;
    int ans=t.size(),count=0;
    for(int i=0;i<s.size()-t.size()+1;i++){
        count=0;
        for(int j=0;j<t.size();j++){
            if(s.at(i+j)==t.at(j))count++;
        }
        //cout << ans << endl;
        if(ans>t.size()-count)ans=t.size()-count;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int n,m,L;
const double eps=1e-9;
double t[N],v[N];
struct point{
	double x,y;
	point(double X=0,double Y=0){x=X;y=Y;}
	point operator + (point a){
		return point(x+a.x,y+a.y);
	}
	point operator - (point a){
		return point(x-a.x,y-a.y);
	}
	double operator * (point a){
		return x*a.y-y*a.x;
	}
}q[N],vec;
bool check(point x,point y,point z){
	return (y-x)*(z-y)<0;
}
double K(point x,point y){
	return (x.y-y.y)/(x.x-y.x);
}
int head,tail;
int main()
{
	scanf("%d%d",&n,&L);
	for (int i=1;i<=n;i++) scanf("%lf%lf",&t[i],&v[i]);
	q[head=tail=n]=point(0,0);
	q[++tail]=point(v[1],v[1]*t[1]);
	for (int i=1;i<=n;i++){
		vec=vec+point(v[i],v[i]*t[i]);
		while (q[tail].x+vec.x>L+eps) tail--;
		double k=K(q[tail],q[tail+1]),y=q[tail].y+k*(L-q[tail].x-vec.x);
		q[++tail]=point(L-vec.x,y);
		printf("%.7lf\n",(q[tail].y+vec.y)/L);
		point now(-vec.x,-vec.y);
		for (;head<tail&&!check(now,q[head],q[head+1]);head++);
		q[--head]=now;
	}
	return 0;
}

Measured memory_bytes: 35712
#include <cstdio>
#include <vector>

int main()
{
	int n, m;
	std::vector<int> target;
	std::vector<int> score;

	scanf("%d%d", &n, &m);
	for(int i = 0; i < m; ++i) {
		int temp;
		scanf("%d", &temp);
		target.push_back(temp);
	}
	score.resize(n, 0);

	for(int game_count = 0; game_count < m; ++game_count) {

		int t = target[game_count] - 1;
		score[t] += n;

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

			int v;
			scanf("%d", &v);
			v -= 1;
			if(v != t)
				continue;
			score[t] -= 1;
			score[i] += 1;
		}
	}

	for(int i = 0; i < n; ++i)
		printf("%d\r\n", score[i]);

	return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

ll dp[100005];

int main() {
	int n, W;
	scanf("%d%d", &n, &W);
	for (int i=0 ; i<n ; i++) {
		int w, v;
		scanf("%d%d", &w, &v);
		for (int j=W ; j-w>=0 ; j--) {
			dp[j] = max(dp[j], dp[j-w] + v);
		}
	}
	printf("%lld\n", dp[W]);
	return 0;
}

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

int main() {
    LL X, K, D;
    cin >> X >> K >> D;

    X = abs(X);
    LL jumps = min(X/D, K);
    K -= jumps;
    X -= jumps*D;

    if (K > 0) {
        assert(X < D);
        if (K&1) {
            X -= D;
        }
    }

    cout << abs(X) << endl;

    return 0;
}


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

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int po, pt;
  po = N * A;
  pt = B;
  
  if(po <= pt){
    cout << po;
  }
  
  else{
    cout << pt;
  }
}

Measured memory_bytes: 256
import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N = I()

ans = 10e10
for i in range(N+1):
    j = N-i
    cnt = 0
    while i > 0:
        cnt += i%6
        i //= 6
    while j > 0:
        cnt += j%9
        j //= 9
    ans = min(ans,cnt)

print(ans)

Measured memory_bytes: 12420
import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        int cnt  =0;

        while(true){
            if(a>k){
                cnt+=k;
                k=0;
                break;
            }else{
                cnt+=a;
                k-=a;
            }
            if(k<=0){
                break;

            }
            if(b>k){
                k=0;
                break;
            }else{
                k-=b;
            }
            if(k<=0){
                break;
            }

            if(c>k){
                cnt-=k;
                k=0;
                break;
            }else{
                cnt-=c;
                k-=c;
            }
            if(k<=0){
                break;
            }



        }
        System.out.println(cnt);
    }
}






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

using namespace std;
#define ll long long
const int N=2e5+5;
ll INF=1e18;
ll a[N];
int n;
ll k;
ll UP(ll r,ll a)
{
    bool f1=0,f2=0;
    if(r%a!=0) f1=1;
    if(r>=0&&a>=0||r<0&&a<0) f2=1;
    r/=a;
    r+=(f1&&f2);
    return r;
}
ll LOW(ll r,ll a)
{
    bool f1=0,f2=1;
    if(r%a!=0) f1=1;
    if(r>=0&&a>=0||r<0&&a<0) f2=0;
    r/=a;
    r-=(f1&&f2);
    return r;
}
bool valid(ll r)
{
    ll cnt=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]>0)
        {
            int idx=upper_bound(a,a+n,LOW(r,a[i]))-a-1;
            cnt+=max(0,idx-i);
        }
        else if(a[i]<0) cnt+=n-max(i+1,(int)(lower_bound(a,a+n,UP(r,a[i]))-a));
        else if(0<=r) cnt+=n-(i+1);
    }
    return cnt>=k;
}
ll solve()
{
    ll s=-INF,e=INF,mid;
    while(s<e)
    {
        mid=s+(e-s)/2;
        if(valid(mid)) e=mid;
        else s=mid+1;
    }
    return s;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    cout<<solve()<<endl;
    return 0;
}


Measured memory_bytes: 1792
import java.awt.*;
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(),b = sc.nextInt();
        int arr[] = new int[1000];
        arr[0] =1;
        for(int i=1;i<1000;i++){
            arr[i] = arr[i-1]+i+1;
        }
        int diff = b-a;
        System.out.println(arr[diff-2] -a);
    }
}


Measured memory_bytes: 21844
K, N = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

A = A + [K]

lis = [0]*N
for i in range(N):
    lis[i] = A[i+1] - A[i]

#一番長い距離を引くか, 端から端までか
print(min(sum(lis[:N-1]), K - max(lis)))

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

#define ll long long

int main()
{
    std::string S;
    std::cin >> S;

    int sum = 0;
    if(S.size() != 3) {
        std::cout << sum << std::endl;
    }
    else {
        int point = -1;
        for(int i=0; i < 3; i++) {
            if(S[i] == 'R') {
                if(point == -1) {
                    point = i;
                    sum++;
                }
                else {
                    if((i-1) == (point)) {
                        sum++;
                        point = i;
                    }
                    else {
                        break;
                    }
                }
            }
        }
        std::cout << sum << std::endl;
    }
}

Measured memory_bytes: 3588
use proconio::{input, fastout};
use std::cmp::*;

#[fastout]
fn main() {
    input!{
        n: i32,
        mut x: i32,
        mut y: i32
    }
    if x > y {
        x ^= y;
        y ^= x;
        x ^= y
    }
    let mut a = vec![0; (n-1) as usize];
    for i in 1..n {
        for j in i+1..n+1 {
            a[(min(j-i, (j-y).abs() + (i-x).abs() + 1) - 1) as usize] += 1;
        }
    }
    for e in a.iter() {
        println!("{}", e);
    }
}



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



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



	int x, y ,z;
	cin >> x >> y>>z;

	cout << x + y + z - max(x, max(y, z)) << endl;
	return 0;
}



Measured memory_bytes: 256
import copy

def check(arr, val):
    for i in arr:
        if not i == val:
            return False
    return True

n, k = map(int, input().split())
a = [int(_) for _ in input().split()]

for _ in range(k):
    aa = [0] * n
    for i in range(n):
        aa[max(0, i-a[i])] += 1
        r = i+a[i]+1
        if r < n:
            aa[r] -= 1
    for i in range(1, n):
        aa[i] += aa[i-1]
    a = aa.copy()
    if check(a, n):
        break

for i in a:
    print(i, end=' ')
print()

Measured memory_bytes: 168476
n=int(input())
a=[int(i) for i in input().split()]

patternlist=[None for i in range(n)]


#まず、n/２より大きい番号に入る玉の数は一通り
for i in range(n//2,n):
    if a[i]==0:
        patternlist[i]=0
    else:
        patternlist[i]=1
# print(patternlist)

#次に、小さい玉から順にやっていく
for i in range(0,n//2):
    i=n//2-1-i
    sumnum=0
    num=i+1
    multiply=1
    while True:
        multiply+=1
        if num*multiply>n:
            break
        sumnum+=patternlist[num*multiply-1]
        sumnum=sumnum%2
        
    if sumnum==a[i]:
        patternlist[i]=0
    else:
        patternlist[i]=1
    
        
    
print(patternlist.count(1))
for i in range(n):
    if patternlist[i]==1:
        print(i+1)
    
    




Measured memory_bytes: 69868