akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void){
  int n,m;
  cin>>n>>m;
  VI x;
  REP(i, m){
    int v;
    cin>>v;
    x.push_back(v);
  }
  SORT(x);
  VI diff;
  REP(i, m-1){
    diff.push_back(abs(x[i]-x[i+1]));
  }
  SORT(diff);
  int ans=0;
  if(m<n)ans=0;
  else{
  REP(i, m-n){
    ans+=diff[i];
  }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main(){
	int N, D;
	cin >> N >> D;
	double x, y;
	int count = 0;

	for (int i = 0; i < N; i++) {
		cin >> x >> y;
		// cout << "sqrt = " <<sqrt(x*x + y*y);
		if(sqrt(x*x + y*y) <= D) {
			count++;
		}
	}

	cout << count << '\n';
	return 0;
}

Measured memory_bytes: 3728
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx,avx2")

#include <bits/stdc++.h>

using namespace std;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define int long long

const int p = 998244353;
const int maxn = 2e5 + 10;

int t[4 * maxn], s[4 * maxn], deg[4 * maxn];

int n;
int st, ed, dt, res;

void push(int v, int l, int r) {
    if (s[v] == -1) return;
    s[2 * v] = s[v];
    s[2 * v + 1] = s[v];
    s[v] = -1;
}

int get_val(int v) {
    return (s[v] == -1 ? t[v] : deg[v] * s[v] % p);
}

void upd(int v, int l, int r) {
    if (l >= ed || r <= st) return;
    if (st <= l && r <= ed) {
        s[v] = dt;
        return;
    }
    push(v, l, r);
    upd(2 * v, l, (l + r) / 2);
    upd(2 * v + 1, (l + r) / 2, r);
    t[v] = (get_val(2 * v) + get_val(2 * v + 1)) % p;
}

int bin_pow(int x, int m) {
    int ans = 1;
    while (m) {
        if (m & 1) ans = (ans * x) % p;
        x = (x * x) % p;
        m >>= 1;
    }
    return ans;
}

void build(int v, int l, int r) {
    s[v] = -1;
    if (l + 1 == r) {
        deg[v] = bin_pow(10, n - l - 1);
        t[v] = deg[v];
        return;
    }
    build(2 * v, l, (l + r) / 2);
    build(2 * v + 1, (l + r) / 2, r);
    deg[v] = (deg[2 * v] + deg[2 * v + 1]) % p;
    t[v] = (get_val(2 * v) + get_val(2 * v + 1)) % p;
}

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

    int q;
    cin >> n >> q;
    build(1, 0, n);
    for (int i = 0; i < q; i++) {
        cin >> st >> ed >> dt;
        st--;
        upd(1, 0, n);
        cout << get_val(1) << '\n';
    }
    return 0;
}


Measured memory_bytes: 15972
// -*- coding:utf-8-unix -*-

use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        x: usize,
        t: usize,
    }
    if n % x == 0 {
        println!("{}", t * (n / x));
    } else {
        println!("{}", t * (n / x + 1));
    }
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define mp make_pair
#define ff first
#define ss second
#define bg begin()
#define en end()
#define pb push_back
#define w(x) scanf("%d",&x);while(x--)
#define ws(x) scanf("%d",&x);getchar();while(x--)
#define rep(i,b) for(i=0;i<=b;i++)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 2*acos(0.0)
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int N=1e6+2;
long long  mod=1e9+9;
int t,j,cs=0,n,a,b,i,dxx[]={1,0,0,-1},dyy[]={0,-1,1,0},k,m;
string s;

int main()
{
    scanf("%d",&n);
    vi dp(3,0),ar(3);
    rep(i,n-1){
        vi ndp(3,0);
        rep(j,2){
            scanf("%d",&ar[j]);
        }
        rep(j,2){
            rep(k,2){
                if(j!=k){
                     ndp[k]=max(ndp[k],dp[j]+ar[k]);
                }

            }
        }
        dp=ndp;
    }
    printf("%d\n",max({dp[0],dp[1],dp[2]}));
}



Measured memory_bytes: 3712
import java.util.*;
import java.io.*;
import java.math.BigInteger;
 
public class Main {
	public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	long A = s.nextLong();
	long B = s.nextLong();
	long K = s.nextLong();

	if(A >= K){
		A = A - K;
		K = 0;
	}else{
		K = K - A;
		A = 0;
	}

	if(K > 0){
		if(B >= K){
			B = B - K;
			K = 0;
		}else{
			K = 0;
			B = 0;
		}
	}
	
	System.out.println(A + " " + B);

    
  }
}

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

using namespace std;

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

    int x, y, a, b, c;

    cin >> x >> y >> a >> b >> c;

    priority_queue<int> p, q, r, all;
    int tmp;

    for(int i = 0; i < a; ++i) {
        cin >> tmp;
        p.emplace(tmp);
    }
    for(int i = 0; i < b; ++i) {
        cin >> tmp;
        q.emplace(tmp);
    }
    for(int i = 0; i < c; ++i) {
        cin >> tmp;
        r.emplace(tmp);
    }

    for(int i = 0; i < x; ++i) {
        all.emplace(p.top());
        p.pop();
    }
    for(int i = 0; i < y; ++i) {
        all.emplace(q.top());
        q.pop();
    }
    for(int i = 0; i < c; ++i) {
        all.emplace(r.top());
        r.pop();
    }

    long long ans = 0;

    for(int i = 0; i < x + y; ++i) {
        ans += all.top();
        all.pop();
    }

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

    return 0;
}

