akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	static List<List<Hen>> list;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < n - 1; i++) {
			String[] sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]) - 1;
			int b = Integer.parseInt(sa[1]) - 1;
			list.get(a).add(new Hen(b, i));
			list.get(b).add(new Hen(a, i));
		}

		int m = Integer.parseInt(br.readLine());
		long[] cond = new long[m];
		for (int i = 0; i < m; i++) {
			String[] sa = br.readLine().split(" ");
			int u = Integer.parseInt(sa[0]) - 1;
			int v = Integer.parseInt(sa[1]) - 1;
			List<Integer> route = new ArrayList<>();
			dfs(u, v, -1, route);
			for (int j : route) {
				cond[i] += 1L << j;
			}
		}
		br.close();

		long ans = 0;
		int m2 = 1 << m;
		for (int i = 0; i < m2; i++) {
			long conds = 0;
			for (int j = 0; j < m; j++) {
				if ((i >> j & 1) == 1) {
					conds |= cond[j];
				}
			}
			int white = Long.bitCount(conds);
			long val = 1L << (n - 1 - white);
			int num = Integer.bitCount(i);
			if (num % 2 == 0) {
				ans += val;
			} else {
				ans -= val;
			}
		}
		System.out.println(ans);
	}

	static boolean dfs(int x, int to, int p, List<Integer> route) {
		if (x == to) {
			return true;
		}
		for (Hen h : list.get(x)) {
			if (h.v == p) {
				continue;
			}
			if (dfs(h.v, to, x, route)) {
				route.add(h.i);
				return true;
			}
		}
		return false;
	}

	static class Hen {
		int v, i;

		public Hen(int v, int i) {
			this.v = v;
			this.i = i;
		}
	}
}


Measured memory_bytes: 23036
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 110;

int a[3][N], f[3][N], n, ans;

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

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

#define fo(i,n)         for(int i=0;i<n;i++)
#define Fo(i,k,n)       for(int i=k;i<n;i++) 
#define endl            "\n"
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define vec(x)          vector<x>
#define matrix(x)       vector<vector<x>>
#define mem(a,b)        memset(a, b, sizeof a)
#define vii             vector<pair<int,int>>
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define MOD             998244353
#define deb(x)          cerr <<#x<<" = "<<x<<"\n"
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for (int i = a; i<b; ++i)
#define len(s)          s.length()
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
int power(int a,int b,int m=mod)
{int ans=1;while(b>0){if(b&1)ans=(ans*a)%m;a=(a*a)%m;b>>=1;}
return ans;}

void angshuGod()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

const int N = 1e5+1;
const double pi = acos(-1);

void solve(){    

   	int x,y;
   	cin>>x>>y;
   	if(y&1)cout<<"No";
   	else if(y>4*x) cout<<"No";
   	else if(y<2*x) cout<<"No";
   	else cout<<"Yes";
}

 
int32_t main()
{
    angshuGod();

    int t;

    t = 1;
    //cin>>t;

    while(t--){
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

bool ok(ll h, ll w, ll a, ll b, ll x, ll y) {
	return (2 * a * x - w * x - a * h == 2 * b * y - h * y - b * w);
}

void solve(ll h, ll w, ll a, ll b, ll x, ll y) {
	vector<string> ans(h, string(w, '0'));
	vll cnth(h, a), cntw(w, b);
	for (ll i = 0; i < h - x; i++) cnth[i] = w - a;
	for (ll j = 0; j < w - y; j++) cntw[j] = h - b;
	for (ll i = 0; i < h; i++) {
		ll cnt = 0;
		for (ll j = 0; j < w && cnt < cnth[i]; j++) {
			if (cntw[j]) {
				ans[i][j] = '1';
				cntw[j]--;
				cnt++;
			}
		}
	}

	xout << x << " " << y << endl;
	for (ll i = 0; i < h; i++) cout << ans[i] << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll h, w, a, b;
	cin >> h >> w >> a >> b;

	for (ll x = 0; x <= h; x++) {
		for (ll y = 0; y <= w; y++) {
			if (ok(h, w, a, b, x, y)) {
				solve(h, w, a, b, x, y);
				return 0;
			}
		}
	}
}


Measured memory_bytes: 2304
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    A = list(map(int, input().split()))
    answer = 0
    for i in range(N):
        if i % 2 == 0 and A[i] % 2 == 1:
            answer += 1
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9120
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll a[1005];
ll m[1005];
ll ans[100000005] = {};
int main(void) {
	int n;
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> m[i];
	}
	ll sum = 0;
	
		for (int bit = 1; bit < (1 << n); bit++) {
			for (int j = 0; j < n; j++) {
				if (bit & (1 << j)) {
					sum += a[j];
				}
			}
			ans[sum] = 1;
			sum = 0;
		}
		
		for (int i = 0; i < q; i++) {
			if (ans[m[i]]) {
				cout << "yes" << endl;
			}
			else {
				cout << "no" << endl;
			}
		}
	
	return 0;
}



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

int main(){
  int a, b;
  cin >> a >> b;
  
  int ans = 0;
  
  if(a>=b) {
    ans+=a;
    a--;
  } else {
    ans+=b;
    b--;
  }
  
    if(a>=b) {
    ans+=a;
    a--;
  } else {
    ans+=b;
    b--;
  }
  
  cout << ans;
  return 0;
}
      


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        int H,W;
    	//?¨??????\??????????????????????????§????????????
		Scanner scanner = new Scanner(System.in);
		
		while(true){
			H = scanner.nextInt();
			W = scanner.nextInt();
			
			if(H == 0 && W == 0){
				break;
			}
			
			for(int i = 0; i < H;i++){
				for(int j = 0; j < W; j++){
					if((i+j)%2 == 0){
						System.out.print("#");	
					}
					else{
						System.out.print(".");
					}
									
				}
				System.out.println();
			}
			System.out.println();
		}
    	scanner.close();
    }
}

