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

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	ll mini=inf;
	for(int i=0; i<s.size()-2; i++){
		ll x=(s[i]-'0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
		mini=min(mini,abs(x-753));
	}
	cout << mini;
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
n,k=gets.chomp.split(" ").map{|s| s.to_i}
a=gets.chomp.split(" ").map{|s| s.to_i}
c=k*(k+1)/2
p=0
q=0
for i in 0..n-1
  for j in 0..n-1
    if a[i]>a[j]
      p+=1 if i>j
      q+=1 if i<j
    end
  end
end
puts (p*(c-k)+q*c)%(10**9+7)

Measured memory_bytes: 1916
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
                  log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


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


def instr():
    s = input()
    return(list(s[:len(s)]))


def invr():
    return(map(int, input().split()))


s = input()
t = input()
c = 0
for i in range(len(s)):
    if s[i] != t[i]:
        c += 1
print(c)


Measured memory_bytes: 10888
def binary_search(ok:, ng:)
  while (ok - ng).abs > 1
    mid = (ok + ng) / 2

    if yield(mid)
      ok = mid
    else
      ng = mid
    end
  end

  ok
end

N, A, B = gets.split.map(&:to_i)
C = (A - B).to_f
H = N.times.map { gets.to_i }

ans = binary_search(ok: 10 ** 9, ng: 0) { |x|
  remain_hp = H.map { |h| h - x * B }
  ret = true

  remain_hp.each do |h|
    next if h <= 0

    c = (h / C).ceil
    x -= c

    if x < 0
      ret = false
      break
    end
  end

  ret
}

puts ans


Measured memory_bytes: 26548
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
struct d_heap {
  int d;
  vector<T> heap;

  d_heap(int d): d(d) {}
  void push(const T& t) {
    heap.push_back(t);

    int i = heap.size() - 1;
    while(i > 0){
      if(heap[(i - 1) / 2] > heap[i]) swap(heap[(i - 1) / 2], heap[i]);
      i = (i - 1) / 2;
    }
  }

  T pop() {
    T ans = heap[0];
    swap(heap.back(), heap.front());
    heap.pop_back();
    for(int i = 1;i < heap.size() && i <= d;i++) {
      if(heap[0] > heap[i]) swap(heap[0], heap[i]);
    }
    return ans;
  }

  bool empty() const {
    return heap.empty();
  }

  T top() {
    return heap[0];
  }
};
#include <vector>
#include <queue>
#include <set>
using namespace std;
 
struct edge{
  int to;
  int cost;
};
int INF = 1 << 30;
using Pii = pair<int,int>;
 
vector<int> Dijkstra(const vector<vector<edge>>& G,int s){
  vector<int> dist(G.size(),INF);
  dist[s] = 0;
  d_heap<Pii> que(8);
  que.push({dist[s],s});
  while(!que.empty()){
    auto d = que.top().first;
    auto v = que.top().second;
    que.pop();
    if(dist[v] < d) continue;
    for(auto & e : G[v]){
      if(dist[e.to] > d + e.cost){
        dist[e.to] = d + e.cost;
        que.push({dist[e.to],e.to});
      }
    }
  }
  return dist;
}
 
#include <iostream>
 
int main(){
  int v,e,r;
  cin >> v >> e >> r;
  vector<vector<edge>> G(v);
  for(int i = 0;i < e;i++){
    int s,t,d;
    cin >> s >> t >> d;
    G[s].push_back({t,d});
  }
  auto res = Dijkstra(G,r);
  for(auto i : res){
    if(i == INF) cout << "INF";
    else cout << i;
    cout << endl;
  }
}




Measured memory_bytes: 12592
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define lbd(a, x) lower_bound(all(a), x)
const int mod = 1e9 + 7;
int power_mod(int a, int b) {
	int res = 1;
	for(; b; b >>= 1, a = (ll) a * a % mod)
		if(b & 1) res = (ll) res * a % mod;
	return res;
}
const int S = 1 << 17;
const int N = 50;
int dp[N][S];
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n, x, y, z;
	cin >> n >> x >> y >> z;
	int m = (1 << x + y + z) - 1;
	int forbidden = (1 << x + y + z - 1) | (1 << y + z - 1) | (1 << z - 1);
	dp[0][0] = 1;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j <= m; j++) {
			if(!dp[i][j]) continue;
			for(int digit = 1; digit <= 10; digit++) {
				int nxt = ((j << digit) | (1 << digit - 1)) & m;
				if((nxt & forbidden) == forbidden) continue;
				dp[i + 1][nxt] = (dp[i + 1][nxt] + dp[i][j]) % mod;
			}
		}
	}
	int res = power_mod(10, n);
	for(int i = 0; i <= m; i++) {
		if((i & forbidden) == forbidden) continue;
		res = (res - dp[n][i]) % mod;
	}
	if(res < 0) res += mod;
	cout << res << '\n';
	return 0;
}


