akhauriyash/Code-Regression huggingface dataset:
class UnionFindNode(object):
    """
    Union-Find構造
    ノードのグループ併合や、所属グループ判定を高速に処理する
    """

    def __init__(self, group_id, parent=None, value=None):
        self.group_id_ = group_id
        self.parent_ = parent
        self.value_ = 1
        self.rank_ = 1

    def __str__(self):
        template = "UnionFindNode(group_id: {}, \n\tparent: {}, value: {}, size: {})"
        return template.format(self.group_id_, self.parent_, self.value_,
                               self.rank_)

    def is_root(self):
        return not self.parent_

    def root(self):
        parent = self
        while not parent.is_root():
            parent = parent.parent_
            self.parent_ = parent
        return parent

    def find(self):
        root = self.root()
        return root.group_id_

    def rank(self):
        root = self.root()
        return root.rank_

    def get_value(self):
        root = self.root()
        return root.value_

    def unite(self, unite_node):
        root = self.root()
        unite_root = unite_node.root()

        if root.group_id_ != unite_root.group_id_:
            if root.rank() > unite_root.rank():
                unite_root.parent_ = root
                root.rank_ = max(root.rank_, unite_root.rank_ + 1)
                root.value_ += unite_root.value_
            else:
                root.parent_ = unite_root
                unite_root.rank_ = max(root.rank_ + 1, unite_root.rank_)
                unite_root.value_ += root.value_


N, M = map(int, input().split())
AB_array = [list(map(int, input().split())) for i in range(M)]
ans_array = [0] * M
# print(AB_array)
node_list = [UnionFindNode(i) for i in range(N)]

ans = N * (N - 1) / 2

for m in range(M - 1, -1, -1):
    ans_array[m] = int(ans)
    if node_list[AB_array[m][0] - 1].find() == node_list[AB_array[m][1]
                                                         - 1].find():
        continue
    A_value = node_list[AB_array[m][0] - 1].get_value()
    B_value = node_list[AB_array[m][1] - 1].get_value()
    node_list[AB_array[m][0] - 1].unite(node_list[AB_array[m][1] - 1])
    ans -= A_value * B_value
    if ans == 0:
        break

for ans in ans_array:
    print(ans)


Measured memory_bytes: 96088
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


void query(int s,int t){
    cout<<"? "<<s<<" "<<t<<endl;
}
int main(){
    int n,s,t;
    cin>>n>>s>>t;
    int d;
    query(s,t);
    cin>>d;
    vector<int> ds(n+1),dt(n+1);
    vector<int> a;
    rep(i,n){
        if(i+1==s)continue;
        query(s,i+1);
        cin>>ds[i+1];
        query(i+1,t);
        cin>>dt[i+1];
        if(ds[i+1]+dt[i+1]==d)a.push_back(i+1);
    }

    sort(a.begin(),a.end(),[&](int x,int y){
        return ds[x]<ds[y]; 
    });
    vector<int> ans;
    ans.push_back(s);
    for(auto e : a){
        int cur=ans.back();
        query(cur,e);
        int x;
        cin>>x;
        if(ds[cur]+x+dt[e]==d)ans.push_back(e);
        else continue;
    }
    cout<<"! ";
    for(auto e : ans){
        cout<<e;
        if(e!=ans.back())cout<<" ";
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 4652
#include<bits/stdc++.h>
using namespace std;
int a[100005][4];
int dp[100005][4];
int n;
 
int func(int ind, int flag) {
 
	if (ind == n) return 0;
 
	if (dp[ind][flag] != -1) return dp[ind][flag];
 
	int maxi = 0;
	if (flag == 0) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 1) {
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else if (flag == 2) {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][3] + func(ind + 1, 3));
	}
	else {
		maxi = max(maxi, a[ind][1] + func(ind + 1, 1));
		maxi = max(maxi, a[ind][2] + func(ind + 1, 2));
	}
 
	return dp[ind][flag] = maxi;
}
 
int main() {
 
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> a[i][j];
		}
	}
 
	memset(dp, -1, sizeof dp);
 
	cout << func(0, 0);
 
	return 0;
}

