akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SandboxCSharp
{
    class Solver
    {

        public void Solve()
        {
            string line = io.ScanString();
            HashSet<char> h = new HashSet<char>();
            foreach (char c in line)
            {
                h.Add(c);
            }
            for (char c = 'a';c <= 'z'; ++c)
            {
                if (!h.Contains(c))
                {
                    io.WriteLine($"{c}");
                    Exit();
                } 
            }
            io.WriteLine("None");
        }

        // =================================================
        // =================================================

        Stdio io;
        bool isjdg;
        static void Main()
        {
            var s = new Solver();
            s.Solve();
            s.io.Flush();
        }
        public Solver(Stdio _io = null)
        {
            isjdg = _io == null;
            io = _io == null ? new Stdio() : _io;
        }

        void Exit()
        {
            if (isjdg)
            {
                io.Flush();
                Environment.Exit(0);
            }
            else
                throw new HaltException();
        }
    }
    class Stdio
    {
        protected string[] stack = new string[0];
        protected int stackptr = 0;
        protected StringBuilder outbuff = new StringBuilder();

        public virtual int ScanInt()
        {
            return Check() ? int.Parse(stack[stackptr++]) : 0;
        }
        public virtual long ScanLong()
        {
            return Check() ? long.Parse(stack[stackptr++]) : 0;
        }
        public virtual string ScanString()
        {
            return Check() ? stack[stackptr++] : string.Empty;
        }
        public virtual double ScanDouble()
        {
            return Check() ? double.Parse(stack[stackptr++]) : 0;
        }
        protected virtual bool Check()
        {
            if (stackptr < stack.Length) return true;
            var l = Console.ReadLine();
            if (l == null) return false;
            stack = l.Split(' ').ToArray(); stackptr = 0;
            return Check();
        }
        public Stdio Write(long v) { return Write($"{v}"); }
        public Stdio WriteLine(long v) { return WriteLine($"{v}"); }
        public Stdio Write(string str)
        {
            outbuff.Append(str);
            return this;
        }
        public Stdio WriteLine(string str = "")
        {
            outbuff.AppendLine(str);
            return this;
        }
        public virtual Stdio Flush()
        {
            Console.Write(outbuff.ToString());
            outbuff.Clear();
            return this;
        }
    }
    class HaltException : Exception { }

}


Measured memory_bytes: 13408
from typing import List


def answer(n: int, t: List[int], m: int, pxs: List[List[int]]) -> str:
    result = []
    for px in pxs:
        t_copy = t.copy()
        t_copy[px[0] - 1] = px[1]
        result.append(str(sum(t_copy)))

    return '\n'.join(result)


def main():
    n = int(input())
    t = list(map(int, input().split()))
    m = int(input())
    pxs = [list(map(int, input().split())) for _ in range(m)]
    print(answer(n, t, m, pxs))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10080
H, N = map(int, input().split())
magics = [tuple(map(int, input().split())) for _ in range(N)]
maxA = max([x for x, y in magics])

dp = [10**18]*(H+maxA+1)
dp[0] = 0

for i in range(1, H+maxA+1):
    for j in range(N):
        a, b = magics[j]
        if a<=i:
            dp[i] = min(dp[i-a]+b, dp[i])

print(min(dp[H:]))

Measured memory_bytes: 43100
import sys
from collections import defaultdict
read = sys.stdin.read
readline = sys.stdin.readline

_ = int(readline())
alst = list(map(int, readline().split()))
_ = int(readline())
m = map(int, read().split())
bc = list(zip(m, m))
s = sum(alst)
dic = defaultdict(int)
for i in alst:
  dic[i] += 1

for b, c in bc:
  pred = dic[b]
  dic[c] += pred
  dic[b] = 0
  s += (c - b) * pred
  print(s)


Measured memory_bytes: 42184
using System;
using System.Collections.Generic;
using System.Linq;
namespace _150c
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] P = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            int[] Q = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            int[] factorial = new int[8]; //NのMAX 8なので
            //forに入れるの面倒なので0と1の階乗は先に入れておく
            factorial[0] = 0;
            factorial[1] = 1;
            //2以上の階乗の値も入れる
            for(int i = 2; i < 8; i++){
                factorial[i] = i * factorial[i-1];
            }
            //一つの数字あたりの組み合わせ数が求められる
            //例えば、例題のN=3のケースだと、1に対して組み合わせ2通り
            //2に対して組み合わせ2通り 3に対して組み合わせ２通り
            //factorial[N-1] = 2を使える
            //例えば 1 3 2 のケースだとまずは1が何番目か調べる必要がある
            //1の場所は配列でいうと0番目か1番目
            //1が最初に出てくる配列番号は0*factorial[N-1]で求められる
            //213だったら、最初の数字が2なので1*factorial[N-1]としたい
            //そのために配列lを生成する
            List<int> l = new List<int>();
            for(int i = 1; i<=N;i++){
                l.Add(i);
            }
            //lが生成できたので行ないたいことを行う
            int a = 0;
            for(int i = 0; i<N;i++){
                a += l.IndexOf(P[i])*factorial[l.Count()-1];
                //1から推定される番号は2通りあるが、
                //次の数字からは1通りになる。
                //その組み合わせ数はfactorial[N-2] = l.Count()-2
                //配列 lからP[i]を削除し、l.COuntをNとして使えばそれと同様のことができる
                l.Remove(P[i]);
            }
            int b = 0;
            //qについても同様の操作を行う
            List<int> m = new List<int>();
            for(int i = 1; i<=N;i++){
                m.Add(i);
            }
            for(int i = 0; i<N;i++){
                b += m.IndexOf(Q[i])*factorial[m.Count()-1];
                //1から推定される番号は2通りあるが、
                //次の数字からは1通りになる。
                //その組み合わせ数はfactorial[N-2] = l.Count()-2
                //配列 lからP[i]を削除し、l.COuntをNとして使えばそれと同様のことができる
                m.Remove(Q[i]);
            }
            
            Console.WriteLine(Math.Abs(a-b));
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 1e18
#define common cout << "Case #" << w+1 << ": "  



