akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<string>
using namespace std;

typedef pair<string,int> P;
string data;
int dx[]={4,1,-4,-1};
set<string> s;
map<string,int> cost;

void bfs(){
	string str="01234567";
	cost[str]=0;
	queue<P> que;
	que.push(P(str,0));
	s.insert(str);
	while(!que.empty()){
		P tmp=que.front();que.pop();
		
		int n_0;
		for(int i=0;i<8;i++)if(tmp.first[i]=='0')n_0=i;
		for(int i=0;i<4;i++){
			if((n_0+dx[i])<8 && (n_0+dx[i])>=0){
				if(n_0==3){
					if(dx[i]==1)continue;
				}
				if(n_0==4){
					if(dx[i]==-1)continue;
				}
				P t=tmp;
				t.second++;
				swap(t.first[n_0],t.first[n_0+dx[i]]);
				if(s.find(t.first)==s.end()){
					que.push(t);
					s.insert(t.first);
					cost[t.first]=t.second;
				}
			}
		}
	}
}
bool input(){
	data.clear();
	for(int i=0;i<8;i++){
		string str;
		if(!(cin>>str))return false;
		data+=str;
	}
	return true;
}


bool check(string str){
	return str=="01234567";
}
int main(){
	bfs();
	while(input()){
		cout<<cost[data]<<endl;
	}
}

Measured memory_bytes: 5336
#include<bits/stdc++.h>
#include<math.h>
//#include<vector>
//#include <iostream>
//#include <algorithm>
#include <limits>
using namespace std;
#define nMAX numeric_limits<long long>::max()
int main(void){
	int N,K;
	int i,j,k;
	cin >> N>>K;
	int h[N+1];
	for(i=0;i<N;i++){
		cin >> h[i+1];
	}
	long long dp[N+1];
	for(i=0;i<N+1;i++){
		dp[i] = nMAX;
	}
	//cout << "aa";
	dp[1]=0;
		for(j=1;j<N;j++){
				//cout << i << " " << j << endl;
			for(k=1;(j+k<=N)&&(k<=K);k++){
				dp[j+k]=min(dp[j+k],dp[j]+abs(h[j+k]-h[j]));
			}
			/*for(k=1;k<=N;k++){
				cout << dp[k] << " ";
			}
			cout << endl;*/
		}
		
		/*for(long long i1=1;i1<=N;i1++){
			for(long long j1=1;j1<=N;j1++){
				cout << dp[i1][j1] << " ";
			}
			cout << endl;
		}*/
	
	/*for(i=1;i<=N;i++){
		for(j=1;j<=N;j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/
	//cout << endl;
	/*long long summin=MAX;
	for(i=1;i<=N;i++){
		summin=min(summin,dp[i][N]);
	}*/
	cout << dp[N] <<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  each(x,vec) is >> x;
  return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  rep(i,vec.size()) {
    if (i) os << " ";
    os << vec[i];
  }
  return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
  rep(i,vec.size()) {
    if (i) os << endl;
    os << vec[i];
  }
  return os;
}

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

bool solve() {
  ll A, B, C, D; cin >> A >> B >> C >> D;
  if (A < B) return false;
  if (D < B) return false;
  if (C >= B) return true;
  ll S = A % B;
  if (S > C) return false;
  ll R = C - S;
  ll g = gcd(B, D);
  if (C < C + g - R % g && C + g - R % g < B) return false;
  // ll X = D;
  // vector<ll> v{X};
  // while (B % X > 0) {
  //   X -= B % X;
  // }
  // ll R = B - S;
  // if (X - R % X < C) return false;
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll T; cin >> T;
  rep(t, T) {
    if (solve()) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}


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

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		//String s = sc.next();
		String s = "Christmas";
		int[] h = new int[n];
		int sum = 0;
		for(int i = 0 ; i < n ; i++) {
			h[i] = sc.nextInt();
			sum += h[i];
		}
		Arrays.sort(h);
		int min = Integer.MAX_VALUE;
		for(int i = 0 ; i < n && i + k - 1 < n; i++) {
			min = Math.min(Math.abs(h[i] - h[i + k - 1]) , min);
		}

		System.out.println(min);

	}
}



Measured memory_bytes: 59360
#include<stdio.h>
#include<iostream>
#include<math.h> 
#include<queue>
using namespace std;
typedef long long ll;
priority_queue<ll,vector<ll>,less<ll> >q;
ll n,m;
ll a;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		q.push(a);
	}
	while(m--)
	{
		a=q.top();
		q.pop();
		a=a/2;
		q.push(a);
	}
	ll sum=0;
	while(!q.empty())
	{
		sum=sum+q.top();
		q.pop();
	}
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 1400
import sys

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    S = ii(str)
    A, B, C, D = (s for s in S)
    for i in ("+", "-"):
        for j in ("+", "-"):
            for k in ("+", "-"):
                s = A + i + B + j + C + k + D
                if eval(s) == 7:
                    return s + "=7"


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 3064
/** Which of the favors of your Lord will you deny ? **/

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

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>using indexed_set = tree<TIn, null_type, less<TIn>,rb_tree_tag, tree_order_statistics_node_update>;