Measured memory_bytes: 37424
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){

    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  int n; cin>>n;
  vector<PII> a;
  rep(i,n){
    int b; cin>>b;
    a.PB({b,i});
  }
  sort(ALL(a));
  rep(i,n) cout<<a[i].second+1<<' ';
  cout<<endl;


  return 0;
}


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

class UF {
    public:
        vector<int> p;
        UF(size_t n) : p(n) {
            for(size_t i=0; i<n; i++)
                p[i] = i;
        };
        int find(int x) {
            if(p[x] == x) return x;
            return p[x] = find(p[x]);
        };
        void unite(int x, int y) {
            x = find(x);
            y = find(y);
            p[x] = y;
        };
};

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

    UF uf(n);
    for(int i=0; i<m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--, y--;
        uf.unite(x, y);
    }
    bitset<100000> bs;

    long res = 0;
    for(int i=0; i<n; i++) {
        res += bs[uf.find(i)] == 0;
        bs[uf.find(i)] = 1;
    }
    cout << res << endl;
}


Measured memory_bytes: 896
const MOD: i64 = 1000000007;

fn main() {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let s: Vec<_> = s.trim().chars().collect();

	let mut dp = [1, 0];
	for &c in s.iter() {
		let mut next = [0, 0];
		let digit = c.to_digit(10).unwrap();
		for k in 0..2 {
			for d in 0..=if k > 0 || digit == 1 { 1 } else { 0 } {
				let nextk = if k > 0 || d < digit { 1 } else { 0 };
				next[nextk] += match d {
					0 => dp[k],
					_ => 2 * dp[k],
				};
				next[nextk] %= MOD;
			}
		}
		dp = next;
	}
	println!("{}", (dp[0] + dp[1]) % MOD);
}


Measured memory_bytes: 2488
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        s = s.substring(0, 1) + (s.length() - 2) + s.substring(s.length() - 1);
        System.out.println(s);
    }
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

int n, h[200001], a[200001];
ll dp[200001];

int main()
{
    IOS
    cin >> n;
    int base = 1;
    while (base <= n) {
        base *= 2;
    }
    ll tree[base*2];
    memset(tree, 0, sizeof tree);

    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i =0; i < n; ++i) {
        int x = h[i] + base;
        ll best = 0;
        while (x > 1) {
            if (x&1) {
                best = max(best, tree[x-1]);
            }
            x >>= 1;
        }
        dp[h[i]] = max(dp[h[i]], best+a[i]);
        for (int j = h[i]+base; j > 1; j>>=1) {
            tree[j] = max(tree[j], dp[h[i]]);
        }
    }
    ll ans = 0;
    for (int i = 0; i <= n; ++i) {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 7424
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                String s = sc.next();
                sc.close();
                char[] you = new char[s.length() - 1];
                for(int i = 0 ; i < s.length() - 1 ; i++){
                        you[i] = s.charAt(i);
                }
                boolean ebishu = true;
                for(int i = s.length() - 1 ; ebishu && i > 0 ; i--){
                        if(i % 2 == 0){
                                boolean pct = true;
                                for(int j = 0 ; j < i / 2 &&  ebishu ; j++){
                                        if(you[j] != you[j + i / 2]) pct = false;
                                }
                                if(pct){
                                        System.out.println(i);
                                        ebishu = false;
                                }
                        }
                }
        }
}
//鶏になれ


Measured memory_bytes: 35320
/* 

Author: Vishal Singh  
(singhvishal0304@gmail.com)

"The days that break you are the days that make you."

*/

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

