akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      	int number_a, number_b, number_k, i, count = 0;
      	number_a = Integer.parseInt(sc.next());
      	number_b = Integer.parseInt(sc.next());
      	number_k = Integer.parseInt(sc.next());
      for(i = Math.min(number_a, number_b); i > 0; i--) {
        if(number_a % i == 0 && number_b % i == 0) count++;
        if(count == number_k) break;
      }
      System.out.println(i);
    }
}

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

int main() {
	char s[101], t[101];
	cin >> s;
	cin >> t;
	int len = strlen(s);
	bool equal = true;
	for (int i = 0; i < len; i++)if (s[i] != t[i])equal = false;
	if (equal) {
		cout << "Yes";
		return 0;
	}
	for (int i = 1; i < len; i++) {
		equal = true;
		int k;
		for (int j = 0; j < len; j++) {
			k = i + j;
			if (k >= len)k = k % len;
			if (s[k] != t[j]) {
				equal = false;
				break;
			}
		}
		if (equal) {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int a[n];
  int i;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (i = n - 1; i >= 0; i--) {
    cout << a[i];
    if (i != 0) {
      cout << " ";
    }
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vector<int> cnt(n, 0);

  rep(i, n-1){
    int a; cin >> a;
    a--;
    cnt[a]++;
  }
  
  rep(i, n){
    cout << cnt[i] << endl;
  }

  return 0;
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second
#define PI (acos(-1))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))

#define MAXN 1123456
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<vi> vvi;

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

    vector<tuple<int,int,int>> ev;
    int n;
    cin >> n;

    vi a(n), b(n);
    rep(i,0,n) {
      int x, l;
      cin >> x >> l;
      ev.pb(make_tuple(x-l, 1, i));
      ev.pb(make_tuple(x+l, -1, i));
      a[i] = x-l+1;
      b[i] = x+l;
    }
    sort(all(ev));
    set<int> out, active;
    trav(p, ev) {
      if (get<1>(p) == -1) {
        active.erase(get<2>(p));
      } else {
        active.insert(get<2>(p));
        if (sz(active) > 1) {
          if (b[*active.begin()] > b[*active.rbegin()]) {
            out.insert(*active.begin());
            active.erase(*active.begin());
          } else {
            out.insert(*active.rbegin());
            active.erase(*active.rbegin());
          }
        }
      }
    }

    cout << n-sz(out) << endl;
}

Measured memory_bytes: 8560
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc133/tasks/abc133_e>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

const ll MOD = 1e9+7;
template<class Type>
Type solve(Type res = Type()){
    ll N,K; cin >> N >> K;
    vector<vector<int>> G(N);
    for(int i = 0; i < N-1;i++){
        int u,v; cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    
    vector<ll> check_cnt(N);
    function<void(ll,ll)> rec = [&](ll n,ll pre){
        ll cnt = 0;
        if(pre != -1){
            cnt = check_cnt[pre] + 1;
        }
        (res *= max(K-cnt,0LL))%=MOD;
        for(auto next:G[n]){
            if(next == pre) continue;
            check_cnt[next]++;
            rec(next,n);
            check_cnt[n]++;
        }
    };
    
    res = 1;
    rec(0,-1);
    
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 12416
private data class Range(val l: Int, val r: Int, val c: Int)

fun main(args: Array<String>) {
    var inputs = readLine()!!

    // 文字列内の RL 区間をそれぞれ求める
    // RL の境目に吸い込まれる筈間違いない
    // 境目と範囲を求める

    var ranges = mutableListOf<Range>()
    var preIsR = true
    var preIsL = false

    var start = 0
    var end = 0
    var center = 0
    inputs = "${inputs}R"

    for (i in 1 until inputs.length) {

        val c = inputs[i]

        if (c == 'R' && preIsR) {
            // R が続いている時
            continue
        }

        if (c == 'R' && preIsL) {
            // L R となった時
            preIsR = true
            preIsL = false
            end = i - 1
            ranges.add(Range(start, end, center))

            start = i
            continue
        }

        if (c == 'L' && preIsR) {
            // R L となった時
            // 収束する場所
            preIsR = false
            preIsL = true
            center = i
            continue
        }

        if (c == 'L' && preIsL) {
            // L が続いている時
            continue
        }
    }

    // 求めた区間での収束位置を判定する
    var ans = LongArray(inputs.length-1) { 0L }.toMutableList()

    val res = powMod(10, 100, 2)
    for (range in ranges) {
        for (j in (range.l)..(range.r)) {
            val dist = Math.abs(range.c - j)

            if (minusMod(res, dist.toLong(), 2) == 0L) {
                ans[range.c] += 1L
            } else {
                ans[range.c - 1] += 1L
            }
        }
    }

    var ansString = ans.joinToString(" ")
    println(ansString)

}

fun plusMod(a: Long, b: Long, modVal: Long): Long {
    return (a + b) % modVal
}

fun minusMod(a: Long, b: Long, modVal: Long): Long {
    return (a - b + modVal) % modVal
}

fun timesMod(inputs: List<Long>, modVal: Long): Long {
    return inputs.reduce { acc, i -> (acc % modVal) * (i % modVal) % modVal }
}

/**
 * a^n mod modVal を計算する
 * 二分累乗法で累乗計算を O(logN) で行いつつ，OverFlow を避けるため適宜 mod 計算を行う
 */
fun powMod(a: Long, n: Long, modVal: Long, ans: Long = 1): Long {

    if (n == 0L) {
        return ans
    }

    // ビット演算の結果 2^0 の桁が 0 の場合は ans に掛けずに次の桁へ
    if (n.and(1L) == 0L) {
        return powMod(a * a % modVal, n.shr(1), modVal, ans)
    }

    // ビット演算の結果 2^9 の桁が 1 の場合は ans を更新
    return powMod(a * a % modVal, n.shr(1), modVal, ans * a % modVal)
}


/**
 * 二分累乗法の実装 a^N を O(logN) で計算
 * 指数部分を２進数で考える -> 指数が2^n になっていなくても問題ない
 */
private fun pow(a: Long, n: Long, ans: Long = 1): Long {

    if (n == 0L) {
        return ans
    }

    // ビット演算の結果 2^0 の桁が 0 の場合は ans に掛けずに次の桁へ
    if (n.and(1L) == 0L) {
        return pow(a * a, n.shr(1), ans)
    }

    // ビット演算の結果 2^0 の桁が 1 の場合は ans を更新
    return pow(a * a, n.shr(1), ans * a)
}

Measured memory_bytes: 44100
while true  do
  arr = gets.split
  num1 = arr[0].to_i
  num2 = arr[2].to_i
  operator = arr[1]
  if operator == "+"
    puts num1 + num2
  elsif operator == "-"
    puts num1 - num2
  elsif operator == "*"
    puts num1 * num2
  elsif operator == "/"
    puts num1 / num2 
  else
    break
  end
end

Measured memory_bytes: 8852
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List

bsReadInts :: B.ByteString -> [Int]
bsReadInts = map (fst . fromJust . B.readInt) . B.words

solve :: Int -> Int -> [Int] -> [Int] -> [Int] -> Int
solve n m xs ys zs =
  maximum [f  1 1 1, f  1 1 (-1), f  1 (-1) 1, f  1 (-1) (-1),
           f (-1) 1 1, f (-1) 1 (-1), f (-1) (-1) 1, f (-1) (-1) (-1)]
  where
    f :: Int -> Int -> Int -> Int
    f a b c  =
      sum $ take m $ reverse $ sort $ zipWith3 h (g a xs) (g b ys) (g c zs)
    g a xs = map (* a) xs
    h p q r = p + q + r

main :: IO ()
main = do
  conts <- B.getContents
  let [n, m] : xyzs = map bsReadInts (B.lines conts)
      [xs, ys, zs] = transpose xyzs
      answer = solve n m xs ys zs
  putStrLn (show answer)


Measured memory_bytes: 1660
from math import gcd as g
n,m=map(int,input().split())
s=input()
t=input()
k=(a:=(N:=(l:=n*m//g(n,m))//n))*(b:=(M:=l//m))//g(a,b)
print(-1 if s[0]!=t[0] or (l==n and s!=t*N) or (l==m and t!=s*M) or s[::b]!=t[::a] else l)

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    lint a, b;
    cin >> a >> b;
    lint c = b / a;//距離がc超ならテレポする
    vector<lint> v(n);
    REP(i, n)
        cin >> v[i];
        
    lint ans=0;
    REP(i,n-1){
        lint d = v[i + 1] - v[i];
        if(d>c){
            ans += b;
        }else{
            ans += a*d;
        }

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
int main()
{
  vector<int> vec(3);
  cin>>vec[0]>>vec[1]>>vec[2];
  int k;
  cin>>k;
  sort(vec.begin(),vec.end(),greater<int>());
  for(int i=0;i<k;i++){
    vec.push_back(vec[0]*2);
    vec.erase(vec.begin());
    sort(vec.begin(),vec.end(),greater<int>());
  }
  cout<<accumulate(vec.begin(),vec.end(),0);
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	N *= 3;
	vi arr (N);
	F0R(i, N) cin >> arr[i];
	sort(arr.begin(), arr.end());
	reverse(arr.begin(), arr.end());

	ll ans = 0;
	for (int i = 0; i < N; i+=2) {
		ans += arr[i+1];
		N--;
	}
	print(ans);
}

Measured memory_bytes: 1408
n, m = map(int,input().split())
l = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(m)]
# n,m = 3,2
# l = [5,1,4]
# s = [[2,3],[1,5]]
# l = [1, 8, 5, 7, 100, 4, 52, 33, 13, 5]
l.sort()
s.sort(key=lambda x: x[1], reverse=True)
idx = 0
for i in range(m):
    for j in range(idx, min(n, idx + s[i][0])):
        if l[j] < s[i][1]:
            l[j] = s[i][1]
    idx += s[i][0]
        # else:
        #     idx += s[i][0]
        #     break
print(sum(l))

Measured memory_bytes: 32968
a[6],x;main(i,j){for(;~j;++i)i<6?x|=1<<(gets(a+i),j=a[i]-=49):i>10?x=i=0:printf("%d\n",x^x&-x&&x-7?j=a[i-5],x&2?j+x%2:j?1:2:3);}

Measured memory_bytes: 524
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[4] = {1,0,-1,0};
constexpr ll ny[4] = {0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x,a;
    cin >> n >> x;
    int ans;
    rep(i,n){
        cin >> a;
        if (i == 0) ans = abs(a-x);
        else ans = gcd(ans,abs(a-x));
    }
    PRINT(ans);
}


Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  long x, y; readV(x, y);
  auto a = [x];
  while (a[$-1]*2 <= y) a ~= a[$-1]*2;
  writeln(a.length);
}


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

e_list1 = [[] for i in range(N)]
e_list2 = [[] for i in range(N)]

for i in range(K):
    p,q = list(map(int,input().split()))
    e_list1[p-1].append(q-1)
    e_list1[q-1].append(p-1)

for i in range(L):
    p,q = list(map(int,input().split()))
    e_list2[p-1].append(q-1)
    e_list2[q-1].append(p-1)


from collections import deque

def BFS(vi,color,color_list,e_list):
    Q = deque([vi])
    color_list[vi]=color
    while len(Q)>0:
        v = Q.pop()
        for v1 in e_list[v]:
            if color_list[v1]==-1:
                color_list[v1]=color
                Q.appendleft(v1)
    return color_list



color_list = [-1 for i in range(N)]
color = 0
for i in range(N):
    if color_list[i]==-1:
        color_list = BFS(i,color,color_list,e_list1)
        color+=1
color_list2 = [-1 for i in range(N)]
color2 = 0
for i in range(N):
    if color_list2[i]==-1:
        color_list2 = BFS(i,color2,color_list2,e_list2)
        color2+=1
M = 1+max(color_list)
color_list = [color_list[i]+M*color_list2[i] for i in range(N)]

from collections import Counter

counter = Counter(color_list)

ans = []

for i in range(N):
    ans.append(counter[color_list[i]])

print(*ans)

Measured memory_bytes: 124656
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 1E+05;

int N;

ll A[MAX_N + 1], B[MAX_N + 1], C[MAX_N + 1];

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

    cin >> N;

    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    for (int i = 1; i <= N; i++) {
        cin >> B[i];
    }
    for (int i = 1; i <= N; i++) {
        cin >> C[i];
    }

    sort(A + 1, A + N + 1);
    sort(B + 1, B + N + 1);
    sort(C + 1, C + N + 1);

    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        //cout << "i = " << i << ", a = " << lower_bound(A + 1, A + N + 1, B[i]) - 1 - A << ", c = " << C + N - upper_bound(C + 1, C + N + 1, B[i]) << "\n";
        ans += (lower_bound(A + 1, A + N + 1, B[i]) - 1 - A) * (C + N + 1 - upper_bound(C + 1, C + N + 1, B[i]));
    }

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << ans << "\n";

    return 0;
}

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

B_list = []
C_list = []
for i in range(N):
    A, B = map(int, input().split())
    B_list.append(B)
    C_list.append((B-A) % B)

count = 0
for i in range(N-1, -1, -1):
    count += (C_list[i] - count) % B_list[i]
print(count)


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

using namespace std;

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

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

    int n;cin>>n;
    vector<ll> c(n-1),s(n-1),f(n-1);
    for(int i=0;i<n-1;i++) cin>>c[i]>>s[i]>>f[i];
    for(int st=0;st<n-1;st++){
        ll tm=0;
        for(int i=st;i<n-1;i++){
            if(tm<s[i]){
                tm=s[i]+c[i];
                continue;
            }
            tm = ((tm-1)/f[i]+1)*f[i]+c[i];
        }
        cout<<tm<<endl;
    }
    cout<<0<<endl;
}


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

main() {
  int N; cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    a[i]--;
  }
  int ans = 0, pos = 0;
  for (int i = 0; i < N; i++) {
    if (pos == 1) break;
    ans++;
    pos = a[pos];
  }
  cout << ( (ans == N) ? -1 : ans ) << endl;
}


Measured memory_bytes: 768
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,N,x,ans=0;
  cin>>N;
  string t;
  vector<string> s(N);
  vec v(N);
  rep(i,N){
    cin>>s[i]>>v[i];
  }
  cin>>t;
  x=0;
  rep(i,N){
    if(x)ans+=v[i];
    if(s[i]==t){
      x=1;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 100005
#define inf 1000000007
using namespace std;

int arr[maxn], dp[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    //freopen("d.in", "r", stdin);

    int n, k;cin >> n >> k;
    for (int i = 1; i <= n; i++){
        cin >> arr[i];
        dp[i] = inf;
    }

    dp[1] = 0;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= k; j++){
            if (i + j <= n){
                dp[i + j] = min(dp[i + j], dp[i] + abs(arr[i] - arr[i + j]));
            }
        }
    }

    cout << dp[n];

    return 0;
}


Measured memory_bytes: 1024
N,W = map(int,input().split())
wv = [[int(i) for i in input().split()] for j in range(N)]

# dpテーブルを初期化
dp = [[0]*(W+1) for i in range(N+1)]

for i in range(N):
    for j in range(W+1):
        # (i-1)番目を選ぶ場合
        if j - wv[i][0] >= 0:
            dp[i+1][j] = max(dp[i+1][j], dp[i][j-wv[i][0]]+wv[i][1])
        # (i-1)番目を選ばない場合
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

print(dp[N][W])


Measured memory_bytes: 121068
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    int a,b,c;
    cin >> a >> b >> c;

    if (a == b + c || b == a + c || c == a + b)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

// テ・ツケツエテヲツ慊暗」ツつ津・ツ?・テ」ツつ古」ツつ凝」ツ?ィテ」ツ?敕」ツ?ョテヲツ慊暗」ツ?古、ツスツ陛ヲツ猟・テゥツ鳴禿」ツ?凝」ツつ津ィツィツ暗ァツョツ療」ツ?凖」ツつ凝ゥツ鳴「テヲツ閉ー
int monthhas(int y, int m){
  // 3テ」ツ?ァテ・ツ可イテ」ツつ甘」ツ?催」ツつ古」ツつ凝・ツケツエテ」ツ?ッテァツ?。テヲツ敖。テ、ツサツカテ」ツ?ォ20テヲツ猟・テゥツ鳴?
  if(y % 3 == 0){ return 20; }
  // テ」ツ?敕」ツつ古、ツサツ・テ・ツ、ツ姪」ツ?ョテ・ツケツエテ」ツ?ッテ」ツ??・ツ?カテヲツ閉ーテヲツ慊暗」ツ?ッ19テヲツ猟・テゥツ鳴禿」ツ??・ツ・ツ?ヲツ閉ーテヲツ慊暗」ツ?ッ20テヲツ猟・テゥツ鳴?
  return m % 2 == 0 ? 19 : 20;
}

// テ・ツケツエテ」ツつ津・ツ?・テ」ツつ古」ツつ凝」ツ?ィテ」ツ?敕」ツ?ョテ・ツケツエテ」ツ?古、ツスツ陛ヲツ猟・テゥツ鳴禿」ツ?凝」ツつ津ィツィツ暗ァツョツ療」ツ?凖」ツつ凝ゥツ鳴「テヲツ閉ー
int yearhas(int y){
  // 3テ」ツ?ァテ・ツ可イテ」ツつ甘」ツ?催」ツつ古」ツつ凝・ツケツエテ」ツ?ッ20テヲツ猟・テδ?0テ」ツδカテヲツ慊?= 200テヲツ猟・テゥツ鳴?
  // 3テ」ツ?ァテ・ツ可イテ」ツつ甘・ツ按?」ツつ古」ツ?ェテ」ツ??・ツケツエテ」ツ?ッ20テヲツ猟・テδ?テ」ツδカテヲツ慊?+ 19テヲツ猟・テδ?テ」ツδカテヲツ慊?= 195テヲツ猟・テゥツ鳴?
  return y % 3 == 0 ? 200 : 195;
}

int main(void){
  int n, i, j, ans;
  int y, m, d;

  // テ」ツδ?」ツδシテ」ツつソテ」ツつサテ」ツδε」ツδ暗ヲツ閉ーテ」ツつ津・ツ?・テ・ツ環?
  scanf("%d", &n);

  for(i = 0; i < n; i++){
    ans = 0;

    // ティツゥツウテァツエツーテ」ツδ?」ツδシテ」ツつソテ・ツ?・テ・ツ環?
    scanf("%d %d %d", &y, &m, &d);

    // テァツ板淌」ツ?セテ」ツつ古」ツ?淌ヲツ猟・テ」ツ?凝」ツつ嘉」ツ?敕」ツ?ョテ・ツケツエテ」ツ?古ァツオツづ」ツつ湘」ツつ凝」ツ?セテ」ツ?ァテ」ツつ津ィツィツ暗ァツョツ?
    for(j = m; j <= 10; j++){
      ans += monthhas(y, j);
    }
    ans -= (d - 1);

    // テァツ板淌」ツ?セテ」ツつ古」ツ?淌ヲツャツ。テ」ツ?ョテ・ツケツエテ」ツ?凝」ツつ嘉」ツδ淌」ツδャテ」ツδ凝」ツつ「テ」ツδ?ィツィツ佚・ツソツオテヲツ猟・テ・ツ可催ヲツ猟・テ」ツ?セテ」ツ?ァテ」ツつ津ィツィツ暗ァツョツ?
    for(j = y + 1; j < 1000; j++){
      ans += yearhas(j);
    }

    // ティツィツ暗ァツョツ療ァツオツ静ヲツ楪愿」ツつ津・ツ?コテ・ツ環?
    printf("%d\n", ans);
  }

  return 0;
}

Measured memory_bytes: 596
<?php

fscanf(STDIN, "%s", $s);

$s_arr = str_split($s);
$len = strlen($s);

$result = true;
$tmp = $s_arr[0];
for ($i = 1; $i < $len; ++$i) {
    if ($tmp == $s_arr[$i]) {
        $result = false;
        break;
    }
    $tmp = $s_arr[$i];
}

echo $result ? 'Good' : 'Bad';


Measured memory_bytes: 4728
#include<cstdio>
#include<queue>
#include<cmath>
using namespace std;
#define MAXN 1005
#define Max(a,b) a>b?a:b
#define INF 2828427224
double x[MAXN],y[MAXN],r[MAXN];
long double Dis(int i,int j)
{
	return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
long double a[MAXN][MAXN];
bool vis[MAXN];
long double dis[MAXN];
queue<int>Q;
int main()
{
	scanf("%lf%lf%lf%lf",&x[0],&y[0],&x[1],&y[1]);
	int n;
	scanf("%d",&n);
	n++;
	for(int i=2;i<=n;i++)
		scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);
	for(int i=0;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			a[i][j]=a[j][i]=Max(0.0,Dis(i,j)-r[i]-r[j]);
	for(int i=1;i<=n;i++)
		dis[i]=INF;
	Q.push(0);
	vis[0]=1;
	while(!Q.empty())
	{
		int u=Q.front();Q.pop();
		vis[u]=0;
		for(int v=1;v<=n;v++)
			if(dis[v]>dis[u]+a[u][v])
			{
				dis[v]=dis[u]+a[u][v];
				if(!vis[v])
				{
					Q.push(v);
					vis[v]=1;
				}
			}
	}
	printf("%.10Lf\n",dis[1]);
}

Measured memory_bytes: 16000
# -*- coding: utf-8 -*-

N = int(input().strip())
A_list = list(map(int, input().rstrip().split()))
#-----

temp_A=[]
for i in range(len(A_list)):
    temp_A.append( A_list[i] - (i+1) )

temp_A.sort()
if N%2 == 1:
    median = temp_A[ N//2 ]
else:
    median = (temp_A[ N//2 - 1] + temp_A[ N//2 ]) // 2

b = median
sum=0
for i,a in enumerate(A_list):
    sum += abs( a - (b+(i+1)) )

print(sum)


Measured memory_bytes: 26180
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func readInts(n int) []int {
	result := make([]int, n)
	for i := 0; i < n; i++ {
		result[i] = nextInt()
	}
	return result
}

func main() {
	S := nextString()
	var num int
	for i := 0; i < len(S); i++ {
		n, _ := strconv.Atoi(S[i : i+1])
		num += n
	}
	if num%9 == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 2196
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)n;i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
#define REP(i,b,e) for(int i=b;i<(int)e;i++)
typedef long long ll;
typedef map<ll,ll> mll;
typedef vector<ll> vll;
ll INF=1e18;
int inf=1e9+1000;
 
string alpha="abcdefghijklmnopqrstuwvxyz";
 
int D,N;
 
 
int main(){
    cin>>D>>N;
    cout<<N+N/100;
    Rep(i,D){
        cout<<"00";
    }
    cout<<endl;
 
    return 0;
}

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

using namespace std;

int main(void){
  int info;
  int building,floor,order,num;

  vector<vector<vector<int>>> vec(4,vector<vector<int>>(3,vector<int>(10,0)));

  cin>>info;
  for(int i=0;i<info;i++){
    cin>>building>>floor>>order>>num;
    vec.at(building-1).at(floor-1).at(order-1)+=num;
  }

  for(int i=0;i<4;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<10;k++){
        cout<<" "<<vec.at(i).at(j).at(k);
      }
      cout<<endl;
    }
    if(i==3) break;
    cout<<"####################"<<endl;
  }
  return 0;

}



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

const long MAX = 100;
const long INFTY = (1<<21);
const long WHITE = 0;
const long GRAY = 1;
const long BLACK = 2;

long n, M[MAX][MAX];

void dijkstra(){
	long minv;
	long d[MAX], color[MAX];

	for (long i = 0; i < n; i++){
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[0] = 0;
	color[0] = GRAY;
	while (1){
		minv = INFTY;
		long u = -1;
		for (long i = 0; i < n; i++){
			if (minv > d[i] && color[i] != BLACK){
				u = i;
				minv = d[i];
			}
		}
		if (u == -1) break;
		color[u] = BLACK;
		for (long v = 0; v < n; v++){
			if (color[v] != BLACK && M[u][v] != INFTY){
				if (d[v] > d[u] + M[u][v]){
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}

	for (long i = 0; i < n; i++){
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	}
}

int main(){
	cin >> n;
	for (long i = 0; i < n; i++){
		for (long j = 0; j < n; j++){
			M[i][j] = INFTY;
		}
	}

	long k, c, u, v;
	for (long i = 0; i < n; i++){
		cin >> u >> k;
		for (long j = 0; j < k; j++){
			cin >> v >> c;
			M[u][v] = c;
		}
	}

	dijkstra();

	return 0;
}

Measured memory_bytes: 1236
V, E = map(int, input().split())

dist = [[float('inf') for _ in range(V)] for _ in range(V)]
for _ in range(E):
    s, t, d = map(int, input().split())
    dist[s][t] = d

# 2**V回、-1がV個の配列を作る
dp = [[-1]*V for _ in range(1<<V)]

def rec(s, v, dp):
    """
    s: 訪れた集合のbit演算（すべて訪れたら2**V-1になる）
    v: いまいる点
    dp: dp配列
    """
    if dp[s][v] >= 0:
        return dp[s][v]
    
    # すべて訪れており、かつ今いる点が0（始点）の場合
    if s == (1<<V)-1 and v == 0:
        dp[s][v] = 0
        return 0

    res = float('inf')
    for u in range(V):
    # まだuに訪れていないときuに訪れる。コストを再帰的に出す
        if (s>>u&1) == 0:
            res = min(res, rec(s|(1<<u), u, dp) + dist[v][u])

    dp[s][v] = res
    return res

ans = rec(0, 0, dp)

if ans == float('inf'):
    print(-1)
else:
    print(ans)


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;
//const int mod = 998244353;

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

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n, m;
  cin >> n >> m;
  vector<bool> flag(n, false);
  vector<int> a(n, 1);
  flag[0] = true;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    flag[y] = flag[x] || flag[y];
    --a[x];
    ++a[y];
    if(a[x] == 0) flag[x] = false;
  }
  int ans = 0;
  rep(i, n) if(flag[i]) ++ans;
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
const int maxn = 1e5 + 10;
using namespace std;

int n;
char s[maxn], str[maxn];

bool lis(char ch1, char ch2) {
    str[0] = ch1; str[1] = ch2;
    for(int i = 1; i < n; i++) {
        int j = (i + 1) % n;
        char ch = str[i];
        if((ch == 'S' && s[i] == 'o') || (ch == 'W' && s[i] == 'x')) {
            if(i == n - 1 && str[j] != str[i - 1]) return false;
            str[j] = str[i - 1];
        } else {
            if(i == n - 1 && str[j] == str[i - 1]) return false;
            if(str[i - 1] == 'S') str[j] = 'W';
            else str[j] = 'S';
        }
    }
    char ch = ch1;
    if((ch == 'S' && s[0] == 'o') || (ch == 'W' && s[0] == 'x')) {
        if(str[1] == str[n - 1]) return true;
        return false;
    } else {
        if(str[1] != str[n - 1]) return true;
        return false;
    }
}

bool solve() {
    if(lis('S', 'S')) return true;
    if(lis('S', 'W')) return true;
    if(lis('W', 'S')) return true;
    if(lis('W', 'W')) return true;
    return false;
}

int main() {
    while(scanf("%d %s", &n, s) != EOF) {
        str[n] = 0;
        bool can = solve();
        if(can) printf("%s\n", str);
        else printf("-1\n");
    }
    return 0;
}


Measured memory_bytes: 512
def solve(m_list):
    m_val = m_list[0]
    for i in m_list:
        m_val = min(m_val,gcd(m_val,i))
    return m_val

def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def main():
    n = int(input())
    m_list = list(map(int,input().split()))

    ans = solve(m_list)
    print(ans)

main()

Measured memory_bytes: 14224
#include <iostream>
#include <string>
#include <vector>

const int horz_node_count = 5;
const int vert_node_count = 5;
const int direction_count = 4;	// [0]:left, [1]:up, [2]:right [3]:down
enum { left, up, right, down };

int index(int x, int y, int direction)
{
	return (y * horz_node_count + x) * direction_count + direction;
}

void read_data(int* walls)
{
	std::vector<std::string> input;
	for (int i = 0; i < vert_node_count * 2 - 1; ++i) {
		std::string line;
		if (std::getline(std::cin, line)) {
			input.push_back(line);
		}
	}

	std::fill_n(walls, horz_node_count * vert_node_count * direction_count, 0);

	for (int y = 0; y < vert_node_count; ++y) {
		for (int x = 0; x < horz_node_count - 1; ++x) {
			if (input[y*2][x] == '1') {
				walls[index(x,y,right)] = 1;
				walls[index(x+1,y,left)] = 1;
			}
		}
	}
	for (int y = 0; y < vert_node_count - 1; ++y) {
		for (int x = 0; x < horz_node_count; ++x) {
			if (input[y*2+1][x] == '1') {
				walls[index(x,y,down)] = 1;
				walls[index(x,y+1,up)] = 1;
			}
		}
	}
}

bool wall_exists(const int* walls, int x, int y, int direction)
{
	return (0 <= x && x < horz_node_count)
		&& (0 <= y && y < vert_node_count)
		&& (walls[index(x,y,direction)] != 0);
}

int main()
{
	int walls[horz_node_count * vert_node_count * direction_count] = {};
	read_data(walls);

	int x = 0, y = 0, direction = right;
	do {
		// determine the next direction
		direction = (direction + direction_count - 1) % direction_count;
		for (int i = 0; i < 4; ++i) {
			if (wall_exists(walls, x, y, direction)) {
				break;
			}
			direction = (direction + 1) % direction_count;
		}
		// step forward
		switch (direction) {
			case left:
				--x;
				std::cout << 'L';
				break;
			case up:
				--y;
				std::cout << 'U';
				break;
			case right:
				++x;
				std::cout << 'R';
				break;
			case down:
				++y;
				std::cout << 'D';
				break;
		}
	} while (x > 0 || y > 0);

	std::cout << std::endl;

	return 0;
}

Measured memory_bytes: 1180
import java.util.Scanner;
import java.lang.Math;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    String in=scan.next();
    String alpha[]={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
    for(int x=0; x<alpha.length-1; x++){
      if(alpha[x].equals(in)){
        System.out.println(alpha[x+1]);
      }
    }
  }
}

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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	vector<int>A(N); rep(i, 0, N) { cin >> A[i]; }

	multiset<int, greater<int>>s;
	rep(i, 0, N) {
		if (s.empty()) {
			s.insert(A[i]);
		}
		else {
			auto x = s.upper_bound(A[i]);
			if (x != s.end()) {
				s.erase(x);
			}
			s.insert(A[i]);
		}
	}
	cout << s.size() << endl;

	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const ll inv=mod/2+1;
int n,m;
vi a;
vvl dp;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	a=vi(n);
	dp=vvl(n,vl(n));
	for(auto &i:a) cin>>i;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(a[i]>a[j]) dp[i][j]++;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		for(int j=0;j<n;j++) if(j!=x&&j!=y){
			ll t=(dp[j][x]+dp[j][y])*inv%mod;
			dp[j][x]=dp[j][y]=t;
		}
		for(int j=0;j<n;j++) if(j!=x&&j!=y){
			ll t=(dp[x][j]+dp[y][j])*inv%mod;
			dp[x][j]=dp[y][j]=t;
		}
		ll t=(dp[x][y]+dp[y][x])*inv%mod;
		dp[x][y]=dp[y][x]=t;
		
	}
	ll res=0;
	for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) (res+=dp[i][j])%=mod;
	for(int i=0;i<m;i++) (res*=2)%=mod;
	cout<<res<<endl;
}

Measured memory_bytes: 72576
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define Q int q; cin >> q; while (q--)
#define endl '\n'
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;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    set<int> a;
    REP(i, n) {
        int x; cin >> x;
        a.emplace(x);
    }
    int m;
    cin >> m;
    set<int> b;
    REP(i, m) {
        int x; cin >> x;
        b.emplace(x);
    }
    set<int> c;
    set_union(ALL(a), ALL(b), inserter(c, end(c)));

    for (auto x : c) cout << x << endl;
}



Measured memory_bytes: 40692
#include <iostream>
#include <string>

int main() {
  std::string N;
  std::cin >> N;
  int remainder = 0;
  for (const auto digit : N) {
    remainder = (remainder + digit - '0') % 9;
  }
  std::cout << ((remainder == 0) ? "Yes" : "No") << std::endl;
  return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;

struct UnionFind{
    vector <int> par;
    vector <int> height;
    vector <int> card;

    UnionFind(int N){
        par.assign(N, 0);
        height.assign(N, 0);
        card.assign(N, 1);
        for(int i = 0; i < N; i++){
            par[i] = i;
        }
    }
    int set_size(int x){
        return card[root(x)];
    }
    int root(int x){
        if(x == par[x]){
            return x;
        }
        par[x] = root(par[x]);
        return par[x];
    }

    int same(int x, int y){
        return root(x) == root(y);
    }

    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if(x == y){
            return;
        }
        if(height[x] >= height[y]){
            par[y] = x;
            if(height[x] == height[y]){
                height[x] ++;
            }
            card[x] += card[y];
        } else {
            par[x] = y;
            card[y] += card[x];
        }
    }
};

int A[100000];
int B[100000];
int main(){
    int N;
    int M;
    cin >> N >> M;
    UnionFind uf(N);
    for(int i = 0; i < M; i++){
        cin >> A[i] >> B[i];
        A[i] --;
        B[i] --;        
    }

    vector <long long> ans;
    long long tmp_inconvenience = (long long) N * (long long) (N - 1) / 2;
    ans.push_back(tmp_inconvenience);
    for(int i = M - 1; i > 0; i--){
        long long before_a_set_size = uf.set_size(A[i]);
        long long before_b_set_size = uf.set_size(B[i]);
        bool same_before = uf.same(A[i], B[i]);
        uf.unite(A[i], B[i]);
        if(!same_before){
            long long cur_set_size = uf.set_size(A[i]);
            //cout << A[i] << " " << B[i] << endl;
            //cout << before_a_set_size << " " << before_b_set_size << " " << cur_set_size << endl;

            tmp_inconvenience = tmp_inconvenience + before_a_set_size * (before_a_set_size - 1) / 2
                                + before_b_set_size * (before_b_set_size - 1) / 2
                                - cur_set_size * (cur_set_size - 1) / 2;
        }
        ans.push_back(tmp_inconvenience);
    }
    for(int i = ans.size() - 1; i >= 0; i--){
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4212
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string s; readV(s);
  writeln(s.predSwitch("A", "T", "T", "A", "C", "G", "G", "C"));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int main(){
  ll n; cin >> n;
  ll mi = LMAX;
  int id;
  rep(i, 5){
    ll d; cin >> d;
    if(d < mi){
      mi = d;
      id = i;
    }
  }

  ll ans;
  if(n % mi == 0){
    ans = id + n/mi + (5 - id - 1);
  }else{
    ans = id + n/mi + 1 + (5 - id - 1);
    // cout <<"a" << endl;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256