Measured memory_bytes: 14484
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    vector<int> common(26, INF);
    vector<int> cnt;
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i){
        string s;
        cin >> s;
        cnt.assign(26, 0);
        int len = s.length();
        for(int j = 0; j < len; ++j)    ++cnt[s[j] - 'a'];
        for(int j = 0; j < 26; ++j) chmin(common[j], cnt[j]);
    }
    string ans = "";
    for(int i = 0; i < 26; ++i){
        for(int j = 0; j < common[i]; ++j){
            ans += 'a' + i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<map>
#include<ctime>

using namespace std;

template <typename T>

inline T read()
{
	T x=0,f=1;char c=getchar();
	while(!isdigit(c))
	{if(c=='-') f=-f;c=getchar();}
	while(isdigit(c))
	{x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint

const int inf=1e9+1e7;
const int MAXN=1e4+1e1;
const int Mod=2019;

int t[MAXN];

int ans=0;
string s;

int main(void)
{

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	cin>>s;

	int l=s.length();
	int x=0,cnt=1;

	t[0]=1;

	for(int i=l-1;i>=0;i--)
	{
		x=(x+(s[i]-'0')*cnt)%Mod;
		cnt=cnt*10%Mod;
		ans+=t[x];
		++t[x];
	}

	printf("%d\n",ans);

	return 0;

}

Measured memory_bytes: 3852
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int maxHappines = 0;
        Scanner sc = new Scanner(System.in);
        int vacationDays = sc.nextInt();
        sc.nextLine();
        //A = 0, B = 1, C = 2
        int[][] happines = new int[vacationDays][3];
        for (int i = 0; i < vacationDays; i++) {
            happines[i][0] = sc.nextInt();
            happines[i][1] = sc.nextInt();
            happines[i][2] = sc.nextInt();
        }

        int[][] res = new int[vacationDays][3];
        res[0][0] = happines[0][0];
        res[0][1] = happines[0][1];
        res[0][2] = happines[0][2];

        for (int day = 1; day < vacationDays; day++) {
            for (int action = 0; action < 3; action++) {
                res[day][action] = 0;
                for (int previousAction = 0; previousAction < 3; previousAction++) {
                    if (action == previousAction) {
                        continue;
                    }
                    res[day][action] = Math.max(res[day][action], res[day - 1][previousAction] + happines[day][action]);
                }
            }
        }
        Integer[] result = {res[vacationDays - 1][0], res[vacationDays - 1][1], res[vacationDays - 1][2]};

        System.out.println(Collections.max(Arrays.asList(result)));

    }
}


Measured memory_bytes: 98264
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] ch = sc.nextLine().toCharArray();
        
        int count = 0;
        
        for(int i=0;i<ch.length-1;i++){
            if(ch[i]==ch[i+1]){
                ch[i+1] = (ch[i]=='0')?'1':'0';
                count++;
            }
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 27068
#include<bits/stdc++.h>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
#include<chrono>
using namespace std;
using namespace std::chrono;
//using namespace __gnu_pbds;
#define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi         first
#define se         second
#define int         long long
#define pb         push_back
#define emp        emplace_back
#define vv(x)      vector<x>
#define mp(x,y)    map<x,y>
#define dq(x)      deque<x>
#define pql(x)     priority_queue<x>
#define pqs(x)     priority_queue<x,vv(x),greater<x> >
#define mod         1000000007
#define forf(i,a,b) for(int i=a;i<b;i++)
#define it(x)      x::iterator
#define ll         long long
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
#define vii        vector<int>
#define big        3e18
#define sm         -2e9
#define mkr        make_pair
#define vpi        vector<pair<int,int> >
#define pii        pair<int,int>
#define rng        500005
#define sz(x)      (int)x.size()
#define rv(x)      reverse(x.begin(),x.end())
#define out(x)     cout<<x.fi<<" "<<x.se<<endl;
 
//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
 
void pr_init()
{
 
#ifndef ONLINE_JUDGE
  freopen("gin.txt", "r", stdin);
  freopen("gout.txt", "w", stdout);
 
#endif
}

void solve()
{
  
  int x;
  cin >> x;

  if(x>=400&&x<600) cout<<"8\n";
  if(x>=600&&x<800) cout<<"7\n";
  if(x>=800&&x<1000) cout<<"6\n";
  if(x>=1000&&x<1200) cout<<"5\n";
  if(x>=1200&&x<1400) cout<<"4\n";
  if(x>=1400&&x<1600) cout<<"3\n";
  if(x>=1600&&x<1800) cout<<"2\n";
  if(x>=1800&&x<2000) cout<<"1\n";
  
  
}
 
 
int32_t main()
{
 // pr_init();
  //fastio;
 
  auto start = high_resolution_clock::now();
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start);
  // cout << "Time taken by function: "
  //       << duration.count() << " microseconds" << endl;
 
}
 

Measured memory_bytes: 3632
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int L = Integer.parseInt(S[0]);
    int R = Integer.parseInt(S[1]);
    
    int min = 2019;
    for(int i = L; i <= R && i < L+2018; i++){
      for(int j = i+1; j <= R && j < L+2019; j++){
        int n = (i % 2019) * (j % 2019);
        if(n % 2019 < min){
          min = n%2019;
        }
      }
    }
    
    System.out.println(min);
  }
}

