akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using V = vector<int>;

int main(int argc, char const *argv[])
{
    int n, k; cin >> n >> k;
    int p[n], c[n];
    rep(i,n) {
        cin >> p[i];
        p[i]--;
    }
    rep(i,n) cin >> c[i];
    vector<vector<int> > v;
    vector<bool> b(n,false);
    rep(i,n) {
        if (b[i]) continue;
        v.push_back({c[i]});
        b[i] = true;
        int j = p[i];
        while (j != i) {
            v.back().push_back(c[j]);
            b[j] = true;
            j = p[j];
        }
    }
    int l, q, r;
    long long int sum, d[10010], ans = -1e14;
    for (auto s : v) {
        l = s.size();
        q = k/l; r = k%l;
        sum = 0;
        for (int i = 0; i < l; i++)
        {
            sum += s[i];
        }
        
        d[0] = s[0]; d[l] = sum+s[0];
        for (int i = 0; i < l-1; i++)
        {
            d[i+1] = d[i] + s[i+1];
            d[l+i+1] = d[i+1] + sum;
        }
        /*
        for (int i = 0; i < 2*l; i++) cout << d[i] << " ";
        cout << endl;
        cout << "l:" << l << endl;
        */
        if (q == 0)
        {
            for (int i = 0; i < l; i++)
            {
                for (int j = 0; j < r; j++)
                {
                    ans = max(ans,d[i+j+1]-d[i]);
                    //cout << d[i+j+1]-d[i] << endl;
                }
            }
        }
        else {
            for (int i = 0; i < l; i++)
            {
                for (int j = 0; j < r; j++)
                {
                    ans = max(ans,max(d[i+j+1]-d[i],d[i+j+1]-d[i]+sum*q));
                    //cout << d[i+j+1]-d[i] << endl;
                }
            }
            for (int i = 0; i < l; i++)
            {
                for (int j = 0; j < l; j++)
                {
                    ans = max(ans,max(d[i+j+1]-d[i],d[i+j+1]-d[i]+sum*(q-1)));
                    //cout << d[i+j+1]-d[i] << endl;
                }
            }

        }
        
        
        //cout << ans << endl;
    }
    cout << ans << endl;




    /*
    cout << v.size() << endl;
    for (auto s : v) {
        for (auto x : s) {
            cout << x << " ";
        }
        cout << endl << s.size() << endl;
    }
    */
    return 0;
}


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

int main(){
  string s;
  ll q;
  cin >> s >> q;
  deque<char> dS(s.size());
  for(int i=0; i<s.size(); i++) dS[i] = s[i];
  
  
  int flag = 0;
  for(ll i=0; i<q; i++){
    int t; cin >> t;
    
    
    if(t==2){
      int f; char c;
      cin >> f >> c; f--;
      
      if(flag) f = 1 - f;
      if(f==0) dS.push_front(c);
      else dS.push_back(c);
    
    }else{
      flag = 1 - flag;
    
    }
  }
  
  if(flag) reverse(dS.begin(), dS.end());
  
  for(auto s:dS) cout << s;
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 3832
#include<cstdio>
#include<set>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 1000000+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;
struct Edge {
    int to,next,val;
    Edge(){}
    Edge(int to,int next,int val):to(to),next(next),val(val){}
    bool operator < (const Edge& rhs)const{
        return val>rhs.val;
    }
}edge[N*2];
int tot,head[N];
void addEdge(int from,int to,int val) {
    edge[tot].next=head[from];
    edge[tot].to=to;
    edge[tot].val=val;
    head[from]=tot++;
}
bool vis[N];
int dis[N];
int SPFA(int s,int e) {
    memset(vis,false,sizeof(vis));
    memset(dis,INF,sizeof(dis));
    dis[s]=0;
 
    priority_queue<Edge> Q;
    Q.push(Edge(s,0,0));
    while (!Q.empty()) {
        Edge temp=Q.top();
        Q.pop();
        if(vis[temp.to])
            continue;
        vis[temp.to]=true;
 
        for(int i=head[temp.to]; i!=-1; i=edge[i].next) {
            if(dis[edge[i].to]>dis[temp.to]+edge[i].val) {
                dis[edge[i].to]=dis[temp.to]+edge[i].val;
                Q.push(Edge(edge[i].to,0,dis[edge[i].to]));
            }
        }
    }
    if(dis[e]!=INF)
        return dis[e]/2;
    return -1;
}
map<int,int> mp[N];
int allPoint;
int getPoint(int x,int y) {
    if (!mp[x][y])
        mp[x][y]=++allPoint;
    return mp[x][y];
}
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    memset(head,-1,sizeof(head));
    allPoint=n;
    for (int i=1; i<=m; i++) {
        int x,y,w;
        scanf("%d%d%d",&x,&y,&w);
 
        int newX=getPoint(x,w);
        int newY=getPoint(y,w);
 
        addEdge(x,newX,1);
        addEdge(newX,x,1);
        addEdge(newX,newY,0);
        addEdge(newY,newX,0);
        addEdge(y,newY,1);
        addEdge(newY,y,1);
    }
    int res=SPFA(1,n);
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 93812
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int main(){
	scanf("%d%d%d",&n,&m,&k);
	if(n==1||m==1) return puts("Yes\n"),0;
	if(!(k%n)||!(k%m)||k==m*n||!k) return puts("Yes\n"),0;
	int temp;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++){
			temp=i*j+(n-i)*(m-j);
			if(temp==k) return puts("Yes\n"),0;
		}
	return puts("No\n"),0;
}

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