Measured memory_bytes: 3572
import java.io.*;

public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br=
		new BufferedReader(new InputStreamReader(System.in));
		
		String str1=br.readLine();
		String[] strs=str1.split(" ",3);
		int[] nums=new int[3];
		int num=0;
		for (int i=0;i<3;i++){
			nums[i]=Integer.parseInt(strs[i]);
		}
		num=nums[0];
		nums[0]=nums[1];
		nums[1]=num;
		num=nums[0];
		nums[0]=nums[2];
		nums[2]=num;
		System.out.print(nums[0]+" "+nums[1]+" " +nums[2]);
	}
}

Measured memory_bytes: 21204
#include <iostream>
#include <limits>
#include <vector>

auto get_digists(int a) -> std::vector<int>
{
    auto result = std::vector<int>();
    while(true)
    {
        if(a == 0)
        {
            break;
        }
        int tmp = a % 10;
        a = a / 10;
        result.push_back(tmp);
        /* std::cout << tmp << " "; */
    }
    std::cout <<  std::endl;

    return result;
}

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

    int min = std::numeric_limits<int>::max();

    for (int i = 1; i < n; ++i) {
        int a = i;
        int b = n - a;

        /* std::cout << a << " " << b << std::endl; */
        auto a_vec = get_digists(a);
        auto b_vec = get_digists(b);

        int sum = 0;
        for(auto aa: a_vec)
        {
            sum += aa;
        }
        for(auto bb: b_vec)
        {
            sum += bb;
        }

        min = std::min(sum, min);
    }
    std::cout << min << std::endl;

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n,p,i;
    cin>>n;
    string s;cin>>s;
    p=s.size();
    if(p<=n)
    cout<<s;
    else{
        for(i=0;i<n;i++)
        cout<<s[i];
        cout<<"...";
    }
    return 0;

}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