Measured memory_bytes: 23636
#include <algorithm>
#include <iostream>
#include <cstring>
#include <iomanip>
#include <vector>
using namespace std;

typedef long long ll;

const int MAX_N = 2e5 + 10, MOD = 1e9 + 7;
ll A, B, C, D;

ll calc (ll a, ll b) {
	return a / b;
}

ll _gcd (ll a, ll b) {
	return !b? a: _gcd(b, a % b);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> A >> B >> C >> D;
	cout << B - A + 1 - (calc(B, C) - calc(A - 1, C) + calc(B, D) - calc(A - 1, D) - calc(B, C / _gcd(C, D) * D) + calc(A - 1, C / _gcd(C, D) * D)) << "\n";
	return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).ok();
	s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().split_whitespace()
		.map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
	(0..n).map(|_| read_vec()).collect()
}

pub trait LexicalPermutation {
	/// Return `true` if the slice was permuted, `false` if it is already
	/// at the last ordered permutation.
	fn next_permutation(&mut self) -> bool;
}
impl<T> LexicalPermutation for [T] where T: Ord {
	/// Original author in Rust: Thomas Backman <serenity@exscape.org>
	fn next_permutation(&mut self) -> bool {
		// These cases only have 1 permutation each, so we can't do anything.
		if self.len() < 2 { return false; }

		// Step 1: Identify the longest, rightmost weakly decreasing part of the vector
		let mut i = self.len() - 1;
		while i > 0 && self[i-1] >= self[i] {
			i -= 1;
		}

		// If that is the entire vector, this is the last-ordered permutation.
		if i == 0 {
			return false;
		}

		// Step 2: Find the rightmost element larger than the pivot (i-1)
		let mut j = self.len() - 1;
		while j >= i && self[j] <= self[i-1]  {
			j -= 1;
		}

		// Step 3: Swap that element with the pivot
		self.swap(j, i-1);

		// Step 4: Reverse the (previously) weakly decreasing part
		self[i..].reverse();

		true
	}
}

fn main() {
	let s: String = read();
	let s: Vec<char> = s.chars().collect();
	if s[0] == s[1] && s[1] == s[2] {
		println!("No");
	} else {
		println!("Yes");
	}
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;
typedef long long LL;

const int Pi = acos(-1.0);
const int INf = 0x7fffffff;
const int eps = 1e-9;

int sgn(double d) {
    if(abs(d) < eps)
        return 0;
    if(d > 0)
        return 1;
    return -1;
}

int dcmp(double x, double y) {
    if(abs(x - y) < eps)
        return 0;
    if(x > y)
        return 1;
    return -1;
}

struct Point {
    double x, y;
    Point(double _x = 0, double _y = 0):x(_x), y(_y){}
};

typedef Point Vector;

Vector operator + (Vector A, Vector B) {
    return Vector(A.x + B.x, A.y + B.y);
}

Vector operator - (Point A, Point B) {
    return Vector(A.x - B.x, A.y - B.y);
}

Vector operator * (Vector A, double p) {
    return Vector(A.x * p, A.y * p);
}

Vector operator / (Vector A, double p) {
    return Vector(A.x / p, A.y / p);
}

bool operator == (const Point &a, const Point &b) {
    if(sgn(a.x-b.x) == 0 && sgn(a.y-b.y) == 0)
        return true;
    return false;
}

double Dot(Vector A, Vector B) {
    return A.x * B.x + A.y * B.y;
}

double Cross(Vector A, Vector B) {
    return A.x * B.y - B.x * A.y;
}

double Length(Vector A) {
    return sqrt(Dot(A, A));
}

double Angle(Vector A, Vector B) {
    return acos(Dot(A, B) / Length(A) / Length(B));
}

double Area2(Point A, Point B, Point C) {
    return Cross(B - A, C - A);
}

Vector Rotate(Vector A, double rad) { // 逆时针旋转rad
    return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) - A.y * cos(rad));
}

Vector Normal(Vector A) {      //A左转90°的单位法向量
    double L = Length(A);
    return Vector(-A.y / L, A.x / L);
}