int main()
{
    int t;
    cin >> t;
    int ac = 0, wa = 0, tle = 0, re = 0;
    string s;
    while (t--)
    {
        cin >> s;
        if (s == "AC")
        {
            ac++;
        }
        else if (s == "WA")
            wa++;
        else if (s == "TLE")
            tle++;
        else if (s == "RE")
            re++;
    }

    cout << "AC x " << ac << "\n"
         << "WA x " << wa << "\n"
         << "TLE x " << tle << "\n"
         << "RE x " << re << "\n";
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi=vector<int>;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int x;
    cin >> x;
    if(x<=599){
        cout << 8 << "\n";
        return 0;
    }else if(x>=600 && x<=799){
        cout << 7 << "\n";
        return 0;   
    }else if(x>=800 && x<=999){
        cout << 6 << "\n";
        return 0;   
    }else if(x>=1000 && x<=1199){
        cout << 5 << "\n";
        return 0;   
    }else if(x>=1200 && x<=1399){
        cout << 4 << "\n";
        return 0;   
    }else if(x>=1400 && x<=1599){
        cout << 3 << "\n";
        return 0;   
    }else if(x>=1600 && x<=1799){
        cout << 2 << "\n";
        return 0;   
    }else if(x>=1800 && x<=1999){
        cout << 1 << "\n";
        return 0;   
    }
}   

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r,g,b,n;
  cin>>r>>g>>b>>n;
  long long count=0;
  for(int i=0;i<=n/r;i++){
    if(i*r>n)break;
    for(int j=0;j<=n/g;j++){
      int k;
      if(i*r+j*g>n)break;
      k=(n-i*r-j*g)/b;
      if(i*r+j*g+k*b>n)break;
      if(i*r+j*g+k*b==n)count++;
    }
  }
  cout<<count<<endl;
  return 0;
}

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

using namespace std;

template<typename T>
T gcd(T a, T b) {
    while(1) {
        if(a<b) swap(a,b);
        if(b==0) break;
        T c = a%b;
        a=b; b=c;
    }
    return a;
}

template<typename T>
T multi_gcd(vector<T>& x) {
    T ans = x[0];
    for(auto v: x) {
        ans = gcd(ans,v);
    }
    return ans;
}

int main(int argc, char const *argv[])
{
    int n; cin >> n;
    vector<unsigned int> a(n,0);
    for(int i=0;i<n;++i) {
        cin >> a[i];
    }
    cout << multi_gcd(a) << endl;
    return 0;
}


Measured memory_bytes: 640
N,W = map(int,input().split())
dp = [[0 for i in range(W+1)] for j in range (N+1)]

for i in range(N):
    w,v = map(int,input().split())
    for sw in range(W+1):
        if sw < w:
            dp[i+1][sw] = dp[i][sw]
        else:
            dp[i+1][sw] = max((dp[i][sw]),(dp[i][sw-w]+v))
print(dp[-1][-1])


Measured memory_bytes: 171400
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  long long mx = min(A, K) - max(0ll, K - (A + B));
  cout << mx << endl;
  return 0;
}


Measured memory_bytes: 3648
dim = int(input())
a, b = list(map(int, input().split())), list(map(int, input().split()))
dif = [ abs(x-y) for x, y in zip(a, b)]
print("%lf\n%lf\n%lf\n%lf" % (sum(dif), 
                                sum([i ** 2 for i in dif]) ** (1 / 2),
                                sum([i ** 3 for i in dif]) ** (1 / 3),
                                max(dif)
                                ))


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

using namespace std;

