akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int X,Y;
    private void solve() {
        X = nextInt();
        Y = nextInt();

        for(int i = 0;i <= X;i++) {
            int a = i * 2;
            int b = (X - i) * 4;

            if (a + b == Y) {
                out.println("Yes");
                return;
            }
        }

        out.println("No");
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

    public double nextDouble() {
        return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] x = new int[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextInt();
        }
        return x;
    }

    public long[] nextLongArray(int n) {
        long[] x = new long[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextLong();
        }
        return x;
    }

    public double[] nextDoubleArray(int n) {
        double[] x = new double[n];
        for(int i = 0;i < n;i++) {
            x[i] = nextDouble();
        }
        return x;
    }
}

Measured memory_bytes: 32524
from collections import deque
n, m, k =map(int, input().split())

directcount = [0] * n # node_iが直接接続しているノードの数
visited = [-1]  * n # nodeの色,
colorcount = [-1] * n # 各色が何個のノードを持つか
# グラフの初期化
g = []
for _ in range(n):
    g.append(deque(list()))

# グラフの生成
for i in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1 # 1origin -> 0 origin
    g[a].append(b)
    g[b].append(a)
    # 直接接続されているノードの数
    directcount[a] += 1
    directcount[b] += 1

# dfs 連結したグラフごとにそのグラフの最初に探索したnodeの色に染める
q = deque(list()) #探索キュー
for i in range(n):
    q.append(i)
    color = i
    cnt = 1
    while len(q) > 0:
        nextnode = q.popleft() # 次の探索
        if visited[nextnode] != -1:
            continue
        visited[nextnode] = color
        q.extend(g[nextnode]) # nextnodeの辺を足す
        cnt += 1
    # 探索が終わったらその色のノードの数を記録
    colorcount[color]  = cnt - 1

# res[i] = ノードの色, その色のノードの数　で初期化する
res = [[visited[i], colorcount[visited[i]] - (directcount[i] + 1)] for i in range(n)]

# ブロックリスト
for i in range(k):
    c, d = map(int, input().split())
    c, d = c - 1, d - 1 # 1 origin -> 0 origin
    # ブロック関係が同じ色だとするなら
    if res[c][0] == res[d][0]:
        # 友達になれると思っていた数を1つ減らす
        res[c][1] -= 1
        res[d][1] -= 1

# 各ノードから「直接つながっているノード」と「自分自身=1」を抜く
#for i in range(n):
#    res[i][1] -= (directcount[i] + 1)

# 結果の表示
print(" ".join(list(map(lambda x: str(x[1]), res))))

Measured memory_bytes: 125832
#include <iostream>
using namespace std;
using ll = long long;

ll Array[100]={};

ll ryuka(int x){
	if(x == 0)return 2;
	if(x == 1) return 1;
	if(Array[x] != 0)return Array[x];
	
	Array[x] = ryuka(x-1)+ ryuka(x-2);
	return Array[x];
}