Measured memory_bytes: 20864
import Control.Applicative
main = do xs <- concatMap words . lines <$> getContents
          putStr . unlines . map show $ solve xs

solve :: [String] -> [Int]
solve (x:o:y:xs) | o == "?" = []
                 | o == "+" = ((read x) + (read y)) : solve xs
                 | o == "-" = ((read x) - (read y)) : solve xs
                 | o == "*" = ((read x) * (read y)) : solve xs
                 | o == "/" = ((read x) `div` (read y)) : solve xs

Measured memory_bytes: 3996
#include <stdio.h>

int main()
{
	int NO,max,p,d1,d2;
	int n,i,j;

	scanf("%d",&n);

	while(n != 0){
		max = 0;

		for(i = 0; i < n; i++){
			scanf("%d%d%d",&p,&d1,&d2);
			if(max < d1+d2){
				max = d1+d2;
				NO = p;
			}
		}

		printf("%d %d\n",NO,max);

		scanf("%d",&n);
	}

	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1000000007;
const long double PI=3.14159265358979;

int main() {
  ll N,M,x,ans=MOD;
  cin>>N>>M>>x;
  ll c[N];
  ll a[N][M];
  ll X[M];
  for(int i=0;i<N;i++){
    cin>>c[i];
    for(int j=0;j<M;j++){
      cin>>a[i][j];
    }
  }
  
  
  
  for(int i=0;i<M;i++){
    X[i]=0;
  }
  for(int t;t<(1<<N);t++){
    ll cnt=0;
    bitset<12> tmp(t);
    for(int i=0;i<N;i++){
      if(tmp.test(i)){
        cnt+=c[i];
        for(int j=0;j<M;j++){
          X[j]+=a[i][j];
        }
      }
    }
    
   
    
    ll c=1;
    for(int i=0;i<M;i++){
      if(X[i]<x){
        c=0;
      }
      X[i]=0;
    }
    if(c){
      ans=min(cnt,ans);
    }
  }
  if(ans==MOD){
    cout<<-1;
  }
  else{
  cout<<ans;
  }
  
}


Measured memory_bytes: 3624
#include <iostream>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i > (b); i--)

using namespace std;

typedef long long ll;

ll A, B, C, D;

template <class Type>
Type gcd(Type x, Type y) {
	if ( y == 0 ) return x;
	return gcd(y, x % y);
}

template <class Type>
Type lcm(Type x, Type y) {
	return (x * y) / gcd(x, y);
}

int main(void) {
    scanf("%lld %lld %lld %lld", &A, &B, &C, &D);

    ll c = B / C - (A - 1) / C; 
    ll d = B / D - (A - 1) / D;
    ll cd = B / lcm<ll>(C, D) - (A - 1) / lcm<ll>(C, D); 

    ll ans = (B - A + 1) - c - d + cd; 
    
    printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  string s = to_string(n);
  Yes(s[0] == '7' || s[1] == '7' || s[2] == '7');

  return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;

int n;
int jc[200005];

int quick_power(int x,int y)
{
	int res=1;
	for (;y;y=y>>1,x=(x*x)%mod)
	{
		if (y&1)  res=(res*x)%mod;
	}
	return res;
}

int ny(int k)
{
	return quick_power(k,mod-2);
}

int C(int n,int k)
{
	if (k==0||n==k)  return 1;
	else if (n<k)  return 0;
	
	return ((jc[n]*ny(jc[k]))%mod*ny(jc[n-k]))%mod;
}

signed main()
{
	cin>>n;
	jc[0]=1;
	for (int i=1;i<=200000;i++)  jc[i]=(jc[i-1]*i)%mod;
	
	int ans=0;
	for (int i=1;i<=(n/3);i++)  ans=(ans+C(n-2*i-1,i-1))%mod;
	cout<<ans<<endl;
	
	return 0;
}

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

int n;
void dfs(string s, char mx) {
  if (s.size() == n) {
    cout << s << endl;
    return;
  }
  for (char c = 'a'; c <= mx+1; c++) dfs(s + c, max(mx, c));
}

int main() {
  cin >> n;
  dfs("", 'a'-1);
  return 0;
}

Measured memory_bytes: 1536
import java.util.*;

public class Main {

    class P {
        int x, y;
        public P(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public boolean equals(Object o) {
            P p = (P) o;
            return this.x == p.x && this.y == p.y;
        }

        @Override
        public int hashCode() {
            return this.x + this.y;
        }
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        P[] pArr = new P[n];

        Map<P, Integer> pMap = new HashMap<>();

        for (int i = 0; i < n; i++) {
            pArr[i] = new P(sc.nextInt(), sc.nextInt());
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;
                P p1 = pArr[i];
                P p2 = pArr[j];
                P p = new P(p1.x - p2.x, p1.y - p2.y);
                int count = pMap.getOrDefault(p, 0) + 1;
                pMap.put(p, count);
            }
        }
        Integer[] arr = pMap.values().toArray( new Integer[0]);
        Arrays.sort(arr, Collections.reverseOrder());

        System.out.println(n == 1 ? 1 : n - arr[0]);
    }


    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


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

typedef vector<vector<int>> Graph;

int N;
Graph G;
vector<int> td, tf;
int timestamp;

void dfs(int v){
	td[v] = timestamp++;

	for(int i=0; i<G[v].size(); i++){
		int u = G[v][i];
		if(td[u] == -1){
			dfs(u);
		}
	}

	tf[v] = timestamp++;
}

int main(){
	cin >> N;
	G.resize(N);
	td.resize(N, -1);
	tf.resize(N, -1);

	for(int i=0; i<N; i++){
		int x; cin >> x; x--;
		int k; cin >> k;
		for(int i=0; i<k; i++){
			int y; cin >> y; y--;
			G[x].push_back(y);
		}
	}

	timestamp = 1;

	for(int i=0; i<N; i++) if(td[i] == -1)
		dfs(i);

	for(int i=0; i<N; i++){
		cout << i+1 << " " << td[i] << " " << tf[i] << endl;
	}

	return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#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 sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N, K; std::cin >> N >> K;
  std::string S; std::cin >> S;

  int X = 0;
  rep(i,sz(S)) {
    if ( S.substr(i,2) == "RL" ) X++;
  }

  int Y = 0;
  if ( S[0] == 'L'   ) Y++;
  if ( S[N-1] == 'R' ) Y++;

  int ans = 0;
  rep(i,sz(S)) {
    if ( i != N-1 && S[i] == 'R' && S[i+1] == 'R' ) ans++;
    if ( i != 0   && S[i] == 'L' && S[i-1] == 'L' ) ans++;
  }
  std::cout << std::min(ans+2*K, N-1) << std::endl;

  return 0;
}


Measured memory_bytes: 512
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	x,y = readline() |> split |> parseMap
	f = 0
	for i in 0:100
		for j in 0:100
			if i+j==x&&2*i+4*j==y
				f = 1
			end
		end
	end
	println(f==1 ? "Yes" : "No")
end

main()

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

void solve(long long A, long long B){
    if (A == B) cout << A * 2 << '\n';
    else if (A > B) {
        int ans = A;
        if (A - 1 >= B)
            ans += A - 1;
        else ans += B;
        cout << ans << '\n';
    } else {
        int ans = B;
        if (B - 1 >= A)
            ans += B - 1;
        else ans += A;
        cout << ans << '\n';
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
// C - Synthetic Kadomatsu
// DFS
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int N;
vi A(4), L(8);
int ans = INT_MAX;

void calc(vi &v){
	vi sum(4), count(4);
	for(int i=0; i<N; ++i){
		count[v[i]]++;
		sum[v[i]] += L[i];
	}

	if(min({count[1], count[2], count[3]})!=0){
		int s = 0;
		for(int i=1; i<4; ++i){
			s += abs(A[i] - sum[i]);
			if(count[i]>1) s += (count[i]-1) * 10;
		}
		ans = min(ans, s);
	}
}

void dfs(int depth, vi &v){
	if(depth==N){
		calc(v);
		return;
	}
	for(int i=0; i<4; ++i){
		v[depth] = i;
		dfs(depth+1, v);
	}
}

int main(){
	cin>>N;
	for(int i=1; i<4; ++i) cin>>A[i];
	for(int i=0; i<N; ++i) cin>>L[i];
	vi v(N); dfs(0, v);
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;

    int main(){
      string s;
      cin >> s;
      bool flag=true;
      for(char i='a';i<='z';i++){
       for(int i=0;i<s.size()-1;i++){
         if(s[i]==s[i+1] && flag){
          flag=false;
           cout << i+1 << ' ' <<  i+2 << endl;
         }
       }
      }
      for(char i='a';i<='z';i++){
       rep(i,s.size()-2){
        if(flag && s[i]==s[i+2]){
         flag=false;
          cout << i+1 << ' ' << i+3 << endl;
        }
       }
      }
      if(flag){
       cout << -1 << ' ' << -1 << endl;
      }
      return 0;}

Measured memory_bytes: 512
while True:
    a,b,c = map(int,input().split())
    if a == -1 and b == -1 and c == -1:
        break
    elif a == -1 or b == -1:
        print("F")
    elif a+b >= 80:
        print("A")
    elif a+b >= 65:
        print("B")
    elif a+b >= 50:
        print("C")
    elif a+b >= 30:
        if c >= 50:
            print("C")
        else:
            print("D")
    else:
        print("F")


Measured memory_bytes: 5596
import math

N, M = map(int, input().split())
ans=0
inf=(10**9)+7
if abs(N-M)==0:
    ans=2*math.factorial(N)*math.factorial(M)
elif abs(N-M)==1:
    ans=math.factorial(N)*math.factorial(M)
else:
    ans=0
print(ans%inf)



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

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    ll n,k;
    cin >> n >> k;
    Vi a(n);
    rp(i,n) cin >> a.at(i);
    vi visited(n+1,0);
    ll town=0;
    ll loop;
    ll res;
    ll anspos;
    rp(i,n+1){
        if(i==k){
            print(town+1);
            return 0;
        }
        if(visited[town]!=0){
            loop=i+1-visited[town];
            res=(k-i)%loop;
            anspos=visited[town]+res;
            break;
        }
        visited[town]=i+1;
        town=a[town]-1;
    }
   
    rp(i,n){
        if(visited[i]==anspos){
            print(i+1);
        }
    }
    return 0;
}

Measured memory_bytes: 5576
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename A,typename B> istream& operator>>(istream&,pair<A,B>&);
template<typename A> istream& operator>>(istream&,vector<A>&);
void add(int&,int);
int mul(int,int);
int powz(int,int);
template<typename A> ostream& operator<<(ostream&,vector<A>&);
 
const int N=500006;

void solve(){
	int n,l;
	cin>>n>>l;
	vi a(n);
	for(int i=0;i<n;i++)a[i]=l+i;
	debug(a);
	int val=1e9;int flag=0;
	for(int i=0;i<n;i++)if(abs(a[i])<val){val=abs(a[i]);if(a[i]<0)flag++;}
	debug(val);
	if(flag)
	cout<<accumulate(all(a),0ll)+val;
	else cout<<accumulate(all(a),0ll)-val;
	
}
	
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tc=1;
	//~ cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
	if(a<0)a+=mod;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=mul(res,a);
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
	    output<<i<<' ';
	return output;	
}


Measured memory_bytes: 256
N, M, X = map(int,input().split())
Book = [[] for _ in range(N)]
mi = float('inf')
for i in range(N):
    Book[i] = list(map(int,input().split()))
for j in range(2**N):
    s = [0 for _ in range(N)]
    k = str(bin(j))[2:]
    o = len(k)
    x = 0
    f = 0
    B = [0 for u in range(M)]
    for l in range(o):
        s[N-l-1]= int(k[o-l-1])
    for p in range(N):
        if s[p] == 1:
            x += Book[p][0]
            for q in range(1,M+1):
                B[q-1] += Book[p][q]
    for n in range(M):
        if B[n] < X:
            break
        f += 1
    if x < mi and f == M:
        mi = x
if mi == float('inf'):
    print(-1)
    exit()
print(mi)

Measured memory_bytes: 9268
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 
  
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = 998244353;
const int MX = (int)1e6 + 10;

void add_self(int &x, int y){x += y; if(x >= mod) x -= mod;}
void sub_self(int &x, int y){x -= y; if(x < 0) x += mod;}
void mul(int &x, int y){x = x * 1LL * y % mod;}

vector<int> nvalid(MX);

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	int n;
	cin >> n;
	vector<int> a(n);
	for(auto &x : a) cin >> x;
	sort(all(a));

	int res = 0;
	for(int i = 0; i < n; ++i){
		int x = a[i];
		if(nvalid[x]) continue;
		if(i == n - 1 || (i + 1 < n && a[i + 1] != x))
			res++;
		for(int j = x; j < MX; j += x)
			nvalid[j] = true;
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 7912
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())printf("%d ",v[_]);cout<<"\n";}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};//RDLU
#define yes puts("YES")
#define no puts("NO")


signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin>>s;
	int n=s.size();
	bool h=false;
	rep(i,n)loop(j,i,n){
		string t=s.substr(0,i)+s.substr(j);
		if(t=="keyence")h=true;
	}
	if(h)yes;
	else no;
}









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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1ll << 60;

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

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

    string S;
    cin >> S;
    int rsl = 0;
    rep(i, 0, S.length()) {
        if(S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] == 'T') {
            int tmp = 1;
            rep(j, i + 1, S.length()) {
                if(S[j] == 'A' or S[j] == 'C' or S[j] == 'G' or S[j] == 'T') {
                    tmp++;
                } else break;
            }
            rsl = max(rsl, tmp);
        } else continue;
    }
    cout << rsl << endl;


}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        long[] XAB = cin.ArrayLong(3,0);
      string ans="";
        if(0>=XAB[2]-XAB[1])ans="delicious";
       else if(XAB[0]>=XAB[2]-XAB[1])ans="safe";
       else ans="dangerous";
      Console.WriteLine(ans);
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
use std::io;