int main() {
    int l, r, d;
    cin>>l>>r>>d;
    int count=0;
    for (int i=l; i<=r; i++){
        if(i%d==0){
            count++;
        }
    }
    cout<<count;
    
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void yes() { cout << "YES" << endl; exit(0); }
void no() { cout << "NO" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> void amax(T &x, T y) { x = max(x, y); }
template <typename T> void amin(T &x, T y) { x = min(x, y); }
template <typename T> T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

template <typename T, typename U>
vector<U> make_vector(T&& n, U&& val) {
  return vector<U>(forward<T>(n), forward<U>(val));
}
template <typename T, typename... Args>
decltype(auto) make_vector(T&& n, Args&&... args) {
  return vector<decltype(make_vector(forward<Args>(args)...))>(forward<T>(n), make_vector(forward<Args>(args)...));
}

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

void solve() {
  int r, c, n;
  cin >> r >> c >> n;
  using T = tuple<int, int>;
  vector<T> v;
  auto check = [&](int x, int y) -> bool {
    if (x == 0 || x == r) return true;
    if (y == 0 || y == c) return true;
    return false;
  };
  auto to = [&](int x, int y) -> int {
    if (x == 0) return y;
    if (y == c) return c + x;
    if (x == r) return c + r + (c - y);
    return r + c * 2 + (r - x);
  };
  int id = 0;
  rep(i, n) {
    vi32 o(4);
    cin >> o;
    if (check(o[0], o[1]) && check(o[2], o[3])) {
      v.emplace_back(to(o[0], o[1]), id);
      v.emplace_back(to(o[2], o[3]), id);
      id += 1;
    }
  }
  sort(all(v));
  stack<int> s;
  vector<bool> exist(id);
  rep(i, sz(v)) {
    int num, id;
    tie(num, id) = v[i];
    if (exist[id]) {
      if (s.top() != id) {
        no();
      }
      s.pop();
    } else {
      s.push(id);
      exist[id] = true;
    }
  }
  yes();
}


Measured memory_bytes: 5400
#include<stdio.h>
int main(void){

  int h,w;
  int i,j;
  int a;
  

  while(1){

    scanf("%d %d",&h,&w);
    if(h==0&&w==0)break;

    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	(a=i+j);
	if(a%2==1){
	  printf(".");
	}else{
	  printf("#");
	}
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1000
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
using namespace std;

const int N = 7777;
int a[N];
int n, m;
int col;
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("flow2.in", "r", stdin);
    //freopen("flow2.out", "w", stdout);
    cin >> n >> m;
    cin >> col;
    int mx = max(n, m);
    if (col % mx == 0){
        cout << col / mx << endl;
    }
    else {
        cout << col / mx + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N=int(input())

A=[[-1]*N for _ in range(N)]
for i in range(N):
  a=int(input())
  for j in range(a):
    x,y=map(int, input().split())
    A[i][x-1]=y
#正直者が正直者に不親切と言われていない
#→正直ものが不親切を正直者と言っていないか
ans=0
for i in range(2**N):
  ok=True
  for j in range(N):
    if (i>>j&1)==1:
      for k in range(N):
        if A[j][k]!=-1 and (i>>k&1)!=A[j][k]:
          ok=False
  if ok:
    ans=max(ans, bin(i).count("1"))
  
print(ans)

Measured memory_bytes: 3188
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
const int MAX_N = 50;
ll N,M;
ll a[MAX_N], b[MAX_N];
bool visited[MAX_N]; // 各頂点が通過済みか
bool graph[MAX_N][MAX_N]; //隣接行列 adjacency matrix

// 現在位置(x)
void dfs(ll v){
	visited[v] = true; // 今いるところをtrueに置き換える
	REP(v2,N){
		if (graph[v][v2]==false) continue; // 隣接してないなら何もしない
		if (visited[v2]==true) continue; // 隣接先が訪問済みなら何もしない
		dfs(v2); // 隣接先について探索
	}
    // return;
}
 
int main() {
	// 入力
	cin >> N>>M;
	REP(i,M){
		cin>>a[i]>>b[i];
		a[i]--;b[i]--;
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
	}
	
	// 解法
	ll ans = 0;
	REP(i,M){ // 各辺について
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = false; // i辺を抜いてみる
		REP(j,N) visited[j] = false; // 訪問済み判定初期化
		dfs(0); // DFSで連結判定
		REP(j,N) if (visited[j]==false){ // 訪問してないとこがあるなら橋
	// 		printf("辺 %lld =橋\n", i);
			ans++;
			break;
		}
		graph[a[i]][b[i]] = graph[b[i]][a[i]] = true; // 抜いた辺を復元
		
		// printf("辺 %lld\n", i);
		// REP(j,N) printf("%lld ", visited[j]);
		// printf("\n");
	}
	cout << ans<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 1e6+3;

Int n;
vector<Int> G[100005];
bool visited[100005];
Int res = 1;

Int ind;
Int d;

bool dfs(Int x) {
    if (visited[x]) return false;
    visited[x] = true;
    Int cnt = 0;
    bool ret = false;
    if (x != ind && (Int)G[x].size() - 1 >= 2) ret = true;
    if (x == ind && G[x].size() >= 2) ret = true;   
    for (Int i = 0; i < (Int)G[x].size(); i++) {
        Int to = G[x][i];
        if (!visited[to]) {
            if (!dfs(to)) {
                cnt++;
            }
            else {
                ret = true;
            }
        }
    }
    res += max((Int)0, cnt - 1);
    return ret;
}

void dfs2(Int x, Int depth) {
    if (visited[x]) return;
    visited[x] = true;
    if (depth > d) {
        d = depth;
        ind = x;
    }
    for (Int i = 0; i < (Int)G[x].size(); i++) {
        Int to = G[x][i];
        if (!visited[to]) {
            dfs2(to, depth + 1);
        }
    }
}

int main() {
    cin >> n;
    for (Int i = 0; i < n - 1; i++) {
        Int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    memset(visited, 0, sizeof(visited));
    dfs2(0, 0);
    memset(visited, 0, sizeof(visited));
    dfs(ind);
    dump(res);
    return 0;
}

Measured memory_bytes: 10496
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: isize = sc.input();
    let ts: Vec<isize> = (0..n)
        .map(|_| sc.input())
        .collect();

    let m: isize = sc.input();
    let drinks: Vec<(isize, isize)> = (0..m)
        .map(|_| (sc.input(), sc.input()))
        .collect();

    let sum: isize = ts.iter().sum();

    for (p, x) in drinks {
        let index = p - 1;
        println!("{}", sum - ts[index as usize] + x);
    }
}


Measured memory_bytes: 4352
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{BufWriter, Write};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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)*}
    };
}
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)*}
    };
}
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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        x: i64,
    }

    for i in -2000..2000 {
        for j in -2000..2000 {
            if (i as i128).pow(5) - (j as i128).pow(5) == x as i128 {
                println!("{} {}", i, j);
                return;
            }
        }
    }
}