bool ToLeftTest(Point a, Point b, Point c) {
    return Cross(b - a, c - a) > 0;
}

struct Line {
    Point v, p;
    Line(Point v, Point p) : v(v), p(p){}
    Point point(double t) {
        return v + (p - v) * t;
    }
};

Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) {
    Vector u = P - Q;
    double t = Cross(w, u) / Cross(v, w);
    return P + v * t;
}

double DistanceToLine(Point P, Point A, Point B) {
    Vector v1 = B - A, v2 = P - A;
    return fabs(Cross(v1, v2) / Length(v1));
}

double DistanceToSegment(Point P, Point A, Point B) {
    if(A == B)
        return Length(P - A);
    Vector v1 = B - A, v2 = P - A, v3 = P - B;
    if(sgn(Dot(v1, v2)) < 0)
        return Length(v2);
    if(sgn(Dot(v1, v3)) > 0)
        return Length(v3);
    return DistanceToLine(P, A, B);
}

Point GetLineProjection(Point P, Point A, Point B) {
    Vector v = B - A;
    return A + v * (Dot(v, P - A) / Dot(v, v));
}

int main() {
    Point A, B, P;
    scanf("%lf%lf%lf%lf", &A.x, &A.y, &B.x, &B.y);
    int q;
    scanf("%d", &q);
    while(q--) {
        scanf("%lf%lf", &P.x, &P.y);
        Point ans = GetLineProjection(P, A, B);
        printf("%.10f %.10f\n", ans.x, ans.y);
    }
    return 0;
}



Measured memory_bytes: 3252
def add(n):
    l = []
    if(n%10 == 0):
        l.append(n*10)
        l.append(n*10+1)
    elif(n%10 == 9):
        l.append(n*10+8)
        l.append(n*10+9)
    else:
        l.append(n*10+n%10-1)
        l.append(n*10+n%10)
        l.append(n*10+n%10+1)
    return l
k = int(input())
list = [1,2,3,4,5,6,7,8,9]
i = 0
while(len(list)<k):
    list += add(list[i])
    i += 1
print(list[k-1])

Measured memory_bytes: 7124
import java.io.*;

class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int h = Integer.parseInt(br.readLine());
		StringBuilder sb = new StringBuilder();
		int a,b;
		for(int i=0 ;i<h ;i++){
			String[] str1 = br.readLine().split(" ");
			a = Integer.parseInt(str1[1]);
			b = Integer.parseInt(str1[2]);
			if(str1[0].equals("reverse")){
				sb.append(str.substring(a,b+1));
				String x = sb.reverse().toString();
				sb.setLength(0);
				sb.append(str);
				sb.replace(a,b+1,x);
				str = sb.toString();
				sb.setLength(0);
			}
			if(str1[0].equals("replace")){
				sb.append(str);
				sb.replace(a,b+1,str1[3]);
				str = sb.toString();
				sb.setLength(0);
			}
			if(str1[0].equals("print")){
				System.out.println(str.substring(a,b+1));
			}
		}
	}
}

Measured memory_bytes: 21336
#include<bits/stdc++.h>
#define lli long long int 
using namespace std;

lli funFrogJump(lli n,lli *dp,lli *values){
	if(n==0||n==1){
		dp[n] = 0;
		return 0;
	}
	if(n==2){
		dp[n] = abs(values[n-1]-values[n-2]);
		return dp[n];
	}
	if(dp[n]!=-1) return dp[n];
	dp[n] = min(funFrogJump(n-1,dp,values)+abs(values[n-1]-values[n-2]),funFrogJump(n-2,dp,values)+abs(values[n-1]-values[n-3]));
	return dp[n];
}