/**

PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;
const LL LINF = 1e17;

template <class T>
string to_str(T x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

int main()
{
    optimizeIO();

    int n,k;
    cin>>n>>k;

    vector<int>v(n);

    for(int i=0;i<n;i++)
        cin>>v[i];

    sort(ALL(v));

    int s= 0;
    for(int i=0;i<k;i++)
        s += v[i];

    cout<<s<<endl;

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}




Measured memory_bytes: 3620
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
const ll s_max = 2e4+10;
#define int ll
template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
struct state{
    ll w, s, v;
    state(){}
};
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<state> v(n);
    rep(i,n){
        cin >> v[i].w >> v[i].s >> v[i].v;
    }
    sort(all(v), [&](const auto &a, const auto &b){
        return a.s + a.w < b.s + b.w;
    });
    vector<vector<ll>> dp(n+1, vector<ll>(s_max));
    rep(i,n){
        rep(j,s_max){
            chmax(dp[i+1][j], dp[i][j]);
            if(j - v[i].w >= 0 && v[i].s >= j - v[i].w){
                chmax(dp[i+1][j], dp[i][j - v[i].w] + v[i].v);
            }
        }
    }

    ll ans = 0;
    rep(j, s_max)chmax(ans, dp[n][j]);
    cout << ans << endl;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 	int n;
 	cin >> n;
 	if(n&1)
 		cout << floor(n/2.0) * ceil(n/2.0) << endl;
 	else
 		cout << n/2 * n/2 << endl;
    return 0;
}

Measured memory_bytes: 256
a,b, c, d = list(map(int, input().split()))

ans = max([a*c, a*d, b*c, b*d])
if a <= 0 and b >= 0:
    ans = max(ans, 0)
if c <= 0 and d >= 0:
    ans = max(ans, 0)

print(ans)

Measured memory_bytes: 61676
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

int main() {
	int k[10], n;
	for (int i = 0; i < 5; ++i) { cin >> k[i]; }
	cin >> n;
	for (int i = 0; i < 5; ++i) {
		for (int j = i + 1; j < 5; ++j) {
			if (abs(k[i] - k[j]) > n) { cout << ":(" << endl; return 0; }
		}
	}
	cout << "Yay!" << endl;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007
int AB[11000][11000];

int par[100001];
int ranks[100001];

int find(int x) {           //親探し
	if (par[x] == x) {
		return x;
	}
	else {
		int z = find(par[x]);
		//par[x] = z;
		return z;
	}
}

bool  unit(int x, int y) {

	int xpar = find(x);
	int ypar = find(y);

	if (xpar == ypar) { return false; }   //すでに結合済み
	if (ranks[xpar]>ranks[ypar]) {
		par[y] = x;
	}
	else if(ranks[xpar]<ranks[ypar]){
		par[x] = y;
	}
	else {
		par[y] = x;
		ranks[xpar] += 1;
	}


	return true;
}

int main()
{

	int N;
	cin >> N;
	vector<int> K(N+1);
	pairs(J)
	pairs(D)
		fx(N) {
		par[x + 1] = x + 1;
		ranks[x + 1] = 1;
		K.at(x+1) = -1;
	}

	fx(N-1) {
		int a, b;
		cin >> a >> b;
		AB[a][b] = 1;
		AB[b][a] = 1;
		unit(a,b);
	}
	vec(C)

	fx(N) {
		vecp(C)
	}

	sorts(C)
		reverses(C)
		ll ans = 0;
	fx(N) {
		pb(J,make_pair(ranks[x+1],x+1))
	}
	sorts(J)
		reverses(J)
	/*fx(N) {
		K.at(J.at(x).second) = C.at(x);
	}*/

	queue<int> where;
	where.push(J.at(0).second);
	bool flag[11000];
	fx(N) {
		flag[x + 1] = false;
	}
	int j = 0;
	while (where.size()>0) {
		int x = where.front();
		where.pop();

		if (flag[x]) { continue; }
		flag[x] = true;
		if (K.at(x) < 0) {
			K.at(x) = C.at(j++);
		}
		fy(N) {
			if (AB[x][y+1] == 1) {
				if (!flag[y + 1]) {
					where.push(y + 1);
					if (K.at(y + 1) < 0) {
						K.at(y + 1) = C.at(j++);
					}
					ans += min(K.at(x), K.at(y+1));
					
				}
			}
		}

	}

	ce(ans)
		fx(N) {
		cout << K.at(x + 1);
		if (x != N - 1) {
			cout << ' ';
		}
		else {
			cout << endl;
		}
	}
    return 0;
}



