akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


int main(){
    while(true){
        int n,x;
        cin >> n >> x;
        if(n == 0 && x == 0) break;

        int count = 0;

        for(int i = 1; i <= n; i++){
            for(int j = i+1; j <= n; j++){
                for(int k = j+1; k <= n; k++){
                    if(i+j+k == x) count++;
                }
            }
        }

        cout << count << endl;
    }
}


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

int r;
int D;
int x;

int main() {
  cin >> r >> D >> x;
  
  for (int i = 0; i < 10; i++) {
    x = r * x - D;
    cout << x << endl;
  }
  return 0;
}


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

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

  string s;cin>>s;
  if(s[0]=='9'||s[1]=='9'){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;

  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

bool cmp (const string &a, const string &b){
    int ac = 0, bc = 0;
    rep(i, a.size()){
        if(a[i] == '#') ac++;
    }
    rep(i, b.size()){
        if(b[i] == '#') bc++;
    }
    return ac < bc;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<string> A(N);
    rep(i, N) cin >> A[i];
    
    vector<int> row(N, 0), col(N, 0);
    int row_zero = 0;
    int row_max = 0, col_max = 0;
    rep(i, N){
        int cnt = 0;
        rep(j, N){
            if(A[i][j] == '#') cnt++;
        }
        row[i] = cnt;
        if(cnt == 0) row_zero++;
        row_max = max(cnt, row_max);
    }
    
    rep(i, N){
        int cnt = 0;
        rep(j, N){
            if(A[j][i] == '#') cnt++;
        }
        col[i] = cnt;
        col_max = max(cnt, col_max);
    }
    if(row_max == 0 && col_max == 0){
        output(-1);
        return 0;
    }
    int col_comp = N;
    rep(i, N){
        int tmp = 0;
        rep(j, N){
            if(A[i][j] == '.'){
                tmp++;
            }
        }
        
        if(col[i] == 0){
            tmp++;
        }
        
        col_comp = min(col_comp, tmp);
    }
    
    // column completed
    int col_cnt = 0;
    rep(i, N){
        if(col[i] == N) col_cnt++;
    }
    output(col_comp + N - col_cnt);
    
    
    
    
    //    sort(all(A), cmp);
    //    rep(i, N) cout << A[i] << endl;
    
    return 0;
}

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

int main() {
  int n;
  cin>>n;  
  vector<long>a(n),b(n);
  rep(i,n){
    cin>>a.at(i)>>b.at(i);
  }
  long ans=0;
  for(int i=n-1;i>=0;i--){
    if((ans+a.at(i))%b.at(i)!=0){
      ans+=b.at(i)-(ans+a.at(i))%b.at(i);
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
// Problem : C - Many Requirements
// Contest : AtCoder - AtCoder Beginner Contest 165
// URL : https://atcoder.jp/contests/abc165/tasks/abc165_c?lang=en
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、 
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 vi a,b,c;
 vl d;
int N,M,Q;
vi v;
ll mx=-1;
inline void calc(int lv,int level)
{
	if(level==N)
	{
		ll ans=0;
		F0R(x,Q)
		{
			if(v[b[x]]-v[a[x]]==c[x])
				ans+=d[x];
			// if(v[0]==1 && v[1]==3 && v[2]==4)
			// {
				// bug(v[a[x]]-v[b[x]]);
				// bug(c[x]);
			// }
		}
		ckmax(mx,ans);
		return;
	}
	FOR(x,lv,M+1)
	{
		v[level]=x;
		calc(x,level+1);
	}
}
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	cin>>N>>M>>Q;
	F0R(x,Q)
	{
		int n1,n2,n3,n4;
		cin>>n1>>n2>>n3>>n4;
		a.pb(n1-1),b.pb(n2-1),c.pb(n3),d.pb(n4),v.pb(0);
	}
	calc(1,0);
	cout<<mx;
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define lli long long int 
int main() {
	// your code goes here
	lli i,k,m,x,y,n,j;
	cin>>x>>n;
	lli a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	i=x;
	j=x;
	m=x;
	while(1)
	{
		if(!binary_search(a,a+n,i))
		{
			m=i;
			break;
		}
		i--;
		if(!binary_search(a,a+n,j))
		{
			m=j;
			break;
		}
		j++;
	}
	cout<<m;

	return 0;
}

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

bool isRuledCell(int x, int y, int field[9][9]) {
    for (int nx = 0; nx < 9; nx++) {
        if (x != nx && field[y][x] == field[y][nx]) {
            return false;
        }
    }
    for (int ny = 0; ny < 9; ny++) {
        if (y != ny && field[y][x] == field[ny][x]) {
            return false;
        }
    }
    for (int ny = y - (y % 3), endy = ny + 2; ny <= endy; ny++) {
        for (int nx = x - (x % 3), endx = nx + 2; nx <= endx; nx++) {
            if (y != ny && x != nx && field[y][x] == field[ny][nx]) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    bool newLineFlag = false;
    for (int i = 0; i < n; i++) {
        if (newLineFlag) {
            cout << endl;
        } else {
            newLineFlag = true;
        }
        int field[9][9];
        for (int j = 0; j < 9; j++) {
            for (int k = 0; k < 9; k++) {
                cin >> field[j][k];
            }
        }
        for (int j = 0; j < 9; j++) {
            for (int k = 0; k < 9; k++) {
                if (isRuledCell(k, j, field)) {
                    cout << " " << field[j][k];
                } else {
                    cout << "*" << field[j][k];
                }
            }
            cout << endl;
        }
    }
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n,k; cin>>n>>k;
  vi a(n);
  rep(i,n) cin>>a[i];
  rep(i,n) a[i]--;
  vi s(n+1,0);
  rep(i,n) s[i+1]=(s[i]+a[i])%k;
  map<int,int> mp;
  ll ans=0;
  queue<int> q;
  rep(i,n+1){
    ans+=mp[s[i]];
    mp[s[i]]++;
    q.push(s[i]);
    if(q.size()==k){
      mp[q.front()]--;
      q.pop();
    }
  }
  cout<<ans<<endl;
}


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

int main(){
	int n, x, ct;

	while(1){
		cin>>n>>x;

		if(n==0 && x==0){
			break;
		}
		ct=0;
		for(int i=1; i<=n; i++){
			for(int j=i+1; j<=n; j++){
				for(int k=j+1; k<=n; k++){
					if(i+j+k==x){
						ct=ct+1;
					}
				}
			}
		}
		cout<<ct<<endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  long long int ans = 0;
  scanf("%d %d", &n, &k);
  int a[n];
  for(int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a+n);
  for(int i = 0; i < n-k; i++) ans += a[i];
  printf("%lld\n", ans);
}


Measured memory_bytes: 1024
n = int(input())
As = input().split()
A = [int(i) for i in As]
f = True
c = 0

while f:
    f = False
    for i in range(n-1):
        if A[i+1] < A[i]:
            w = A[i+1]
            A[i+1] = A[i]
            A[i] = w
            c += 1
            f = True

for i in range(n-1):
    print("{} ".format(A[i]), end="")
print(A[n-1])
print(c)



Measured memory_bytes: 5612
import java.util.*;
import java.util.stream.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		if(s.charAt(0) != 'A') {
			System.out.println("WA");
			return;
		}
		if(s.length() < 4) {
			System.out.println("WA");
			return;
		}
		String tmp = s.substring(2, s.length()-1);
		// System.out.println(tmp);
		if(tmp.replaceAll("C", "").length() != tmp.length() - 1) {
			System.out.println("WA");
			return;
		}
		if(s.replaceAll("C", "").length() != s.length() - 1) {
			System.out.println("WA");
			return;
		}
		for(char ch : s.toCharArray()) {
			if(ch == 'A' || ch == 'C') {
				continue;
			}
			if(!Character.isLowerCase(ch)) {
				System.out.println("WA");
				return;
			}
		}
		System.out.println("AC");
	}
}


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

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

    vector<int> X(N);
    vector<int> Y(N);
    for (int i = 0; i < N; i++)
    {
        cin >> X.at(i) >> Y.at(i);
    }

    int count = 0;
    for (int i = 0; i < N; i++)
    {
        if (pow(X.at(i), 2) + pow(Y.at(i), 2) <= pow(D, 2))
        {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 4840
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

	int R;
	cin >> R;
	if (R < 1200) {
		cout << "ABC";
	}
	else if (R < 2800) {
		cout << "ARC";
	}
	else {
		cout << "AGC";
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second

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

const int MOD = 1e9+7;
const int INF = 1e9+7;

vector<vi> graph;
ll dp[2][100007];
//bool vis[100007];

void dfs(int i, int p){

	ll white = 1, sum = 1;
	for(auto& v: graph[i]){
		if(v != p){
			dfs(v, i);
			white = (white * dp[0][v])%MOD;
			ll add = (dp[0][v] + dp[1][v]) %MOD;
			sum = (sum * add )%MOD;
		}
	}

	if(white == 0 && sum == 0)
		white = sum = 1;

	dp[0][i] = sum;
	dp[1][i] = white;
}

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

	int n; cin >> n;
	graph.resize(n);
	FOR(i, n-1){
		int x, y; cin >> x >> y;
		graph[x-1].push_back(y-1);
		graph[y-1].push_back(x-1);
	}

	dfs(0, -1);
	
	cout << (dp[0][0] + dp[1][0])%MOD << '\n';

	return 0;
}

Measured memory_bytes: 14208
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int n;
int main(void) {
    cin >> n;
    cout << "ABC" << n << endl;
    return 0;
}

Measured memory_bytes: 3576
n, m = list(map(int, input().split()))
graph = [float("INF") for i in range(n)]
graph[0] = 0
edge = [tuple(map(int, input().split())) for i in range(m)]
for i in range(2*n):
  flag = False
  for e in edge:
    a, b, c = e
    a, b, c = a-1, b-1, -c
    if graph[b] > graph[a]+c:
      if b==n-1:
        flag = True
      graph[b] = graph[a]+c
if flag:
  print("inf")
else:
  print(-graph[n-1])

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

int main(){
	string s;
	cin >> s;
	bool a = true;
	for(int i = 0;i < s.length(); i++){
		if(i % 2 == 0){//Odds are even
			//cout << s.at(i) << endl;
			if(s.at(i) == 'R' ||
		     s.at(i) == 'U' ||
		     s.at(i) == 'D' ){
		     	continue;
		  }else{a = false;break;}
		}else{
			//cout << s.at(i) << endl;
			if(s.at(i) == 'L' ||
		     s.at(i) == 'U' ||
		     s.at(i) == 'D' ){
		     	continue;}else{a = false;break;}
		  }
}
if(a){cout << "Yes" << endl;}else{cout << "No" << endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
 string s;
  cin >>s;
 if(s.size()%2==0){
 for(int i=0;i<s.size();i+=2){
  if(s[i]!='h'||s[i+1]!='i'){
  cout << "No";
  return 0;
  }
 }
 }else{
 cout << "No";
   return 0;
 }
 cout << "Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    int n;
    string s;
    cin >> n >> s;
    int ctr=0;
    rp(i,1000){
        int d1=i/100,
            d2=i/10%10,
            d3=i%10;
        int phase=0;
        rp(j,n){
            if(phase==0&&s[j]-'0'==d1){
                phase=1;
                continue;
            }
            if(phase==1&&s[j]-'0'==d2){
                phase=2;
                continue;
            }
            if(phase==2&&s[j]-'0'==d3){
                phase=3;
                continue;
            }
        }
        if(phase==3) ctr++;
    }
    print(ctr);
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
using namespace std;

int main() {
	int x, y; cin >> x >> y;
	cout << x + y / 2 << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to,cap,rev; 
	edge (int from, int to, int cap, int rev){
		this->from=from; this->to=to; this->cap=cap; this->rev=rev;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;



int main(){

	int n;
	cin >> n;
	for (int i = 40000; ; i--) {
		if (i*i <= n) {
			cout << i*i << endl;
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
int n, a;


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> n >> a;
    if((n % 500) <= a)puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
    input = input.trim();
    input = input.split(" ");
    var R = input[0];
    var G = input[1];
    var B = input[2];
    var N = input[3];
    var tmpR;
    var tmpG;
    var count = 0;

    for(var i = 0; i < N/R+1; i++){
        tmpR = N - R*i;
        if(tmpR >= 0){
            for(var j = 0; j < tmpR/G+1; j++){
                tmpG = tmpR - G*j;
                if(tmpG >= 0 && tmpG%B == 0){
                    count++;
                }
            }
        }
    }

    console.log(count);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 200010
#define MAXS 1000010
using namespace std;

int read(){
	char c;
	while(((c=getchar())<'0' || c>'9') && c!='-');
	int flag=1;
	int res=c-'0';
	if(c=='-'){
		flag=-1;
		res=0;
	}
	while((c=getchar())>='0' && c<='9') res=res*10+c-'0';
	return res*flag;
}

int n,m,v0,maxs;
int a[MAXN];
int lim[MAXN];
int f1[MAXS],f2[MAXS];
int p[20][MAXN][2];
int c[MAXN];

void calcP(int l){
	int last=1;
	for(int i=1;i<=n;i++){
		if(i==n || a[i+1]-a[i]>lim[l]){
			for(int j=last;j<=i;j++){
				p[l][j][0]=last;
				p[l][j][1]=i;
			}
			last=i+1;
		}
	}
	p[l][0][0]=1;
	p[l][n+1][1]=n;
}

void dp(){
	f1[0]=0; f2[0]=n+1;
	for(int s=1;s<maxs;s++){
		f2[s]=n+1;
		for(int i=1,l=1;i<=m;i++,l<<=1)
			if(s&l){
				f1[s]=max(f1[s],p[i][f1[s^l]+1][1]);
				f2[s]=min(f2[s],p[i][f2[s^l]-1][0]);
			}
	}
}

int main(){
#ifdef DEBUG
	freopen("g012e.in","r",stdin);
#endif
	n=read(); v0=read();
	for(int i=1;i<=n;i++) a[i]=read();
	lim[0]=v0;
	while(v0) lim[++m]=(v0/=2);
	maxs=1<<m;
	for(int i=0;i<=m;i++) calcP(i);
	dp();
	memset(c,-1,sizeof c);
	for(int i=0;i<maxs;i++)
		c[f2[i]]=max(c[f2[i]],f1[(maxs-1)^i]);
	int cur=-1,now=-1;
	for(int i=1;i<=n;i++)
		if(p[0][i][0]==i){
			while(cur<p[0][i][1]+1) now=max(now,c[++cur]);
			if(now>=i-1)
				for(int j=p[0][i][0];j<=p[0][i][1];j++)
					puts("Possible");
			else
				for(int j=p[0][i][0];j<=p[0][i][1];j++)
					puts("Impossible");
		}
	return 0;
}


Measured memory_bytes: 43776
<?php
class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}
class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner();
$n = $sc->nextInt();
$f = substr($n,-1,1);
switch($f) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        $result = 'hon';
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        $result = 'pon';
        break;
    case 3:
        $result = 'bon';
        break;
}
out::println($result);

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

typedef pair<int, int> P;
typedef long long ll;
const int mod = 1000000007;

bool square(ll a){ll n=(ll)sqrt(a);return a==n*n;}
int digitsum(ll N,int a);//a進数におけるNの各桁の和、計算量はloga(N)
ll mpow(ll x, ll n);
ll inv_mod(ll a){return mpow(a,mod-2);}
int gcd(int x,int y){return y ? gcd(y,x%y) : x;};//xとyの最大公約数
int lcm(int x,int y){return x*y/gcd(x,y);}//xとyの最小公倍数

int main(){
    int N;
    cin>>N;
    vector<int> W(N);
    REP(i, N) cin >> W[i];
    int ans=INT_MAX;
    REP(i,N){
        int WL=0,WR=0;
        REP(j,i) WL+=W[j];
        for(int j=i;j<N;j++) WR+=W[j];
        ans=min(ans,abs(WL-WR));
    }
    cout<<ans<<endl;
}

int digitsum(ll N,int a){
    if(N==0) return 0;
    int ret=0;
    ret+=digitsum(N/a,a)+N%a;
    return ret;
}
ll mpow(ll x, ll n){ //x^n(mod division) ←普通にpow(x,n)では溢れてしまうため，随時mod計算 2分累乗法だから早い
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % mod;
        x = x*x % mod;
        n = n >> 1;
    }
    return ans;
}
/*
class Fuctorical{//階乗とその逆元を求めて計算に利用するクラス
private:
    vector<ll> fac;
public:
    
    Fuctorical(ll N){
        fac.push_back(1);
        for(int i=0;i<N;i++) fac.push_back(fac[i]*(i+1)%mod);
    }

    ll fact(ll a){return fac[a];}
    ll ifact(ll a){return inv_mod(fac[a]);}

    ll cmb(ll a,ll b){
        if(a==0&&b==0) return 1;
        if(a<b||a<0) return 0;
        ll tmp =ifact(a-b)*ifact(b)%mod;
        return tmp*fac[a]%mod;
    }
};
*/

/*
class UnionFind{//UnionFind木
 private:
    vector<int> Parent;
 public:
    UnionFind(int N){
        for(int i=0;i<N;i++) Parent.push_back(-1);
    }

    int root(int A){
        if(Parent[A]<0) return A;
        return Parent[A]=root(Parent[A]);
    }

    int size(int A){
        return -Parent[root(A)];
    }

    bool connect(int A,int B){
        A=root(A);
        B=root(B);
        if(A==B) return false;
        if(size(A)<size(B)) swap(A,B);
        Parent[A]-=Parent[B];
        Parent[B]=A;
    }
};
*/

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
std::map<pii, vvi> map;
struct Bruteforcer {
    const int n, k;
    int id = 0;
    vvi arr;
    vi cntRow, cntCol;
    vvi answ;
    Bruteforcer(int n_, int k_) 
        : n(n_), k(k_), arr(n, vi(n,0)), cntRow(n,0), cntCol(n,0) 
    { brute(0,0); }
    void brute(int r, int c) {
        if (c == n) {
            if (cntRow[r] == k)
                if (answ.empty()) brute(r+1,0);
            return; 
        }
        if (r == n) {
            int val = cntRow[0];
            if (val == 0 || cntRow != vi(n, val) || cntRow != cntCol) { return; }
            answ = arr;
            return;
        }
        if (arr[r][c]) { if (answ.empty()) brute(r, c+1); return; }
        if (c + 1 < n && !arr[r][c+1]) {
            cntRow[r]++; cntCol[c]++; cntCol[c+1]++;
            arr[r][c] = arr[r][c+1] = ++id;
            if (answ.empty()) brute(r,c+1);
            cntRow[r]--; cntCol[c]--; id--; cntCol[c+1]--;
            arr[r][c] = arr[r][c+1] = 0;
        }
        if (r + 1 < n && !arr[r+1][c]) {
            cntRow[r]++; cntRow[r+1]++; cntCol[c]++;
            arr[r][c] = arr[r+1][c] = ++id;
            if (answ.empty()) brute(r,c+1);
            cntRow[r]--; cntRow[r+1]--; cntCol[c]--; id--;
            arr[r][c] = arr[r+1][c] = 0;
        }
        if (answ.empty()) brute(r,c+1);
    }
};
int main() {
    std::vector<pii> interest{{3,2},{4,3},{5,3},{6,3},{7,3}};
    std::vector<vvi> precalc(9);
    for (auto key : interest) {
        Bruteforcer bruteforcer(key.first, key.second);
        precalc[key.first] = bruteforcer.answ;
    }
    for (int n; std::cin >> n; std::cout << std::endl) {
        if (n <= 2) { std::cout << -1 << std::endl; continue; }
        std::vector<std::string> answ(n, std::string(n, '.'));
        auto fill = [&](int delta) {
            n -= delta;
            for (int i = n; i < n + delta; i++) {
                for (int j = n; j < n + delta; j++) {
                    const int item = precalc[delta][i-n][j-n];
                    answ[i][j] = item ? char('a' + item - 1) : '.';
                }
            }
        };
        while (n > 7) fill(4);
        fill(n);
        for (auto it : answ) std::cout << it << '\n';
    }
    return 0;
}

Measured memory_bytes: 2304
def examC():
    N = I(); A = [I() for _ in range(N)]
    AS = sorted(A)
    A0 = A[::2]
    d = defaultdict(bool)
    for i in AS[::2]:
        d[i] = True
    ans = 0
    for i in A0:
        if not d[i]:
            ans +=1
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()

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

int main()
{
  string S;
  int A=0;
  cin >> S;
  rep(i, 4){
    if (S.at(i)=='+') A++;
    else A--;
  }
  cout << A << endl;
}

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

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        mut hs: [usize; n],
    }
    for i in (1..n).rev() {
        if hs[i - 1] > hs[i] {
            hs[i - 1] -= 1;
        }
        if hs[i - 1] > hs[i] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#define inf 1e9+7
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl;
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}

typedef pair<ll,ll> Pair;
typedef set<ll> Set;

int main(){
    ll x;
    ll ans=0;
    cin >> x;
    ans+=(x/500)*1000;
    x%=500;
    ans+=(x/5)*5;
    kaku(ans);
}



Measured memory_bytes: 384
/**
*    author:  Dooloper
*    created: 29.08.2020 21:01:18
**/

#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;
using ll = long long;

#define rep(i,n) for(int i = 0; i < (n); i++)
#define repn(i,n) for(int i = 1; i <= (n); i++)
#define pb push_back
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

const double PI = acos(-1);
const int mod = 1000000007;
class mint {
   long long x;
public:
   mint(long long x=0) : x((x%mod+mod)%mod) {}
   mint operator-() const {
     return mint(-x);
   }
   mint& operator+=(const mint& a) {
       if ((x += a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator-=(const mint& a) {
       if ((x += mod-a.x) >= mod) x -= mod;
       return *this;
   }
   mint& operator*=(const  mint& a) {
       (x *= a.x) %= mod;
       return *this;
   }
   mint operator+(const mint& a) const {
       mint res(*this);
       return res+=a;
   }
   mint operator-(const mint& a) const {
       mint res(*this);
       return res-=a;
   }
   mint operator*(const mint& a) const {
       mint res(*this);
       return res*=a;
   }
   mint pow(ll t) const {
       if (!t) return 1;
       mint a = pow(t>>1);
       a *= a;
       return a;
   }
   // for prime mod
   mint inv() const {
       return pow(mod-2);
   }
   mint& operator/=(const mint& a) {
       return (*this) *= a.inv();
   }
   mint operator/(const mint& a) const {
       mint res(*this);
       return res/=a;
   }

   friend ostream& operator<<(ostream& os, const mint& m){
       os << m.x;
       return os;
   }
};
#pragma endregion

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string s,t;
  cin >> s >> t;
  int ans,rec = 1e9;
  for(int i = 0; i < s.length()-t.length()+1; i++){
    ans = 0;
    for(int j = 0; j < t.length(); j++){
      if(s[i+j] != t[j]) ans++;
    }
    rec = min(ans,rec);
  }
  cout << rec << endl;
  return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>
#include<string.h>
int main()
{
  
 long int a,b,c,i,flag=0;
  scanf("%ld %ld %ld",&a,&b,&c);
  for(i=1;i<=b;i++)
  {
      if(i*a%b==c)
      {
          flag=1;
         break;
      }else{
         
      }

  }
if(flag==1)
{

  printf("YES");
}else{
printf("NO");
}
    return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        
        Shiritori shiritori = new Shiritori();
        for(int i= 0; i< N; i++){
            String word = br.readLine();
            if(!(shiritori.isRightInitial(word) && shiritori.isNotContains(word))){
                System.out.println("No");
                return;
            }
            shiritori.accepted(word);
        }
        System.out.println("Yes");
    }
}
class Shiritori{
    private List<String> wordList;
    public Shiritori(){
        this.wordList = new ArrayList<String>();
    }
    public boolean isRightInitial(String nextword){
        if(this.wordList.size() == 0) return true;
        String lastword = this.wordList.get(this.wordList.size() - 1);
        String head = nextword.substring(0, 1);
        String butt = lastword.substring(lastword.length() - 1, lastword.length());
        return head.equals(butt);
    }
    public boolean isNotContains(String nextword){
        return !(this.wordList.contains(nextword));
    }
    public boolean accepted(String nextword){
        this.wordList.add(nextword);
        return true;
    }
}

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

int32_t main(){
	int n; cin>>n;
	map<string, long long> map;
	for(int i = 0; i < n;i++){
		string s; cin>>s;
		sort(s.begin(), s.end());
		map[s]++;
	}
	long long ans = 0;
	for(auto x: map){
		if(x.second > 1){
			ans += (long long)(x.second * (x.second - 1)) / 2;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 11264
s = input()

ans = True
if s[0] == 'A' and s[1].islower() and s[-1].islower() and s[2:len(s) - 1].count('C') == 1:
    for i in range(2, len(s) - 1):
        if s[i].isupper() and s[i] != 'C':
            ans = False
else:
    ans = False

print('AC' if ans else 'WA')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int m=1e9+7;
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    fastio
    int n,tot;
    cin>>n>>tot;
    if(n*500<tot) cout<<"No";
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 3612
<?php
while(fscanf(STDIN, "%f %f %f %f %f %f", $a, $b, $p, $c, $d, $q)){
    $tmp = $a * $d - $b * $c;
    $x = ($d * $p - $b * $q) / $tmp;
    $y = ($a * $q - $c * $p) / $tmp;
    printf("%.3f %.3f\n", $x, $y);
}

Measured memory_bytes: 6552
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
using pp=pair<int,pair<int,int>>;
#define MAX 1000000
#define MOD 1000000007
#define INF 1000000000

int main(){
  int N,H,W;
  cin>>N>>H>>W;
  cout<<max(N-H+1,0)*max(N-W+1,0)<<endl;
}


Measured memory_bytes: 3564
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
logging.disable(logging.CRITICAL)

def main():
    N, L = (int(x) for x in input().split())

    logging.info("Hello!")

    apples = [L - 1 + i for i in range(1, N + 1)]
    apples_abs = [abs(x) for x in apples]
    
    apple_pie_answer = sum(apples) - apples[apples_abs.index(min(apples_abs))]
    
    print(apple_pie_answer)
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
ll INF = 1000000007;


//-----------------//
  #define amin main
//-----------------//


int amin()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t,i,j;
	ll n,k,d;
	cin>>n>>k>>d;
	n = (ll)abs(n);
	if(n/d>k)
	{
		ll h  = n - k*d;
		cout<<h<<endl;
	}
	else
	{

		k = k - n/d;

		if(k%2==0)
			cout<<n%d<<endl;
		else
			cout<<d - n%d<<endl;
		
	}
	
	
	


	
	return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

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

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::setprecision(10);

    ll x, k, d; std::cin >> x >> k >> d;
    if (x < 0) x *= -1;

    ll ans = 0;
    if (d < (x+k-1) / k) {
        ans = x - d*k;
    } else {
        k -= x / d;
        x %= d;
        if (x > abs(x-d)) k--, x = abs(x-d);
        if (k & 1) ans = abs(x - d);
        else ans = x;
    }
    std::cout << ans << "\n";
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long N;
	cin >> N;
	long long int a, b, c;
	cin >> a >> b >> c;
	long long int ab = a + b, bc = b + c, ac = a + c;
	vector<string>s(N);
	for (auto &i : s)cin >> i;
	set<int>AB;
	set<int>AC;
	set<int>BC;
	for (int i = 0; i < N; i++) {
		if (s[i] == "AB")AB.insert(i);
		else if (s[i] == "AC")AC.insert(i);
		else BC.insert(i);
	}
	AC.insert(1e9+7);
	AB.insert(1e9+7);
	BC.insert(1e9+7);
	vector<char>ans;
	int cnt = 0;
	for (auto i : s) {
		if (i == "AB") {
			if (ab == 0) {
				cout << "No\n";
				return 0;
			}
			if (ac < bc) {
				ac++;
				bc--;
				ans.push_back('A');
			}
			else if(ac>bc){
				bc++;
				ac--;
				ans.push_back('B');
			}
			else if(*AC.lower_bound(cnt)<*BC.lower_bound(cnt)){
				ac++;
				bc--;
				ans.push_back('A');
			}
			else {
				bc++;
				ac--;
				ans.push_back('B');
			}
		}
		else if (i == "AC") {
			if (ac == 0) {
				cout << "No\n";
				return 0;
			}
			if (ab < bc) {
				ab++;
				bc--;
				ans.push_back('A');
			}
			else if (ab > bc) {
				ab--;
				bc++;
				ans.push_back('C');
			}
			else if (*AB.lower_bound(cnt) < *BC.lower_bound(cnt)) {
				ab++;
				bc--;
				ans.push_back('A');
			}
			else {
				ab--;
				bc++;
				ans.push_back('C');
			}
		}
		else {
			if (bc == 0) {
				cout << "No\n";
				return 0;
			}
			if (ab < ac) {
				ab++;
				ac--;
				ans.push_back('B');
			}
			else if (ab > ac) {
				ab --;
				ac++;
				ans.push_back('C');
			}
			else if (*AB.lower_bound(cnt) < *AC.lower_bound(cnt)) {
				ab++;
				ac--;
				ans.push_back('B');
			}
			else {
				ab--;
				ac++;
				ans.push_back('C');
			}
		}
//		if (ab > a + b + c || ac > a + b + c || bc > a + b + c) {
//			cout << "No\n";
//		}
		cnt++;
	}
	cout << "Yes\n";
	for (auto i : ans)cout << i << endl;
}

Measured memory_bytes: 11376
n, m = gets.to_s.split.map{|t|t.to_i}

  l = n/2
  r = n/2+1
if n.odd?
  
  m.times do |i|
    puts "#{l} #{r}"
    l -= 1
    r += 1
  end
  
else
  
  t = 0
  m.times do |i|
    r += 1 if i == n/4
    # puts "#{l} #{r} #{r-l} #{n -(r-l)}"
    puts "#{l} #{r}"
    l -= 1
    r += 1
  end
end


Measured memory_bytes: 14380
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define Inf 1000000000
#define nmax_def 110000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	int N, K, S;
	cin >> N >> K >> S;
	int Aaft = Inf;
	if (S == Inf) {
		Aaft = 3;
	}
	rep(i, N) {
		if (i < K)
			cout << S << " ";
		else
			cout << Aaft << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
const int INF = 1001001001;

int main(){
	int N, M, L;
	cin >> N >> M >> L;
	vector<vector<int>> dist(N, vector<int>(N, INF));
	rep(i,N) dist[i][i]=0;
	rep(i,M){
		int a, b, c;
		cin >> a >> b >> c;
		--a; --b;
		dist[a][b] = dist[b][a] = c;
	}
	rep(k,N)rep(i,N)rep(j,N) chmin(dist[i][j], dist[i][k]+ dist[k][j]);
	vector<vector<int>> dist2(N, vector<int>(N, INF));
	rep(i,N)rep(j,N){
		if(dist[i][j]<=L) dist2[i][j] = 1;
	}
	rep(k,N)rep(i,N)rep(j,N) chmin(dist2[i][j], dist2[i][k]+ dist2[k][j]);	
	int Q;
	cin >> Q;
	rep(qi, Q){
		int s, t;
		cin >> s >> t;
		--s; --t;
		int ans = dist2[s][t] -1;
		if(dist2[s][t] == INF) ans = -1; 
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1280
from collections import deque
MOD = pow(10,9)+7
N,K = map(int,input().split())
A = list(map(int,input().split()))
P = []; M = []; Z = []
for i in range(N):
  if A[i] >0:
    P.append(A[i])
  elif A[i] <0:
    M.append(A[i])
  else:
    Z.append(0)
P.sort(reverse=True)
M.sort(reverse=True)
ans = 1
if K == 1:
  print(P[0]%MOD)
  exit()
if len(Z) > N-K:
  print(0)
  exit()
if len(M) == 0: #全て正の場合。0があれば0
  for i in range(K):
    ans = ans*P[i]%MOD
  print(ans)
  exit()
if len(P) == 0: #全て負の場合
  if K%2 == 1 and len(Z) > 0:
    print(0)
    exit()
  if K%2 == 1:
    for i in range(K):
      ans = ans*M[i]%MOD
  else:
    M.sort()
    for i in range(K):
      ans = ans*M[i]%MOD
  print(ans)
  exit()

L = [[],[]]
M.sort()
P = deque(P); M = deque(M)
pm = [0,0] #正負の数を保存
pnow = 0; mnow = 0
#print(P,M)

for i in range(K):
  if not P:
    temp = M.popleft()
    pm[1] +=1
    L[1].append(temp)
  elif not M:
    temp = P.popleft()
    pm[0] +=1
    L[0].append(temp)
  elif P and M:
    if P[0] >= abs(M[0]):
      temp = P.popleft()
      pm[0] += 1
      L[0].append(temp)
    else:
      temp = M.popleft()
      pm[1] += 1
      L[1].append(temp)
#一個ずらす
#print(L)
#print(M,P,L)
if pm[1]%2 == 1:
  if not P and not M:
    pass
  elif not M: #もう負の数が残っていない
    L[1].pop()
    L[0].append(P[0])
  elif not P: #もう正の数が残っていない
    L[0].pop()
    L[1].append(M[0])
  elif M and P:
    if L[0] and L[1]:
      if L[0][-1]*P[0] >= L[1][-1]*M[0]:
        L[1].pop()
        L[0].append(P[0])
      else:
        L[0].pop()
        L[1].append(M[0])
    elif not L[0]:
      L[1].pop()
      L[0].append(P[0])
    elif not L[1]:
      L[0].pop()
      L[1].append(M[0])
#print(L)    
for num in range(2):
  for s in L[num]:
    ans = ans*s%MOD
print(ans)


Measured memory_bytes: 107796