int main(){
	int n;
	cin >> n;
	cout << ryuka(n) << endl;
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> P(N);
  for (int i=0;i<N;i++){
    cin >> P[i];
    P[i]--;
  }
  vector<int> a(N);
  for (int i=0;i<N;i++){
    a[P[i]]=i;
  }
  multiset<int> s;
  s.insert(-1);
  s.insert(-1);
  s.insert(N);
  s.insert(N);
  long long ans=0;
  for (int i=N-1;i>=0;i--){
    int j=a[i];
    s.insert(j);
    auto itr=s.find(j);
    vector<int> l(2),r(2);
    for (int i=0;i<2;i++){
      --itr;
      l[i]=*itr;
    }
    itr=s.find(j);
    for (int i=0;i<2;i++){
      ++itr;
      r[i]=*itr;
    }
    ans+=(i+1)*((long long)(l[0]-l[1])*(r[0]-j)+(long long)(j-l[0])*(r[1]-r[0]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 5760
x,y = map(int,input().split())

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod
 
    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

if (x+y)%3!=0:
    print(0)
else:
    a = (2*x - y) // 3
    b = (2*y - x) // 3

    mod = 10 ** 9 + 7
    mc = ModComb(1000000, mod=mod) 

    print(mc.nCk(a + b, a) % mod)

Measured memory_bytes: 122016
import sys
#input = sys.stdin.readline
sys.setrecursionlimit(10**7)
N, M = map(int, input().split())
S = input()

rS = [i for i in reversed(S)]
res = []
step = 0

lenS = len(S)
while 1:
    if step == lenS-1:
        break
    for i in range(M, -1, -1):
        if step+i > lenS-1:
            continue
        if i == 0:
            print(-1)
            exit()
        if rS[step+i] == '0':
            step += i
            res.append(i)
            break

print(*reversed(res))


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


#define ll long long
#define pb push_back
#define mp make_pair
#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, a, b) for(int i = (a); i > (b); --i)

typedef pair <int,int> ii;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <ll> vl;

const int mod = 1e9+7;
const int inf = 2e18+5;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    ll n,tot_weight;
    cin>>n>>tot_weight;
    vi w(n),v(n);

    ll sum_value=0;
    loop(i,0,n){
        cin>>w[i]>>v[i];
        sum_value+=v[i];
      }

    vl dp(sum_value+1 , inf);
    // dp[i] - the minimum total weight of items with total value exactly i
  	dp[0]=0;

    for(int i=0 ; i<n ; i++){
          for(ll cur_val=sum_value - v[i]; cur_val>=0; cur_val--){
            dp[cur_val+v[i]] = min(dp[cur_val+v[i]] , dp[cur_val]+w[i]);
          }
    }
    ll answer=0;
    loop(i,0,sum_value+1){
      if(dp[i]<=tot_weight)
         answer = max(answer , (ll) i);
    }
    cout<<answer;
    return 0;
}


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

int main() {
	int h, w; cin >> h >> w;
	vector<string> a(h);
	for (int i = 0; i < h; i++) cin >> a[i];

	vector<bool> row(h, false);
	vector<bool> col(w, false);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				row[i] = true;
				col[j] = true;
			}
		}
	}

	for (int i = 0; i < h; i++) {
		if (row[i] == true) {
			for (int j = 0; j < w; j++) {
				if (col[j] == true) {
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);    
int n;
cin>>n;
int a[n][n-1];
for(int i=0;i<n;i++){
    for(int j=0;j<n-1;j++){
        cin>>a[i][j];
    }
}
int m[n]={};

int oi;
int ans=0;
int t=0;
/*
for(int i=0;i<n;i++){
    for(int j=0;j<n-1;j++){
        cout<<a[i][j];
    }
    cout<<endl;
}
*/
while(true){
    bool f[n]={};
    for(int i=0;i<n;i++){
        //cout<<i<<"ready?"<<endl;
        if(m[i]==n-1){
            //continue;
            f[i]=1;
        }
        oi=a[i][m[i]]-1;
        //cout<<"today"<<m[i]<<endl;
        //cout<<i<<"'s flag"<<f[i]<<endl;
        if(f[i]==0&&f[oi]==0&&a[oi][m[oi]]==i+1){
            //cout<<i<<"VS"<<oi<<endl;
            f[i]=1;
            f[oi]=1;
            m[oi]++;
            m[i]++;                 
        t++;
        }

    }
    //cout<<"t="<<t<<endl;
    if(t>0){
        ans++;
    }else{
    //    cout<<"break!";
        break;
    }
    //cout<<"day"<<ans<<endl;
    //cout<<t<<"game"<<endl;
    //
    t=0;
}
for(int i=0;i<n;i++){
    if(m[i]!=n-1){
    cout<<-1;
    return 0;
    }
}

cout<<ans;
}

Measured memory_bytes: 4224
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


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

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

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k,m,d,x; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

int main() {
	cin >> n;
	cout << 180 * (n - 2) << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3

def solve(h,w,a):
  h_flags = [True]*h
  w_flags = [False]*w
  for i in range(h):
    if not "#" in a[i]:
      h_flags[i] = False
    for j in range(w):
      if a[i][j] == "#":
        w_flags[j] = True
  for i in range(h):
    if not h_flags[i]:
      continue
    for j in range(w):
      if w_flags[j]:
        print(a[i][j],end="")
    print("")
  return 



def main():
  H,W = map(int,input().split())
  a = [input() for _ in range(H)]
  solve(H,W,a)
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9336
using System;
using System.Linq;

class Program
{
    public static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        if (s.Max() == s[0]) Console.WriteLine("A");
        else if (s.Max() == s[1]) Console.WriteLine("B");
        else Console.WriteLine("C");
    }
}


Measured memory_bytes: 20476
#include <bits/stdc++.h>
#ifdef DEBUG
  #include "debug.hpp"
#else
  #define DUMP(var)
#endif

using namespace std;
template< class T1, class T2 > inline istream &
operator>>( istream & fin, pair< T1, T2 > & pr )
{ fin >> pr.first >> pr.second; return fin; }
template< class T0, class T1, class T2 > inline istream &
operator>>( istream & fin, tuple< T0, T1, T2 > & t )
{ fin >> get<0>(t) >> get<1>(t) >> get<2>(t); return fin; }
template< class T > inline istream &
operator>>( istream & fin, vector< T > & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class T, size_t n> inline istream &
operator>>( istream & fin, array<T, n> & a ) {
for(auto & u: a) fin >> u; return fin; }
template<class FwdIter> inline auto
dump(FwdIter first, FwdIter last, const char * dlm = " ") -> void {
using value_type = typename iterator_traits<FwdIter>::value_type;
copy(first, last, ostream_iterator<value_type>(cout, dlm)); }
template<typename T> vector<T> & operator--(vector<T> & a)
{ for(auto & i: a) --i; return a; }
/* @@@ ----------------------------------- */

int main(const int /*argc*/, char ** /*argv*/) {
  ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

  size_t m, d;
  cin >> m >> d;
  size_t out = 0;
  for (size_t i = 2; i < 10; ++i) {
    for (size_t j = 2; j < 10; ++j) {
      const auto x = i * 10 + j;
      if (x <= d && i * j <= m) {
        ++out;
      }
    }
  }
  cout << out;

  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define szxb 200010
#define F(a,b,c,d,e) for(register int (a)(b);((e)?((a)<=(c)):((a)>=(c)));(a)+=(d))
using namespace std;
int n,a[szxb];
inline void print(int x){putchar(32),printf("%d",x);return;}
signed main()
{
	scanf("%d",&n);
	F(i,1,n,1,1){scanf("%d",&a[i]);}printf("%d",a[n]);
	F(i,(n-2),1,-2,0){print(a[i]);}F(i,(1+(n&1)),n,2,1){print(a[i]);}
	return putchar(10),0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10,mod=998244353;
typedef long long ll;
int n,m,k,t;
int cnt[maxn];
ll qpow(ll x,ll y)
{
    ll ret=1;
    while(y)
    {
        if(y&1)
        {
            ret=ret*x%mod;
        }
        x=x*x%mod;
        y>>=1;
    }
    return ret;
}
int main(){
    int i,j;
    //freopen("in.txt","r",stdin);
    scanf("%d",&n);
    int f=1;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&j);
        if(i==1 && j!=0)
        {
            f=0;
        }
        else if(i!=1 && j==0)
        {
            f=0;
        }
        cnt[j]++;
    }
    if(!f)
    {
        puts("0");
        return 0;
    }
    ll ret=1;
    for(i=1;i<=n;i++)
        ret=ret*qpow(cnt[i-1],cnt[i])%mod;
    printf("%lld\n",ret);
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;


namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();
            var N = cin.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++)
            {
                a[i] = cin.nextInt();
            }

            int[] bucket = new int[32];
            for (int i = 0; i < N; i++)
            {
                var item = a[i];
                BitArray b = new BitArray(new int[] { item });
                for (int j = 0; j <32 ; j++)
                {
                    bucket[j] += b[j]? 1 : 0;
                }
            }

            for (int i = 0; i < 32; i++)
            {
                if(bucket[i] % 2 != 0)
                {
                    Console.WriteLine("No");
                    return;
                }
            }

            Console.WriteLine("Yes");
        }
    }

    

    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: 29916
/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - Knapsack for All Segments
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 3000;
const int MAX_S = 3000;
const int MOD = 998244353;

/* typedef */

/* global variables */

int as[MAX_N];
int dp0[MAX_N + 1][MAX_S + 1], dp1[MAX_N + 1][MAX_S + 1];

/* subroutines */

inline void addmod(int &a, int b) { a = (a + b) % MOD; }

/* main */

int main() {
  int n, s;
  scanf("%d%d", &n, &s);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  dp0[0][0] = 1;
  for (int i = 0; i < n; i++) {
    int ai = as[i];
    for (int j = 0; j <= s; j++) {
      if (dp0[i][j]) {
	addmod(dp0[i + 1][j], dp0[i][j] + 1);
	if (j + ai <= s)
	  addmod(dp1[i + 1][j + ai], dp0[i][j]);
      }
      if (dp1[i][j]) {
	addmod(dp1[i + 1][j], dp1[i][j]);
	if (j + ai <= s)
	  addmod(dp1[i + 1][j + ai], dp1[i][j]);
      }
    }
  }

  int sum = 0;
  for (int i = 0; i <= n; i++) addmod(sum, dp1[i][s]);

  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 70144
#include<stdio.h>
int main(){
  int i,j;
  char s[1010];
  char c[]={"1234567890TLURD"};
  char w[]={" kstnhmyrwaiueo"};
  scanf("%s",s);
  for(i=0;s[i];i++){
    if(s[i]=='1')continue;
    if(s[i]=='0'&&s[i+1]=='U'){
      printf("nn");
      i++;
      continue;
    }
    for(j=0;s[i]-c[j];j++);
    printf("%c",w[j]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

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

const ll INF = 1e17;
const ll MOD = 1e9+7;

int main() {
    // input, ready
    int K;
    cin >> K;
    vector<ll> vec;
    vector<ll> vec_before;
    for (int i=1; i<10; i++) vec.push_back(i);
    for (int i=1; i<10; i++) vec_before.push_back(i);
    vector<ll> vec_tmp;

    // resolve
    while(vec.size() < K) {
      vec_tmp.clear();
      for (auto v: vec_before) {
        ll a = v % 10;
        ll newv = v * 10 + a;
        if (a != 0) {
          vec_tmp.push_back(newv-1);
          vec.push_back(newv-1);
        }
        vec_tmp.push_back(newv);
        vec.push_back(newv);
        if (a != 9) {
           vec_tmp.push_back(newv+1);
           vec.push_back(newv+1);
        }
      }
      vec_before.clear();
      copy(vec_tmp.begin(), vec_tmp.end(), back_inserter(vec_before));
    }

    // output
    sort(vec.begin(), vec.end());
    cout << vec[K-1] << endl;

    return 0;
}


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

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ll arr[n+1];
    ll sum=0;
    bool state=0;
    for(int i=0;i<=n;i++){
        cin>>arr[i];sum+=arr[i];
    }
    if(n==0){if(arr[0]==1){cout<<"1\n";return 0;}if(arr[0]==2){cout<<"-1\n";return 0;}}
    ll cnt=1,node=1;
    for(int i=1;i<=n;i++){
        node=min(node*2,sum);
        cnt+=node;
        node-=arr[i];
        sum-=arr[i];
        if(node<0)state=1;
    }
    if(state||arr[0]>0){cout<<"-1\n";return 0;}
    cout<<cnt<<"\n";
}


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

const std::string END_OF_TEXT = "END_OF_TEXT";

int main(void)
{
	std::string w, t_w;
	std::cin >> w;
	int matchWords = 0;
	while (std::cin >> t_w)
	{
		if (t_w == END_OF_TEXT)
		{
			break;
		}
		if (t_w[0] != '"' || t_w[0] != '\'')
		{
			if (w.size() != t_w.size())
			{
				continue;
			}
		}
		for (int i = 0; i + w.size() <= t_w.size(); i++)
		{
			int matchChars = 0;
			while (matchChars < w.size() 
				&& tolower(w[matchChars]) == tolower(t_w[i]))
			{
				matchChars++;
				i++;
			}
			if (matchChars != w.size())
			{
				matchChars = 0;
			}
			else
			{
				matchWords++;
			}
		}
	}
	std::cout << matchWords << '\n';
	return 0;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, int b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, k;
    int l[50];
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    sort(l, l + n, greater<int>());

    int sum = 0;
    for (int i = 0; i < k; i++)
        sum += l[i];
    cout << sum << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<math.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
vector<int> make_map(int size){
	vector<int> pr(size,1);
	pr[0]=0;//1 is not prime
	for(int i=1;i+1<=sqrt(size);i++){
		if(pr[i]==1){//i+1 is prime
			for(int j=2*(i+1);j<size;j+=(i+1)){//2*(i+1),3*(i+1),... is not prime
				pr[j-1]=0;
			}
		}
	}
	return pr;
}





int main(){
	int q;
	cin>>q;
	vector<int>l(q),r(q),sum(100000,0);
	rep(i,q){
		cin>>l[i]>>r[i];
	}
	vector<int> pr;
	pr = make_map(100000);
	for(int i=1;i<100000;i++){//No.i+1 is checked
		if((i+1)%2==1){// if the no is odd
			if(pr[i]==1&&pr[(i+2)/2-1]){
				sum[i]=sum[i-1]+1;
			}else{
				sum[i]=sum[i-1];
			}
		}else{
			sum[i]=sum[i-1];
		}
	}
	rep(i,q){
		cout<<sum[r[i]-1]-sum[l[i]-2]<<endl;
	}
	return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    long long k;//
    cin >> n >> k;
    long long arr[100001] = {};
    for (int i = 0 ; i < n ; i++){
        int num , qty;
        cin >> num >> qty;
        arr[num] += qty;
    }
    long long count = 0;
    for (int i = 1 ; i < 100001 ; i++ ){
       count += arr[i];
       if( count >= k ){
         cout << i;
         return 0;
       }
    }
}



Measured memory_bytes: 1024
//          ★★ ASHWINI SHARMA ★★ 
#include <bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (int i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
#define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
#define ull unsigned long long int
#define ll long long int
#define ui unsigned int
#define pb push_back
 
#define PI 3.1415926535897932385
#define INF 1e18
#define EPS 1e-7
#define MAXN 1000000005
#define MOD 1000000007
                              //          ★★ ASHWINI SHARMA ★★      
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll exp(ll x, ll y, ll p)
{
    ll res = 1;   
    x = x % p;  
    while (y > 0)
    {
        if (y & 1)    
            res = (res*x) % p;
        y = y>>1;     
        x = (x*x) % p; 
    }
    return res;
}



int main() {
    
    fastio;
    string s;
    cin >> s;
    int cnt = 0;
    rep(i, 3)
    {
        if(s[i] == 'R')
            cnt++;


    }
    if(cnt == 2)
    {
        bool an = false;
        rep(i, 2)
        {
            if(s[i] == s[i+1])
                an = true;
        }
        if(an)
            cout << 2;
        else
            cout << 1;
    }
    else
        cout << cnt;

    return 0; 

}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int x[1010];

int main(void){
	int n,m,p;
	while(cin >> n >> m >> p){
		if(n==0)
			break;
		rep(i,n) cin >> x[i];
		int sum=0;
		rep(i,n) sum+=x[i];
		sum*=(100-p);
		if(x[m-1]==0)
			cout << 0 << endl;
		else
			cout << sum/x[m-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {

    static final int MOD=1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char[] str = s.toCharArray();
        char[] moji = "abcdefghijklmnopqrstuvwxyz".toCharArray();


        if(s.equals("zyxwvutsrqponmlkjihgfedcba")){
            System.out.println(-1);
            return;
        }
        HashSet<Character> alphabet = new HashSet<>();

        for(int i=0;i<str.length;i++){
            alphabet.add(str[i]);
        }

        if(str.length>=26){
            int i;
            HashSet<Character> used = new HashSet<>();

            for(i=1;i<str.length;i++){//どこまで逆順になっているか
                used.add(str[str.length-i]);
                if(str[str.length-i-1]-str[str.length-i]<0) break;
            }

            for(int j=0;j<str.length-i-1;j++) System.out.print(str[j]);

            char min = 'z';
            for(Character c :used){
                if(c>str[str.length-i-1]&&min>c)min=c;
            }
            System.out.println(min);
            return;

        }else{
            for(int i=0;i<26;i++){
                if(!alphabet.contains(moji[i])){
                    s+=moji[i];
                    break;
                }
            }
            System.out.println(s);
        }

    }
}


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

// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0208

int d[] = { 0, 1, 2, 3, 5, 7, 8, 9 };

int div(int n) {
	if (n >= 8) div(n / 8);
	cout << d[n % 8];
}

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) break;
		div(n);
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
const int N=1e6+10;
const int M=1e6;
const int mod7=1e9+7;
const int mod=998244353;
void read(int &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
void read(ll &a)
{
    a=0;int d=1;char ch;
    while(ch=getchar(),ch>'9'||ch<'0') if(ch=='-') d=-1;
    a=ch^48;
    while(ch=getchar(),ch>='0'&&ch<='9') a=(a<<3)+(a<<1)+(ch^48);
    a*=d;
}
ll fac[N],ifac[N];
ll quickmod(ll x,ll y)
{
    ll res=1,base=x;
    while(y)
    {
        if(y&1) res=res*base%mod;
        base=base*base%mod;
        y>>=1;
    }
    return res;
}
void init()
{
    fac[0]=1;
    for(re int i=1;i<=M;i++) fac[i]=fac[i-1]*i%mod;
    ifac[M]=quickmod(fac[M],mod-2);
    for(re int i=M-1;~i;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}
ll C(int n,int m) {return n<m?0:fac[n]*ifac[n-m]%mod*ifac[m]%mod;}
ll f(int n,int m)
{
    if(n<=0||m<0) return 0;
    return C(n+m-1,m);
}
int main()
{
    init();
    int n,m,k;
    read(n),read(m),read(k);
    ll ans=0;
    for(re int i=k;~i;i--) ans=(ans+1ll*m*quickmod(m-1,n-i-1)%mod*f(n-i,i)%mod)%mod;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 19352
/*
AizuOnline A0078
Title:Magic Square
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int A[15][15];
int N;
//
show()
{
  int i,j;

  for(i=0;i<N;i++)
    {
      for(j=0;j<N;j++)
	printf("%4d",A[i][j]);
      printf("\n");
    }
}
main()
{
  int i,j,y,x;

  while(EOF != scanf("%d",&N) && N)
    {
      for(i=0;i<N;i++)
	for(j=0;j<N;j++)
	  A[i][j]=0;
      i=1;x=N/2;y=x+1;
      while(i<=N*N)
	{
	  //printf("%d %d %d\n",y,x,i);
	  A[y][x]=i;
	  x=(x+1)%N ;y=(y+1)%N;
	  if(A[y][x])
	    {
	      x=(x-1)%N;
	      if(x<0)x+=N;
	      y=(y+1)%N;
	    }
	  i++;
	}
	show();
    }


return(0);
}

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

int main()
{
  i64 n;
  cin >> n;
  vector<i64> a(n), x[n], y[n];
  for (i64 i = 0; i < n; i++)
  {
    cin >> a[i];
    x[i].resize(a[i]);
    y[i].resize(a[i]);
    for (i64 j = 0; j < a[i]; j++)
      cin >> x[i][j] >> y[i][j];
  }
  i64 ans = 0;
  for (i64 i = 0; i < (1 << n); i++)
  {
    bool ok = true;
    for (i64 j = 0; j < n; j++)
      if (i & (1 << j))
        for (i64 k = 0; k < a[j]; k++)
          if (y[j][k] ^ ((i >> (x[j][k] - 1)) & 1))
            ok = false;
    if (ok)
    {
      i64 cnt = 0;
      for (i64 j = 0; j < n; j++)
        if (i & (1 << j))
          cnt++;
      ans = max(ans, cnt);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> X(m), Y(m);
    rep(i, m){
        cin >> X[i] >> Y[i];
        X[i]--; Y[i]--;
    }

    vector<bool> isRed(n, false);
    vector<int> number(n, 1);
    isRed[0] = true;

    rep(i, m){
        int x = X[i], y = Y[i];
        if(isRed[x]) isRed[y] = true;
        number[x]--; number[y]++;
        if(number[x] == 0) isRed[x] = false;
    }

    int ans = 0;
    rep(i, n) ans += isRed[i];
    cout << ans << ln;
}


Measured memory_bytes: 1408
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>

using namespace std;

typedef long long ll;

const ll N = 2e5 + 10;
const ll p = 1e9 + 7;

ll n;
ll a[N];
ll res = 0;
ll q[N];

int main() {
	cin >> n;
	
	for (ll i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] %= p;
		q[i] = (q[i - 1] + a[i]) % p;
	}
	
	for (ll i = 1; i <= n; i++) {
		res = (res % p) + ((a[i] * ((q[n] - q[i] + p)) % p) % p);
//		cout << i << ":" << (q[n] - q[i]) << endl;
	}
	
	cout << res << endl;
	
	return 0;
}

Measured memory_bytes: 6688
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int L[] = new int[N];
		int max = 0;
		int n = 0;
		for(int i = 0; i < N; i++) {
			L[i] = sc.nextInt();
			if(max < L[i]) {
				max = L[i];
				n = i;
			}
		}
		
		int sum = 0;
		for(int i = 0; i < N; i++) {
			if(i == n) continue;
			sum += L[i];
		}
		
		if(max < sum) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23380
#include<stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	printf("Christmas");
		if (n == 24) {
			printf(" Eve");
		}
	if (n == 23) {
		printf(" Eve Eve");
	}
	if (n == 22) {
		printf(" Eve Eve Eve");
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;

	auto result = "No";
	for (auto i = 0; i < S.length(); ++i)
	{
		auto flag = true;
		for (auto j = 0; j < S.length(); ++j)
		{
			auto k = (i + j) % S.length();
			if (S[k] != T[j])
			{
				flag = false;
				break;
			}
		}

		if (flag)
		{
			result = "Yes";
			break;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Node{
  int32_t id;
  Node* parent;
  size_t depth;
  vector<Node*> child;
  void set_depth(size_t n){
    depth=n;
    for(auto&& c:child) c->set_depth(n+1);
  }
  const char* type() const {
    if(parent==nullptr) return "root";
    else if(child.empty()) return "leaf";
    return "internal node";
  }
};
ostream& operator<<(ostream& os, const Node& x){
  os<<"node "<<x.id
    <<": parent = "<<(x.parent==nullptr?-1:x.parent->id)
    <<", depth = "<<x.depth
    <<", "<<x.type()
    <<", [";
  const char* dlm="";
  for(const auto& c:x.child) os<<exchange(dlm,", ")<<c->id;
  os<<"]";
  return os;
}
int32_t main(){
  size_t n; cin>>n;
  vector<Node> tree(n);
  for(size_t i=0; i<n; ++i){
    size_t id,k; cin>>id>>k;
    tree[id].id=id;
    tree[id].child.resize(k);
    for(auto&& c:tree[id].child){
      size_t tmpc; cin>>tmpc;
      c=addressof(tree[tmpc]);
    }
  }
  for(auto&& t:tree) t.parent=nullptr;
  for(auto&& t:tree){
    for(const auto& c:t.child) tree[c->id].parent=addressof(t);
  }
  find_if(begin(tree),end(tree),[](const Node& x){ return x.parent==nullptr; })->set_depth(0);
  for(const auto& t:tree) cout<<t<<'\n';
}


Measured memory_bytes: 8276
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
#include <cassert>
#include <cmath>
#include <sstream>
#include <time.h>
#include <complex>
#include <iomanip>

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l4;
const double eps = 1e-6;
const int maxn = 1e5+10;
const ll mod = 1e9+7;
int n,l,t,w;
int a[maxn];
int W[maxn];
int b[maxn];
int main() {
    scanf("%d%d%d",&n,&l,&t);
    for (int i = 0; i < n; i++) {
        scanf("%d%d",&a[i],&w);
        if (w == 2) {
            w = -1;
        }
        W[i] = w;
        b[i] = ((a[i]+w*t)%l+l)%l;
    }
    int target = b[0];
    sort(b,b+n);
    ll cur = 0;
    for (int i = 1; i < n; i++) {
        if (W[i] != W[0]) {
            if (W[0] == 1) {
                if (2*t >= a[i]-a[0]) {
                    cur++;
                    cur += (2*t-a[i]+a[0])/l;
                    
                    cur %= n;
                }
            } else {
                if (2*t >= a[0]-a[i]+l) {
                    cur--;
                    cur -= (2*t-l+a[i]-a[0])/l;
                    cur %= n;
                }
            }
        }
    }
    cur = (cur%n+n)%n;
    for (int i = 0; i < n; i++) {
        if (b[i] == target) {
            cur = i-cur;
            if (i < n && W[0] == 1 && b[i] == b[i+1]) {
                cur++;
            }
            break;
        }
    }
    cur = (cur+n)%n;
    for (int i = cur; i < n; i++) {
        printf("%d\n",b[i]);
    }
    for (int i = 0; i < cur; i++) {
        printf("%d\n",b[i]);
    }
}





Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    int p[100];
    int n; cin>>n;
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    rep(i,n){
        rep(j,n){
            swap(p[i],p[j]);
            bool flag = true;
            rep(k,n){
                if(p[k]!=k)flag = false;
            }
            if(flag){
                cout<<"YES"<<endl;
                return 0;
            }
            swap(p[i],p[j]);
        }
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long int ll;
typedef pair<int, int> P;
 
int n, q;
string s;
vector<set<int>> moji(30, set<int>());
 
int main()
{
    cin >> n >> s >> q;
    rep(i, n)
    {
        moji[s[i] - 'a'].insert(i);
    }
 
    rep(i, q)
    {
        int f;
        cin >> f;
        if(f == 1)
        {
            int num;
            char c;
            cin >> num >> c;
            num--;
            moji[s.at(num) - 'a'].erase(num);
            moji[c - 'a'].insert(num);
            s.at(num) = c;
        }
        else
        {
            int l, r;
            cin >> l >> r;
            l--; r--;
            int res = 0;
            rep(j, 26)
            {
                if(moji[j].lower_bound(l) != moji[j].upper_bound(r))
                {
                    res++;
                }
            }
            cout << res << endl;
        }
    }
 
    return 0;
}

Measured memory_bytes: 24196
#include<stdio.h>
int height[10002];
int main(void){
    int h;
    for(int i = 0;i < 10;i++){
        scanf("%d",&h);
        height[h]++;
    }
    int cnt = 0;
    for(int i = 10000;i >= 0;i--){
        if(height[i] > 0){
            printf("%d\n",i);
            height[i]--;
            i++;
            if(++cnt >= 3) break;
        }
    }
    return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    string s;
    ll a, b, n;
    cin >> n >> a >> b >> s;
    ll nai, gai;
    nai = gai = 0;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == 'a')
        {
            if (nai + gai < a + b)
            {
                cout << "Yes" << endl;
                nai++;
            }
            else
                cout << "No" << endl;
        }
        else if (s[i] == 'b')
        {
            if (nai + gai < a + b && gai < b)
            {
                cout << "Yes" << endl;
                gai++;
            }
            else
                cout << "No" << endl;
        }
        else
            cout << "No" << endl;
    }
}


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

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

  int step = 1;
  sort(a, a+n);
  for(int i=0; i<n; i++) {
    if (i+1 == n) break;
    if (a[i] < a[i+1]) ++step;
  };

  cout << step << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

int n;
map<int, int> a;
int q;
//vector<int> b, c;

int main()
{
  ll sum;
  int b, c;

  cin >> n;

  sum = 0;
  for (int i=0; i<n; i++) {
    int ain;
    cin >> ain;
    auto it = a.find(ain);
    if (it != a.end()) {
      a[ain] = a[ain]+1;
    } else {
      a[ain] = 1;
    }
    sum += ain;
  }
  cin >> q;
  for (int i=0; i<q; i++) {
    int bnum, cnum;
    cin >> b >> c;
    auto it = a.find(b);
    if (it != a.end()) {
      bnum = a[b];
    } else {
      bnum = 0;
    }
    a[b] = 0;
    it = a.find(c);
    if (it != a.end()) {
      cnum = a[c];
    } else {
      cnum = 0;
    }
    a[c] = bnum+cnum;
    sum += (c-b)*bnum;
    printf("%lld\n", sum);
  }


  return 0;
}


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

int main(){
	long int n,m,l,A[100][100],B[100][100],C[100][100]={};
	cin>>n>>m>>l;
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>A[i][j];
		}
	}
	
	for(int i=0;i<m;i++){
		for(int j=0;j<l;j++){
			cin>>B[i][j];
		}
	}
		
		for(int i=0;i<n;i++){
			for(int j=0;j<m; j++){
				for(int k=0;k<l;k++){
					C[i][k]+=A[i][j]*B[j][k];
					}
				}
			}
			
			for(int i=0;i<n;i++){
				for(int j=0;j<l;j++){
					if(j!=l-1)cout<<C[i][j]<<" ";
					else cout<<C[i][j]<<endl;
				}
			}
			
	return 0;
}


Measured memory_bytes: 3300
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n, k;
    cin >> n >> k;
    k++;
    vector<ll> p(n);
    for (ll i = 0; i < n; i++) {
        ll y;
        cin >> y;
        p.at(i) = y - 1;
    }
    vector<ll> r(n);
    ll s = 0;
    ll d = 0;
    ll q = 0;
    for (ll i = 1; i < 10000000; i++) {
        if (r.at(s) != 0) {
            d = i - r.at(s);
            q = r.at(s);
            break;
        }
        else {
            r.at(s) = i;
            s = p.at(s);
        }
    }
    if (k < q)q = k;
    else {
        ll tt = k % d;

        for (ll i = 0; i < 10000000; i++) {
            if ((q + i) % d == tt) {
                q += i;
                break;
            }
        }
    }
    for (ll i = 0; i < n; i++) {
        if (r.at(i) == q) {
            cout << i + 1 << endl;
            break;
        }
    }
}

Measured memory_bytes: 6424
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++) arr[i] = sc.nextInt();

        int res = Integer.MAX_VALUE;
        int tmp = Integer.MAX_VALUE;
        for(int i = 0; i + (k - 1)< N; i++) {
            int l = arr[i];
            int r = arr[i+k-1];
            tmp = Math.min(Math.abs(l) + Math.abs(l-r), Math.abs(r) + Math.abs(l-r));
            res = Math.min(tmp, res);
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 59780
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<ll>u;
int main()
{

    ll n,m,i,j,k,p,q,o,l,s,t,a;
    cin>>n>>m;
    if(n>m){swap(n,m);}
    for(i=1; ;i++)
    {
        if(m*i%n==0){cout<<m*i<<endl;break;}

    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc, out);

		out.flush();
	}
	
	public static void solve(FastScanner sc, PrintWriter out) {
		String s = sc.next();
		out.println(s.contains("9")?"Yes":"No");
	}
	
	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

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

        return tokenizer.nextToken("\n");
    }

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 22484
import bisect
n = int(input())
l = list(map(int, input().split()))
sort_l = sorted(l)
count = 0

for a in range(n):
    for b in range(a+1, n):
        c = bisect.bisect_left(sort_l, sort_l[a] + sort_l[b])
        if c > b:
            count += c - b -1
        else:
            pass     
        

print(count)

Measured memory_bytes: 3188