Measured memory_bytes: 430976
import sys
from io import StringIO
import unittest
import math
from functools import reduce

def tri_gcd(l):
    return reduce(math.gcd, l)

def resolve():
    k = int(input())
    ans = 0

    """
    すべて同じ1
    ２つ同じ3
    すべて異なる6    
    """

    for i in range(1, k+1, 1):
        for j in range(i, k + 1, 1):
            for m in range(j, k + 1, 1):
                if i == j and j == m:
                    ans += tri_gcd([i, j, m])
                elif i == j or j == m:
                    ans += tri_gcd([i, j, m]) * 3
                else:
                    ans += tri_gcd([i, j, m]) * 6

    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2"""
        output = """9"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """200"""
        output = """10813692"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 16276
#include<stdio.h>

void print();

int n,i,j;
int Adj[100][100];

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

  print();

  return 0;
}

void print() {
  for( i=0 ; i<n ; i++ ) {
    for( j=0 ; j<n ; j++ ) {
      printf("%d", Adj[i][j]);
      if(j != n-1) printf(" ");
    }
    printf("\n");
  }
}

Measured memory_bytes: 636
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s=chomp(readline())
    if length(s)%2==1 || "hi"^(length(s)÷2)!=s
        println("No")
    else
        println("Yes")
    end
end
main()

Measured memory_bytes: 110272
#include<iostream>
#include<climits>
#include<string>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
using namespace std;
#define fr first
#define sc second
#define INF INT_MAX
typedef pair<int,int> Pi;
typedef pair< Pi,pair<Pi,int> > P;
struct Edge{
  int to,denger;
  Edge(){}
  Edge(int to,int denger):to(to),denger(denger){};
};
int n,m;
int m_cost[151][11][(151+1)/2+1];
vector<vector<Edge> > info;
int Dijkstra();
int main(){
  while(cin >> n >> m && n||m){
    info.resize(n);
    for(int i=0,k;i<n;i++){
      cin >> k;
      for(int j=0,t,d;j<k;j++){
        cin >> t >> d;
        info[i].push_back(Edge(t,d));
      }
    }
    cout << Dijkstra() << endl;
    info.clear();
  }
}
int Dijkstra(){
  for(int i=0;i<151;i++){
    for(int j=0;j<11;j++){
      for(int k=0;k<(151+1)/2+1;k++){
        m_cost[i][j][k] = INF;
      }
    }
  }
  priority_queue<P,vector<P>,greater<P> > que;
  for(int i=0,l=info[0].size();i<l;i++){
    que.push(P(Pi(0,m),make_pair(Pi(0,info[0][i].to),info[0][i].denger)));
    m_cost[0][i][m] = 0;
  }
  if(m != 0){
    for(int i=0,l=info[1].size();i<l;i++){
      que.push(P(Pi(0,m-1),make_pair(Pi(1,info[1][i].to),info[1][i].denger)));
      m_cost[1][i][m-1] = 0;
    }
  }
  while(!que.empty()){
    P p = que.top();
    int den = p.fr.fr,limit = p.fr.sc,slip=p.sc.sc;
    Pi pt = Pi(p.sc.fr.fr,p.sc.fr.sc);
    que.pop();
    if(pt.fr + 1 >= n) return den;
    for(int j=1;j<3;j++){
      if(j==2 && limit == 0) break;
      if(j==2 && pt.fr + 1 == n) break;
      if(j==2 && pt.fr + 2 == n) return den;
      if(j==1 && pt.fr + 1 == n) return den;
      for(int i=0,l=info[pt.fr+j].size();i<l;i++){
        int next_now = info[pt.fr+j][i].to;
        int next_den = info[pt.fr+j][i].denger;
        int hmhm = den + (slip + next_den) * abs(next_now - pt.sc);
        if(hmhm < m_cost[pt.fr+j][i][limit-(j-1)]){
          m_cost[pt.fr+j][i][limit-(j-1)] = hmhm;
          que.push(P(Pi(hmhm,limit-(j-1)),make_pair(Pi(pt.fr+j,next_now),next_den)));
        }
      }
    }
  }
}