#define fastio() ios_base::sync_with_stdio(false);\
cin.tie(NULL);

#define md 1000000007


#define lli long long int
#define pb push_back
#define mp make_pair
#define vvi(r,c) vector<vector<lli>> v(r,vector<lli>(c));
#define fi first
#define se second
#define mem(arr,x) memset(arr,x,sizeof(arr))

lli power(lli a,lli b){
	if(b==0)
		return 1;
	if(b%2)
		return ((a%md)*(power(a,b-1)))%md;
	else
	{
		lli x=power(a,b/2);
		return (x*x)%md;
	}
}

void solve(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int r=0,w=0;
	for(int i=0;i<n;i++)
		s[i]=='R'?r++:w++;
	string p(s);
	int ans=0;
	for(int i=0;i<n;i++){
		if(i<r)
		p[i]='R';
		else
		p[i]='W';

		if(p[i]!=s[i])
			ans++;
	}
	cout<<ceil(ans/2)<<endl;
}


int main()
{	
    fastio();
	int t;
	// cin>>t;
	t=1;
	while(t--){
		solve();
	}

	return 0;
}

Measured memory_bytes: 3880
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<int> a;
int n,x;
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	int st,en;
	st=a[0]; en=a[n-1];
	for(int i=1;i<n-1;i++)
	{
		if(a[i]<0) en=en-a[i];
		else st=st-a[i];
	}
	cout<<en-st<<"\n";
	st=a[0]; en=a[n-1];
	for(int i=1;i<n-1;i++)
	{
		if(a[i]<0) cout<<en<<" "<<a[i]<<"\n",en=en-a[i];
		else cout<<st<<" "<<a[i]<<"\n",st=st-a[i];
	}
	cout<<en<<" "<<st;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;


int main(){
  ll n, q;
  cin >> n >> q;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i, n-1) cin >> a[i] >> b[i];
  vector<ll> p(q);
  vector<ll> x(q);
  rep(i, q) cin >> p[i] >> x[i];

  rep(i, n-1) a[i]--, b[i]--;
  rep(i, q) p[i]--;

  vector<set<ll>> g(n, set<ll>());

  rep(i, n-1){
    g[a[i]].insert(b[i]);
    g[b[i]].insert(a[i]);
  }

  vector<ll> memo(n, 0);
  rep(i, q) memo[p[i]] += x[i];

  vector<ll> res(n, 0);
  queue<pair<ll, ll>> que;
  que.push({0, memo[0]});
  set<ll> visited;
  while(!que.empty()){
    auto pr = que.front(); que.pop();

    if(0 < visited.count(pr.first)) continue;
    visited.insert(pr.first);

    res[pr.first] = pr.second;

    for(auto to : g[pr.first]){
      que.push({to, pr.second + memo[to]});
    }
  }


  string pt = "";
  rep(i, n) cout << pt << res[i], pt = " ";
  cout << endl;

  
  
  return 0;
}

Measured memory_bytes: 52480
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int a,b,d,r;
  double f;
  cin >> a >> b;
  d=a/b;
  r=a%b;
  f=(double)a/(double)b;

  printf("%d %d %.5f\n", d, r, f);
}



Measured memory_bytes: 3160
#include<iostream>
using namespace std;
int main(){
    int n,cnt=0,m=0;
    cin>>n;
    int a[n];
    int g[100]={1};
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    while(g[m]<n){
        g[m+1]+=3*g[m];
        m++;
    }
    if(n==1){
        m=1;
    }
    for(int i=m-1;i>=0;i--){
        for(int k=g[i];k<n;k++){
            int v=a[k];
            int j=k-g[i];
            while(j>=0&&a[j]>v){
                a[j+g[i]]=a[j];
                j=j-g[i];
                cnt++;
            }
            a[j+g[i]]=v;
        }
    }
    cout<<m<<endl;
    for(int i=m-1;i>0;i--){
        cout<<g[i]<<" ";
    }
    cout<<g[0]<<endl;
    cout<<cnt<<endl;
    for(int i=0;i<n;i++){
        cout<<a[i]<<endl;
    }
    return 0;
}


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