Measured memory_bytes: 2032
#include <stdio.h>
 
int main(void)
{
int a,b,c,n,i;
 
scanf("%d %d",&a,&b);
 
while(a!=0&&b!=0){
for(i=0;i<a;i++)
{
     
     
        if(i==0||i==a-1){
            for(c=0;c<b;c++)
            printf("#");
        }
        else
        {
            printf("#");
            for(c=0;c<b-2;c++)
            {
                printf(".");
            }
            printf("#");
        }
 
        printf("\n");
    }
printf("\n");
scanf("%d %d",&a,&b);
}
return 0;
 
}

Measured memory_bytes: 572
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <climits>
#include <string>
#include <vector>

using namespace std;

int main () {
    long long n = 0, k = 0;
    cin >> n >> k;
    vector<long long> candle(n);
    for (int i=0; i<n; i++) {
        cin >> candle.at(i);
    }
    int zero = lower_bound(candle.begin(), candle.end(), 0) - candle.begin();
    long long mini = (n - zero >= k) ? candle.at(zero-1+k) : LLONG_MAX;
    for (int i=0; i<zero; i++) {
        if (zero - i > k) continue;
        if (k + i - 1 > n-1) break;
        if (zero - i == k) mini = min(abs(candle.at(i)), mini);
        else mini = min(abs(candle.at(i)) + candle.at(k + i - 1) + min(abs(candle.at(i)), candle.at(k+i-1)), mini);
    }
    cout << mini << endl;
    return 0;
}


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

bool comp(const pair<string,int> a, const pair<string,int> b) {
  if (a.first != b.first)
    return a.first < b.first; // 高い順に並べたいので演算子を逆に
  
  else{
      return a.second > b.second;

  }
}

int main(){
  int N;
  vector<pair<string,int>> list;
  vector<pair<string,int>> copy;

  cin >>N;

  for(int i = 0; i< N;i++){
      string s;
      int p;
      cin >>s>>p;
      list.push_back(make_pair(s,p));
      copy.push_back(make_pair(s,p));
  }

  sort(list.begin(),list.end(),comp);

  for(int i = 0; i< N ; i++){
      for(int j = 0;j < N;j++){
          if(list[i].first == copy[j].first && list[i].second == copy[j].second){
              cout <<j+1<<endl;
          }

      }
  }

  return 0;
  }

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

int main(int argc, char *argv[]) {
    long long n;
    cin >> n;
    long long a[n];
    long long c=1000;
    long long k=0;
    long long d;
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n-1;i++){
        if(a[i]<a[i+1]){
            d=c/a[i];//買う株の数
            c=c-d*a[i];
            k=k+d;
        }
        else if(a[i]>a[i+1]){
            c=c+k*a[i];
            k=0;
        }
    }
    c=c+k*a[n-1];
    cout << c << endl;
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    if(n%1000==0)
    {
        cout<<"0";
        return 0;
    }
    int k=n/1000;
    int ans=((k+1)*1000)-n;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int a[2];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	int x=a[2]-a[0];
	int y=a[2]-a[1];
	int sum=0;
    if((x-y)%2==0){
        sum=x+(y-x)/2;
    }
	if((x-y)%2!=0){
		if(a[2]%2==a[0]%2){
			
			sum=x+1+(y-x+1)/2;
		}
		else{
			sum=x+1+(y-x)/2;
		}
	}
	cout<<sum<<endl;
}

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