fn main() {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let input: Vec<i32> = buf.split_whitespace().map(|n| n.parse::<i32>().unwrap()).collect();
    let a = input[0];
    let b = input[1];

    if (a*b) % 2 == 0 {
        println!("Even");
    }
    else {
        println!("Odd");
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main(){
    string S;  cin >> S;
    int n = S.length();
    string ABC = "ABC";
    vector<vector<ll>> dp;
    dp = vector<vector<ll>>(n + 1, vector<ll>(4,0));

    dp[n][3] = 1;
    dp[n][0] = dp[n][1] = dp[n][2] = 0;
    for(int i=n-1; i>=0; i--){
        for(int j=3; j>=0; j--){
            if(j==3){
                ll m = (S[i]=='?' ? 3ll:1ll);
                dp[i][j] = m*dp[i+1][3];
            }else{
                ll m1 = (S[i]=='?' ? 3ll:1ll);
                ll m2 = (S[i]==ABC[j] || S[i] == '?' ? 1ll:0ll);
                dp[i][j] = m1*dp[i+1][j] + m2*dp[i+1][j+1];
            }
            dp[i][j]%=MOD;
        }
    }

    cout << dp[0][0] << endl;
}


Measured memory_bytes: 7424
# 087 b問題
a = int(input())
b = int(input())
c = int(input())
x = int(input())

count = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1): 
            if 500*i + 100*j + 50*k == x:
                count += 1
                
print(count)

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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, m, s, t;
// string s;

int main() {
    cin >> n >> m >> s >> t;
    V<V<P<int, Pll>>> adj(n+1);
    REP(i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        adj[u].push_back({v, {a, b}});
        adj[v].push_back({u, {a, b}});
    }

    priority_queue<P<ll, int>, V<P<ll, int>>, greater<P<ll, int>>> q;
    Vl distanceA(n+1, 1e18);
    q.push({0LL, s});
    distanceA[s] = 0;
    while (!q.empty()) {
        ll cost = q.top().first;
        int node = q.top().second;
        q.pop();
        if (distanceA[node] != cost) continue;

        FOR(i, adj[node]) {
            int v = i->first;
            ll a = i->second.first;
            if (distanceA[v] > distanceA[node] + a) {
                distanceA[v] = distanceA[node] + a;
                q.push({distanceA[v], v});
            }
        }
    }

    Vl distanceB(n+1, 1e18);
    q.push({0LL, t});
    distanceB[t] = 0;
    while (!q.empty()) {
        ll cost = q.top().first;
        int node = q.top().second;
        q.pop();
        if (distanceB[node] != cost) continue;

        FOR(i, adj[node]) {
            int v = i->first;
            ll b = i->second.second;
            if (distanceB[v] > distanceB[node] + b) {
                distanceB[v] = distanceB[node] + b;
                q.push({distanceB[v], v});
            }
        }
    }

    V<Pll> distance(n);
    REP(i, n) distance[i] = {distanceA[i+1] + distanceB[i+1], i+1};
    sort(ALL(distance));

    ll now = 0;
    REP(i, n) {
        std::cout << (ll)1e15 - distance[now].first << '\n';
        while (i+1 < n && distance[now].second <= i+1) {
            now++;
        }
    }

    return 0;
}


Measured memory_bytes: 14328
#include <iostream>

using namespace std;
int log(long long int x,long long int y){
    int count=0;
    while(x<=y){
        x=x*2;
        count++;
    }
    return count;
}
int main(){
    long long int x,y;
    cin>>x;
  	cin>>y;
    cout<<log(x,y);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

const ll mod = 1e9+7;

void solve() {
    /*ll a, b, c, d;
    cin>>a>>b>>c>>d;
    string winner = "No";
    ll i = 0;
    while(1) {
        if(a<=0 or c<=0)break;
        if(i%2==0){c-=b;winner="Yes";}
        else {a-=d;winner="No";}
        i++;
    }
    cout<<winner;*/
    set < string > st;
    ll n;
    cin>>n;while(n--){string temp;cin>>temp;st.insert(temp);}
    cout<<((ll)st.size());
}

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


Measured memory_bytes: 19196
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::collections::{BTreeMap};
use std::cmp;
use std::mem;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<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 read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn calc(n: i32, l: &[char], s: &mut BTreeMap<char, i32>) -> Option<(char, i32)> {
    let (ls, lr) = l.split_first().unwrap();
    *s.entry(*ls).or_insert(0) += 1;
    let mut first = ('*', 0);
    let mut second = ('*', 0);
    /* aoj の rustc 1.17だからfor_each ないんだって
     * 悲しいね
    s.iter().for_each(|(k,v)| {
        if second.1 <= *v { second = (*k,*v); }
        if first.1 < second.1 { mem::swap(&mut first, &mut second); }
    });
    */
    for (k,v) in s.iter() {
        if second.1 <= *v { second = (*k,*v); }
        if first.1 < second.1 { mem::swap(&mut first, &mut second); }
    }
    if second.1 + n < first.1 { Some((first.0, n)) }
    else { 
        if n == 0 { None }
        else { calc(n-1, lr, s) }
    }
}


fn main(){
	let cin = stdin();
	let cin = cin.lock();
	let mut sc = Scanner::new(cin);
    loop{
        let n : i32 = sc.read();
        if n == 0 { break; }
        let mut k = Vec::<char>::new();
        // aoj のバージョンだとcharがFromStrにimplementされてないよ
        for _ in 0..n { k.push(sc.read::<String>().chars().next().unwrap()); }
        let mut m = BTreeMap::<char, i32>::new();
        m.insert('*',0);
        if let Some((c, d)) = calc(n-1, k.as_slice(), &mut m){
            println!("{} {}", c, n-d);
        } else {
            println!("TIE");
        }
    }
}





Measured memory_bytes: 5048
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

using ll = long long;

inline ll min(ll a, ll b) {
	return a < b ? a : b;
}

const int Max = 1e5 + 12;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	cout << max({ a + b, a - b, a * b });
	
	//system("pause");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
#define ll long long
using namespace std;
int n,m,sum,flag,s[4],id[N],gg;ll Ans;
vector<int>a[N],b[N];
void dfs(int x,int y)
{
	if (!id[x]) sum++,id[x]=y;
	else
	{
		if (id[x]!=y) flag=1;
		return;
	}
	s[id[x]]++;
	for (int i=0;i<a[x].size();i++)
		dfs(a[x][i],y%3+1),gg++;
	for (int i=0;i<b[x].size();i++)
		dfs(b[x][i],(y+1)%3+1),gg++;
}
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		a[x].push_back(y);
		b[y].push_back(x);
	}
	for (int i=1;i<=n;i++)
	{
		if (!id[i])
		{
			flag=0;sum=0;gg=0;
			s[1]=s[2]=s[3]=0;
			dfs(i,1);
			if (flag) Ans+=(ll)sum*sum;
			else if (!s[1]||!s[2]||!s[3]) Ans+=gg/2;
			else Ans+=(ll)s[1]*s[2]+(ll)s[2]*s[3]+(ll)s[3]*s[1];
		}
	}
	printf("%lld\n",Ans);	
} 

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