template <int mod>
struct ModInt {
    ll x;
    ModInt() : x(0) {}
    ModInt(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = 1LL * x * p.x % mod; return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        ll a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(ll n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
};
const int mod = 1000000007;
using mint = ModInt<mod>;

template <typename T>
struct Combination {
    vector<T> _fac, _finv, _inv;

    Combination(int n) : _fac(n+1), _finv(n+1), _inv(n+1){
        _fac[0] = _finv[n] = _inv[0] = 1;
        for (int i = 1; i <= n; ++i) _fac[i] = _fac[i-1] * i;
        _finv[n] /= _fac[n];
        for (int i = n-1; i >= 0; --i) _finv[i] = _finv[i+1] * (i+1);
        for (int i = 1; i <= n; ++i) _inv[i] = _finv[i] * _fac[i-1];
    }
    inline T fac(int k) const { return _fac[k]; }
    inline T finv(int k) const { return _finv[k]; }
    inline T inv(int k) const { return _inv[k]; }

    T perm(int n, int k) const {
        return (k < 0 || n < k) ? 0 : fac(n) * finv(n-k);
    }
    T comb(int n, int k) const {
        return (k < 0 || n < k) ? 0 : fac(n) * finv(k) * finv(n-k);
    }
};
Combination<mint> C(2000010);

int main(){
    int x, y;
    cin >> x >> y;
    if ((-x + 2 * y) % 3 != 0 || (2 * x - y) % 3 != 0) {cout << 0 << endl; return 0;}
    int a = (-x + 2 * y) / 3;
    int b = (2 * x - y) / 3;

    cout << C.comb(a + b, a) << endl;
}

Measured memory_bytes: 50056
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
#include<deque>
#include<iomanip>
#include<ctime>
using namespace std;

int main()
{
	unsigned long long int H, W;
	cin >> H >> W;

	if (H == 1 || W == 1)
	{
		cout << "1" << endl;
		return 0;
	}
	else if ((H * W) % 2 == 0)
	{
		cout << (H * W) / 2 << endl;
		return 0;
	}
	else if ((H * W) % 2 == 1)
	{
		cout << (H * W) / 2 + 1 << endl;
		return 0;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int gcd(lint m,lint n){
  if(n==0)return m;
  else return gcd(n,m%n);
}

int main(){
  int N;
  cin>>N;
  int A[N];
  REP(i,N)cin>>A[i];
  int R[N],L[N];
  L[0]=0;
  R[N-1]=0;
  for(int i=1;i<N;i++)L[i]=gcd(L[i-1],A[i-1]);
  for(int i=N-2;i>=0;i--)R[i]=gcd(R[i+1],A[i+1]);
  // REP(i,N)cerr<<L[i]<<" "<<R[i]<<endl;
  int ans=0;
  REP(i,N)ans=max(ans,gcd(L[i],R[i]));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1408
#include<queue>
#include<cstdio>

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

using namespace std;

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

int h,w,c;

struct Panel{ int a[8][8]; };
struct Point{ int x,y; };

int count(const Panel &pnl){
	int ans=1;
	bool visited[8][8]={}; visited[0][0]=true;

	queue<Point> qu; qu.push((Point){0,0});
	while(!qu.empty()){
		Point p=qu.front(); qu.pop();
		rep(i,4){
			Point q={p.x+dx[i],p.y+dy[i]};
			if(0<=q.y && q.y<h && 0<=q.x && q.x<w
			&& !visited[q.y][q.x] && pnl.a[q.y][q.x]==c){
				visited[q.y][q.x]=true;
				ans++;
				qu.push((Point){q.x,q.y});
			}
		}
	}

	return ans;
}

int dfs(Panel pnl,int depth){
	if(depth==5) return count(pnl);

	int ans=0;
	char prev=pnl.a[0][0];
	for(int cc=1;cc<=6;cc++){
		if(cc==prev || (depth==4 && cc!=c)) continue;
		Panel tmp=pnl;

		pnl.a[0][0]=cc;
		bool visited[8][8]={}; visited[0][0]=true;
		queue<Point> qu; qu.push((Point){0,0});
		while(!qu.empty()){
			Point p=qu.front(); qu.pop();
			rep(i,4){
				Point q={p.x+dx[i],p.y+dy[i]};
				if(0<=q.y && q.y<h && 0<=q.x && q.x<w
				&& !visited[q.y][q.x] && pnl.a[q.y][q.x]==prev){
					visited[q.y][q.x]=true;
					pnl.a[q.y][q.x]=cc;
					qu.push((Point){q.x,q.y});
				}
			}
		}

		ans=max(ans,dfs(pnl,depth+1));

		pnl=tmp;
	}

	return ans;
}

int main(){
	for(;scanf("%d%d%d",&h,&w,&c),h;){
		Panel pnl;
		rep(i,h) rep(j,w) scanf("%d",&pnl.a[i][j]);

		printf("%d\n",dfs(pnl,0));
	}

	return 0;
}

Measured memory_bytes: 0
unittest
{
	assert( [ "5 2", "2 4 5 1 3", "3 4 -10 -8 8" ].solve == 8 );
	assert( [ "2 3", "2 1", "10 -7" ].solve == 13 );
	assert( [ "3 3", "3 1 2", "-1000 -2000 -3000" ].solve == -1000 );
	assert( [ "10 58", "9 1 6 7 8 4 3 2 10 5", "695279662 988782657 -119067776 382975538 -151885171 -177220596 -169777795 37619092 389386780 980092719" ].solve == 29507023469 );

	assert( [ "3 1", "2 3 1", "-1 -2 -3" ].solve == -1 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.format;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = 0L;
	auto k = 0L;
	input.front.formattedRead!"%s %s"( n, k );
	input.popFront;
	auto ps = input.front.split.to!( long[] );
	ps[] -= 1;
	input.popFront;
	auto cs = input.front.split.to!( long[] );
	
	auto ans = long.min;
	foreach( i, p; ps )
	{
		auto t = 0L;
		auto c = 0L;
		
		// 1周するまでのスコアと移動回数を計算
		foreach( j; 0L .. k )
		{
			t += cs[ p ];
			ans = max( ans, t );
			c++;
			if( p == i ) break;
			p = ps[ p ];
		}
		
		// 最大までループしたあとにいくつか移動する場合のスコアを計算
		auto r = k / c - 1;
		t *= r;
		c *= r;
		foreach( j; c .. k )
		{
			p = ps[ p ];
			t += cs[ p ];
			ans = max( ans, t );
		}
	}
	return ans;
}


Measured memory_bytes: 3292
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define mt make_tuple
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<ll,ll> pi;
typedef stringstream sst;
typedef vector<ll> vi;

int h,w;

bool larger(int a,int b,int c,int d){
	return a*a+b*b > c*c+d*d || a*a+b*b == c*c+d*d && a>c;
}

void main2(){
	int H=999,W=0;
	rep2(i,1,200)rep2(j,i+1,200){
		if(larger(i,j,h,w) && larger(H,W,i,j))H=i,W=j;
	}
	cout<<H<<" "<<W<<endl;
}

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>h>>w && h){
		main2();
	}
}

Measured memory_bytes: 1192
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

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

    for (int a = 0; a <= n; a++) {
        for (int b = 0; b <= (n - a); b++) {
            int i = 10000 * a + 5000 * b + 1000 * (n - a - b);
            if (i > y) {
                break;
            }

            if (i == y) {
                cout << a << " " << b << " " << (n - a - b) << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;

    return 0;
}

Measured memory_bytes: 256
<?php
  
  list($s) = explode(" ", trim(fgets(STDIN)));

  $n = strlen($s);
  $a = -1;
  $z = -1;
  for ($i=0; $i<$n; $i++) {
    if($s[$i] == "A" && $a == -1) {
      $a = $i;
    }
    if($s[$i] == "Z"){
      $z = $i;
    }
  }

  echo $z - $a + 1;

Measured memory_bytes: 16472
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static String str;
	static Scanner scan = new Scanner(System.in);
	public static void main(String[] args) {
		//???????????????????????°???dice???????´?
		str = scan.nextLine();
		String[] dice1 = str.split(" ");
		str = scan.nextLine();
		String[] dice2 = str.split(" ");
		
		
		if(sort(dice1, dice2)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
		
	}

	
	private static boolean sort(String[] dice, String[] diceOrigin){
		boolean bool = false;
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 4; j++){
				for (int h = 0; h < 4; h++) {
					String[] direction = new String[i+j+(h*3)];
					String[] dice2 = Arrays.copyOf(dice, dice.length);
					//??????????????¢?????????
					for (int k = 0; k < i; k++) {
						direction[k] = "N";
					}
					//?¨????????????¢?????????
					for (int l = 0; l < j; l++) {
						direction[i+l] = "E";
					}
					//?????????????????????
					for (int f = 0; f < h; f++) {
						int num = f * 3;
						direction[i+j+num] = "W";
						direction[i+j+(num+1)] = "S";
						direction[i+j+(num+2)] = "E";
					}
					
					//move????????????
					bool = move(dice2, direction, diceOrigin);
					if(bool){
						return true;
					}
				}
			}
		}
		return bool;
	}
	
	
	/**
	 * move
	 * ???????????????????????°???????????????
	 * @param dice
	 * @param designate
	 * @return 
	 */
	private static boolean move(String[] dice, String[] direction, String[] diceOrigin) {
		for (int i = 0; i < direction.length; i++) {
			if(direction[i].equals("E")){
				str = dice[0];
				dice[0] = dice[3];
				dice[3] = dice[5];
				dice[5] = dice[2];
				dice[2] = str;
			}else if(direction[i].equals("W")){
				str = dice[0];
				dice[0] = dice[2];
				dice[2] = dice[5];
				dice[5] = dice[3];
				dice[3] = str;
			}else if(direction[i].equals("S")){
				str = dice[0];
				dice[0] = dice[4];
				dice[4] = dice[5];
				dice[5] = dice[1];
				dice[1] = str;
			}else if(direction[i].equals("N")){
				str = dice[0];
				dice[0] = dice[1];
				dice[1] = dice[5];
				dice[5] = dice[4];
				dice[4] = str;
			}
		}
		
		boolean diceCheck = true;
		for (int i = 0; i < diceOrigin.length; i++) {
			for (int j = 0; j < diceOrigin.length; j++) {
				if(!(diceOrigin[i].equals(dice[i]))){
					return false;
				}
			}
		}
		return diceCheck;	
	}
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string O, E;
    cin >> O >> E;

    ll i = 0;
    string ans = "";
    if (O.size() == E.size()) {
        for (ll i = 0; i < E.size(); i++) {
            ans += O[i];
            ans += E[i];
        }
    } else {
        for (ll i = 0; i < E.size(); i++) {
            ans += O[i];
            ans += E[i];
        }
        ans += O[O.size()-1];
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
ll p=1000000007;
ll fac[4000010];
ll ifac[4000010];
ll inv[4000010];
void init(int n)
{
	int i;
	fac[0]=fac[1]=ifac[0]=ifac[1]=inv[0]=inv[1]=1;
	for(i=2;i<=n;i++)
	{
		inv[i]=-(p/i)*inv[p%i]%p;
		fac[i]=fac[i-1]*i%p;
		ifac[i]=ifac[i-1]*inv[i]%p;
	}
}
ll c(int x,int y)
{
	if(x<y)
		return 0;
	return fac[x]*ifac[y]%p*ifac[x-y]%p;
}
ll f[2010][2010];
int main()
{
	int n,k;
	scanf("%d%d",&n,&k);
	if(k<=1)
	{
		printf("1\n");
		return 0;
	}
	init(n*k);
	int i,j;
	f[0][0]=1;
	for(i=1;i<=n;i++)
		for(j=n;j>=0;j--)
		{
			if(j<=i)
				f[i][j]+=f[i-1][j-1]*c(k*i-j-1,k-2)%p;
			f[i][j]=(f[i][j]+f[i][j+1])%p;
		}
	ll ans=(f[n][0]%p+p)%p;
	ans=ans*fac[n]%p;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 125440
"use strict"
const Main = (input)=>{
  let xs = input.trim().split("\n");
  let N = xs[0]-0;
  let A = xs[1].split(" ").map(v=>parseInt(v,10));
  let ans = 0;
  for(let i = 0; i<N; i++){
  ans+= 1/A[i];
  }
  let ans1 = 1/ans; 
  console.log(ans1);

}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 7372
#include<stdio.h>

int main(void){
    long a,b,c,d,N;
    scanf("%ld %ld %ld %ld\n",&a,&b,&c,&d);
    scanf("%ld\n",&N);
    if(N%2==0){
        long min=a*4;
        if(min>b*2)min=b*2;
        if(min>c)min=c;
        if(min>d/2){
            printf("%ld\n",N/2*d);
        }else{
            printf("%ld\n",N*min);
        }
    }else{
        long min=a*4;
        if(min>b*2)min=b*2;
        if(min>c)min=c;
        if(min>d/2){
            printf("%ld\n",(N-1)/2*d+min);
        }else{
            printf("%ld\n",N*min);
        }
    }
       return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int[] a = new int[3];
    for(int i = 0; i < 3; i++){
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    System.out.println(a[0] + a[1]);
  }
}


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

int main() {
    int N;
    vector<int> V;
    vector<int> C;

    // in
    cin >> N;
    for(int i=0; i<N; i++){
        int l;
        cin >> l;
        V.push_back(l);
    }
    for(int i=0; i<N; i++){
        int l;
        cin >> l;
        C.push_back(l);
    }

    // calc
    int result=0;
    for(int i=0; i<N; i++){
        int l = V[i] - C[i];
        if (l > 0){
            result+=l;
        }
    }

    // out
    cout << result << endl;
    return 0;
}

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

int main() {
	// your code goes here
	int a,b,c,d,e;
	cin >>a >>b >>c >>d >>e;
	if(a < 0&&b < 0){
		cout <<(b - a)*c <<endl;
	}
	else if(a <= 0&&b>=0){
		cout <<abs(a)*c+d+b*e <<endl;
	}
	else{
		cout <<(b - a)*e<<endl;
	}
	return 0;
}

Measured memory_bytes: 3040
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  kane=1000
  pairs=[]
  i=0
  j=1
  while True:
    if j>=n:
      break
    if l[i]<l[j]:
      pairs.append((i,j))
      i=j
      j=i+1
    elif l[i]==l[j]:
      i=j
      j+=1
    else:
      i=j
      j+=1

  # print(pairs)
  kabu=0
  for x,y in pairs:
    kabu+=kane//l[x]
    kane%=l[x]
    kane+=kabu*l[y]
    kabu=0

  return kane

# main()
print(main())


Measured memory_bytes: 10624
#include <stdio.h>
int main(){
    int n;
    int node,k,a;
    scanf("%d",&n);
    int mat[n][n];
    for (int i = 0; i < n; i++)
    {
        /* code */
        for(int j=0;j<n;j++){
            mat[i][j] = 0;
        }
    }
    
    for(int i=0;i<n;i++){
        scanf("%d %d",&node,&k);
        for(int j=0;j<k;j++){
            scanf("%d",&a);
            mat[node-1][a-1] = 1;
        }
    }
    for (int i = 0; i < n; i++)
    {
        /* code */
        for(int j = 0; j < n; j++){
            printf("%d",mat[i][j]);
            if (j != n-1)
            {
                /* code */
                printf(" ");
            }
            
        }
        printf("\n");
    }
    
    
    


    
}


Measured memory_bytes: 2760
#include <bits/stdc++.h>
using namespace std;
long long Euclid(long long x,long long y){
    long long S = y % x;
    while(x != 0){
        S = y % x;
        if(S == 0) return x;
        y = x;
        x = S;
    }
    return 1;
}
int main(void){
    long long A,B,C,D;
    cin >> A >> B >> C >> D;
    long long E = C * D /Euclid(C,D);
    cout << B -(B/C + B/D - B/E) - (A-1 - ((A-1)/C + (A-1)/D - (A-1)/E)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 23
using namespace std;
int x[maxn], y[maxn], n;
long long p[maxn], ans[maxn];
int In[maxn], Line[maxn];

void Search(int step, int K, int Sum) {
	if(step > n) {
		long long Ans = 0;
		for(int i = 1; i <= Sum; ++i) {
			int t = In[i];
			int Cur = min(abs(x[t]), abs(y[t]));
			for(int j = 1; j <= K; ++j) {
				if(Line[j] > 0) {
					Cur = min(Cur, abs(x[t] - x[Line[j]]));
				} else {
					Cur = min(Cur, abs(y[t] - y[-Line[j]]));
				}
			}
			Ans += Cur * p[t];
		}
		ans[K] = min(ans[K], Ans);
		return;
	}
	In[Sum + 1] = step;
	Search(step + 1, K, Sum + 1);
	Line[K + 1] = step;
	Search(step + 1, K + 1, Sum);
	Line[K + 1] = -step;
	Search(step + 1, K + 1, Sum);
}

int main() {
	memset(ans, 0x3f, sizeof ans);
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) 
		scanf("%d%d%lld", x + i, y + i, p + i);
	Search(1, 0, 0);
	for(int i = 0; i <= n; ++i) {
		printf("%lld\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 3708
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define mod 1000000007
#define maxn 1000010
using namespace std;
typedef long long ll;
ll n;
ll f[maxn];
int main(){
    scanf("%lld",&n);
    f[0]=1;
    f[1]=n;
    f[2]=n*n;
    ll now=0;
    for(int i=3;i<=n;i++)
    {
        f[i]=f[i-1];
        f[i]=(f[i]+(n-1)*(n-1)%mod)%mod;
        f[i]=(f[i]+now)%mod;
        f[i]=(f[i]+(ll)(n-i+2))%mod;
        now=(now+f[i-2])%mod;
    }
    printf("%lld\n",f[n]);
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int N; cin >> N;
    int cnt = N;
    while (true) {
        if (cnt % 2 == 0 && cnt % N == 0) break;
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (1000)
#define MAX_M (2000)
#define INFL (1000000000000000000L)

using namespace std;

int dp_reach[3 * MAX_N + 1][MAX_N];
long dp_point[3 * MAX_N + 1][MAX_N];

int main(int argc, char *argv[]) {
  // read inputs
  int N, M, as[MAX_M], bs[MAX_M], cs[MAX_M];
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    scanf("%d %d %d", &as[i], &bs[i], &cs[i]);
    as[i]--;  // NOTE : modify input
    bs[i]--;  // NOTE : modify input
  }

  // init dp
  for (int k = 0; k <= 3 * N; k++) {
    for (int i = 0; i < N; i++) {
      dp_reach[k][i] = 0;
      dp_point[k][i] = -INFL;
    }
  }
  dp_reach[0][0] = 1;
  dp_point[0][0] = 0L;

  // solve dp
  for (int k = 1; k <= 3 * N; k++) {
    for (int i = 0; i < M; i++) {
      const int a = as[i], b = bs[i], c = cs[i];
      if (dp_reach[k - 1][a]) {
        dp_reach[k][b] = 1;
        dp_point[k][b] = max(dp_point[k][b], dp_point[k - 1][a] + c);
      }
    }
  }

  // print answer
  long ans = -INFL;
  for (int k = 1; k <= N; k++) {
    if (dp_reach[k][N - 1]) {
      ans = max(ans, dp_point[k][N - 1]);
    }
  }
  int improved = 0;
  for (int k = N + 1; k <= 3 * N; k++) {
    if (dp_reach[k][N - 1] && dp_point[k][N - 1] > ans) {
      improved = 1;
    }
  }

  if (improved) {
    printf("inf\n");
  } else {
    printf("%ld\n", ans);
  }

  return 0;
}


Measured memory_bytes: 35328
import math
import sys

class SegmentTree(object):
    __slots__ = ["elem_size", "tree_size", "tree", "default", "op"]

    def __init__(self, a: list, default: int, op):
        real_size = len(a)
        self.elem_size = 1 << math.ceil(math.log2(real_size))
        self.tree_size = 2 * self.elem_size
        self.tree = tree = [default] * self.elem_size + a + [default] * (self.elem_size - real_size)
        self.default = default
        self.op = op

        for i in range(self.elem_size - 1, 0, -1):
            tree[i] = op(tree[i<<1], tree[(i<<1)+1])

    def get_value(self, x: int, y: int):
        l, r = x + self.elem_size, y + self.elem_size
        tree, result, op = self.tree, self.default, self.op
        while l < r:
            if l & 1:
                result = op(tree[l], result)
                l += 1
            if r & 1:
                r -= 1
                result = op(tree[r], result)
            l, r = l >> 1, r >> 1

        return result

    def set_value(self, i: int, value: int):
        k = self.elem_size + i
        self.tree[k] = value
        self.update(k)

    def update(self, i: int):
        op, tree = self.op, self.tree
        while i > 1:
            i >>= 1
            tree[i] = op(tree[i<<1], tree[(i<<1) + 1])

if __name__ == "__main__":
    n, q = map(int, input().split())
    tree = SegmentTree([2**31-1]*n, 2**31-1, min)
    ans = []
    append = ans.append
    for com, x, y in (map(int, l.split()) for l in sys.stdin.readlines()):
        if com == 0:
            tree.set_value(x, y)
        else:
            append(tree.get_value(x, y+1))
    print(*ans, sep="\n")


Measured memory_bytes: 16352
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
typedef long long ll;
#define MAX 100100
using namespace std;

char S[110];
int main()
{	
	scanf("%s", S);
	int len = strlen(S), cnt = 0;
	for (int i = 0; i < len; i++) {
		if (S[i] != S[len - i - 1]) cnt++;
	}
	printf("%d", cnt / 2);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define int long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int , int>
#define vi vector<int>
#define inf 1e18 //(10^18
#define pqmax priority_queue<int>
#define mii map<int , int>
#define ps(x, y) fixed<<setprecision(y)<<x
// double ans = 1.012345668992
//cout<<ps(ans , 6)
// ans = 1.012345 // 6 decimal places
#define pqmin priority_queue<int , vi , greater<int> >
#define mk(arr , n , type) type *arr = new type[n];
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
// 48->11000(4) (returns no. of zeros after first one)
#define mod 1000000007 //1e9 +7
#define w(t) int t; cin>>t;while(t--)
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//shuffle(arr , arr +n , rng)
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>pbds;
//pbds s;
//s.order_of_key(4);
//*s.find_by_order(4);
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);



    int n ;
    cin >> n;
    int sum = 0;

    int i = 1;
    int j = 1;
    int k  = 1;



    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++ ) {
            for (int k = 1; k <= n; k++) {
                sum += __gcd(k , __gcd( j , i));
            }
        }
    }



    cout << sum << "\n";
    return 0;


}





Measured memory_bytes: 3644
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int N;
	string S;
	cin >> N >> S;
	for (int count = 0; count < S.length(); count++)
	{
		if (S.at(count) + N > 'Z')
		{
			S.at(count) = 'A' + (N - ('Z' - S.at(count))) - 1;
		}
		else
		{
			S.at(count) += N;
		}
	}
	cout << S << endl;
}

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

#define REP(i,s,n) for(i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define MAX_V 100001

int V,E;
int par[MAX_V],degree[MAX_V];

int find(int x) {
  if( x == par[x] ) return x;
  return par[x] = find(par[x]);
}

void unit(int x,int y){
  x = find(x), y = find(y);
  if( x != y ) par[x] = y;
}

void swap(int *x,int *y){
  int temp = *x;
  *x = *y;
  *y = temp;
}

int main(){
  int i,j,u,v;
  while( scanf("%d %d",&V,&E), V|E ){
    rep(i,V) par[i] = i, degree[i] = 0;
    bool success = true;
    rep(i,E){
      scanf("%d %d",&u,&v);
      --u, --v;
      if( u > v ) swap(&u,&v);
      ++degree[u], ++degree[v];
      if( degree[u] > 2 || degree[v] > 2 ) success = false;
      if( find(u) == find(v) ) success = false;
      unit(u,v);
    }
    puts(success?"yes":"no");
  }
  return 0;
}

Measured memory_bytes: 1364
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n = int(input())
a = list( map(int, input().split()))

from collections import defaultdict
ar = defaultdict(list)
al = defaultdict(list)

for i in range(n):
    al[i+a[i]].append(i)
    ar[i-a[i]].append(i)

x = al.keys()

ans = 0
for i in x:
    ans += len(ar[i]) * len(al[i])

print(ans)


Measured memory_bytes: 164908
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n; cin >> n;
    int res = 0;
    cout << n * (n - 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)

using namespace std;
vector<tuple<double,double,double> > a(21);
double ans = 0;
int n,m;

void solve(int num,vector<int> candidate, double tmpans){
		REP(i,candidate.size()){
			tmpans += (get<0>(a[candidate[i]])-get<0>(a[candidate[candidate.size()-1]]))*(get<0>(a[candidate[i]])-get<0>(a[candidate[candidate.size()-1]]))
				+ (get<1>(a[candidate[i]])-get<1>(a[candidate[candidate.size()-1]]))*(get<1>(a[candidate[i]])-get<1>(a[candidate[candidate.size()-1]]))
				+ (get<2>(a[candidate[i]])-get<2>(a[candidate[candidate.size()-1]]))*(get<2>(a[candidate[i]])-get<2>(a[candidate[candidate.size()-1]]));
		}

		if(candidate.size() == m){
			ans = max(ans,tmpans);
			return;
		}
		for(int i = num;i < n + candidate.size() + 1 - m;i++){
		candidate.push_back(i);
		solve(i + 1, candidate,tmpans);
		candidate.pop_back();
	}
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	while(cin>>n>>m,n){
		REP(i,n)cin >> get<0>(a[i]) >> get<1>(a[i]) >> get<2>(a[i]);
		ans = 0;
		solve(0,vector<int>(),0);
		cout << fixed << setprecision(5) << ans << endl;
		break;
	}
  return 0;
}

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

int main() {
  double b_in;
  unsigned long long a, b,ans;
  cin >> a >> b_in;
  b = b_in * 1000;
  ans = a*b;
  ans /= 1000;
  cout << ans;

  return 0;
}


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

int main()
{
  int N, K;
  cin >> N >> K;
  vector<double> p(N);
  rep(i, N) cin >> p[i];
  vector<double> q(N);
  rep(i, N)
  {
    long long sum = 0;
    for (int j = 1; j < p[i] + 1; j++)
    {
      sum += j;
    }
    q[i] = sum / p[i];
  }

  int s = 0;
  int g = K;
  double ans = 0;
  rep(i, K)
  {
    ans += q[i];
  }

  double pre_ans = ans;

  while (g < N + 1)
  {
    pre_ans = pre_ans - q[s] + q[g];
    if (ans < pre_ans)
    {
      ans = pre_ans;
    }
    s++;
    g++;
  }

  printf("%10.2lf\n", ans);
}

Measured memory_bytes: 3328
function main(input) {
    var n = parseInt(input);
    var count = function(t) {
        if (n < t) return 0;
        var ts = t.toString();
        var cnt =  0 <= ts.indexOf('7') && 0 <= ts.indexOf('5') && 0 <= ts.indexOf('3') ? 1 : 0;
        [7, 3, 5].forEach(function(i) {
            cnt += count(10 * t + i);
        });
        return cnt;
    };
    console.log(count(0));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21192
X,Y,Z,K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i).sort.reverse
B = gets.split.map(&:to_i).sort.reverse
C = gets.split.map(&:to_i).sort.reverse

tmp = []
X.times do |i|
  Y.times do |j|
    tmp.push(A[i] + B[j])
  end
end
tmp.sort!
tmp.reverse!
tmp = tmp[0..K]

res = []
tmp.each do |t|
  Z.times do |k|
    res.push(t + C[k])
  end
end
res.sort!
res.reverse!
K.times {|i| puts res[i]}


Measured memory_bytes: 70132
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll solve() {
    ll K, Q;
    cin >> K >> Q;
    //vector<ll> D(K), cd(K+1);
    vector<ll> D(K);
    for ( int i = 0; i < K; i++ ) {
        cin >> D[i];
        //cd[i+1] = cd[i] + D[i];
    }
    vector<ll> ans;
    ll N, X, M;
    for ( int q = 0; q < Q; q++ ) {
        cin >> N >> X >> M;
        vector<ll> cd(K+1);
        for ( int i = 0; i < K; i++ ) {
            cd[i+1] = cd[i] + (D[i] == 0 ? M : (((D[i]-1) % M) + 1));
        }
        ll y = X + ((N-1)/K) * cd[K] + cd[(N-1)%K];
        ll c = y/M - X/M;
        ans.push_back(N-1-c);
    }

    for ( int q = 0; q < Q; q++ ) {
        cout << ans[q] << "\n";
    }
    return 0;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long 
#define ull unsigned long long 
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
 
#define y1 what
 
using namespace std;
 
const int N = (int) 1e5 + 10;
const int M = (int) 101;
const ll big =  (1LL << 51);
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int INF1 = (int) 1e9 + 3;
const double EPS = (double) 1e-6;
const double PI =  3.14159265359;
 
int n, m;
vector<int> v[N];
int u[N], clr[N];
int bad;
 
void dfs(int x, int c = 0) {
  u[x] = 1;
  clr[x] = c;
  for (auto it : v[x]) {
    if (!u[it]) 
        dfs(it, clr[x] ^ 1);
    else if (clr[x] == clr[it]) {
        bad = 1;
    }
  }
}
 
int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    srand(time(0));
    cin >> n >> m;
    while (m--) {
      int x, y;
      cin >> x >> y;
      --x, --y;
      v[x].pb(y);
      v[y].pb(x);
    }
    ll isolated = 0, bipartite = 0, comp = 0;
    for (int i = 0; i < n; i++) {
      if (!u[i]) {
        if (v[i].empty()) {
            ++isolated;
        } else {
            bad = 0;
            dfs(i);
            bipartite += 1 - bad;
            comp++;
        }
      }
    }
    cerr << isolated << " " << bipartite << " " << (comp - bipartite) << endl;
    ll ans = bipartite * bipartite * 2;
    ans += isolated * (n - isolated) * 2;
    ans += isolated * isolated;
    ans += (comp - bipartite) * bipartite * 2;
    ans += (comp - bipartite) * (comp - bipartite);
    cout << ans;
    return 0;
}

Measured memory_bytes: 9472
#include<iostream>
#include<string>
#include<cctype>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int n;
	char x, c;
	string s;
	int cnt_a=0,cnt_b=0,cnt_o=0,cnt_ab=0;
	while(cin >> n >> x >> s){
//	cout << n << x << s << endl;
//	transform(s.begin(),s.end(),s.begin(),toupper)
	if(s=="A"){
		cnt_a++;
	}
	else if(s=="B"){
		cnt_b++;
	}
	else if(s=="O"){
		cnt_o++;
	}
	else if("AB"){
		cnt_ab++;
	}
}
	cout<<cnt_a <<endl<<cnt_b<<endl<<cnt_ab<<endl<<cnt_o<<endl;

}

Measured memory_bytes: 1200
#include <iostream>
#include <cmath>
using ld = long double;
using std::cin;
using std::cout;
using std::endl;

int main()
{
    ld a, b, s, l, h, C;
    cin >> a >> b >> C;

    //s = 1/2 * a * b * sin(C)
    //l = a + b + c;
    //c = a**2 + b**2 - 2*a*b*cos(C)
    //h = b sin(c)

    s = 1.0 / 2.0 * a * b * sin(C * M_PI / 180.0);
    l = a + b + sqrt(a * a + b * b - 2 * a * b * cos(C * M_PI / 180.0));
    h = b * sin(C * M_PI / 180.0);

    cout << std::fixed;
    cout << s << endl;
    cout << l << endl;
    cout << h << endl;

    return 0;
}


Measured memory_bytes: 3572
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int ans[200000] = {};
int main() {
	int n, m;
	cin >> n >> m;
	REP(i, m) {
		int a, b;
		cin >> a >> b;
		ans[a]++;
		ans[b]++;
	}
	for (int i = 1;i <= n;++i) {
		if (ans[i] % 2 == 1) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

ll check[110000];

int main() {
  ll n, x, m;
  cin >> n >> x >> m;
  vll v;
  ll cnt = 0LL;
  ll a = x;
  rep(i,m*2) {
    v.push_back(a);
    cnt += a;
    check[a] = true;
    a *= a;
    a %= m;
    if(check[a]) break;
    if(a==0) {
      cout << cnt << endl;
      return 0;
    }
  }
  ll ans = 0LL;
  bool swi = true;
  vll vv;
  rep(i,v.size()) {
    if(v[i]==a) swi = false;
    if(swi) {
      ans += v[i];
      n--;
    }
    else vv.push_back(v[i]);
  }
  ll s = vv.size();
  ll sum = 0LL;
  rep(i,s) sum += vv[i];
  ans += sum*(n/s);
  rep(i,n%s) ans += vv[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4864
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        long count = 0;
        while (n-- > 0) {
            long num = sc.nextLong();
            
            while (num % 2 == 0) {
                num /= 2;
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 34804
import java.io.*;

public class Main{
	public static void main(String args[]) throws IOException{
		BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in));
		String str = br.readLine();
		String data[] = str.split(" ",0);
		int a[] = new int[3];
		int sum = 0;
		int s = 0;
		for(int i = 0; i < data.length; i++){
			sum += Integer.parseInt(data[i]);
			a[i] = Integer.parseInt(data[i]);
		}
		if(sum != 17){
		} else {
			if(a[0] == 5 || a[0] == 7){
				if(a[1] == 5 || a[1] == 7){
					if(a[2] == 5 || a[2] == 7){
						System.out.println("YES");
						s++;
					}
				}
			}
		}
		if(s == 0){
			System.out.println("NO");
		}
		
	}
}

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


char x[105][105];


int main()
{
	int a, b;
	cin >> a >> b;
	a--,b--;
	for(int i = 1; i <= 50; i++)
		for(int j = 1; j <= 100; j++)
			x[i][j] = '.';
	for(int i = 51; i <= 100; i++)
		for(int j = 1; j <= 100; j++)
			x[i][j] = '#';  
	for(int i = 1; i <= 50 && b; i += 2)
		for(int j = 1; j <=100 && b; j += 2)
			x[i][j] = '#', b--;
	for(int i = 100; i > 50 && a; i-=2)
		for(int j = 1; j <= 100 && a; j += 2)
			x[i][j] = '.', a--;
	puts("100 100");
	for(int i = 1; i <= 100; i++, puts(""))
		for(int j = 1; j <= 100; j++)
			cout << x[i][j];
	return 0;
}


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

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

    if (N/100 == 7) {
        cout << "Yes" << endl;
    } else if ((N%100)/10 == 7) {
        cout << "Yes" << endl;
    } else if (((N%100)%10) == 7) {
        cout << "Yes" << endl; 
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3624
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    for (i in 1..N) {
        val (xa, ya, ra) = Array(3, { sc.nextDouble() })
        val (xb, yb, rb) = Array(3, { sc.nextDouble() })
        val dist = Math.hypot(xa-xb, ya-yb)
        val ans = when {
            dist < ra-rb -> 2
            dist < rb-ra -> -2
            dist <= (ra+rb) -> 1
            else -> 0
        }
        println(ans)
    }
}


Measured memory_bytes: 26980
import java.util.*;
class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
  int l=sc.nextInt();int r=sc.nextInt();int n=sc.nextInt();
  int count=0;
  for(int i=l;i<=r;i++){
  if(i%n==0)count++;
  }System.out.println(count);
}
}

Measured memory_bytes: 35584
N=int(input())
A=list(map(int,input().split()))
f=True
X=[A]
c=0
while f:
  B=sorted(X[c])
  while 0 in B:
    B.remove(0)
  mod=B[0]
  for i in range(1,len(B)):
    B[i]%=mod
  X.append(B)
  c+=1
  if X[c]==X[c-1]:
    f=False
print(min(X[c]))

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(void){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int t = 0;
    while(a > 0 && c > 0){
        if(t%2==0){
            c -=b;
        }else{
            a-=d;
        }
        t++;
    }
    if(a > 0) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 3632