struct dat{ int id, point; };
#define MAX_N 1 << 17

int N, R, L;
int res[MAX_N + 1];
dat seg[2 * MAX_N];
int n;

void init(){
//	printf("c");
	n = 1;
	while(n < N) n *= 2;//nはseg木の要素数
//	printf("[n = %d]", n);
	for(int i = 0; i < 2 * n - 1; i++) seg[i].point = 0;
//	printf("a");
	for(int j = 1; j <= N; j++){
		seg[n + j].id = j;
	}
//	printf("b");
}

void add(int p, int x){
	p += n;
	seg[p].point += x;
	while(p > 0){
		//printf("p = %d\n", p);
		p = (p - 1) / 2;
		if(seg[p * 2 + 1].point >= seg[p * 2 + 2].point){
			seg[p] = seg[p * 2 + 1];
		}
		else{
			seg[p] = seg[p * 2 + 2];
		}
	}
}

int main(){
	scanf("%d%d%d", &N, &R, &L);
	
	init();
	
	int lb = 0;//左端
	int d, t, x;
	for(int i = 0; i < R; i++){
		scanf("%d%d%d", &d, &t, &x);
		if(i > 0) res[seg[0].id] += t - lb;
		add(d, x);
		lb = t;
//		for(int i = 1; i <= N; i++){
//			printf("%d ", res[i]);
//		}
//		printf(": seg[0].id = %d\n", seg[0].id);
	}
	res[seg[0].id] += L - t;
	
	int longest = 0;//最長の映り時間
	for(int i = 1; i <= N; i++) longest = max(longest, res[i]);
	for(int i = 1; i <= N; i++){
		if(res[i] == longest){
			printf("%d\n", i);
			return 0;
		}
	}
}

Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111



	void solve(){


		vi morty;
		ini(n);
		FOR(i,0,n){
			ini(x);
			morty.push_back(x);
		}
		//multiset<int> set1;
		//set1.insert(0);
		map<int,int>map1;
		map1[0]++;
		int tmp = 0;
		int rick = 0;
		FOR(i,0,n){
			tmp+=morty[i];
			rick+=map1[tmp];
			map1[tmp]++;
		}
		out(rick);





	}	























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 14320
#include <iostream>

using namespace std;
int main(){
        int a,b,c,x;
        cin >> a >> b >> c >> x;
        int res = 0;
        for (size_t i = 0; i <= a; i++) {
                for (size_t j = 0; j <= b; j++) {
                        for (size_t k = 0; k <= c; k++) {
                                if(500*i + 100*j + 50*k == x) res++;
                        }
                }
        }
        cout << res << endl;

        return 0;
}

Measured memory_bytes: 256
# Dinic's algorithm
from collections import deque
class Dinic:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [None]*self.N
        deq = deque([s])
        level[s] = 0
        G = self.G
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        return level[t] is not None

    def dfs(self, v, t, f):
        if v == t:
            return f
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        INF = 10**9 + 7
        G = self.G
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow


import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

score = 0
INF = float('inf')
graph = Dinic(n+2)

for i in range(n):
    if a[i]>0:
        graph.add_edge(i+1,n+1,a[i])
        score += a[i]
    elif a[i]<0:
        graph.add_edge(0,i+1,-a[i])