int main(){
	lli n;
	cin>>n;
	lli a[n];
	for(lli i=0;i<n;i++) cin>>a[i];
	lli dp[n+1];
	for(lli i=0;i<=n;i++) dp[i] = -1;
	cout<<funFrogJump(n,dp,a)<<endl;
	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define P pair<long,long>
#define all(a) a.begin(),a.end()
using namespace std;
signed main(){
    int n; cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a.at(i);
    int ans=1;
    if(n==1 or n==2){
        cout<<ans<<endl; return 0;
    }
    bool isup=true, isfirst=true, islast=false;
    rep(i,n-1){
        if(a.at(i)<a.at(i+1)){
            if(isfirst){
                isup=true; isfirst=false;
                continue;
            }
            if(!islast and !isup){
                ans++;
                islast=true;
                isup=true;
                continue;
            }
            islast=false;
            isup=true;
        }else if(a.at(i)>a.at(i+1)){
            if(isfirst){
                isup=false; isfirst=false;
                continue;
            }
            if(!islast and isup){
                ans++;
                islast=true;
                isup=false;
                continue;
            }
            islast=false;
            isup=false;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main()
{

  int a,b,c,i,count=0;;
  scanf("%d%d%d",&a,&b,&c);
 
  for(i=a;i<=b;i++){
    if(c%i==0) count++;
  }
  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9+7;
const int mod= 1e9 + 7;

ll A[10000];
ll B[10000];

ll N,ans;

int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N;
	FOR(i, 0, N) {
		ll cur; cin >> cur;
		ll cnt = 0;
		FOR(j,0,61){
			if (cur % 2 == 1)A[cnt]++;
			else B[cnt]++;
			cur /= 2;
			cnt++;
		}
	}
	ll cur = 1;
	FOR(i, 0, 61) {
		ans = (ans + ((A[i] * B[i])%mod)*cur) % mod;
		cur = (cur * 2) % mod;
	}
	cout << ans %mod<< endl;

	return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll A,B,N;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>N;
	if(N>=B) N=B-1;
	cout<<(A*N/B)-A*(N/B)<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3548
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
int INF = 1e9 + 7;
ll MOD = 998244353;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	vector<vector<ll>> dp(c+10,vector<ll>(d+10,0));
	
	for(int i = a; i <= c; ++i){
		for(int j = b; j <= d; ++j){
			if(i == a && j == b){
				dp[i][j] = 1;
				continue;
			}
			dp[i][j] = dp[i-1][j]*j + dp[i][j-1]*i - dp[i-1][j-1]*(i-1)*(j-1);
			//dp[i][j] %= MOD;
			dp[i][j] = (MOD + dp[i][j] % MOD) % MOD;
		}
	}
	cout << dp[c][d] << endl;
	return 0;
}


Measured memory_bytes: 74148
#include <stdio.h>


    int writelist[300000];
    int unko;
    
int write(int N,int x){
    if(unko>=N){
        for(int i=0;i<N;i++){
            if(writelist[i]>N||writelist[i]<=0){printf("-1");return 1;}
        }
        for(int i=0;i<N;i++)printf("%d ",writelist[i]);
        return 1;
    }
    else{
        writelist[unko]=x;
        unko++;
        return 0;
    }
}

int main(void){
    unko=0;
    int N,A,B;
    scanf("%d %d %d",&N,&A,&B);
    if(A+B>N+1)printf("-1");
    else{
        int gensyo=0;
        for(int i=1;;i++){
            for(int j=N-A*i+1;j<=N-A*(i-1);j++){if(write(N,j)==1)return 0;}//printf("%d ",j);//TODO
            gensyo++;
            if(N-i*A>=B-gensyo&&N-(i+1)*A<B-(gensyo+1)){
                int leng=N-i*A-(B-gensyo-1);
                for(int j=N-i*A-leng+1;j<=N-i*A;j++){if(write(N,j)==1)return 0;}
                for(int j=N-i*A-leng;j>=1;j--){if(write(N,j)==1)return 0;}
                break;
            }
        }
    }
    write(N,0);
    return 0;
}


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

int main(){
  int n; cin >> n;
  vector<int> D(n);
  int MAX = 0;
  rep(i,n){
    cin >> D[i];
    MAX = max(MAX, D[i]);
  }
  if (D[0] != 0){
    cout << 0 << endl;
    return 0;
  }
  sort(D.begin(),D.end());
  if (n > 1 && D[1] == 0){
    cout << 0 << endl;
    return 0;
  }
  int countA = 0, countB = 1;
  ll ans = 1;
  for(int i=1; i<n; i++){
    if (D[i] > D[i-1] + 1){
        cout << 0 << endl;
        return 0;
    }
    if (D[i] == D[i-1]+1){
      countA = countB;
      countB = 0;
    }
    ans *= countA;
    ans %= MOD;
    countB++;
  }
  cout << ans << endl;
  return 0;
}

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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); ++i)
#define REP(i,start,end) for(int i=(start);i<=(end);++i)
#define all(n) begin(n),end(n)

#define DEBUG

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

	if(m == n) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;
typedef pair<int,int> P;

ll gcd(ll x,ll y){
  return y? gcd(y,x%y):x;
}
ll lcm(ll x,ll y){
  return x*y/gcd(x,y);
}

P f(int n){
  int a,b=n%10;
  while(n){
    a=n;
    n/=10;
  }
  return P(a,b);
}

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

  map<P,int> freq;
  REP2(i,1,n+1){
    P p=f(i);
    freq[p]++;
  }
  ll ans=0;
  REP2(i,1,10){
    REP2(j,1,10){
      P p=make_pair(i,j),q=make_pair(j,i);
      ans+=freq[p]*freq[q];
    }
  }

  cout<<ans<<endl;
  
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

///////////////////////////////////////////////////////////////////////////



int main(){

    ll x,k,d;
    cin >> x >> k >> d;

    if(x < 0)x = -x;

    if(x/d >= k){
	x -= d*k;
	P(x);
	ret 0;
    }else{
	k -= x/d;
	x %= d;

	if(k&1){
	    P(min(abs(x+d),abs(x-d)));
	}else{
	    P(x);
	}
    }
    return  0;
}


Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ABC155A
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var tmp = NNList(3);
            if (tmp.Distinct().Count() > 2 || tmp.Distinct().Count() == 1)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}


Measured memory_bytes: 15200
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final String s = scanner.next();
        final String t = scanner.next();
        final long count = IntStream.range(0, s.length())
            .filter(i -> s.charAt(i) == t.charAt(i))
            .count();
        System.out.println(count);
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

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

Measured memory_bytes: 27988
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define endl "\n"
#define all(v) (v).begin(),(v).end()
#define sz(v) (v).size()
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define d0(x) cout<<(x)<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define d5(a,b,c,d,e) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<endl
#define d6(a,b,c,d,e,f) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<" "<<(e)<<" "<<(f)<<endl
bool desc_sort(const int & lhs,const int & rhs)
{
    return lhs>rhs;
}
bool desc_pii_sort(const pii & lhs , const pii & rhs)
{
    return lhs>rhs;
}
bool second_sort(const pii & lhs , const pii & rhs)
{
    pii a,b;
    a.F = lhs.S;
    a.S = lhs.F;
    b.F = rhs.S;
    b.S = rhs.F;
    return a<b;
}
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    return os << "]";
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
#else
    #define trace(...)
#endif


// #define int long long
#define modd 1e0



inline ll fast_expo(ll base,ll power,ll modulo=modd){
    base%=modulo;
    if (base<0LL) base+=modulo;
    ll x=base,cnt=power,ans=1LL;
    while(cnt){
        if (cnt&1LL) ans=(ans*x)%modulo;
        x=(x*x)%modulo;
        cnt>>=1LL;
    }
    // int tmp=ans;
    return ans;
}
inline ll inv(ll base,ll modulo=modd){
    return fast_expo(base,modulo-2LL,modulo);
}



signed main()
{
    #ifdef _SUBLIME
    ifstream cin("input.txt");
    ofstream cout("output.txt");
    #endif
    fio;
    int n;
    cin>>n;
    n = n%10;
    if(n==3)
        cout<<"bon\n";
    else if(n==0 or n==1 or n==6 or n==8)
        cout<<"pon\n";
    else
        cout<<"hon\n";
    return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;
import java.util.Stack;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Stack<Integer> stack = new Stack<Integer>();
		while (sc.hasNext()) {
			int inputNum = sc.nextInt();
			//??????0??§???????????????????????????pop
			if (inputNum == 0) {
				System.out.println(stack.pop());
			//0??\??????????????\???????????????push
			} else {
				stack.push(inputNum);
			}
		}
	}

}