bool b[30][30];

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        for(int j=0;j<k;j++){
            int a;
            cin>>a;
            b[i][a-1]=true;
        }
    }
    int cnt=0;
    for(int i=0;i<m;i++){
        bool f=true;
        for(int j=0;j<n;j++){
            if(b[j][i]==false){
                f=false;
                break;
            }
        }
        if(f)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int h, w, k;
	cin >> h >> w >> k;
	string s[h];
	for(int i=0; i<h; i++) cin >> s[i];

	int d[h][w];
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			d[i][j]=0;
		}
	}

	int cnt=0;
	for(int i=0; i<h; i++){
		int t=0;
		for(int j=0; j<w; j++){
			if(s[i][j]=='#'){
				cnt++;
				t++;
			}
			if(t>0) d[i][j]=cnt;
		}
		if(t>0){
			for(int j=w-1; j>=0; j--){
				if(d[i][j]==0) d[i][j]=d[i][j+1];
			}
		}
	}

	for(int j=0; j<w; j++){
		int t=0;
		for(int i=0; i<h; i++){
			if(d[i][j]==0 && i>0) d[i][j]=d[i-1][j];
		}
		for(int i=h-1; i>=0; i--){
			if(d[i][j]==0 && i<h-1) d[i][j]=d[i+1][j];
		}
	}

	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			cout << d[i][j];
			if(j<w-1) cout << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
import sys
H, W = map(int, sys.stdin.readline().rstrip().split())

if W == 1 or H == 1:
    print(1)
else:
    h_syou, h_amari = divmod(H, 2)
    w_syou, w_amari = divmod(W, 2)
    if w_amari == 0:
        print(w_syou * H)
    else:
        print((w_syou * H) + h_syou + h_amari)


Measured memory_bytes: 2940
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (chunk)
{
  var x = parseInt(chunk.trim(), 10);
  var h = Math.floor(x / 3600);
  var mod = x % 3600;
  var m  = Math.floor(mod / 60);
  s = mod % 60;
  console.log(h + ":" + m + ":" + s);
});

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

int main(){
    using namespace std;
    unsigned long K;
    long X, Y, x{1}, y{1};
    cin >> K >> X >> Y;
    if(~K & (X ^ Y) & 1)return 0 & puts("-1");
    Y = (X += Y) - 2 * Y;
    if(X < 0)X *= x = -1;
    if(Y < 0)Y *= y = -1;
    vector<pair<long, long>> ans;
    if(X < K && Y < K){
        if(X & 1){
            ans.emplace_back(X - K + 1, K);
            ans.emplace_back(X - K, 0);
        }else ans.emplace_back(X - K, K);
    }else{
        unsigned long time = (max(X, Y) - 1) / K + 1;
        if(K & (time ^ X) & 1)++time;
        unsigned long remX{time * K - X}, remY{time * K - Y}, a{0}, b{0}, t, k{0};
        for(unsigned long i = 1; i < time; ++i){
            remX -= t = min(remX, 2 * K);
            if(!t)remY -= k = min(remY, 2 * K);
            ans.emplace_back(a += K - t, b += K - k);
        }
    }
    ans.emplace_back(X, Y);
    cout << ans.size() << endl;
    for(const auto& i : ans)cout << (x * i.first + y * i.second) / 2 << " " << (x * i.first - y * i.second) / 2 << endl;
    return 0;
}

Measured memory_bytes: 6128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> pint;
#define rep(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

int main(){
	int n;
	cin>>n;
	rep(i,n){
		string str;
		int out=0;
		int rui=0;
		int score=0;
		for(;out<3;){
			cin>>str;
			if(str=="HIT"){
				if(rui==3)score++;
				else rui++;
			}
			if(str=="HOMERUN"){
				score+=rui+1;
				rui=0;
			}
			if(str=="OUT"){
				out++;
			}
		}
		cout<<score<<endl;
	}
	return 0;
}

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

int main(){
	int a;
	stack<int> sta;
	while(cin >> a){
		if(a == 0 && !sta.empty()){
			cout << sta.top() << endl;
			sta.pop();
		}else{
			sta.push(a);
		}
	}
	return 0;
}

Measured memory_bytes: 1204
#include <stdio.h>
int main(void){
    long long int n;
    scanf("%lld",&n);
for(int i=-120;i<120;i++){
    for(int j=-120;j<120;j++)
    if((i*i*i*i*i)-(j*j*j*j*j)==n){
        printf("%d %d",i,j);
        return 0;
    }
}
}


Measured memory_bytes: 1736
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n = int(input())
    aa = list(map(int, input().split()))
    cc = Counter(aa)
    ans = 0
    for k, v in cc.items():
        if k < v: ans += v - k
        if k > v: ans += v
    print(ans)

main()


Measured memory_bytes: 18328
N, M = map(int, input().split())
cities = []
for cNo in range(M):
    P, Y = map(int, input().split())
    cities.append((Y, P, cNo))

cities.sort()

IDs = ['' for _ in range(M)]
nums = [0] * (N + 1)
for Y, P, cNo in cities:
    nums[P] += 1
    IDs[cNo] = str(P).zfill(6) + str(nums[P]).zfill(6)

print('\n'.join(IDs))