Measured memory_bytes: 4344
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;
u64 over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n, m, x, y;
  cin >> n >> m;
  bool r[n+1];
  int c[n+1];
  for (int i = 0; i <= n; ++i) {r[i] = false; c[i] = 1;}
  r[1] = true;
  for (int i = 0; i < m; ++i) {
    cin >> x >> y;
    c[x]--;
    c[y]++;
    if (r[x]) r[y] = true;
    if (c[x]==0) r[x] = false;
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (r[i] && c[i] > 0) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  ll t = abs(x) / d;
  if (abs(abs(x) - d * t) > abs(abs(x) - d * (t + 1))) t = t + 1;
  ll min_potition;
  if (t >= k) {
    min_potition = abs(abs(x) - d * k);
    cout << min_potition << endl;
  } else {
    min_potition = abs(abs(x) - d * t);
    t = k - t;
    t %= 2;
    if (t == 0) {
      cout << min_potition << endl;
    } else {
      cout << min(abs(min_potition + d), abs(min_potition - d)) << endl;
    }
  }
  return 0;
}

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

int main() {
	int n=0;
	while(cin >> n){
		if(n==0)	break;
		int m=100000;
		while(--n>=0){
			m+=m*0.05;
			m+=(m%1000==0?0:1000);
			m/=1000;	m*=1000;
		}
		cout << m <<endl;
	}
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    map<long long,long long> maps;
    long long ans=0;
    long long m1=0;
    long long m2=0;

    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if (maps.find(-a) != maps.end() ) {
            maps[-a]++;
        }else{
            maps[-a]=1;
        }
        if (maps[-a]>=2){
            if (m1<a){
                m2=m1;
                m1=a;
                maps[-a]=0;
            }else if (m2<a){
                m2=a;
                maps[-a]=0;
            }
        }
    }
    ans=m1*m2;
    cout <<ans<<endl ;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n; i >= 0; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }

bool even(string s) {
  int n = sz(s);
  if(n % 2 == 1) return false;
  n /= 2;
  rep(i,n) {
    if(s[i] != s[i+n]) return false;
  }
  return true;
}

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

  string s;
  cin >> s;
  REP(i,sz(s)) {
    string t = s.substr(0, sz(s)-i);
    if(even(t)) {
      cout << sz(t) << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int N;
  cin >> N;
  vector<long long> a(3 * N);
  rep(i, 3 * N)
  {
    cin >> a[i];
  }
  RSORT(a);
  long long ans = 0;
  rep(i, N)
  {
    ans += a[2 * i + 1];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
using namespace std;
int main() {
	int m, d, m1, d1;
	cin >> m >> d >> m1 >> d1;
	if (m != m1) {
		cout << "1" << endl;
	}
	else {
		cout << "0" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for _ in range(n)]

maxa = max(a)
maxb = max(a)
cntmax = a.count(maxa)
if cntmax >= 2:
    for i in range(n):
        print(maxa)
    exit()
else:
    maxi = a.index(maxa)
    x = 0
    y = 0
    if maxi >= 1:
        x = max(a[:maxi])
    if maxi < n - 1 :
        y = max(a[maxi+1:])
    maxb = max(x,y)

for i in a:
    if i == maxa:
        print(maxb)
    else:
        print(maxa)

Measured memory_bytes: 12972
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  string alpha = "abcdefghijklmnopqrstuvwxyz";
  ll n;
  cin >> n;

  string ans = "";

  while(n) {
    n--;
    ans += 'a' + (n % 26);
    n /= 26;
  }
  // n--;
  // ans += alpha[n % 26];

  reverse(ans.begin(), ans.end());

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9+9;

const int maxn = 1e5*+5;
int X[maxn];

int gcd(const int a, const int b)
{
    if (b == 0)
        return a;
    return gcd(b,a%b);
}

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    int n,x;
    while (cin >> n >> x) {
        int d = inf;
        FOR(i,0,n) {
            cin >> X[i];
            d = min(d, abs(x-X[i]));
        }
        while (x > 0) {
            x -= d;
        }
        FOR(i,0,n)
            X[i] -= x;
        int g = X[0];
        FOR(i,1,n)
            g = gcd(g,X[i]);
        const int ans = min(g,d);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 640
from itertools import chain
n=int(input())
c=list(range(2*n))
for _ in[0]*int(input()):
 k=int(input())
 c=c[k:]+c[:k]if k else list(chain.from_iterable(zip(c[:n],c[n:])))
for x in c:print(x+1)


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

int main(){ 
  int N; cin >> N;
  int ans = 0;
  
  int test = 1;
  
  for(int i = 0; i < 7; i++){ 
    if( test == N){ cout << 10 << endl; return 0;}
    test *= 10;
  }
  
  while( N > 0){
    ans += N%10;
    N /= 10;
  }
  
  cout << ans << endl; return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,x,y;std::cin>>n>>x>>y;
    std::vector<lint>a(n);
    for(lint i=1;i<=n;i++){
        for(lint j=i+1;j<=n;j++){
            a.at(std::min({
                j-i,
                std::abs(i-x)+1+std::abs(y-j),
                std::abs(i-y)+1+std::abs(x-j)
            }))++;
        }
    }
    for(lint k=1;k<n;k++){
        std::cout<<a.at(k)<<'\n';
    }
}


Measured memory_bytes: 256
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
// https://atcoder.jp/contests/abc169/tasks/abc169_c
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll ans = 0;
    ll n;
    cin >> n;
    if(n != 1){
        ll nn = n;
        ll count = 0;
        for (ll i = 2; i * i <= nn; i++) {
            ll loop = 0;
            while (n % i == 0) {
                n /= i;
                loop++;
            }
            for (ll j = 1; j <= loop; j++) {
                loop -= j;
                count++;
            }
        }
        if (n != 1) {
            ans = count + 1;
        } else {
            ans = count;
        }
    }
    cout << ans;
    
 
    return 0;
}

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

using namespace std;

const int MX = 200001;

int x[MX];
__int128_t s[MX];

int main() {
	int n, X;
	ignore = scanf("%d %d", &n, &X);
	for (int i = 1; i <= n; i++) {
		ignore = scanf("%d", x + i);
		s[i] = s[i - 1] + x[i];
	}
	
	__int128_t ans = 1e18;
	for (int k = 1; k <= n; k++) {
		__int128_t cur = X * 1ll * (n + k) + 2 * (s[n] - s[n - k]);
		for (int f = n, coef = 3; f > 0; f -= k, coef += 2) {
			__int128_t sum = s[f] - s[max(f - k, 0)];
			cur += sum * coef;
		}
		ans = min(ans, cur);
	}
	
	printf("%lld\n", (long long)ans);
	
	return 0;
}


Measured memory_bytes: 4096
while (1):
	n = int(raw_input())
	way = 0
	if n == 0:	
		break
	for d in range(2, n):
		if d % 2 == 0 :
			if  (n % d) * 2 == d and n / d >= d / 2:
				way += 1
		else :
			if n % d == 0 and n / d > (d - 1) / 2:
				way += 1
	print way

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

// using mint = modint1000000007;
// using mint = modint998244353;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

void solve() {
    string s;
    cin >> s;
    if (s.back() == 's') {
        print(s + "es");
    } else {
        print(s + 's');
    }
}

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


Measured memory_bytes: 3632
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        n: usize,
    }
    let mut k = 1;
    let mut stime = 0;
    while k <= n {
        let mut time = 0;
        for i in 1..k + 1 {
            if k % i == 0 {
                time+=1;
            }
        }
        if time == 8 {
            stime+=1;
        }
        k = k + 2;
    }
    println!("{}", stime);
}

Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

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

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


pii plus(pii&a, pii&b)
{
	pii ret={a.first+b.first, a.second+b.second};
	return ret;
}


struct solve
{
	int h, w;
	int f_inf;
	vvi f;
	queue<pii> c;

	solve(vector<string>&s) {
		h=s.size();
		w=s[0].size();
		f.resize(h);
		f_inf=w*h;
		for(auto&m:f) m.assign(w, f_inf);

		for(int y=0;y<h;y++)
		{
			for(int x=0;x<w;x++)
			{
				if(s[y][x]=='#') f[y][x]=-1;
			}
		}
	}
	void fill(int x, int y, int v)
	{
		int vx[]={ 0,-1, 0, 1};
		int vy[]={-1, 0, 1, 0};

		if(x<0 || w<=x) return;
		if(y<0 || h<=y) return;

		if(f[y][x]!=f_inf) return;
		queue<pii> q;

		f[y][x]=v;
		q.push(make_pair(x, y));
		while(!q.empty())
		{
			auto [x, y]=q.front();
			c.push(make_pair(x, y));
			q.pop();
			for(int i=0;i<4;i++)
			{
				int nx=x+vx[i];
				int ny=y+vy[i];
				if(nx<0 || w<=nx) continue;
				if(ny<0 || h<=ny) continue;
				if(f[ny][nx]==f_inf)
				{
					f[ny][nx]=v;
					q.push(make_pair(nx, ny));
				}
			}
		}
	}
	ll operator()(int sx, int sy, int gx, int gy)
	{
		fill(sx-1, sy-1, 0);
		while(!c.empty())
		{
			auto [x, y]=c.front();
			c.pop();
			for(int vy=-2;vy<=2;vy++)
			{
				for(int vx=-2;vx<=2;vx++)
				{
					fill(x+vx, y+vy, f[y][x]+1);
				}
			}
		}
		int ans=f[gy-1][gx-1];
		if(ans==f_inf) return -1;

		return ans;
	}
};

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

	for(;;)
	{
		int h, w, cy, cx, gy, gx;
		cin >> h >> w >> cy >> cx >> gy >> gx;
		if(cin.fail()) break;

		vector<string> s(h);
		for(auto&m:s) cin >> m;

		cout << solve(s)(cx, cy, gx, gy) << "\n";
	}
	return 0;
}


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

const int N = 200054;

int n;
int p[N], fc[N], nc[N];
int cnt = 0, cyc[N];
int f[N], mark[N];
bool used[N];

inline void link(int x, int px) {nc[x] = fc[px], fc[px] = x;}

int dfs(int x) {
	int y, &g = f[x];
	for (y = fc[x]; y; y = nc[y]) dfs(y);
	for (y = fc[x]; y; y = nc[y]) mark[f[y]] = x;
	for (; mark[g] == x; ++g); return g;
}

int main() {
	int i, C, _;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) scanf("%d", p + i);
	for (C = 1; !used[C]; C = p[C]) used[C] = true;
	i = C;
	do cyc[cnt++] = i, _ = p[i], p[i] = 0, i = _; while (i != C);
	if (!(cnt & 1)) return puts("POSSIBLE"), 0;
	for (i = 1; i <= n; ++i) if (p[i]) link(i, p[i]);
	dfs(*cyc);
	for (i = 1; i < cnt; ++i)
		if (dfs(cyc[i]) != dfs(*cyc)) return puts("POSSIBLE"), 0;
	return puts("IMPOSSIBLE"), 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define nosol { printf("0\n"); return 0; }
#define ll long long
using namespace std;
const int N=1e6+6,P=998244353;
int n,s,k,fa[N],sz[N],a[N],lm[N],rm[N],st[N],l[N],r[N];
vector<int> G[N];
int getfa(int u){ return fa[u]==u?u:fa[u]=getfa(fa[u]); }
int calc(int x){ return x==n?n:max(x-(k-1),0); }
void merge(int x,int y){
	x=getfa(x),y=getfa(y); if (x==y) return;
	s+=calc(sz[x]+sz[y])-calc(sz[x])-calc(sz[y]); 
	fa[y]=x,sz[x]+=sz[y];
}
bool check(int x){
	int m=G[x].size(); if (!m) return true;
	if (G[x][0]==1||G[x][m-1]==n){
		int c=0,t=n; while (a[t]==x) ++c,--t; l[x]=t;
		t=1; while (a[t]==x) ++c,++t; r[x]=t;
		return c==m;
	}
	else{
		int c=0,t=G[x][0]; while (a[t]==x) ++c,++t; 
		l[x]=G[x][0]-1,r[x]=t; return c==m;
	}
}
int pre(int i){ return i==1?n:i-1; }
int suc(int i){ return i==n?1:i+1; }
int main(){
	int c1=0; scanf("%d",&n); 
	rep(i,1,n){
		scanf("%d",&a[i]); G[a[n+i]=a[i]].push_back(i);
	}
	if (G[1].size()==n){
		int ans=1; rep(i,2,n) ans=(ll)ans*i%P; 
		printf("%d\n",ans); return 0;
	}
	rep(i,1,n) if (!check(i)) nosol 
	int tp=0;
	rep(i,1,2*n){
		while (tp&&a[st[tp]]<a[i]) --tp;
		lm[i]=st[tp]?st[tp]:-n; st[++tp]=i;	
	}
	tp=0;
	per(i,2*n,1){
		while (tp&&a[st[tp]]<a[i]) --tp;
		rm[i]=st[tp]?st[tp]:3*n; st[++tp]=i;
	}
	int ans=1; k=G[1].size();
	rep(i,1,n) fa[i]=i,sz[i]=0;
	rep(i,1,n){
		int m=G[i].size();
		if (m){	
			if (m>k) nosol
			if (a[l[i]]<i&&a[r[i]]<i) ans=(ll)ans*(k-m+1)%P;
			else if (a[l[i]]>i&&a[r[i]]>i&&m!=k) nosol
		}
		else{
			if (s<i) nosol;
			ans=(ll)ans*(s-i+1)%P;
		}
		rep0(j,m) sz[G[i][j]]=1;
		rep0(j,m){
			int t=G[i][j];
			if (a[pre(t)]<=i) merge(pre(t),t);
			if (a[suc(t)]<i) merge(suc(t),t);
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

#define MAX 2002
int n;
int k1;

#define MOD 924844033
int dp[MAX][MAX][2];
int dp3[MAX][MAX][2];
int dp2[4002][MAX];

int cnt[4002];
long long int kk[MAX];

int main(){
	kk[0] = 1;
	for (int i = 1; i < MAX; i++){
		kk[i] = kk[i - 1] * (long long int)(i);
		kk[i] %= MOD;
	}
	cin >> n >> k1;
	dp[0][0][1] = 1;
	for (int i = 0; i + 1 < MAX; i++){
		for (int k = 0; k < MAX; k++){
			for (int j = 0; j < 2; j++){
				dp[i][k][j] %= MOD;
				if (dp[i][k][j]){
					if (j == 0){
						dp[i + 1][k + 1][0] += dp[i][k][j]; 
						dp[i + 1][k + 1][0] %= MOD;
					}
					dp[i + 1][k+1][1] += dp[i][k][j];
					dp[i + 1][k + 1][1] %= MOD;
					dp[i + 1][k][0] += dp[i][k][j];
					dp[i + 1][k][0] %= MOD;
				}
			}
		}
	}
	dp3[0][0][0] = 1;
	for (int i = 0; i + 1 < MAX; i++){
		for (int k = 0; k < MAX; k++){
			for (int j = 0; j < 2; j++){
				dp3[i][k][j] %= MOD;
				if (dp3[i][k][j]){
					if (j == 0){
						dp3[i + 1][k + 1][0] += dp3[i][k][j];
					}
					dp3[i + 1][k + 1][1] += dp3[i][k][j];
					dp3[i + 1][k + 1][1] %= MOD;
					dp3[i + 1][k][0] += dp3[i][k][j];
					dp3[i + 1][k][0] %= MOD;
				}
			}
		}
	}
	int k = k1;
	k*= 2;
	for (int i = 0; i < n; i++){
		cnt[i%k]++;
	}
	dp2[0][0] = 1;
	for (int i = 0; i < k; i++){
		int las = ((((n-i)+k-1) / k)-1)*k+i;
		long long int f1 = (las + k / 2 < n);
		long long int f0 = (i >= k / 2);
		for (int j = 0; j < MAX; j++){
			if (dp2[i][j]){
				dp2[i][j] %= MOD;
				for (int jj = 0; jj <= cnt[i]; jj++){
					if (f0 == 0LL){
						dp2[i + 1][j + jj] +=((long long int)( dp2[i][j]) * (dp[cnt[i]][jj][0] + f1*dp[cnt[i]][jj][1]))%MOD;
					}
					else{
						dp2[i + 1][j + jj] += ((long long int)dp2[i][j] * (dp3[cnt[i]][jj][0] + f1*dp3[cnt[i]][jj][1]))%MOD;
					}
					dp2[i+1][j + jj] %= MOD;
				}
			}
		}
	}
	long long int ans = 0;
	for (int j = 1; j < MAX; j++){
		if (dp2[k][j]){
			int rest = n - j;
			long long int way = kk[rest] * dp2[k][j];
			way %= MOD;
			if (!(j&1)){
				ans += MOD - way;
			}
			else{
				ans += way;
			}
			ans %= MOD;
		}
	}
	ans = kk[n] + MOD - ans;
	ans %= MOD;
	printf("%lld\n", ans);
	return 0;
}

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

int main(){
    string o, e;
    cin >> o >> e;
    for(int i=0;i<max(o.size(),e.size());++i){
        cout << o[i];
        if(i < e.size())cout << e[i];
    }
    cout << endl;

    return 0;
}


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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	int a, p;
	cin >> a >> p;
	cout << (3*a+p)/2 << endl;
	return 0;
} 


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	
    public static void main(String[] args) {
    	FastScanner sc = new FastScanner();
    	long X = sc.nextLong();
    	long Y = sc.nextLong();
    	
    	int l = 1;
    	
    	while(X<=Y){
    		X = X*2;
    		l += 1;
    	}
    	
    	System.out.println(l-1);
    }
    
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 23252
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 998244353;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i==n-1];};

struct BIT { //1-indexed
private:
    int n,n2;
    vector<ll> bit;

public:
    BIT(ll N){
        n = N;
        bit.resize(n+1);
        rep(i,0,n) bit[i+1] = 0;
        n2 = 1;
        while(n2 * 2 <= n) n2 *= 2;
    }

    ll sum(ll i){
        ll s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }

    void add(ll i, ll x){
        if(i == 0) return;
        while(i <= n){
            bit[i] += x;
            i += i & -i;
        }
    }
    ll lower_bound(ll w) {
        if (w <= 0) return 0;
        ll x = 0;
        for (ll k = n2; k > 0; k /= 2) {
            if (x + k <= n && bit[x + k] < w) {
                w -= bit[x + k];
                x += k;
            }
        }
        return x + 1;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll x[200010], y[200010];
    rep(i,0,N) cin >> x[i] >> y[i];
    vector<ll> X, Y;
    rep(i,0,N){
        X.push_back(x[i]);
        Y.push_back(y[i]);
    }
    X.push_back(-INF);
    X.push_back(INF);
    Y.push_back(-INF);
    Y.push_back(INF);
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());

    rep(i,0,N){
        x[i] = lower_bound(X.begin(), X.end(), x[i]) - X.begin();
        y[i] = lower_bound(Y.begin(), Y.end(), y[i]) - Y.begin();
    }
    vector<lpair> lp;
    rep(i,0,N) lp.push_back(make_pair(x[i], y[i]));
    sort(lp.begin(), lp.end());
    rep(i,0,N){
        x[i] = lp[i].first;
        y[i] = lp[i].second;
    }

    BIT Lb(200010), Rb(200010);
    rep(i,0,N) Rb.add(y[i], 1);
    ll pow_mod[200010] = {};
    pow_mod[0] = 1;
    rep(i,0,N+1) pow_mod[i+1] = pow_mod[i] * 2 % MOD;
    ll ans = 0;
    rep(i,0,N){
        Rb.add(y[i], -1);
        rep(bit,0,16){
            ll RT = Rb.sum(N) - Rb.sum(y[i]);
            ll RD = Rb.sum(y[i]);
            ll LT = Lb.sum(N) - Lb.sum(y[i]);
            ll LD = Lb.sum(y[i]);
            ll b0 = ((bit>>0) & 1);
            ll b1 = ((bit>>1) & 1);
            ll b2 = ((bit>>2) & 1);
            ll b3 = ((bit>>3) & 1);
            RT = b0 ? pow_mod[RT] - 1 : 1;
            RD = b1 ? pow_mod[RD] - 1 : 1;
            LT = b2 ? pow_mod[LT] - 1 : 1;
            LD = b3 ? pow_mod[LD] - 1 : 1;
            
            ll v = RT * RD % MOD * LT % MOD * LD % MOD;
            if((b0 && b3) || (b1 && b2)) (v *= 2) %= MOD;
            (ans += v) %= MOD;
        }
        Lb.add(y[i], 1);
    }
    print(ans);
}

Measured memory_bytes: 15328
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long INF = 1e9 + 7;
using namespace std;
typedef long long ll;

map<int, int> mp;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	char s[101], p[101];
	cin >> s;
	cin >> p;
	int j, s_length = 0;
	for (int i = 0; s[i] != '\0'; i++) s_length++;
	for (int left = 0; s[left] != '\0'; left++) {
		for (j = 0; p[j] != '\0' && p[j] == s[(left + j) % s_length]; j++);
		if (p[j] == '\0') {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3216
MOD = 1_000_000_007

n, k = gets.split.map(&:to_i)
table = Array.new(k + 1, 0)
table[0] = 1
n.times do
  new_table = Array.new(k + 1, 0)
  (1..k).each do |i|
    new_table[i] = (table[i - 1] + table[i] * i) % MOD
  end
  table = new_table
end
p table[k]



Measured memory_bytes: 14712
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int length = line.length();
        String ans = "";
        char[] a;
        a = new char[length];
        for(int i=0; i<length; i++) {
            a[i] = line.charAt(i);
            if(Character.isLowerCase(a[i])) ans += Character.toUpperCase(a[i]);
            else ans += Character.toLowerCase(a[i]); 
        }
        System.out.println(ans);
    }
}


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

int main(void){
    int A,B,C;
    cin >> A >> B >> C ;
    bool can = false;
    for(int i=1 ; i < A*B ;i++){
        if(A*i % B ==C) can = true;
    }
    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int maxx = 110;
int n, m[maxx][maxx];
int u, num, v;
int flag[maxx];
int d[maxx];


void bfs() {
	queue<int>q;

	q.push(1);
	d[1] = 0;
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		for (int i = 2; i <= n; i++) {
			if (m[u][i] == 1 && flag[i] == 0) {
				// ?????°???????????????
				flag[i] = 1;
				// ??´??°??????
				d[i] = d[u] + 1;
				// ?????\??????
				q.push(i);
			}
		}
	}
}
int main()
{

	scanf("%d", &n);
	memset(m, 0, sizeof(m));
	for (int i = 1; i <= n; i++) {
		scanf("%d %d", &u, &num);

		// ????§????
		flag[i] = 0;
		d[i] = -1;
		for (int j = 1; j <= num; j++) {
			scanf("%d", &v);
			m[u][v] = 1;
		}
	}
	bfs();
	for (int i = 1; i <= n; i++) {
		printf("%d %d\n", i, d[i]);
	}
	return 0;
}

Measured memory_bytes: 3276