Measured memory_bytes: 17208
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; 
typedef long long int ll;
#define ull unsigned long long int
#define all(a) a.begin(),a.end()s
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define hell 1000000007
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define pb push_back
#define MAX 10000001
int main()
{
    ll a,b;
    cin>>a>>b;
    if(a!=1&&b!=1)
        cout<<"1";
    else if(a!=2&&b!=2)
        cout<<"2";
    else
        cout<<"3";
}

Measured memory_bytes: 256
#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 <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main () {
  int n, m;
  cin >> n >> m;
  vector<int> l(m);
  vector<int> r(m);
  REP(i, m){
    cin >> l[i] >> r[i];
  }
  int max = *min_element(r.begin(), r.end());
  int min = *max_element(l.begin(), l.end());
  if (min>max) cout << 0;
  else cout << max-min+1;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)
ll mod=1e9+7;
//cout << fixed << setprecision(14);
//cf dont use unordered map. use simply map<... , ... > m;

//They are Iterator minus v.begin() krna //lower_bound(v.begin(),v.end(),x)-v.begin()  //upper_bound(v.begin(),v.end(),x)-v.begin()
// lower bound tells greater than or equal to // upper bound tells strictly greater than
//int a[1001][1001] //aise global me hi// ll lcm(ll a, ll b){ return a / __gcd(a, b) * b; }
//memset can initialize to 0 or -1 ONLY //memset(str, 't', sizeof(str)); // string //memset(a, 0, sizeof(a));  //1D array    // memset(a,0,sizeof(a[0][0])*n*n); //2D array
// set.insert(),find() //for(auto it=set.begin();....) cout<<*it;   // sort(v.begin(),v.end(),compare)