for i in range(1,n//2+1):
    for j in range(2*i,n+1,i):
        graph.add_edge(i,j,INF)

print(score-graph.flow(0,n+1))

Measured memory_bytes: 9248
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
using ll = long long;
using ull = unsigned long long;

int a[5][5];
bool f[5][5];
vector<int> v;

int main() {
    FAST;

    rep(i, 3){
        rep(j, 3){
            cin >> a[i][j];
        }
    }

    int n;
    cin >> n;
    rep(i, n){
        int val;
        cin >> val;

        rep(j, 3){
            rep(k, 3){
                if(val == a[j][k]){
                    f[j][k] = true;
                }
            }
        }
    }

    bool flag = false;
    for(int i = 0; i < 3; ++i){
        if(f[i][0] == 1 && f[i][1] == 1 && f[i][2] == 1){
            flag = true;
        }

        if(f[0][i] == 1 && f[1][i] == 1 && f[2][i] == 1){
            flag = true;
        }
    }


    if(f[0][0] == 1 && f[1][1] == 1 && f[2][2] == 1){
        flag = true;
    }
    if(f[0][2] == 1 && f[1][1] == 1 && f[2][0] == 1){
        flag = true;
    }


    if(flag){
        println("Yes");
    }else{
        println("No");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define MP make_pair
#define PB push_back
#define PII pair<int,int>
typedef long long LL;
const LL P = 1e9+7;
const int N = 5005;
const double pi = acos(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int n,m,p,x[N],y[N],z[N];
int d[N];
 
int main(){
	scanf("%d%d%d",&n,&m,&p);
	rep(i,1,m){
		scanf("%d%d%d",&x[i],&y[i],&z[i]);
		z[i] = p - z[i];
	}
	rep(i,1,n)d[i]=1e9;
	d[1] = 0;
	rep(i,1,n-1)rep(j,1,m)
		d[y[j]] = min(d[y[j]], d[x[j]]+z[j]);
	int ans = d[n];
	rep(i,1,n)rep(j,1,m)
		d[y[j]] = min(d[y[j]], d[x[j]]+z[j]);
	cout<<(ans==d[n]?max(0,-ans):-1)<<endl;
	return 0;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	q := getNextInt(scanner)
	seg := newSegment(n)
	v := 1
	seg.update(0, n, math.MaxInt32, v)
	for i := 0; i < q; i++ {
		switch getNextInt(scanner) {
		case 0:
			s := getNextInt(scanner)
			t := getNextInt(scanner)
			x := getNextInt(scanner)
			v++
			seg.update(s, t+1, x, v)
			continue
		}
		fmt.Fprintln(writer, seg.get(getNextInt(scanner)))
	}
}

type version struct {
	updated, x int
}

type segment [][]version

func newSegment(n int) segment {
	seg := make(segment, 0)
	for n > 1 {
		seg = append(seg, make([]version, n))
		n = (n + 1) >> 1
	}
	seg = append(seg, make([]version, 1))
	return seg
}
func (seg segment) get(i int) int {
	var x version = seg[0][i]
	for h := 0; h < len(seg); h++ {
		if seg[h][i].updated >= x.updated {
			x = seg[h][i]
		}
		i >>= 1
	}
	return x.x
}
func (seg segment) update(l, r, x, updated int) {
	for h := 0; h < len(seg) && l < r; h++ {
		if l%2 == 1 {
			seg[h][l].updated = updated
			seg[h][l].x = x
			l++
		}
		l >>= 1
		if r%2 == 1 {
			seg[h][r-1].updated = updated
			seg[h][r-1].x = x
		}
		r >>= 1
	}
}



Measured memory_bytes: 7268
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        long n = Long.parseLong(buffer.readLine());
        String name = "";
        while (n != 0)
        {
            n--;
            name += (char)('a'+ (n%26));
            n /= 26;
        }
        sb.append(name);
        sb = sb.reverse();
        sb.append("\n");
        System.out.println(sb);
    }
}


Measured memory_bytes: 36940
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define ll long long
int main() {
    char ca;
    cin>>ca;
    if(ca=='A')
    cout<<"T"<<endl;
    else if(ca=='T')
    cout<<"A"<<endl;
    else if(ca=='C')
    cout<<"G"<<endl;
    else {if(ca=='G')
    cout<<"C"<<endl;}
}

Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main() {
    string s;
    cin>>s;
    int n=s.size();
    bool same=false;
    for(int i=0;i<n;++i){
        for(int j=0;j<i;++j){
            if(s[i]==s[j]){
                same=true;
            }
        }
    }
    if(same==false){
        cout<<"yes"<<endl;
    }else{
        cout<<"no"<<endl;
    }
    return 0;
}

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

using namespace std;
int main(int argc, const char * argv[]) {
    
    int s0_unex = 0;// 010101...を想定した場合の想定外の数した場合の想定外の数
    int s1_unex = 0;// 101010...
    int s0_next_exp = 0;
    int s1_next_exp = 1;
    string line;
    cin >> line;
    for(int i = 0; i < line.length(); i++) {
        char c = line[i];
        if(c == '0') {
            if(s0_next_exp != 0) {
                s0_unex++;
            }
            if(s1_next_exp != 0) {
                s1_unex++;
            }
        } else {
            if(s0_next_exp != 1) {
                s0_unex++;
            }
            if(s1_next_exp != 1) {
                s1_unex++;
            }
        }
        s0_next_exp = (s0_next_exp+1)%2;
        s1_next_exp = (s1_next_exp+1)%2;
    }

    cout << min(s0_unex, s1_unex) << endl;
    
    return 0;
}


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


int main()
{
    string s,t;
    cin>>s>>t;
    int ans=s.size();
    for(int i=0;i<=s.size()-t.size();++i) {
        int cnt=0;
        for(int j=0;j<t.size();++j) if(s[i+j]==t[j]) cnt++;
        ans=min(ans,(int)t.size()-cnt);
    }
    cout<<ans;
}

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

#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define __m  int mid=(l+r)>>1;

const int maxn=1000;
const int inf =2e9+7;
const int mod =1e9+7;

char num[maxn];
int main()
{
#ifdef LOCAL
    freopen("1.in","r",stdin);
#endif
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    sprintf(num,"%d",n);
    int len=strlen(num);
    int have=0;
    for(int i=0;i<len;i++) 
        have+=num[i]-'0';
    if(n%have==0)
        cout<<"Yes"<<endl;
    else 
        cout<<"No"<<endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


int32_t main()
{


  
    IOS


   	string s,t;
   	cin >> s >> t;

   	int ans =0;
   	for(int i = 0; i < s.size(); i++)
   	{
   		ans += (s[i] != t[i]);
   	}


   	cout << ans;
    return 0;
}


Measured memory_bytes: 3756
//package AtCoder.ABC158;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) {
        Deque<Character> que = new LinkedList<>();
        String ini = in.next();
        for (int i=0;i<ini.length();i++) que.addLast(ini.charAt(i));
        int q = in.NI();

        int flipcoun = 0;
        for (int i=0;i<q;i++) {
            int type = in.NI();
            if (type==1) {  flipcoun++; continue;}
            else {
                int subtype = in.NI(); String ch = in.next();
                if (flipcoun%2==0) {
                    if (subtype==2) que.addLast(ch.charAt(0));
                    else que.addFirst(ch.charAt(0));
                } else {
                    if (subtype==2) que.addFirst(ch.charAt(0));
                    else que.addLast(ch.charAt(0));
                }
            }
        }

        if(flipcoun%2==0) {
            while(que.size()>0) {
                out.print(que.poll());
            }
        } else {
            while(que.size()>0) {
                out.print(que.pollLast());
            }
        }
        out.println();
        out.close();
    }


    static InputStream inputStream = System.in;
    static OutputStream outputStream = System.out;
    static InputReader in = new InputReader(inputStream);
    static PrintWriter out = new PrintWriter(outputStream);

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        public int NI() {
            return Integer.parseInt(next());
        }

        public long NL() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 77804
/*input
4 5
##...
.##..
..##.
...##
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double

typedef pair<int,int> pi;

typedef vector<int> vi;
typedef vector<pi> vpi;

#define f first
#define s second
#define mp make_pair
#define pb push_back

#define gcd __gcd

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int fast_ex(int a,int n,int m){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= fast_ex(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int i,j;

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int ans = 0;
  int n,m;
  cin >> n >> m;
  for(i = 0;i < n;i++){
  	for(j = 0;j < m;j++){
  		char o;cin >> o;
  		if(o == '#')ans++;
  	}
  }
  if(ans == n+m-1)cout << "Possible";
  else cout << "Impossible";
  return 0;
}

Measured memory_bytes: 256
def absolute(N,K):
    return abs(N-K)
    
N,K=map(int,input().split())
N=N%K
valuelist = [N%K]

for i in range (0,pow(10,1)):
    i+=1
    N=absolute(N,K)
    valuelist.append(absolute(N,K))
    
print(min(valuelist))

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int X, t;
  cin >> X >> t;
  cout << (X >= t ? X - t : 0) << "\n";
  return 0;
}

Measured memory_bytes: 256
i = lambda: map(int, input().split())
c = lambda x: -x*2+1
h, w = i()
l = []
for q in range(h):
    l += list(i())[::c(q%2)]
o = []
for j in range(w*h-1):
    if l[j] % 2:
        a, b = divmod(j, w)
        y, m, n = a+1, a%2, b==w-1
        x = [b+1, w-b][m]
        o += [[y, x, [y, y+1][n], [x+c(m), x][n]]]
        l[j+1] += 1
print(len(o))
for p in o:
    print(*p)

Measured memory_bytes: 28008
#include <bits/stdc++.h>
#define yy first
#define xx second
using namespace std;

const int NN = 3e3 + 5;
typedef pair <int, int> pii;
string ss; int nn;
string tt; int mm;
int dp[NN][NN];
pii tr[NN][NN];
deque <int> re;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
        cin >> ss >> tt;
        nn = ss.size(); ss = ' ' + ss;
        mm = tt.size(); tt = ' ' + tt;
        for (int ii = 1; ii <= nn; ++ii)
        for (int jj = 1; jj <= mm; ++jj)
            if (ss[ii] == tt[jj]) {
                dp[ii][jj] = dp[ii - 1][jj - 1] + 1;
                tr[ii][jj] = pii(ii - 1, jj - 1);
            }
            else {
                dp[ii][jj] = max(dp[ii - 1][jj - 1], max(dp[ii - 1][jj], dp[ii][jj - 1]));
                if (dp[ii][jj] == dp[ii - 1][jj - 1]) tr[ii][jj] = pii(ii - 1, jj - 1);
                if (dp[ii][jj] == dp[ii - 0][jj - 1]) tr[ii][jj] = pii(ii - 0, jj - 1);
                if (dp[ii][jj] == dp[ii - 1][jj - 0]) tr[ii][jj] = pii(ii - 1, jj - 0);
            }
        int ii = nn; int jj = mm;
        while (ii != 0 || jj != 0) {
            int ll = tr[ii][jj].yy;
            int rr = tr[ii][jj].xx;
            if (dp[ll][rr] < dp[ii][jj])
                re.push_front(jj);
            ii = ll; jj = rr;
        }
        for (int ii = 0; ii < re.size(); ++ii)
            cout << tt[re[ii]];
    return 0;
}


Measured memory_bytes: 105984
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	int m1, d1;
	cin >> m1 >> d1;
	int m2, d2;
	cin >> m2 >> d2;

	int ans = 0;
	if (m1 != m2) ans = 1;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
x,k,d = map(int,input().split())

ax = abs(x)

kd = k*d

if(ax>kd):
    print(ax-kd)
else:
    num = ax//d
    if((num%2)==(k%2)):
        print(ax-(d*num))
    else:
        if(num==k):
            print(ax-d*num)
        else:
            print(abs(ax-d*num-d))

    


Measured memory_bytes: 9096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll a[50];
	ll ma=0;
	ll manu=-1;
	ll mi=0;
	ll minu=-1;
	for(ll i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>ma){
			manu=i;
		}
		if(a[i]<mi){
			minu=i;
		}
		ma=max(a[i],ma);
		mi=min(a[i],mi);
	}
	vector<pair<ll,ll>>b;
	if(abs(ma)>abs(mi)){
		for(ll i=1;i<n;i++){
			while(a[i-1]>a[i]){
				a[i]+=ma;
				b.push_back(make_pair(manu,i));
				if(a[i]>ma){
					ma=a[i];
					manu=i;
				}
			}
		}
	}
	else{
		for(ll i=n-2;i>=0;i--){
			while(a[i]>a[i+1]){
				a[i]+=mi;
				b.push_back(make_pair(minu,i));
				if(a[i]<mi){
					mi=a[i];
					minu=i;
				}
			}
		}
	}
	cout << b.size()<<endl;
	for(ll i=0;i<b.size();i++){
		cout << b[i].first+1 << " " <<b[i].second+1<<endl;
	}
	// your code goes here
	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++)

const int MAX = 100;

int main(){
    int a, b, k;
    cin >> a >> b;
    if(abs(a - b) % 2 == 1){
        cout << "IMPOSSIBLE" << endl;
    }else{
        cout << (a + b) / 2 << endl;
    }
 }

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N_MAX 10001
struct node{
  int key;
  int cost;
  struct node *next;
};
typedef struct node *Gg;
Gg G[N_MAX];
Gg MNode(int key,int cost,Gg Node){
  Gg n;
  n=(Gg)malloc(sizeof(struct node));
  n->key=key;
  n->cost=cost;
  n->next=Node;
  return n;
}
Gg Insert(int s,int t,int u){
  Gg GG;
  GG=MNode(t,u,G[s]->next);
  G[s]->next=GG;
}
int main(){
  int i,j,n,count=0,v,c,c1,v1;
  int color[N_MAX],D[N_MAX],pi[N_MAX],minC,ii;
  Gg GG;
  scanf("%d",&n);
  for(i=0;i<n;i++)G[i]=MNode(0,0,NULL);
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&c);
    for(j=0;j<c;j++){
      scanf("%d%d",&v1,&c1);
    Insert(i,v1,c1);
  }
}
for(i=0;i<n;i++){
  color[i]=0;
  pi[i]=-1;
  D[i]=10000001;
 }
 D[0]=0;

while(1){
  minC=10000001;
  for(i=0;i<n;i++){
    if(color[i]!=2&&D[i]<minC){
      minC=D[i];
      ii=i;
    }
  }
  if(minC==10000001)break;
  color[ii]=2;
  for(GG=G[ii];GG!=NULL;GG=GG->next){
    if(color[GG->key]!=2&&(GG->cost+D[ii])<D[GG->key]){
        pi[GG->key]=ii;
        D[GG->key]=GG->cost+D[ii];
        color[GG->key]=1;
    }
  }
 }
 for(i=0;i<n;i++)printf("%d %d\n",i,D[i]);
return 0;
}

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

using namespace std;

int main(){
	int n, m, i, j, flag;
	int a[3];
	while(~scanf("%d", &n)){
		if(n == 1) cout << "Hello World" << endl;
		if(n == 2)  { scanf("%d %d", &i, &j); cout << i + j << endl;}
	}
	return 0;
}

Measured memory_bytes: 256