int main(){
    int n,l;
    scanf("%d %d",&n,&l);
    int max=0;
    int ans;
    for(int i=1;i<n+1;i++) max+=l+i-1;
    for(int i=1;i<n+1;i++){
        int save=max-(l+i-1);
        if(i==0) ans=save;
        if(abs(save-max)<abs(ans-max)) ans=save;
    }
    printf("%d\n",ans);


}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n;
    cin>>n;
    bool csz = true;
    while(n--){
        int t;
        cin>>t;
        if(t%2 == 0){
            if(t%3 != 0 && t%5 != 0) csz = false;
        }
    }
    if(csz) cout<<"APPROVED";
    else cout<<"DENIED";
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

answer_list = []

for i in range(N):
    answer = 0
    if i == 0:
        for j in range(N):
            # print(i, j, i-1-j, A[i-1-j])
            if j % 2 == 0:
                answer += A[i-1-j]
            else:
                answer -= A[i-1-j]
    else:
        answer = 2*A[i-1] - answer_list[i-1]

    answer_list.append(answer)
print(" ".join(map(str, answer_list)))

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

using namespace std;

int main() {
    std::ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int N;
    string A, B, C;
    cin >> N >> A >> B >> C;

    int res = 0;
    for (int i = 0; i < N; ++i) {
        if (A[i] == B[i] && B[i] == C[i]) {
            res += 0;
        } else if (A[i] == B[i] || B[i] == C[i] || A[i] == C[i]) {
            res += 1;
        } else {
            res += 2;
        }
    }
    cout << res << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define CMAX(m, x)  m = max(m,x);
#define CMIN(m, x)  m = min(m,x);
#define itn int
typedef long long lint;
const int INF = 1e9;
const lint LINF = 1e18;
int main(){
    lint n,k;
    lint temp;
    cin >> n >> k;
    while(true){
        if(n / k > 0)
            temp = abs(n -  k * (n / k));
        else
            temp = abs(n - k);
        if(temp > n)
            break;
        n = temp;
    }
    cout << min(temp,n) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 100005;

int a[maxn],a2[maxn];
string s,s2;

int main() {
 // freopen("in.cpp","r",stdin);
  cin>>s>>s2;
  int n = s.size(), m=s2.size();
  for(int i=0;i<n;i++)a[i+1]=a[i]+(s[i]=='A'?1:-1);
  for(int i=0;i<m;i++)a2[i+1]=a2[i]+(s2[i]=='A'?1:-1);
  int T;
  cin>>T;
  while(T--){
    int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    int t1=a[y1]-a[x1-1];
    int t2=a2[y2]-a2[x2-1];
    if(t1<t2)swap(t1,t2);
    if((t1-t2)%3==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}


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

using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a, b;
	cin >> a >> b;
	int x = a + b, y = a - b, z = a * b;
	int m = max(x, y);
	m = max(m, z);

	cout << m;
}

Measured memory_bytes: 256
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")

using namespace std;
using namespace __gnu_pbds;

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifdef HOME
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef gp_hash_table < int, int > fast;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5, LG = 20;
const int INF = INT_MAX;
const db PI = acos(-1), EPS = 1 / db(1e6);
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());

void test() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0, b; i < n - 1; ++i) {
        cin >> b;
        if (!i) {
            a[0] = a[1] = b;
        } else {
            a[i + 1] = b;
            a[i] = min(a[i], b);
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += a[i];
    }
    cout << ans << "\n";
}

int main() {
    fast_io();
    #ifdef HOME
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    cout << fixed << setprecision(15);
    test();
    #ifdef HOME
        cout << "Time: " << (int)(clock() * 1000. / CLOCKS_PER_SEC) << "ms";
    #endif
    return 0;
}


Measured memory_bytes: 256
while True:
    n,k =map(int,input().split())
    if n==0 and k==0:
        break
    a=[int(input()) for _ in range(n)]
    s=sum(a[0:k])
    ss=[s]
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        ss.append(s)
    print(max(ss))


Measured memory_bytes: 11700
#include <iostream>

using namespace std;

int main()
{
    long long x,s=0;
    cin>>x;
    if(x<7)cout<<1;
    else{
        if(x<12)cout<<2;
        else{
            if(x%11!=0){
                if(x%11<7)s++;
                else s+=2;
            }
            s+=((x/11)*2);
            cout<<s;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define endl "\n"
#define int long long

using namespace std;

void dout() {
    cerr << endl;
}

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}


typedef pair <int, int> pii;

const int N = 1e5 + 3;
string s, t;
vector <int> pos[26];
int last[26], ind[N], cnt, ans;

void cleanup() {
    return;
}

void solve() {
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        pos[s[i] - 'a'].pb(i);
    }
    for (int i = 0; i < t.size(); i++) {
        int tmp = t[i] - 'a';
        if (pos[tmp].empty()) {
            cout << -1;
            return;
        }
        if (i > 0) {
            auto it = upper_bound(pos[tmp].begin(), pos[tmp].end(), ind[i - 1]);
            if (it == pos[tmp].end()) {
                ind[i] = pos[tmp][0];
                cnt++;
            }   else {
                ind[i] = pos[tmp][(int)(it - pos[tmp].begin())];
            }
        }   else {
            ind[i] = pos[tmp][0];
        }
        ans = ind[i] + 1;
    }
    ans += cnt * (int)s.size();
    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
    int tc = 1;
//    cin >> tc;
    while (tc--) {
        solve();
        cleanup();
    }
}


Measured memory_bytes: 2256
//
//  main.cpp
//  HelloWorld
//
//  Created by purple on 2020/04/13.
//  Copyright © 2020 Purple. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <cmath>

using namespace std;


int main(int argc, const char * argv[]) {


    string s;
    int cnt;
    cin >> s;

    
    while(s!="-"){
        int m;
        cin >> m;
        for(int i=0; i<m; i++){
            int h;
            cin >> h;
            string tmp;
            tmp = s.substr(h,s.size()-h) + s.substr(0,h);
            
            s = tmp;
        }
        cout << s << endl;
        cin >> s;
    }
    
    return 0;
}



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

int main() {
	int N,A,B,sum=0;
	int keta,i;
	cin>>N;
	cin>>A>>B;
	for(i=0;i<N+1;i++){
		if(0<i<10){
	    	keta=i;
		        }
		if(9<i<100){
		keta=i/10+i%10;
		}
		if(99<i<1000){
		keta=i/100+(i%100)/10+i%10;
		}
		if(999<i<10000){
		keta=i/1000+(i%1000)/100+(i%100)/10+(i%10);
		}
		if(9999<i<100000){
		keta=i/10000+(i%10000)/1000+(i%1000)/100+(i%100)/10+(i%10);
		}
	    if((A-1<keta)&&(keta<B+1)){
			       sum+=i;
		                               }
		                               
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256