void solve()
{
    int k,a,b;cin>>k>>a>>b;
bool ans=false;
    f(i,a,b+1)
    {
    	if(i%k==0) ans=true;
    }
    if(ans) cout<<"OK";
    else cout<<"NG";

}

int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
    //cin>>t;
    while(t--)
    {
     solve();
    }
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define INF 1e9
using namespace std;
int main(){
  int n,m,l,k,a,h,t1,t2,t3;
  while(cin>>n>>m>>l>>k>>a>>h,n){
    set<int>q;q.insert(a),q.insert(h);
    int b[n][n],e,x[n][n];
    r(i,n)r(j,n)x[i][j]=b[i][j]=INF;
    r(i,l)cin>>e,q.insert(e);
    r(i,k)cin>>t1>>t2>>t3,b[t1][t2]=b[t2][t1]=t3;
    r(o,n)r(i,n)r(j,n)b[i][j]=min(b[i][j],b[i][o]+b[o][j]);
    r(i,n)if(q.count(i))r(j,n)if(q.count(j))if(b[i][j]<=m)x[i][j]=b[i][j];
    r(o,n)r(i,n)r(j,n)x[i][j]=min(x[i][j],x[i][o]+x[o][j]);
    if(x[a][h]>=INF)cout<<"Help!"<<endl;
    else if(x[a][h]<m)cout<<x[a][h]<<endl;
    else cout<<x[a][h]*2-m<<endl;
  }
}

Measured memory_bytes: 3072
import scala.collection.mutable._
import io.StdIn.readInt
import io.StdIn.readLine

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  def calculate(q:Array[Int],d:Array[Array[Int]]):Int = {
    val ts = q(0)
    val te = q(1)
    val st = q(2)

    val a = d.filter(_(2) == st)
    val map = new HashMap[Int,Array[Int]]
    val log = ListBuffer.empty[Tuple2[Int,Int]]
    a.foreach(l => {
      if(l(3) == 1) map.put(l(1),l)
      else {
        val e = map.remove(l(1)).get
        log += {( e(0), l(0) )}
        }
    })
    // println(log.mkString)

    val time = Array.ofDim[Boolean](721)
    log.par.foreach(t => {
      val s = math.max(ts, t._1) -540
      val e = math.min(te, t._2) -540
      (s until e).foreach(time(_) = true)
    })
    time.count(_==true)
  }

  def solve(s:String):Unit = {
    val Array(n, m) = s.split(" ").map(_.toInt)
    val r = readInt
    val d = Iterator.continually(readLine)
      .take(r)
      .map(_.split(" ").map(_.toInt))
      .toArray
    val q = readInt
    Iterator.continually(readLine)
      .take(q)
      .map(_.split(" ").map(_.toInt))
      .foreach(qd => out.println(calculate(qd,d)))
  }

  Iterator.continually(readLine)
    .takeWhile(_ != "0 0")
    .foreach(solve(_))
  
  out.flush
}


Measured memory_bytes: 64352
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <cstdio>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;(i)>=0;(i)--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;