int main()
{
    fastio;
    int n;
    cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++)
        cin >> v[i];
    vector<int>cum(n);
    int temp=0;
    for(int i=n-1;i>-1;i--)
    {
        temp=(temp*1LL+v[i])%mod;
        cum[i]=temp;
    }
    int ans=0;
    for(int i=0;i<n-1;i++)
    {
        ans=(ans*1LL+(v[i]*1LL*cum[i+1])%mod)%mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4776
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main(){
  int x;
  cin>>x;
  int ans;
  if(x==1)cout<<1<<endl;
  else{
    for(int i=1;i<=x;i++){
      for(int j=2;j<x;j++){
        int k=pow(i,j);
        if(k>x)break;
        else ans=max({ans,k});
      }
    }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 256
H,W,N = gets.split.map(&:to_i)
sr,sc = gets.split.map(&:to_i)
S = gets.chomp
T = gets.chomp

l = 1
r = W
u = 1
d = H
i = N
while 0 <= i
  l -= 1 if T[i] == 'R' && 1 < l
  r += 1 if T[i] == 'L' && r < W
  u -= 1 if T[i] == 'D' && 1 < u
  d += 1 if T[i] == 'U' && d < H
  l += 1 if S[i] == 'L'
  r -= 1 if S[i] == 'R'
  u += 1 if S[i] == 'U'
  d -= 1 if S[i] == 'D'
  if r < l || d < u
    puts 'NO'
    exit 0
  end
  i -= 1
end
if sc < l || r < sc || sr < u || d < sr
  puts 'NO'
else
  puts 'YES'
end



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

int main(){
    int n;
    cin >> n;
    vector<int> c(n-1),s(n-1),f(n-1),sum(n-1,0);
    for(int i=0;i<n-1;i++){
        cin >> c[i] >> s[i] >> f[i];
        sum[i]+=c[i]+s[i];
    }

    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n-1;j++){
            if(sum[i]<s[j])sum[i]=s[j];
            else if(sum[i]%f[j])sum[i]+=f[j]-(sum[i]%f[j]);
            sum[i]+=c[j];
        }
    }
    
    for(int i=0;i<n-1;i++)cout << sum[i] << endl;
    cout << 0 << endl;

}


Measured memory_bytes: 256
def output_res(row):
    print(''.join(map(lambda num: str(num).rjust(5), row)), str(sum(row)).rjust(5), sep='')


def main():
    while True:
        n = int(input())
        if n == 0:
            break

        bottom_total = [0 for _ in range(n)]
        for _ in range(n):
            each_line = list(map(int, input().split(' ')))
            output_res(each_line)
            bottom_total = [x + y for x, y in zip(bottom_total, each_line)]

        output_res(bottom_total)


if __name__ == '__main__':
    main()

Measured memory_bytes: 7692
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
    ll n; cin >> n;
    if(n % 1000 == 0) cout << 0 << endl;
    else{
        ll r = n % 1000;
        cout << 1000 - r << endl;
    }
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////
vector<int>lillywhite;
void wub(int n) {
	lillywhite.push_back(2);
	for (int i = 3; i <= n; i+=2) {
		bool key = true;
		for (int j = 3; j <= sqrt(i); j+=2) {
			if (i%j == 0) {
				key = false;
				break;
			}
		}
		if (key) {
			lillywhite.push_back(i);
		}
	}
}
int main() {
	int N; cin >> N;
	wub(55555);
	int cnt = 0;
	int key = 0;
	while (cnt < N) {
		if (lillywhite[key] % 5 == 1) {
			cout << lillywhite[key] << " ";
			cnt++;
		}
		key++;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << "\n"
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

void warshal_floyd(vector<vector<ll>>& dist) {
  int V = dist.size();
  rep(k, V) {
    rep(i, V) {
      rep(j, V) {
        // 負の辺のために必要なif文
        if (dist[i][k] != LINF && dist[k][j] != LINF)
          chmin(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
}

int N;
vector<vector<int>> G;

int bfs(int s) {
  queue<int> q;
  vector<int> k(N, -1);

  q.push(s);
  k[s] = 0;

  while (!q.empty()) {
    int now = q.front();
    q.pop();

    for (int next : G[now]) {
      if (k[next] != -1) {
        if (abs(k[next] - k[now]) != 1) {
          return -1;
        }
      } else {
        k[next] = k[now] + 1;
        q.push(next);
      }
    }
  }


  int res = 0;
  rep(i, N) {
    chmax(res, k[i]);
  }

  res++;

  // debug(s);
  // debug(k);
  // debug(res);
  // cout << '\n';


  return res;
}


signed main() {
  cin >> N;
  vector<vector<char>> S(N, vector<char>(N));
  rep(i, N) {
    rep(j, N) {
      cin >> S[i][j];
    }
  }

  G = vector<vector<int>>(N);
  rep(i, N) {
    rep(j, N) {
      if (S[i][j] == '1')
        G[i].pb(j);
    }
  }

  int ans = -1;
  rep(i, N) {
    chmax(ans, bfs(i));
  }

  cout << ans << "\n";
}

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

#define ll long long
#define EPSION numeric_limits<double>::epsilon()
#define REP(i,n) for(int i=0; i<n; ++i)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

//ifstream f("input.in");
//ofstream g("output.out");

signed main(int argc, char **argv)
{
    IOS;

    string t;
    int ans = 0, count = 0;

    getline(cin, t);
    int i =0, j = 0;;
    while(i < t.length())
    {
        count = 0;
        j = 0;
        if(t[i] == 'A' ||t[i] == 'T' ||t[i] == 'C' ||t[i] == 'G')
        {
            count++;
            j = i + 1;
            while(j < t.length())
            {
                if(t[j] == 'A' ||t[j] == 'T' ||t[j] == 'C' ||t[j] == 'G')
                {
                    count++;
                    j++;
                }
                else
                    break;
            }
            ans = max(ans, count);
        }
        i = max(j, i+1);
    }

    cout<<ans;

    return 0;
}



Measured memory_bytes: 256
import collections
N, M = [int(_) for _ in input().split()]
UV = [[int(_) for _ in input().split()] for _ in range(M)]
s, t = [int(_) for _ in input().split()]
v = [[0] * (N + 1) for _ in range(3)]
v[0][s] = 1
G = collections.defaultdict(set)
for U, V in UV:
    G[U].add(V)
Q = collections.deque([[0, s]])
while Q:
    d, i0 = Q.popleft()
    d += 1
    for i1 in G[i0]:
        if not v[1][i1]:
            v[1][i1] = 1
            for i2 in G[i1]:
                if not v[2][i2]:
                    v[2][i2] = 1
                    for i3 in G[i2]:
                        if i3 == t:
                            print(d)
                            exit()
                        elif not v[0][i3]:
                            v[0][i3] = 1
                            Q += [[d, i3]]
print(-1)


Measured memory_bytes: 52564
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String [] S = new String[N];
		String AC ="AC";
		String WA ="WA";
		String TLE ="TLE";
		String RE ="RE";
		int C0=0;
		int C1=0;
		int C2=0;
		int C3=0;
		if((1<=N)&&(N<=Math.pow(10, 5))) {
		for(int i=0;i<N;i++) {
			S[i] = sc.next();
		}
		
		for(int i=0;i<N;i++) {
			if(S[i].equals(AC)) {
				C0++;
			}else if(S[i].equals(WA)) {
				C1++;
			}else if(S[i].equals(TLE)) {
				C2++;
			}else if(S[i].equals(RE)) {
				C3++;
			}
		}
		}
		System.out.println("AC x "+C0);
		System.out.println("WA x "+C1);
		System.out.println("TLE x "+C2);
		System.out.println("RE x "+C3);
		
		sc.close();
	}

}

Measured memory_bytes: 63992
#include <bits/stdc++.h>
using namespace std;
int main () {
	int N;
	cin >> N;
	std::vector<int> v;
	for (int i = 0; i < N; ++i)
	{
		int tmp;
		cin >> tmp;
		v.push_back(tmp);
	}
	sort(v.begin(), v.end());
	long long w = 0;
	long long h = 0;
	int a = -1;
	for (int i = N-1; i >= 0; --i)
	{
		if(a == v[i]){
			//辺決定
			if(w != 0){
				h = a;
				break;
			}else{
				w = a;
			}
			a = -1;
		}else{
			a = v[i];
		}		
		

	}
	cout << w * h << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct node {
    node() : next(2) {}
    vector<unique_ptr<node>> next;
};
void insert(node* p, int i, string const& s) {
    if(i == (int)s.size()) return;
    const int idx = s[i] - '0';
    if(!p->next[idx]) p->next[idx] = make_unique<node>();
    insert(p->next[idx].get(), i + 1, s);
}

int main() {
    ll n, l; cin >> n >> l;
    auto root = make_unique<node>();
    for(int i = 0; i < n; ++i) {
        string s; cin >> s;
        insert(root.get(), 0, s);
    }

    function<ll(node*, int)> dfs = [&] (node* p, int depth) {
        if(!p->        next[0] && !p->next[1]) return 0LL;
        if(p->next[0] && p->next[1]) {
          
          
            return dfs(p->next[0].get(), depth + 1) ^ dfs(p->next[1].get(), depth + 1);
        }
        if(p->next[1]) swap(p->next[0], p->next[1]);
        ll cnt = 0, dist = l - depth;
        while(dist % 2 == 0) {
            cnt += 1;
            dist >>= 1;
        }
        return dfs(p->next[0].get(), depth + 1) ^ (1LL << cnt);
    };

    cout << (dfs(root.get(), 0) ? "Alice" : "Bob") << endl;
}

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

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

typedef long long lint;

using namespace std;

bool is_kaibun(string S){
  int N=S.length();
  bool ret =true;
  REP(i,N/2){
    if(S[i]!=S[N-1-i])ret=false;
  }
  return ret;
}

int main(){
  string S;
  cin>>S;
  int N=S.length();
  bool ans = is_kaibun(S) && is_kaibun(S.substr(0,(N-1)/2));
  cout<<(ans?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c;cin >> a >> b >> c;
	if(a==b) cout << c << endl;
	else if(b==c) cout << a << endl;
	else cout << b << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#define minn 1e-10
#define INF 500050
typedef long long ll;
using namespace std;
int arr[INF],brr[INF];
int dist(int a,int b) {
	return pow(a-b,2);
}
int main()
{
    int n,d;
    cin >> n;
    for(int i=1; i<=n; i++) {
    	cin >> arr[i];
	}
	for(int i=1; i<=n; i++) {
		if(i%2) {
			brr[1] += arr[i];
		}else{
			brr[1] -= arr[i];
		}
	}
	if(brr[1] < 0)	brr[1]=0;
	brr[n] = 2 *arr[n] - brr[1];
	for(int i=2; i<n; i++) {
		brr[i] = 2*arr[i-1] - brr[i-1];
	}
	
	for(int i=1; i<=n; i++) {
		cout << brr[i] << " ";
	}
	
	
    
    return 0;
}

Measured memory_bytes: 2048
'use strict'
function main(inp) {
  inp = Number(inp.trim())
  let ans = 0
  for (let i = 1; i < 10; i++) {
    if ((inp % i == 0) && (inp / i < 10)) {
      ans++
    }
  }
  console.log(ans ? 'Yes' : 'No')
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 22080
#include <iostream>
using namespace std;
int main() {
  int a, b, c, d, i;
  cin >> a >> b;
  int A[114514] = {};
  for(i=0;i<b;i++) {
    cin >> c >> d;
    A[d]++;
    A[c]++;
  }
  for(i=1;i<=a;i++) {
    cout << A[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Long N, K;
        Scanner sc = new Scanner(System.in);
        N = sc.nextLong();
        K = sc.nextLong();
        Long check = Math.min((N%K),(-N%K)+K);
        System.out.println(check);
    }
}


Measured memory_bytes: 35744
#include<bits/stdc++.h>
using namespace std;
int main() {
	char a[3][3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> a[i][j];
		}
	}
	cout << a[0][0] << a[1][1] << a[2][2] << endl;
}

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

using namespace std;

int main () {
	int a, b;
	cin >> a >> b;
	int x = a*b;
	int y = x/2;
	
	if ( x == y*2 ){
	cout << "Even" << endl;
	}
	else {
	cout << "Odd" << endl;
	}
	// cout << x << endl;
	// cout << y << endl;
}


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

int digit_total(int N) {
    int total = 0;
    while (N>0) {   
        total += N%10;
        N /= 10;
    }
    return total;
}

int main(){
    int N, A, B, total = 0, sum=0;
    cin >> N >> A >> B;

    for (int i = 1; i <= N; i++) {       
        total = digit_total(i);
        if (total >= A && total <= B) {
            sum += i;
        }
    }

    cout << sum << endl;

    return 0;
    
}

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

/**
 * Created by zhangrunfeng on 2/18/20
 */
public class Main {
    private int N;
    private int[] arr;

    public Main(Scanner sc) {
        N = sc.nextInt();
        arr = new int[N];
        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }
    }

    // [startIx, endIx)
    public long mergeSort(int[] arr, int startIx, int endIx) {
        if (endIx - startIx <= 1) return 0;

        int midIx = startIx + (endIx - startIx) / 2;
        long leftSum = mergeSort(arr, startIx, midIx);
        long rightSum = mergeSort(arr, midIx, endIx);

        // merge section
        long currSum = 0;
        int[] leftArr = Arrays.copyOfRange(arr, startIx, midIx);
        int[] rightArr = Arrays.copyOfRange(arr, midIx, endIx);

        int leftIx = 0, rightIx = 0, ix = startIx;
        while (leftIx < leftArr.length && rightIx < rightArr.length) {
            if (leftArr[leftIx] <= rightArr[rightIx]) {
                arr[ix] = leftArr[leftIx];
                leftIx++;
            } else {
                arr[ix] = rightArr[rightIx];
                rightIx++;
                currSum += (leftArr.length - leftIx);
            }
            ix++;
        }
        while (leftIx < leftArr.length) {
            arr[ix] = leftArr[leftIx];
            ix++;
            leftIx++;
        }
        while (rightIx < rightArr.length) {
            arr[ix] = rightArr[rightIx];
            ix++;
            rightIx++;
        }

        return leftSum + rightSum + currSum;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        long res = m.mergeSort(m.arr, 0, m.N);
        System.out.println(res);
    }
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string a,b;
    while(cin>>a>>b)
    {
        int cnt=0;
        for(int i=0;i<a.size();i++)
        {
            if(a[i]==b[i])
            {
                cnt++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


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

int main(){

  //initialization
  string s;
  int start, end;
  int i=0;
  //input
  cin >> s;
  
  //output
  while(true){
    if(s[i] == 'A'){
      start = i;
      break;
    }
    i++;
  }
  
  i = 0;
  while(true){
    if(s[s.size()-i] == 'Z'){
      end = s.size() - i;
      break;
    }
    i++;
  }
 //  cout << start << " " << end << "\n"; 
  cout << end - start + 1 << "\n";

}


Measured memory_bytes: 3736
#include <cstdio>
#include <cstring>
typedef long long ll;

int n,a[405],b[405],pa[405],pb[405],t[405][405],f[2][405][405];
const int p=1000000007;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",&a[i]),pa[a[i]]=i;
    for(int i=1;i<=n;++i)scanf("%d",&b[i]),pb[b[i]]=i;
    for(int i=0;i<=n;++i)
        for(int j=0;j<=n;++j)
            for(int k=1;k<=n;++k)
                t[i][j]+=pa[k]<=i||pb[k]<=j;
    for(int k=f[0][0][0]=1;k<=n/3;++k)
    {
        memset(f[k&1],0,sizeof f[0]);
        for(int i=1;i<=n;++i)
            for(int j=1;j<=n;++j)
            {
                f[k&1][i][j]=((ll)f[k&1][i-1][j]+f[k&1][i][j-1]+p-f[k&1][i-1][j-1])%p;
                if(i<pa[b[j]]&&j<=pb[a[i]])f[k&1][i][j]=(f[k&1][i][j]+f[(k&1)^1][i-1][j-1]*(3ll*k-t[i][j]))%p;
            }
    }
    int Ans=f[n/3&1][n][n];
    for(int i=1;i<=n;++i)if(i%3)Ans=(ll)Ans*i%p;
    printf("%d\n",Ans);
    return 0;
}

Measured memory_bytes: 2176
from operator import mul
from functools import reduce
from collections import Counter
# from itertools import combinations as comb
# from itertools import permutations as perm
# from copy import copy
# 配列二分法アルゴリズム
# https://docs.python.jp/3/library/bisect.html
# import bisect
# 桁数指定
# print('{:.3f}'.format(X))
# from collections import defaultdict
# dic = defaultdict(lambda: ...)
# 値で辞書をソート
# sorted(dic.items(), key=lambda x:x[1])
# ヒープキュー
# https://docs.python.org/ja/3/library/heapq.html
# import heapq
# 正規表現(regular expression)のためのモジュール
# import re

import sys

sys.setrecursionlimit(2000)


def inpl():
    return list(map(int, input().split()))


# 重複組み合わせは nHr = (n + r - 1)Cn
def cmb(n, r):
    # combination
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0:
        return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under


def gcd(a, b):
    # greatest common divisor
    while b > 0:
        a, b = b, a % b

    return a


def lcm(a, b):
    # least common multiple
    return a * b // gcd(a, b)


N = int(input())
A = inpl()
ans = 0
for i, a in enumerate(A):
    if A[a - 1] == i + 1:
        ans += 1

print(ans // 2)


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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a + b + c < 22){
        cout << "win" << endl;
    }
    else{
        cout << "bust" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
tree = [None] * n
root = set(range(n))


def set_pd(i, parent, depth):
    node = tree[i]
    node[1], node[2] = parent, depth
    for child in node[0]:
        set_pd(child, i, depth + 1)


while n:
    l = list(map(int, input().split()))
    c = l[2:]
    tree[l[0]] = [c, None, None]
    root -= set(c)
    n -= 1

set_pd(root.pop(), -1, 0)

for i, node in enumerate(tree):
    c, p, d = node
    print('node {}: parent = {}, depth = {}, {}, [{}]'.format(
        i, p, d, 'root' if not d else 'internal node' if c else 'leaf', ', '.join(map(str, c))
    ))

Measured memory_bytes: 35656
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

		set<pair<pair<int,int>, int> > st;
		rep(i, h) {
			string s;
			int a, b;
			cin >> s >> a >> b;

			if(s == "xy") {
				rep(i,n) {
					st.insert(mp(mp(a,b),i+1));
				}
			} else if(s == "xz") {
				rep(i,n) {
					st.insert(mp(mp(a,i+1),b));
				}
			} else if(s == "yz") {
				rep(i,n) {
					st.insert(mp(mp(i+1,a),b));
				}
			}
		}

		cout << n * n * n - st.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 4332
import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static java.util.Map.Entry.comparingByKey;
import static java.util.Map.Entry.comparingByValue;

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

        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());

        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            String s = sc.nextLine();

            Integer c = map.get(s);
            if(c == null){
                map.put(s, 0);
            } else {
                map.put(s, c+1);
            }
        }

        List<Map.Entry<String, Integer>> collect = map.entrySet().stream()
                .sorted(comparingByKey())
                .sorted(Collections.reverseOrder(comparingByValue()))
                .collect(Collectors.toList());

        int max = 0;
        for (Map.Entry<String, Integer> e : collect) {
            if(max <= e.getValue()){
                max = e.getValue();
                System.out.println(e.getKey());
            } else {
                break;
            }
        }
    }
}


Measured memory_bytes: 177100
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, M, P = getNM()
que = [getList() for i in range(M)]

edges = []
for a, b, c in que:
    # 次の点に行った時に獲得できる点 - 支払うコインP
    # 重みが負になることもある　→　ベルマンフォード
    edges.append([a - 1, b - 1, c - P])

# どのようにNに到達すればいいか
# 最長距離を求める


# after contest
# 1 → 2 1
# 2 → 3 1
# 3 → 2 1
# 3 → 4 1
# 1 → 4 100000の場合
# 2 ~ 3間でループがあるため値を無限に増やせるが、N - 1のループでは検出できない
# 1 → 4 100000 が十分大きいため
def bellman(edges, num_v):
    dist = [-float('inf') for i in range(num_v)]
    dist[0] = 0

    # 一回目のループ
    for i in range(N - 1):
        for edge in edges:
            if dist[edge[1]] < dist[edge[0]] + edge[2]:
                dist[edge[1]] = dist[edge[0]] + edge[2]

    # 負閉路検出
    nega = [0] * N
    for i in range(N):
        for edge in edges:
            # rootの頂点が既に更新されている（ループ検出）されていたなら
            # 行先にも無条件で「更新される」フラグを立てる
            if nega[edge[0]] == 1:
                nega[edge[1]] = 1
            if dist[edge[1]] < dist[edge[0]] + edge[2]:
                dist[edge[1]] = dist[edge[0]] + edge[2]
                nega[edge[1]] = 1

    if nega[N - 1]:
        print('-1')
        exit()

    return dist

ans = bellman(edges, N)[N - 1]
if ans <= 0:
    print(0)
else:
    print(ans)

Measured memory_bytes: 86552
#include<iostream>
#include<algorithm>
using namespace std;
bool used[10];
int dp[11][331];
void solve(int s,int d,int cnt)
{
	/*for(int i = 0; i < 10; ++i)
	{
		if(used[i]) cout<<i<<endl;
	}*/
	//cout<<"s="<<s<<",d="<<d<<",cnt="<<cnt<<endl;
	if(s<d)
	{
		dp[s][cnt]++;
		return;
	}

	for(int i = 0; i < 10; ++i)
	{
		if(!used[i])
		{
			used[i]=true;
			solve(s,d+1,cnt+i*d);
			used[i]=false;
		}
	}

	return;
}


int main()
{
	for(int i = 1; i < 11; ++i)
	{
		solve(i,1,0);
	}
	int n,s,mx;
	while(cin>>n>>s)
	{
		if(s<0||330<s) cout<<0<<endl;
		else cout<<dp[n][s]<<endl;
	}
	//cout<<"here"<<endl;
	/*for(int i = 1; i < 10; ++i)
	{
		for(int j = 1; j < 331; ++j)
		{
			cout<<"i="<<i<<",j="<<j<<",ans="<<dp[i][j]<<endl;
		}
	}*/
  return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a,b;
	cin>>a>>b;
	vector<long long>mi,po;
	mi.push_back(0);
	po.push_back(0);
	for(int i=0;i<a;i++){
		long long x;
		cin>>x;
		if(x<0){
			mi.push_back(x);
			continue;
		}
		po.push_back(x);
	}
	sort(mi.begin(),mi.end());
	reverse(mi.begin(),mi.end());
	long long ma=9999999999999999;
	for(int i=0;i<mi.size();i++){
		if(abs(i-b)<po.size()){
			ma=min(ma,abs(mi[i])+abs(mi[i]-po[abs(i-b)]));
		}
//		cout<<abs(mi[i])<<" "<<po[abs(i-b)]<<" "<<abs(mi[i])+abs(mi[i]-po[abs(i-b)])<<endl;
	}
	for(int i=0;i<po.size();i++){
		if(mi.size()>abs(i-b)){
			ma=min(ma,po[i]+abs(po[i]-mi[abs(i-b)]));	
		}
		
	}
	cout<<ma<<endl;
}

Measured memory_bytes: 1656
#include <iostream>
#include <string.h>

using namespace std;

int main(){
	string s, t;
	char d;
	cin >> s >> t;
	for (int i = 0; i < 101; i++) {
		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
		for (int j = 0; j < t.length(); j++) {
			if (j == 0) {
				d = t[0];
			}
			t[j] = t[j + 1];
			if (j == t.length() - 1) {
				t[j] = d;
			}
		}
	}
	cout << "No";
	
	
	
	
	return 0;
}


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

int S_first;
int S_second;
int S;
int main() {
	cin >> S;
	S_first = S / 100;
	S_second = S % 100;
	if (S_first > 0 && S_first <= 12) {
		if (S_second > 0 && S_second <= 12) {
			cout << "AMBIGUOUS" << endl;
		}
		else cout << "MMYY" << endl;
	}
	else if (S_second > 0 && S_second <= 12) {
		cout << "YYMM" << endl;
	}
	else cout << "NA" << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int h[123];

int solve(int l, int r, int t){
	int i,m=INF,ret,j;
	bool flag = false;
	for(i=l; i<r; ++i){
		m = min(m,h[i]);
	}
	ret = m-t;
	for(i=l; i<r; ++i){
		if((!flag) && h[i]>m){
			j = i;
			flag = true;
		}else if(flag && h[i]==m){
			ret += solve(j,i,m);
			flag = false;
		}
	}
	if(flag){
		ret += solve(j,r,m);
	}
	return ret;
}

int main(void){
	int i,n;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> h[i];
	}
	cout << (solve(0,n,0)) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back

int main(){
    int k,a,b;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}

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

int main(){
  int n;
  string s;
  int ans[30];
  for(int i = 0;i < 30;i++) ans[i] = INT_MAX;

  cin >> n;
  for(int i = 0;i < n;i++){
    int tmp[30] = {};
    cin >> s;
    for(int j = 0;j < s.size();j++){
      tmp[s[j]-'a']++;
    }
    for(int j = 0;j < 26;j++){
      ans[j] = min(ans[j],tmp[j]);
    }
  }

  char tmp2 = 'a';
  for(int i = 0;i < 26;i++){
    for(int j = 0;j < ans[i];j++){
      cout << tmp2;
    }
    tmp2++;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;


int main()
{
	LL n;cin>>n;
	vector<LL> a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++){
		if(a[i]==0){
			cout<<0<<"\n";
			return 0;
		}
	}
	LL ans=1ll,k = 1e18;
	for(int i=0;i<n;i++){
		if(a[i]>k/ans){
			ans = -1ll;break;
		}
		ans*=a[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4048
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		long plus_op = 0, minus_op = 0; // start with +, -
		long sum = 0;
		for(int i = 0; i < n; i++) {
			sum += a[i];
			if(i % 2 == 0 && sum > 0 || i % 2 == 1 && sum < 0) continue;
			if(i % 2 == 0) {
				// + なのに - になってる -> sumを+1にもっていく
				plus_op += (long)Math.abs(1 - sum);
				sum = 1;
			}else {
				// - なのに + になってる -> sumを-1にもっていく
				plus_op += (long)Math.abs(sum + 1);
				sum = -1;
			}
		}

		sum = 0;
		for(int i = 0; i < n; i++) {
			sum += a[i];
			if(i % 2 == 0 && sum < 0 || i % 2 == 1 && sum > 0) continue;
			if(i % 2 == 0) {
				// - なのに + になってる -> sumを-1にもっていく
				minus_op += (long)Math.abs(sum + 1);
				sum = -1;
			}else {
				// + なのに - になってる -> sumを+1にもっていく
				minus_op += (long)Math.abs(1 - sum);
				sum = 1;
			}
		}
		System.out.println(Math.min(plus_op, minus_op));
	}
}

Measured memory_bytes: 53720
#include<stdio.h>
int main(void)
{
	long long int a,s,d,f,g,h,j,i;
	while(1){
		f=0;	
		scanf("%lld %lld",&a,&s);
		if(a==0&&s==0){
			break;
		}
		if(a<s){
			d=s;
			s=a;
			a=d;
		}
		while(1){
			if(s==0){
				break;
			}
			a=a%s;
			d=s;
			s=a;
			a=d;
			f++;
		}
		printf("%lld %lld\n",a,f);
	}
	return 0;
}

Measured memory_bytes: 1028
#include<stdio.h>
#include<string.h>

int main(){
	char s[11];
	int L=0,i=0,max=0;
	scanf("%s",s);
	while(1){
		if(s[i]=='\0')break;
		if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
			L++;
		}
		else {
			L=0;
		}
		if(max<L)max=L;
		i++;
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}
// --------------------------------------------------</TEMPLATE>--------------------------------------------------


void solve()
{
    ll n,x,t;
    cin>>n>>x>>t;
    ll c=ceil(n/(x*1.0));
    cout<<c*t<<endl;
}

int main()
{
    IOS
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return(0);
}


Measured memory_bytes: 3756
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n, m;
	cin >> n >> m;
	vector<queue<int> > graph(100001);
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		graph[a].push(b);
		graph[b].push(a);
	}
	vector<bool> ischecked(100001, false);
	deque<int> ans;
	ans.push_front(1);
	ans.push_back(graph[1].front());
	int start = 1;
	int end = graph[1].front();
	graph[1].pop();
	bool endisok = false, startisok = false;
	ischecked[start] = true;
	ischecked[end] = true;
	while(!graph[end].empty() && !endisok){
		int next = graph[end].front();
		graph[end].pop();
		if(ischecked[next]) continue;
		ans.push_back(next);
		end = next;
		ischecked[next] = true;
		endisok = true;
		while(!graph[next].empty()){
			int tmp = graph[next].front();
			if(!ischecked[tmp]){
				endisok = false;
				break;
			}
			graph[next].pop();
		}
	}
	while(!graph[start].empty()){
			int tmp = graph[start].front();
			if(!ischecked[tmp]){
				startisok = false;
				break;
			}
			graph[start].pop();
		}
	while(!graph[start].empty() && !startisok){
		int next = graph[start].front();
		graph[start].pop();
		if(ischecked[next]) continue;
		ans.push_front(next);
		start = next;
		ischecked[next] = true;
		startisok = true;
		while(!graph[next].empty()){
			int tmp = graph[next].front();
			if(!ischecked[tmp]){
				startisok = false;
				break;
			}
			graph[next].pop();
		}
	}
	cout << ans.size() << endl;
	for(int i = 0; i < ans.size(); i++){
		if(i > 0) cout << " ";
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

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

int M, K;
bool is_one_hot[1 << 18];

int main()
{
    cin >> M >> K;

    if(M == 0)
    {
        if(K == 0)cout << "0 0" << endl;
        else cout << -1 << endl;
        return 0;
    }
    if(M == 1)
    {
        if(K == 0)cout << "0 0 1 1" << endl;
        else cout << -1 << endl;
        return 0;
    }

    if(K == 0)
    {
        for(int i = 0; i < (1 << (M + 1)); i++)
        {
            cout << i / 2;
            if(i != (1 << (M + 1)) - 1)cout << " ";
        }
        cout << endl;
        return 0;
    }
    if(K >= (1 << M))
    {
        cout << -1 << endl;
        return 0;
    }

    vector<int> v1, v2;
    for(int i = 0; i <= M; i++)is_one_hot[1 << i] = true;
    for(int i = 0; i < (1 << M); i++)
    {
        if(is_one_hot[i])
        {
            if(i & K)v1.push_back(i);
            else v2.push_back(i);
        }
        else v2.push_back(i);
    }

    vector<int> ans;
    for(int i = 0; i < v1.size(); i++)ans.push_back(v1[i]);
    for(int i = 0; i < v2.size(); i++)ans.push_back(v2[i]);
    reverse(v1.begin(), v1.end());
    reverse(v2.begin(), v2.end());
    for(int i = 0; i < v1.size(); i++)ans.push_back(v1[i]);
    for(int i = 0; i < v2.size(); i++)ans.push_back(v2[i]);

    for(int i = 0; i < ans.size(); i++)
    {
        cout << ans[i];
        if(i != ans.size() - 1)cout << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3572
n,k=map(int,input().split())
a=list(map(int,input().split()))

def imos(a):
  imos_l=[0 for i in range(n)]

  for i in range(n):
    left=max(i-a[i],0)
    right=min(i+a[i],n-1)

    imos_l[left]+=1
    if right+1!=n:
      imos_l[right+1]-=1

  b=[0]
  for i in range(1,n+1):
    b.append(b[i-1]+imos_l[i-1])

  return b[1:]

for i in range(k):
  a=imos(a)
  if a.count(n)==n:
    break

print(*a)

Measured memory_bytes: 185372
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
#include <utility>
#include <stack>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int R,C,n;
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> R>> C >> n;
    vector<bool>on_edge;
    vector<pii>A[4];
    rep(i,n){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        int cnt = 0;
        if(a==0 or b==0 or a==R or b==C)cnt++;
        if(c==0 or d==0 or c==R or d==C)cnt++;
        if(cnt==2){
            // cerr <<"i = " << i << endl;
            if(a==0)A[0].push_back(pii(b,i));
            else if(b==C)A[1].push_back(pii(a,i));
            else if(a==R)A[2].push_back(pii(b,i));
            else A[3].push_back(pii(a,i));
            swap(a,c);
            swap(b,d);
            if(a==0)A[0].push_back(pii(b,i));
            else if(b==C)A[1].push_back(pii(a,i));
            else if(a==R)A[2].push_back(pii(b,i));
            else A[3].push_back(pii(a,i));
        }
    }
    sort(A[0].begin(),A[0].end());
    sort(A[1].begin(),A[1].end());
    sort(A[2].rbegin(),A[2].rend());
    sort(A[3].rbegin(),A[3].rend());
    vector<int>vec;
    rep(i,4){
        for(auto &x:A[i]){
            vec.push_back(x.second);
            // cerr << x.second << endl;
        }
    }
    stack<int>st;
    for(auto &x:vec){
        if(st.empty()){
            st.push(x);
            continue;
        }
        if(st.top() == x){
            st.pop();
        }else{
            st.push(x);
        }
    }
    if(st.empty()){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
int n,f,x[100001];
int gcd(int x,int y)
{
	if(y==0)
	return x;
	return gcd(y,x%y);
}
int main()
{
	cin>>n>>f;
	for(int i=0;i<n;i++)
	{
		cin>>x[i];
	}
	int ans=0;
	for(int i=1;i<n;i++)
	{
		if(i==1)
		ans=gcd(abs(f-x[0]),abs(f-x[i]));
		else
		ans=min(ans,gcd(abs(f-x[0]),abs(f-x[i])));
	}
	if(n==1)
	ans=abs(x[0]-f);
	cout<<abs(ans);
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int H, W;
    cin >> H >> W;
    vector<vector<ll>> dp(H, vector<ll>(W, 0));
    dp[0][0] = 1;
    for (int i = 0; i < H; i++)
    {
        string s;
        cin >> s;
        for (int j = 0; j < W; j++)
        {
            if (s[j] == '#')
                continue;
            if (j != 0)
            {
                dp[i][j] += dp[i][j - 1];
                dp[i][j] %= MOD;
            }
            if (i != 0)
            {
                dp[i][j] += dp[i - 1][j];
                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[H - 1][W - 1] << endl;
}

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

int main(){
  int N;
  int l, r;
  int Sum = 0;
  
  cin >> N;
  for ( int i=0; i < N; i++){
    cin >> l >> r;
    Sum += r - l + 1;
  }
  cout << Sum;
}


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

const int a = 1000000007;
int main(){
  int X;
  cin >> X;
  for(ll i=0;i<10000;++i){
    for(ll j=0;j<50000;++j){
      if(pow(j,5)-pow(i,5)==X){
        cout << j << " " << i << endl;
        return 0;;
      }
      else if(pow(j,5)+pow(i,5)==X){
        cout << j << " " << -i << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4124
# 060_a
A, B, C = input().split()

if (1<=len(A) and len(A)<=10 and A.islower()) and (1<=len(B) and len(B)<=10 and B.islower())\
        and (1<=len(C) and len(C)<=10 and C.islower()):
    if (A[len(A) - 1] == B[0]) and (B[len(B) - 1] == C[0]):
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 8924