Measured memory_bytes: 32544
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;

    if (s.size() < t.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    int flag = 0;
    for (int i = s.size()-t.size(); i >= 0; i--) {
        flag = 1;
        for (int j = t.size() - 1; j >= 0; j--) {
            if (s[i+j]!='?'&&s[i + j] != t[j]) {
                flag = 0;
                break;
            }
            if (j == 0)flag = 1;
        }
        if (flag) {
            for (int k = 0; k < t.size(); k++) {
                s[i + k] = t[k];
            }
            break;
        }

    }

    if (!flag) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '?')
            cout << 'a';
        else
            cout << s[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        h1: i32,
        m1: i32,
        h2: i32,
        m2: i32,
        k: i32,
    }

    println!("{}", (60 * (h2 - h1) + m2 - m1 - k));
}


Measured memory_bytes: 2200
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
const int maxn = 1e5+100;
ll n, l, t;
ll x[maxn];

//如何锁定第一只蚂蚁的位置
int main() {
  //  freopen("input.txt", "r", stdin);
    cin >> n >> l >> t;
    int w;
    ll temp;
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> w;
        if (w == 1) {
            temp = x[i] + t;
            x[i] = temp % l;
            cnt += temp / l;
        } else {
            temp = x[i] - t;
            x[i] = temp % l;
            cnt += temp / l;
            if (x[i] < 0) {
                x[i] += l;
                cnt--;
            }
        }
    }
    sort(x, x + n);
    cnt %= n;
    cnt = (cnt + n) % n;
    for (int i = cnt; i < cnt + n; i++) {
        cout << x[i % n] << endl;
    }
    return 0;

}

Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}

ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

template<typename T>
vector<vector<T>> bfs(vector<vector<T>> &g){
    queue<T>q;
    int n=g.size();
    T INFTY=numeric_limits<T>::max();
    vector<vector<T>>dist(n,vector<T>(n,INFTY));
    for(int i=0;i<n;++i){
        dist[i][i]=0;
        q.emplace(i);
        while(!q.empty()){
            int v=q.front();
            q.pop();
            for(auto x:g[v]){
                if(dist[i][x]==INFTY){
                    q.emplace(x);
                    dist[i][x]=dist[i][v]+1;
                }
            }
        }
    }
    return dist;
}