int main(){
    
    int N;
    cin>>N;
    vector<int> a(N*2);
    REP(i,2*N)cin>>a[i];
    
    sort(a.begin(),a.end());
    
    int ans=0;
    REP(i,N){
        ans+=min(a[i*2],a[i*2+1]);
    }
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C;
    cin>>A>>B>>C;
    int day=0;
    int count=0;
    int ans=0;
    while(1){
        if(count>=C)break;
        ans++;
        day++;
        count=count+A;
        if(day==7){day=0;count=count+B;}
    }
    cout<<ans<<endl;
    
    return 0;
    
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int n,m;
struct jxb{
	int x,y;
};
bool cmp(jxb b,jxb c){
	return b.x<c.x;
}
jxb a[100010];
int ans[200010];
map<int,int>mp;
map<int,int>f;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&a[i].x,&a[i].y);
	}
	sort(a+1,a+m+1,cmp);
	for(int i=1;i<=n;i++) ans[i]=1;
	for(int i=1;i<=m;i++){
		if(mp[a[i].y]==1){
			ans[a[i].y]=ans[a[i].y+1]=ans[a[i].y]+ans[a[i].y+1]-f[a[i].y];
			f[a[i].y]=ans[a[i].y];
		}else{
			mp[a[i].y]=1;
			ans[a[i].y]+=ans[a[i].y+1];
			ans[a[i].y+1]=ans[a[i].y];
			f[a[i].y]=ans[a[i].y];
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d",ans[i]);
		if(i!=n) printf(" ");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 13804
#include<algorithm>
#include<bits/allocator.h>
#include<bits/basic_ios.h>
#include<bits/basic_string.h>
#include<bits/basic_string.tcc>
#include<bits/c++config.h>
#include<bits/char_traits.h>
#include<bits/cpp_type_traits.h>
#include<bits/cxxabi_forced.h>
#include<bits/ios_base.h>
#include<bits/locale_classes.h>
#include<bits/localefwd.h>
#include<bits/ostream_insert.h>
#include<bits/postypes.h>
#include<bits/range_access.h>
#include<bits/stl_algobase.h>
#include<bits/stl_function.h>
#include<bits/stl_iterator.h>
#include<bits/stl_iterator_base_funcs.h>
#include<bits/stl_iterator_base_types.h>
#include<bits/stringfwd.h>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<cmath>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwchar>
#include<cwctype>
#include<debug/debug.h>
#include<deque>
#include<exception>
#include<ext/atomicity.h>
#include<ext/numeric_traits.h>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<valarray>
#include<vector>
using namespace std;
int n,l,r;
bool prime[100010];
vector<int> b,v;
int main()
{
	cin>>n;
    for(int i=2;i*i<=100000;i++)
        if(!prime[i])
            for(int j=i*i;j<=100000;j+=i) prime[j]=1;
    for (int i=3;i<=100000;i+=2) if (!prime[i]&&!prime[(i+1)/2]) v.push_back(i);
    for (int i=0;i<n;i++){
    	cin>>l>>r;
    	int num=0;
    	for (int i=0;i<=672;i++){
			if (v[i]>=l&&v[i]<=r) num++;
			if (r<v[i]) break;
		}
    	b.push_back(num);
	}
	for (int i=0;i<n;i++) cout<<b[i]<<endl;
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
void print(ll x){
	if(x<0)putchar('-'),x=-x;
	int y=x%10+'0';
	if(x>=10)print(x/10);
	putchar(y);
}
int n,m,a[105],dp[100005];
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=0;i<=m;i++)
		for(int j=1;j<=n;j++)
			if(i+a[j]>m)break;
			else if(!dp[i])dp[i+a[j]]=1;
	puts(dp[m]?"First":"Second");
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();

		if (n.charAt(2) == n.charAt(3) && n.charAt(4) == n.charAt(5)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		sc.close();

	}
}

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

bool is_palindrome(string s){
    string t(s.rbegin(),s.rend());
    return s == t;
}

int main(){
    string s;
    cin>>s;
    int n=s.size();
    if(is_palindrome(s) && is_palindrome(s.substr(0,(n-1)/2)) && is_palindrome(s.substr((n+1)/2))){
        cout<<"Yes"<<endl;
    }
    else cout<<"No\n";
    return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define ef else if
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll myXOR(ll x, ll y)
{
	return (x|y)&(~x|~y);	
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
int main()
{
	ll t,n,m,i,j,k,l,x,y,z,a,b,c,d,e,p,nl,np,q,r,s,h;
	string str,str1;
	cin>>n;
	ll arr[n];
	map<ll,vector<ll>>mp;
	ll total  =0;
	rep(i,0,n)
		cin>>arr[i];
	rep(i,0,n)
		mp[arr[i]].pb(i);
	for(auto &x:mp)
	{
		if(mp[x.first].size()>=2)
		{
			a = mp[x.first].size();
			total+=(a*(a-1))/2;
		}
	}
	rep(i,0,n)
	{
		if(mp[arr[i]].size()<2)
			cout<<total<<endl;
		else
		{
			cout<<total-(mp[arr[i]].size()-1)<<endl;
		}
	}
}

Measured memory_bytes: 17280