void solve(){
    int n,x,y;
    cin>>n>>x>>y;
    vector<vector<int>>g(n);
    rep(i,n-1){
        g[i].pb(i+1);
        g[i+1].pb(i);
    }
    x--;y--;
    vector<int>d(n+5);
    g[x].pb(y);
    g[y].pb(x);
    auto dist=bfs(g);
    rep(i,n-1){
        REP(j,i+1,n){
            d[dist[i][j]]++;
        }
    }
    rep(i,n-1){
        cout<<d[i+1]<<endl;
    }
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define CANCER ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define f first
#define s second
#define mod 1000000007

using namespace std;


int main()
{
	CANCER;
	int n,a;
	cin>>n>>a;
	vector<int> v;
	int cnt=1;
	for(int y=0;y<n;y++)
	{
		int m;cin>>m;
		v.pb(m);
	}
	int val=0;
	for(int y=0;y<n;y++)
	{
		if(val+v[y]<=a)
			cnt++;
		val+=v[y];
	}
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define rep(i,n) for(int i = 0;  i < n ; ++i)
#define REP(i,a,b) for(int i = a ; i <= b ; ++i)
#define s(n) scanf("%d",&n)
#define rev(i,n) for(int i = n ; i >= 0 ; --i)
#define REV(i,a,b) for(int i = a ; i >= b ; --i)
#define miN(a,b) (((a)<(b))?(a):(b))
#define sc(n) scanf("%c",&n)
#define tr(c,i) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define INF 1000000000
#define pii pair<long long int,long long int>
#define pb(a) push_back(a)
typedef long long ll;
using namespace std;
void pre(){}
void solve(){
    pii arr[2001];
    ll j = -1000;
    for(ll i = 0;i<=2000;i++){
        arr[i]={pow(j,5),j};
        j++;
    }
    ll x;cin>>x;
    for(ll i=0;i<=2000;i++){
        for(ll j=0;j<=2000;j++){
            if(arr[i].first-arr[j].first==x){
                cout<<arr[i].second<<" "<<arr[j].second<<"\n";
                return;
            }
        }
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    solve();
}




Measured memory_bytes: 4108
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int n;
int a;
int main(){
  cin>>n;
  int ans=0;
  int b=1;
  for(int i=0;i<n-1;i++)b*=3;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a%2==0){ans+=b;b/=3;b*=2;}
    if(a%2==1){ans+=(2*b);b/=3;}
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import itertools
s=input()

moji = []
for i in s:
    moji.append(int(i))
ans = []
for j in itertools.product([1,-1], repeat=4):
    if moji[0]*j[0]+moji[1]*j[1]+moji[2]*j[2]+moji[3]*j[3] == 7:
        if j[0] == 1:
            ans.append(moji[0])
        else:
            ans.append('-')
            ans.append(moji[0])
        if j[1] == 1:
            ans.append('+')
            ans.append(moji[1])
        else:
            ans.append('-')
            ans.append(moji[1])
        if j[2] == 1:
            ans.append('+')
            ans.append(moji[2])
        else:
            ans.append('-')
            ans.append(moji[2])
        if j[3] == 1:
            ans.append('+')
            ans.append(moji[3])
        else:
            ans.append('-')
            ans.append(moji[3])
        ans.append('=7')
        print(''.join(map(str,ans)))
        exit()

Measured memory_bytes: 38568
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  map<string,int>dict;
  for (int i = 0;i<n;i++){
    string x;
    cin>>x;
    dict[x]++;
  }
  cout<<dict.size()<<endl;
  return 0;
}

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

int main(){
  int n;
  ll a,b;
  cin>>n>>a>>b;
  ll h[n];
  rep(i,0,n) cin>>h[i];
  ll l=0;
  ll r=1e9+1;
  while(l<r){
    ll x=(l+r)/2;
    ll cnt=0;
    rep(i,0,n){
      if(h[i]-b*x>0){
        cnt+=(h[i]-b*x+a-b-1)/(a-b);
      }
    }
    if(cnt>x) l=x+1;
    else r=x;
  }
  cout<<l<<endl;
}

Measured memory_bytes: 1024
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
const ll MAX = 1e5+10;
vector<vector<ll>> XG(MAX);
vector<vector<ll>> YG(MAX);
vector<bool> usedX(MAX,false);
vector<bool> usedY(MAX,false);
void dfs_x(ll,ll&,ll&,ll&);
void dfs_y(ll,ll&,ll&,ll&);
void dfs_y(ll v,ll &xc, ll &yc,ll &lc){
  if(usedY[v]) return;
  yc++;
  usedY[v] = true;
  lc += YG[v].size();
  for(auto nv: YG[v]){
    dfs_x(nv,xc,yc,lc);
  }
}
void dfs_x(ll v,ll &xc, ll &yc,ll &lc){
  if(usedX[v]) return;
  xc++;
  usedX[v] = true;
  lc += XG[v].size();
  for(auto nv: XG[v]){
    dfs_y(nv,xc,yc,lc);
  }
}
signed main(){
  init_io();
  ll n,ans=0;
  cin >> n;
  vector<ll> x(n),y(n);
  for(int i=0;i<n;i++){
    cin >> x[i] >> y[i];
    XG[x[i]].push_back(y[i]);
    YG[y[i]].push_back(x[i]);
  }
  for(int i=0;i<n;i++){
    ll xc = 0,yc = 0,lc = 0;
    dfs_x(x[i],xc,yc,lc);
    ans += xc*yc - lc/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 17188
#include<bits/stdc++.h>
using namespace std;
int n, a[10000], dem, kq = 0;

int main(){
    cin >> n;
    dem = 1;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] == a[i-1]) dem++;
        else{
            kq += dem/2;
            dem = 1;
        }
    }
    kq += dem/2;
    cout << kq;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
using ll = long long;
 
int main(){
  ll D,T,S;
  cin >> D >> T >> S;
  
  if(D <= T*S){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" <<endl;
  }
 
 
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
//template< typename T >
//T mod_pow(T x, T n, const T &p) {
//  T ret = 1;
//  while(n > 0) {
//    if(n & 1) (ret *= x) %= p;
//    (x *= x) %= p;
//    n >>= 1;
//  }
//  return ret;
//}
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
#define mp make_pair
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
//
//
//
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n,k;
  cin >> n >> k;
  if(n>=10){
    pri(k);
  }else{
    pri(k+(100*(10-n)));
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
result = a[0]
num = 2
temp = 0
for i in range(1, n):
    temp = i
    num += 2 
    result += a[i] * 2
    if(num >= n):
        break
print(result - a[temp] * (num- n))

Measured memory_bytes: 94204
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }


int N; // 頂点数
const int MAX_N = 10;
const int INFC = 1000000000;
vector<vector<int>> d(MAX_N, vector<int>(MAX_N, INFC));
  // d[u][v]...辺e=(u,v)のコスト。存在しない場合はINF, 但しd[i][i]=0とする

void warshall_floyd() {
  for (int k=0; k<N; k++) for (int i=0; i<N; i++) for (int j=0; j<N; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int res = INFC;

int main() {
  N = 10;
  int h,w; cin >>h >>w;
  rep(i, 10) rep(j, 10) cin >>d[i][j];
  vector<vector<int>> a(h, vector<int>(w, 0));
  rep(i, h) rep(j, w) cin >>a[i][j];
  warshall_floyd();
  int res = 0;
  rep(i, h){ rep(j, w){
    int digit = a[i][j];
    if (digit == -1) continue;
    res += d[digit][1];
  }}
  cout <<res <<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	string s;cin>>s;
	ll q;cin>>q;
	deque<char> t;
	for(int i = 0; i < s.size(); i++) {
		t.push_back(s[i]);
	}
	bool reverse = false;
	for(int i = 0; i < q; i++) {
		int a;cin>>a;
		if(a == 1){
			reverse = !reverse;
		}
		else{
			int f;char c;cin>>f>>c;
			if (reverse){
				if(f == 1){
					t.push_back(c);
				}
				else{
					t.push_front(c);
				}
			}
			else{
				if(f == 1){
					t.push_front(c);
				}
				else{
					t.push_back(c);
				}
			}
		}
	}
	while(!t.empty()){
		if(reverse){
			cout << t.back();
			t.pop_back();
		}
		else{
			cout << t.front();
			t.pop_front();
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3992
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);
    private static final int MOD = 1000000007;

    public static void main(String[] args) {
	int N = Integer.parseInt(scan.next());

	long result = 1;
	for (int i = 1; i <= N; i++) {
	    result = (result * i) % MOD;
	}

	System.out.println(result);
	scan.close();
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	int i, q;

	Scanner s = new Scanner(System.in);
	int n = s.nextInt();
	int A[]= new int[n];
	    
	for(i=0; i<n; i++){
	    A[i] = s.nextInt();
	}
  
	q = partition(A, 0, n-1);

	for(i=0; i<n; i++){
	    if(i!=0) System.out.print(" ");
	    if(i==q) System.out.print("[");
	    System.out.print(A[i]);
	    if(i==q) System.out.print("]");
	}
	System.out.println();
    }
    
    public static int partition(int A[], int p, int r){
	int x, i, j, t;
	x = A[r];
	i = p-1;
	for(j=p; j<r; j++){
	    if(A[j]<=x){
		i++;
		t = A[i]; A[i] = A[j]; A[j] = t;
	    }
	}
	t = A[i+1]; A[i+1] = A[r]; A[r] = t;
	return i+1;
    }
}

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

int main()
{
  string s;
  cin >> s;
  cout << (s == "SUN" ? 7 : s == "MON" ? 6 : s == "TUE" ? 5 : s == "WED" ?  4 : s == "THU" ? 3 : s == "FRI" ? 2 : 1) << endl;
}

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

int main() {
    int N, x;
    cin>>N>>x;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin>>a[i];
    sort(a.begin(), a.end());
    int n;
    for(n=0; n<N && x>0; n++) x-=a[n];
    if(x!=0) n-=1;
    cout<<n<<endl;

    return 0;
}

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

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	double a, b, c, d;
	cin >> a >> b >> c >> d;
	if(ceil(a/d) >= ceil(c/b))
		cout << "Yes\n";
	else
		cout << "No\n"; 
}

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

#define ll          long long int
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pair<int,int>>
#define mi          map<int,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define rep(i,a,b)  for(i=a;i<b;i++)
#define inf         INT_MAX

template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }

using namespace std;
void solve()
{
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    if(x>0 && (x/d)>=k)
    {
        cout<<x-d*k;
        return;
    }
    k-=(x/d);
    x-=(x/d)*d;

    //cout<<k<<endl;
    if(k&1)cout<<min(abs(x-d),abs(x+d));
    else cout<<abs(x);
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3660
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int main()
{
   ll n, x[101] = {}, y[101] = {}, h[101] = {};
   int l;
   cin >> n;
   FOR(i, 0, n)
   {
      cin >> x[i] >> y[i] >> h[i];
      if (h[i] > 0)
         l = i;
   }

   ll height;
   bool flag;
   FOR(i, 0, 101)
   FOR(j, 0, 101)
   {
      height = h[l] + abs(x[l] - i) + abs(y[l] - j);
      flag = true;
      FOR(k, 0, n)
      {
         if (h[k] != max(0LL, height - abs(x[k] - i) - abs(y[k] - j)))
         {
            flag = false;
            break;
         }
      }

      if (flag)
      {

         cout << i << " " << j << " " << height << endl;
         return 0;
      }
   }
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/////////////////
// 2D geometry //
/////////////////
 
// 2D geometry basic //
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
#define X real
#define Y imag
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
typedef vector<P> G;
struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
  double R(double h){
    return sqrt(max(r*r-h*h,0.0));
  }
};
 
// UVA 453 (Intersecting Circles)
pair<P, P> circle_circle_intersect(const P& c1, const double& r1, const P& c2, const double& r2) {
  P A = conj(c2-c1), B = (r2*r2-r1*r1-(c2-c1)*conj(c2-c1)), C = r1*r1*(c2-c1);
  P D = B*B-4.0*A*C;
  P z1 = (-B+sqrt(D))/(2.0*A)+c1, z2 = (-B-sqrt(D))/(2.0*A)+c1;
  return pair<P, P>(z1, z2);
}
 
// solve //
vector<C> in;
void init(){
  in.clear();
}
bool input(){
  int n;
  cin>>n;
  if(n==0)return false;
  for(int i=0;i<n;i++){
    double x,y,r;
    cin>>x>>y>>r;
    in.push_back(C{P{x,y},r});
  }
  return true;
}
bool judge2(P p,double m){
  for(int i=0;i<in.size();i++){
    double dist = abs(in[i].p - p);
    if(dist - EPS > in[i].R(m)){
      return false;
    }
  }
  return true;
}
bool judge(double m){
  //cerr<<"judge::"<<m<<" ";
  for(int i=0;i<in.size();i++){
    if(m>=in[i].r)return false;
  }
  for(int i=0;i<in.size();i++){
    for(int j=0;j<in.size();j++){
      const double dist = abs(in[i].p-in[j].p);
      if(dist>in[i].R(m)+in[j].R(m)){
        return false;
      }
    }
  }
  if(in.size()==1)return true;
  //cerr<<" val ";
  for(int i=0;i<in.size();i++){
    if(judge2(in[i].p,m))return true;
    for(int j=0;j<in.size();j++){
      const double dist = abs(in[i].p-in[j].p);
      if(dist+in[i].R(m)<=in[j].R(m)+EPS)continue;
      if(dist+in[j].R(m)<=in[i].R(m)+EPS)continue;
      pair<P,P> p = circle_circle_intersect(in[i].p,in[i].R(m),in[j].p,in[j].R(m));
      if(judge2(p.first,m))return true;
      if(judge2(p.second,m))return true;
    }
  }
  return false;
}
 
double req(double l,double r){
  double m = (l+r)/2;
  if(abs(l-r)<EPS)return r;
  if(judge(m)){
    //cerr<<"true"<<endl;
    return req(m,r);
  }else{
    //cerr<<"false"<<endl;
    return req(l,m);
  }
}
 
double solve(){
  double ans = req(0.5,301.0);
  return ans;
}
 
 
int main(){
  while(init(),input()){
    cout<<fixed<<setprecision(10)<<solve()<<endl;
  }
}

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

signed main(){
	int n;
	cin>>n;
	vector<int>v(n);
	r(i,n)cin>>v[i];
	if(prev_permutation(v.begin(),v.end())){
		r(i,n){
			if(i)cout<<' ';
			cout<<v[i];
		}
		cout<<endl;
	}
	next_permutation(v.begin(),v.end());
	r(i,n){
		if(i)cout<<' ';
		cout<<v[i];
	}
	cout<<endl;
	if(next_permutation(v.begin(),v.end())){
		r(i,n){
			if(i)cout<<' ';
			cout<<v[i];
		}
		cout<<endl;
	}
}


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

int main () {
	string s;
	cin >> s;
	int sl = s.length();
	for (int i = 1; i < sl; i++) {
		if (s[i] == s[i-1]) {
			cout << i << " " << i+1 << "\n";
			return 0;
		}
	}
	for (int i = 2; i < sl; i++) {
		if (s[i] == s[i-2]) {
			cout << i-1 << " " << i+1 << "\n";
			return 0;
		}
	}
	cout << "-1 -1\n";
	return 0;
}

Measured memory_bytes: 512
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    print(n+n**2+n**3)
        
if __name__ == "__main__":
    main()

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

int main()
{
    int a, b;
    cin >>a >>b;
    
    string aa, bb;
    
    for (int i = 0; i<b; i++){
        aa.push_back('0' + a);
    }
    for (int i = 0; i<a; i++){
        bb.push_back('0' + b);
    }
    
    if (aa < bb) cout << aa<<endl;
    else if (bb < aa) cout << bb <<endl;
    else cout << bb <<endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from bisect import bisect_left
from collections import deque

def main():
    N = int(input())
    counter = deque([])
    for _ in range(N):
        a = int(input())
        ind = bisect_left(counter, a)
        if ind == 0:
            counter.appendleft(a)
        else:
            counter[ind-1] = a
    print(len(counter))


if __name__ == '__main__':
    main()

Measured memory_bytes: 44252
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(void) {
    int n;
    string s[200000];

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

    map<string, int> mp;
    int count = 0;
    for (int i = 0; i < n; i++) {
        if (mp.count(s[i]) == 0) {
            mp[s[i]] = 1;
            count++;
        }
    }

    cout << count;

    return 0;
}


Measured memory_bytes: 25472