akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define LL long long
#define FOR(i,a,b) for(int i=a;i<=b;++i)
using namespace std;

const int mn=2e5+7,mod=2019;
char s[mn];
int pre[mn],cnt[mn];
LL ans;

int poww(int a,int b)
{
	int ans=1;
	while(b) {
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}

int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	cnt[0]=1;
	for(int i=len;i>=1;--i) pre[i]=(pre[i+1]+(s[i]-'0')*poww(10,len-i))%mod,cnt[pre[i]]++;
	FOR(i,0,2019) ans+=1ll*cnt[i]*(cnt[i]-1)/2;
	printf("%lld",ans);
}

Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int a[N]; 
    rep(i, N)cin >> a[i];
    int ans = 0;
    rep(i, N) {
        if(a[a[i]-1] == i+1) ans++;
    }
    cout << ans/2 << endl;


    return 0;
}


Measured memory_bytes: 640
n, m = gets.split.map(&:to_i)
a = []
b = []

n.times { a << gets.chomp }
m.times { b << gets.chomp }

all_read = false

0.upto(n - m) do |row_a|
  0.upto(n - m) do |i|
    0.upto(m - 1) do |j|
      all_read = false
      break unless b[j] == a[row_a][i, m]
      all_read = true
      row_a += 1
    end
    next unless all_read
    puts 'Yes'
    exit
  end
end

puts 'No'


Measured memory_bytes: 1788
from itertools import product
n = int(input())
s = input()
r = []
g = []
b = []
for i in range(len(s)):
    if s[i] == 'R':
        r.append(i)
    elif s[i] == 'G':
        g.append(i)
    elif s[i] == 'B':
        b.append(i)

ng_cnt = 0
for i in range(n):
    for j in range(i+1, n):
        if s[i] == s[j]:
            continue
        else:
            k = 2 * j - i
            if k < n and s[i] != s[k] and s[j] != s[k]:
                ng_cnt += 1

print(len(r) * len(g) * len(b) - ng_cnt)


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

using namespace std;

int arr[200005];
int bit[200005];

int main(){
	ios_base::sync_with_stdio(false);
	int n; cin >> n;
	
	for(int i = 1;i < 2*n;i++) cin >> arr[i];
	
	int low = -1; int high = 2*n+1;
	while(true){
		if(low == high - 1) break;
		int s = (low + high)/2;
		
		for(int i = 1;i < 2*n;i++){
			bit[i] = (arr[i] > s);
			//cout << bit[i] << " ";
		}
		//out << "\n";
		
		int res = -1;
		for(int d = 1;d < n;d++){
			if(bit[n+d-1] == bit[n+d]){
				res = bit[n+d];
				break;
			}
			if(bit[n-d+1] == bit[n-d]){
				res = bit[n-d];
				break;
			}
		}
		
		if(res == -1){
			res = ((bit[n] ^ (n&1)) ^ 1);
		}
		//cout << s << " " << res << "\n";
		if(res == 1) low = s;
		else high = s;
	}
	
	cout << high;
}

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

int main()
{
  int N,i,flag;
  cin >> N;
  flag=0;
  for(i=1;i<10;i++)
  {
    if(N%i==0&&N<=i*9)
    {
       flag=1;
       break;
    }
  }
  if(flag==0)
  {
     cout << "No" << endl;
  }
    else
    {
      cout << "Yes" << endl;
    }
    
}
  

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/c.in", "r", stdin);
//  freopen("../IO/c.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int H, W, K;
  in >> H >> W >> K;
  vector<string> b(H);
  for (string &s : b) in >> s;
  int ans = 0;
  for (int m1 = 0; m1 < (1 << H); ++m1) {
    for (int m2 = 0; m2 < (1 << W); ++m2) {
      int cnt = 0;
      for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
          if ((m1 >> i & 1) && (m2 >> j & 1)) {
            cnt += b[i][j] == '#';
          }
        }
      }
      ans += cnt == K;
    }
  }
  out << ans << '\n';
}

Measured memory_bytes: 3632
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int d[200][200];
int main(){

	for(int i = 0;i < 200;i++){
		for(int j = 0;j < 200;j++){
			if(i != j)d[i][j] = INF;
			else d[i][j] = 0;
		}
	}
	int n,m,r;
	cin >> n >> m >> r;
	vector<int> city(r);
	for(int i = 0;i < r;i++){
		cin >> city[i];
		city[i]--;
	}

	for(int i = 0;i < m;i++){
		int a,b,c;
		cin >> a >> b >> c;
		a--,b--;
		d[a][b] = c;
		d[b][a] = c;
	}

	for(int k = 0;k < n;k++){//kまでを使う
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}


	ll ans = 1e18;
	sort(city.begin(),city.end());
	do{
		ll now = 0;
		for(int i = 0;i < r-1;i++){
			now += d[city[i]][city[i+1]];
		}
		ans = min(now,ans);
	}while(next_permutation(city.begin(),city.end()));
	
	cout << ans << endl;
}


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

const int MAXN = 100005;
const int INF = 2000000000;
int dp[MAXN][3];
int h[MAXN][3];

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < 3; j++)
            cin >> h[i][j];
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < 3; j++)
            dp[i][j] = max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]) + h[i][j];
    cout << max(dp[n][0], max(dp[n][1], dp[n][2]));
    return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<int> a(n, 0);
    vector<int> b(n, 0);
    for (int i = 0; i < n; ++i) {
        int t;
        cin >> t;
        a[i] = t;
        b[i] = t;
    }
    sort(b.begin(), b.end());
    int x = n / 2 - 1;
    for (int i = 0; i < n; ++i) {
        if (a[i] <= b[x]) {
            cout << b[x+1] << "\n";
        } else {
            cout << b[x] << "\n";
        }
    }
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >

using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=2e3+10, mod=1e9+7;
ll dp[N][N],n;
pair<ll,ll> a[N];

ll solve(int i,int l,int r){
    if(i==n)return 0;
    ll &ret = dp[l][r];
    if(ret+1)return ret;
    ret = 0 ;
    ret = max(ret,solve(i+1,l+1,r)+a[i].F*abs(l-a[i].S));
    ret = max(ret,solve(i+1,l,r-1)+a[i].F*abs(r-a[i].S));
    return ret;
}

int main ()
{
    FASTIO
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i].F;
        a[i].S = i;
    }
    sort(a,a+n,greater<pair<ll,ll>>());
    memset(dp,-1,sizeof dp);
    cout << solve(0,0,n-1) << endl;
    return 0;
}
/**
5 5 6 1 1 1
1 1 1 5 5 6

6*3 + 5*3 + 5*3 + 1 + 1*3 + 1*5

*/


Measured memory_bytes: 35408
H,W = (int(i) for i in input().split())
S = [0] * H
for i in range(H):
    S[i] = input()

L = [[1]*W for i in range(H)]
R = [[1]*W for i in range(H)]
U = [[1]*W for i in range(H)]
D = [[1]*W for i in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            L[i][j] = 0
            U[i][j] = 0
        elif i == 0 and j == 0:
            continue
        elif i == 0:
            L[i][j] = L[i][j-1] + 1
        elif j == 0:
            U[i][j] = U[i-1][j] + 1
        else:
            L[i][j] = L[i][j-1] + 1
            U[i][j] = U[i-1][j] + 1


for i in range(H-1,-1,-1):
    for j in range(W-1,-1,-1):
        if S[i][j] == "#":
            R[i][j] = 0
            D[i][j] = 0
        elif i == H-1 and j == W-1:
            R[i][j] = 1
        elif i == H-1:
            R[i][j] = R[i][j+1] + 1
        elif j == W-1:
            D[i][j] = D[i+1][j] + 1
        else:
            R[i][j] = R[i][j+1] + 1
            D[i][j] = D[i+1][j] + 1
        tmp = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3
        if tmp > ans:
            ans = tmp

print(ans)


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

int main() {
	long x;
	cin >> x;
	if (0 == x % 11) cout << x / 11 * 2;
	else if (6 < x % 11) cout << 2 + x / 11 * 2;
	else cout << 1 + x / 11 * 2;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

/**
 * Property Distribution
 */
public class Main {

	static char DISTRIBUTED = '\0';
	static Queue<Integer> xs, ys;
	static int count;

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		StringBuilder sb = new StringBuilder();
		while (!(line = br.readLine()).equals("0 0")) {

			int h = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int w = Integer.parseInt(line.substring(line.indexOf(' ') + 1));

			// read in.
			char[][] prop = new char[h + 2][w + 2];
			for (int i = 1; i < h + 1; ++i) {
				line = br.readLine();
				for (int j = 1; j < w + 1; ++j) {
					prop[i][j] = line.charAt(j - 1);
				}
			}

			// solve
			xs = new ArrayDeque<Integer>();
			ys = new ArrayDeque<Integer>();
			count = 0;
			for (int i = 1; i < h + 1; ++i) {
				for (int j = 1; j < w + 1; ++j) {
					if (prop[i][j] != DISTRIBUTED) {
						char fruit = prop[i][j];
						xs.add(i);
						ys.add(j);
						while (!xs.isEmpty() && !ys.isEmpty()) {
							distribute(prop, fruit);
						}
						++count;
					}
				}
			}
			sb.append(count + "\n");
		}
		// print
		System.out.print(sb.toString());
	}

	static void distribute(char[][] prop, char fruit) {

		final int V[] = { 1, -1, 0, 0 };
		final int H[] = { 0, 0, 1, -1 };

		int x, y;
		x = xs.poll();
		y = ys.poll();

		if (prop[x][y] == fruit) {

			// prop[x][y] = DISTRIBUTED;
			prop[x][y] ^= prop[x][y];

			for (int i = 0; i < 4; ++i) {
				int xv, yh;
				xv = x + V[i];
				yh = y + H[i];
				if (prop[xv][yh] == fruit) {
					xs.offer(xv);
					ys.offer(yh);
				}
			}
		}
	}
}

Measured memory_bytes: 26340
// Atcoder beginner round 174 B - Distance

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;

ll X[2000005], Y[2000005];

int main() {
    ll N, D, ans = 0;
    cin >> N >> D;
    for (int x = 0; x < N; x++)
        cin >> X[x] >> Y[x];
    for (int x = 0; x < N; x++) 
        if(X[x]*X[x] + Y[x]*Y[x] <= D*D) 
            ans++; 
    cout << ans;
    return 0;
}

Measured memory_bytes: 6320
#include<bits/stdc++.h>
using namespace std;
#define set_null(a,n) memset(a,0,sizeof(a))
#define pi acos(-1)
#define ll long long int
#define fr(a,b) for(int i=a;i<b;i++)
#define modulo 1000000007

int main()
{
    int n;
    cin>>n;
    long long int sum=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0)
            sum+=i;
    }
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 3600
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> k;
  rep(i, n) cin >> a[i];
  ans = LINF;
  rep(i, n - k + 1) {
    ll fr = a[i], to = a[i + k - 1], mi, ma;
    mi = min(abs(fr), abs(to));
    ma = max(abs(fr), abs(to));
    if (fr * to >= 0) {
      ans = min(ans, ma);
    } else {
      ans = min(ans, mi * 2 + ma);
    }
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 1024
h, w = [ int(v) for v in input().split() ]

mod = 10**9+7
ans_list = [ 0 for i in range(w) ]
ans_list[0] = 1


line = input()
for i in range(1,w):
    if line[i] == ".":
        ans_list[i] = ans_list[i-1]
    else:
        ans_list[i] = 0


for j in range(1,h):
    new_ans_list = [ 0 for i in range(w) ]
    line = input()
    if line[0] == ".":
        new_ans_list[0] = ans_list[0] 
    else:
        new_ans_list[i] = 0

    for i in range(1,w):
        if line[i] == ".":
            new_ans_list[i] = (new_ans_list[i-1] + ans_list[i]) % mod
        else:
            new_ans_list[i] = 0

    ans_list = new_ans_list

print(ans_list[-1])

Measured memory_bytes: 42716
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v){stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modpow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isprime(ll n){if(n<2)return 0;if(!(n%2))return !(n-2);lll d=n-1,t,y;while(!(d%2))d>>=1;vl al={2,325,9375,28178,450775,9780504,1795265022};for(ll a:al){if(n<=a)break;t=d,y=modpow(a,t,n);while(t!=n-1&&y!=1&&y!=n-1)y=y*y%n,t<<=1;if(y!=n-1&&!(t%2))return 0;}return 1;}
void dout(double d){printf("%.12f\n",d);}
void YN(bool z){cout<<(z?"YES\n":"NO\n");}
void Yn(bool z){cout<<(z?"Yes\n":"No\n");}
void yn(bool z){cout<<(z?"yes\n":"no\n");}
const mt19937 rnd(unsigned(1357986421));
const int iinf = 1e9+6;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;

const int N = 1e5;
multiset<int> s;
int n, k, h[N];

main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  FOR(i, 0, n) cin >> h[i];
  sort(h, h+n);
  int ans = iinf;
  FOR(i, 0, n-k+1) mins(ans, h[i+k-1]-h[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
import scala.io.StdIn._
import scala.math._

object Main extends App with StdInHelper {
  val Array(a, b) = readInts
  println(a * b)
}

trait StdInHelper {
  def readInts = readLine.split(" ").map(_.toInt)
  def readLongs = readLine.split(" ").map(_.toLong)
}


Measured memory_bytes: 54612
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i < en; i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)

int32_t main(){ fast;
	
	int n, m, x; cin>>n>>m>>x;
	vector<bool> a(n + 1, false);
	rep(i, m){
		int t; cin>>t;
		a[t] = true;
	}
	int res = 0, res2 = 0;
	rep(i, n + 1){
		if(a[i]){
			if(i < x){
				res++;
			}
			else res2++;
		}
	}
	cout<<min(res, res2)<<endl;
}


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

void insertionSort();
void out();

int n,a[N];

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

void insertionSort(){
  out();
  for(int i=1;i<n;i++){
    int t=a[i],j=i-1;
    while(j>=0&&a[j]>t){
      a[j+1]=a[j];
      j--;
    }
    a[j+1]=t;
    out();
  }
}

void out(){
  for(int i=0;i<n;i++){
    if(i)cout<<' ';
    cout<<a[i];
  }
  cout<<endl;
}

Measured memory_bytes: 1164
using System;
namespace kozaiyApp
{
    public class A
    {
        static void Main()
        {
            int K = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);

            int flag = 0;

            for (int i = A; i <= B; i++)
            {
                if (i % K == 0)
                {
                    Console.WriteLine("OK");
                    flag = 1;
                    break;
                }
            }

            if (flag == 0)
            {
                Console.WriteLine("NG");
            }
        }
    }
}


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

int main(void){
    int n,m;
    cin >> n >> m;
    using P = pair<ll,ll>;
    vector<P> vp(n);
    rep(i,n) {
        ll a,b;
        cin >> a >> b;
        vp[i] = {a,b};
    }
    sort(all(vp));
    ll res = 0;
    rep(i,n){
        ll a = vp[i].first, b = vp[i].second;
        if(m-b > 0) {
            res += a*b;
            m -= b;
        } else {
            res += a*m;
            break;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string.h>
using namespace std;
int main(void){
    int A,B,C;
    bool exist=0;
    cin >> A >> B >> C;
    for(int i=1;i<=100;i++){
        if((i*A)%B==C){
            exist=1;
        }
    }
    if(exist){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int gcd(int,int);

int main(){
  int a,b,ans;
  scanf("%d %d",&a,&b);
  if(a>=b) ans=gcd(a,b);
  else ans=gcd(b,a);
  printf("%d\n",ans);
  return 0;
}

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



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout << endl;}
typedef long long ll;
typedef pair<int, int> P;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

const int MAX_N = 1005;
vector<int> node[MAX_N]; 
bool visited[MAX_N];
bool completed[MAX_N];
int n;

bool bfs(int v, vector<int> &min_loop){

    queue<int> que;
    vector<int> step(n, -1); //距離を
    vector<int> pre(n, -1); //逆経路用に確保
    step[v] = 0;
    que.push(v);
    while(!que.empty()){
        int now = que.front(); que.pop();
        for (auto next: node[now]){
            if (step[next] != -1) continue;
            step[next] = step[now] + 1;
            pre[next] = now;
            que.push(next);
        }

    }

//    show(step);
    int ans = MOD;
    int min_v = -1;
    for (int t = 0; t < n; t++)
    {
        if (t == v || step[t] == -1) continue;
        for(auto next: node[t]){
            if (next == v) {
                ans = min(ans, step[t] + 1);
                min_v = t;
            }
        }
    }
    if (ans == MOD){
        return false;
    } else {
        while(min_v != v) {min_loop.push_back(min_v); min_v = pre[min_v];}
        min_loop.push_back(v);
        return true;
    }

}

int main()
{
    int m;
    cin >> n >> m;
    rep(i, m){ 
        int tmpa, tmpb; cin >> tmpa >> tmpb;
        tmpa--; tmpb--;
        node[tmpa].push_back(tmpb);        
    }
   //rep(i, n)    show(node[i]);

    bool loop = false;
    vector<int> ans_loop(n+1);
    vector<int> min_loop;

    rep(i,n){
        min_loop = vector<int>();
        if (bfs(i, min_loop)){
//            cout << i <<  ":";
//            show(min_loop);
            if (min_loop.size() < ans_loop.size()){
                ans_loop = min_loop;
            }
            loop = true;
        }
    }
    if(loop){
        cout << ans_loop.size() << endl;
        rep(i, ans_loop.size()) cout << ans_loop[i] + 1 << endl; 
    } else {
        puts("-1");
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
using namespace std;
typedef long long ll;
typedef vector<int>VI;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define fi first
#define se second
#define MAX 100100//5
#define MAX_N 200100
#define MAX_B 1001001//6
#define MAX_S 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL
#define MAX_INT INT_MAX

int main(){
    int n,d;cin>>n>>d;
    int x=2*d+1;
    cout<<(n+x-1)/x<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  vector<int> T(N);
  for(int i=0; i<N; i++){
    cin >> S.at(i) >> T.at(i);
  }
  string X;
  cin >> X;
  bool sleep = false;
  int ans = 0;
  for(int i=0; i<N; i++){
    if(sleep){
      ans += T.at(i);
    }
    if(X == S.at(i)){
      sleep = true;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<cctype>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int k = 1;
	if (a != b)
		k++;
	if (a != c && b != c)
		k++;
	cout << k << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string n;cin>>n;
    if(n[0]==n[1]&&n[1]==n[2]){
        cout<<"Yes"<<endl;
    }
    else if(n[1]==n[2]&&n[2]==n[3]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include<cstdio> 
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#define ms(i, j) memset(i, j, sizeof i)
#define LL long long
#define db double
#define fir first
#define sec second
#define mp make_pair
using namespace std;

namespace flyinthesky {

	pair<int, int > gg[100000 + 5];
	
	int tot = 0;

    void clean() {
    }
    int solve() {
    	
    	clean();
    	int n; cin >> n;
    	if (n % 2 == 1) {
    		for (int i = 1; i <= n; ++i) {
				for (int j = i + 1; j <= n; ++j) 
				if (j != n - i) gg[++tot] = make_pair(i, j);
			}
			printf("%d\n", tot);
			for (int i = 1; i <= tot; ++i) {
				printf("%d %d\n", gg[i].first, gg[i].second);
			}
		} else {
			for (int i = 1; i <= n; ++i) {
				for (int j = i + 1; j <= n; ++j) 
				if (j != n - i + 1) gg[++tot] = make_pair(i, j);
			}
			printf("%d\n", tot);
			for (int i = 1; i <= tot; ++i) {
				printf("%d %d\n", gg[i].first, gg[i].second);
			}
		}

        return 0;
    }  
}
int main() {
    flyinthesky::solve();
    return 0;
}
/*
*/

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

#define MAX 44

int DP[MAX + 1];

int fib(int n) {
	if (DP[n] != -1) {
		return DP[n];
	} else {
		return DP[n] = fib(n - 1) + fib(n - 2);
	}
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < MAX + 1; i++)
		DP[i] = -1;
	DP[0] = 1;
	DP[1] = 1;
	cout << fib(n) << endl;
	return 0;
}



Measured memory_bytes: 3100
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define ll long long
const int maxn=1e4+50;
const int maxm=1e5+50;
const int mod=1234567;
using namespace std;
int c[1100][1100];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            if((i<=b&&j<=a)||(i>b&&j>a))
                c[i][j]=1;
        }
    }
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            cout<<c[i][j];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define mod 1000000007
using namespace std;

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);cout.tie(NULL);
	int n;
	cin>>n;
	vector<vector<int> >a(n,vector<int>(3)),dp(n,vector<int>(3));
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i][0]>>a[i][1]>>a[i][2];
	}
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];

	for(int i=1;i<n;++i){
		dp[i][0] = max(dp[i-1][1],dp[i-1][2])+a[i][0];
		dp[i][1] = max(dp[i-1][0],dp[i-1][2])+a[i][1];
		dp[i][2] = max(dp[i-1][1],dp[i-1][0])+a[i][2];
	}
	cout<< max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

	// cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
	return 0;
}	

Measured memory_bytes: 11136
A,B,C = map(int,input().split())
X = []
Y = []
if A >= B and A >= C:
    X.append(str(A))
    if B >= C:
        X.append(str(B))
        Y.append(str(C))
    else:
        X.append(str(C))
        Y.append(str(B))

elif B >= A and B >= C:
    X.append(str(B))
    if A >= C:
        X.append(str(A))
        Y.append(str(C))
    else:
        X.append(str(C))
        Y.append(str(A))

else:
    X.append(str(C))
    if A >= B:
        X.append(str(A))
        Y.append(str(B))
    else:
        X.append(str(B))
        Y.append(str(A))
ans = int((''.join(X))) + int((''.join(Y)))
print(ans)


Measured memory_bytes: 3064
import numpy as np

# 足場は1~N 添え字は0~N-1
# 足場iの最小値は、min(dp[j]+abs(h[i]-h[j]))  min(0,i-K)<=j<=i-1<i
# 参照させてもらいました　https://harutech.hateblo.jp/entry/2019/02/10/202515　

# 入力 添え字のN-1が足場Nに相当する
N, K = map(int, input().split())
h = np.array(list(map(int, input().split())))

# 初期化
dp = np.zeros(N, dtype=np.int)

dp[0] = 0
for i in range(1, N):
    start = max(0, i - K)
    dp[i] = np.min(dp[start:i] + np.abs(h[i] - h[start:i]))

print(dp[N - 1])

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

int main() {
	int n,m;
	cin >> n>>m;
	vector<int> a(n);
	int sum=0;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		sum+=a[i];
	}
	int count=0;
	for (int i = 0; i < n; i++){
		if(a[i]*4*m>=sum)count++;
	}
	if(count>=m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

int main(void)
{
    ll A, B;
    cin >> A >> B;
    int K;
    cin >> K;

    vector<ll> container;
    // 小さい方からK番目以内
    for (int i = A; i < min(A + K, B); i++)
    {
        container.push_back(i);
    }

    //大きい方からK番目以内
    for (int i = max(B - K + 1, A); i <= B; i++)
    {
        container.push_back(i);
    }

    sort(container.begin(), container.end());
    bool unique;
    for (int i = 0; i < container.size() - 1; i++)
    {
        unique = true;
        for (int j = i + 1; j < container.size(); j++)
        {
            if (container[i] == container[j])
            {
                unique = false;
            }
        }
        if (unique == true)
        {
            cout << container[i] << endl;
        }
    }
    cout << container[container.size() - 1] << endl;

    return (0);
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(),a = sc.nextInt(),b = sc.nextInt();
        String s = sc.next();
        char[] schar = s.toCharArray();
        boolean[] ans = new boolean[n];
        int countA =0,countB = 0;
        for(int i = 0;i<n;i++){
            if(schar[i]=='a'){
                if(countA<a+b){
                    ans[i] = true;
                    countA ++;
                }
            }
            if(schar[i]=='b'){
                if((countA<a+b)&&(countB<b)){
                    ans[i] = true;
                    countA ++;
                    countB ++;
                }
            }
        }
        for(int i =0 ;i<n;i++){
            if(ans[i]){
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}

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

int main(){
	ll n,p; cin >> n >> p;
	string s; cin >> s;
	ll ans = 0;
	if(p==2){
		rep(i,n){
			if((s[i]-'0')%2==0) ans += i+1;
		}
	}else if(p==5){
		rep(i,n){
			if((s[i]-'0')%5==0) ans += i+1;
		}
	}else{
		vl v(p,0);
		v[0] = 1;
		ll now = 0;
		ll mul = 1;
		for(ll i=n-1; i>=0; i--){
			now = (now + (s[i]-'0') * mul) % p;
			ans += v[now];
			v[now]++;
			mul *= 10;
			mul %= p;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
p = list(map(int, input().split()))
E = [0]*K
max = 0
for i in range(K):
    E[i%K] = (1+p[i])/2
    max += E[i%K]
tmp_E = max
for j in range(K, N):
    tmp_E -= E[j%K]
    E[j%K] = (1+p[j])/2
    tmp_E += E[j%K]
    if max < tmp_E:
        max = tmp_E
print(max)

Measured memory_bytes: 67824
from math import pi
K, N = map(int, input().split())
A = list(map(int, input().split()))
D = [0 for i in range(N)]
D[0] = abs(A[0] + (K - A[-1]))
for i in range(1, N):
  D[i] = abs(A[i] - A[i-1])
print(sum(D) - max(D))

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

using namespace std;
#define INF 100000000

int main(void){

    int n, m, x;
    int minValue = INF;
    cin >> n >> m >> x;
    vector<int> a(n, 0);
    for(int i = 0;i < m;i++) {
        int x; cin >> x;
        a[x-1] = 1;
    }

    int count = 0;
    for(int i = 0;i < x;i++){
        count += a[i];
    }
    minValue = min(minValue, count);
    count = 0;
    for(int i = x;i < a.size() - 1;i++){
        count += a[i];
    }
    minValue = min(minValue, count);

    cout << minValue << endl;



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n, k; cin >> n >> k;
	int p[1001];
	for (int i = 0; i < n; i++)  cin >> p[i];
	sort(p, p + n);
	int ans = 0;
	for (int i = 0; i < k; i++) { ans = ans + p[i]; }
	cout << ans << endl;
}

Measured memory_bytes: 3552
#include <iostream>
#include <string>
using namespace std;
int main(){
    string S;
    cin >> S;
bool aok = false;
bool bok = false;
    for(int i= 0; i < S.size(); i++){
       if(S[i] == 'A' ){
           aok = true;
       }
       if(S[i] == 'B'){
           bok = true;
       }
    }

    if(aok && bok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;

}


Measured memory_bytes: 256
K,N = map(int,input().split())
A = [int(i) for i in input().split()]
diff = []
for i in range(N):
  if i == 0:
    diff.append(K-A[i]-(K-A[N-1]))
  else:
  	diff.append(K-(A[i]-A[i-1]))
print(min(diff))

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


int main()
{
    int n,a,b,x,y;
    double k;


    cin>>a>>b;
    if(a!=b)
    {
        k=(a+b)*0.5;
        if(k==(int)k)
        {
            x=abs(a-k);
            y=abs(b-k);
            if(x==y)
            {
                cout<<fixed<<setprecision(0)<<k<<endl;
            }
            else {
                cout<<"IMPOSSIBLE"<<endl;
            }

        }
        else{
            cout<<"IMPOSSIBLE"<<endl;}
    }

    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
P = [*map(lambda x: int(x)-1, input().split())]
C = [*map(int, input().split())]

score = -10**18
for st in range(n):
    lap_sc = sum_sc = 0
    nx = st
    for lap_cn in range(1, n+1):
        lap_sc += C[nx]
        nx = P[nx]
        if nx == st: break
    lap_sc = max(0, lap_sc)

    for k_cn in range(1, k+1):
        sum_sc += C[nx]
        score = max(score, sum_sc + lap_sc * ((k - k_cn) // lap_cn))
        nx = P[nx]
        if nx == st: break

print(score)


Measured memory_bytes: 92084
#include<iostream>
#include<string>
using namespace std;
int main() {
	string S[3];
	cin >> S[0] >> S[1] >> S[2];
	int people = 0;
	int time[3]{ 0 };
	while (S[people].size() > time[people]) {
		++time[people];
		people = S[people][time[people]-1] - 'a';
	}
	cout << (char)(people+'A') << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class AThumbnail {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n;
	    in >> n;
	    double sum = 0.0;
	    vector<int> a(n);
	    for(int i=0; i<n; i++){
	        in >> a[i];
	        sum += (double)a[i];
	    }

	    double ave = sum / (double)n;

	    int res = 0;
	    double mi = inf;
	    for(int i=0; i<n; i++){
            double diff = abs(ave - (double)a[i]);
            if(diff < mi){
                mi = diff;
                res = i;
            }
	    }

	    out << res << endl;
	}
};


int main() {
	AThumbnail solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

const int N_MAX = 1e4;

int n, m;

vector<int> edge[N_MAX], redge[N_MAX], cntIn(N_MAX), cntOut(N_MAX), group(N_MAX), order;
vector<bool> use(N_MAX);

int dfs(int now, vector<int> e[], int s = -1)
{
  use[now] = true;
  group[now] = s;
  for (int t : e[now])
    if (!use[t])
      dfs(t, e, s);
  if (s == -1)
    order.push_back(now);
}

int main()
{
  cin >> n >> m;
  for (int i = 0; i < m; i++)
  {
    int s, t;
    cin >> s >> t;
    edge[s].push_back(t);
    redge[t].push_back(s);
  }
  for (int i = 0; i < n; i++)
    if (!use[i])
      dfs(i, edge);
  use = vector<bool>(N_MAX, false);
  int cnt = 0;
  reverse(order.begin(), order.end());
  for (int t : order)
    if (!use[t])
    {
      dfs(t, redge, cnt);
      cnt++;
    }
  for (int i = 0; i < n; i++)
    for (int t : edge[i])
      if (group[i] != group[t])
      {
        cntIn[group[t]]++;
        cntOut[group[i]]++;
      }
  int noIn = 0, noOut = 0;
  for (int i = 0; i < cnt; i++)
  {
    if (cntIn[i] == 0)
      noIn++;
    if (cntOut[i] == 0)
      noOut++;
  }
  cout << (cnt == 1 ? 0 : max(noIn, noOut)) << endl;

  return 0;
}



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

struct Edge {
	int to;
	// int64_t dist{1};

	// int64_t cost;
	// int from;
	// int rev_i;
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// ここからコピペ ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

// コンストラクタに渡すのは子に向かう有向グラフでも無向グラフでもいい
class LCA {
private:
	using ve = std::vector<Edge>;
	using vve = std::vector<ve>;
	using vi = std::vector<int>;
	using vvi = std::vector<vi>;

	const vve& edges_;
	vvi ancestors_;
	vi depthList_;
	const int root_;

	void dfs(const int index, const int parent, const int depth)
	{
		ancestors_[index].front() = parent;
		depthList_[index] = depth;
		for (auto& e: edges_[index])
			if (e.to != parent)
				dfs(e.to, index, depth + 1);
	}
	
public:
	const vi& depthList;

	LCA(const vve& adjacentList, const int root)
		: edges_(adjacentList), root_(root), depthList(depthList_)
	{
		int size{1};
		while (1 << (size - 1) <= (int)edges_.size()) size++;
		ancestors_.resize(edges_.size(), vi(size));
		depthList_.resize(edges_.size());
		dfs(root_, root_, 0);
		for (int i{1}; i < size; i++)
			for (auto& e: ancestors_)
				e[i] = ancestors_[e[i - 1]][i - 1];
	}

	int calcAncestor(const int from, const int distance)
	{
		int ret{from};
		for (int digit{}, rest{distance}; rest > 0; rest >>= 1, digit++)
			if (rest & 1)
				ret = ancestors_[ret][digit];
		return ret;
	}

	int calcLCA(int index0, int index1)
	{
		if (depthList_[index0] > depthList_[index1])
			index0 = calcAncestor(index0, depthList_[index0] - depthList_[index1]);
		else
			index1 = calcAncestor(index1, depthList_[index1] - depthList_[index0]);
		if (index0 == index1) return index0;
		
		for (int digit{(int)ancestors_.front().size() - 1}; digit >= 0; digit--)
			if (ancestors_[index0][digit] != ancestors_[index1][digit])
			{
				index0 = ancestors_[index0][digit];
				index1 = ancestors_[index1][digit];
			}
		return ancestors_[index0][0];
	}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////// ここまでコピペ ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int main()
{
	int n;
	scanf("%d", &n);
	using ve = std::vector<Edge>;
	using vve = std::vector<ve>;
	vve graph(n);
	for (auto& e: graph)
	{
		int k;
		scanf("%d", &k);
		e.resize(k);
		for (auto& f: e)
			scanf("%d", &f.to);
	}
	LCA lca(graph, 0);
	int q;
	scanf("%d", &q);
	for (int i{}; i < q; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		printf("%d\n", lca.calcLCA(u, v));
	}
	return 0;
}


Measured memory_bytes: 21808
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication50
{
    class Program
    {
        static void Main()
        {
            while (true)
            {
                string r = Console.ReadLine();
                if (r == null) break;
                decimal s = decimal.Parse(r), k = s;
                for (int a = 0; a < 9; a++)
                {
                    if (a % 2 == 0) { s *= 2; k += s; }
                    else { s /= 3; k += s; }
                }
                Console.WriteLine(k);
            }
        }
    }
}

Measured memory_bytes: 9256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int Z = sc.nextInt();
		System.out.print(Z+" ");
		System.out.print(X+" ");
		System.out.print(Y);
	}
}


Measured memory_bytes: 21716
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 便利関数
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 auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

// 入出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

// 初期時読み込み
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

const int INF = 2002002002;

void solve(std::string S){
    S.replace(3, 1, "8");
    print(S);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

typedef long long int lli;

using namespace std;

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

	int N, M; cin >> N >> M;
	vector <int> cnt(M);

	for (int i = 0; i < N; ++i) {
		int K; cin >> K;
		for (int j = 0; j < K; ++j) {
			int A; cin >> A; 
			A--;
			cnt[A]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < M; ++i) {
		if (cnt[i] == N) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
int main()
{
  int x,y,pro,r;

  scanf("%d%d",&x,&y);
  if(x<=y){
    pro=x;
    x=y;
    y=pro;
  }

  r=x%y;
  while(r!=0){
    x=y;
    y=r;
    r=x%y;
  }
  printf("%d\n",y);
  return 0;
}
  



Measured memory_bytes: 2712
import bisect
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))
A = A[::-1]
S = [A[0]]
c = 1
for i in range(1, N):
    t = A[i]
    if t >= S[-1]:
        S.append(t)
        c += 1
    else:
        p = bisect.bisect_right(S, t)
        S[p] = t
print(c)

Measured memory_bytes: 56920
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str, replace, repbe;
		int index;
		char code;
		int num;

		while( scan.hasNext()) {
			// Scan
			str = scan.next();
			index = 0;

			// Replace
			while(true) {
				index = str.indexOf("@",index);
				if(index!=-1) {
					num = str.charAt(index+1) - '0';
					code = str.charAt(index+2);
					repbe = "@" + num + String.valueOf(code);
					replace = "";
					for( int i=0; i<num; i++) replace += String.valueOf(code);
					str = str.replaceFirst(repbe, replace);
				}else break;
			}
			System.out.println(str);
		}
	}
}

Measured memory_bytes: 12000
//InTheNameOfGod
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,j,k) for(int i=j;i<k;++i)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define pb push_back
#define int ll
const int maxn =2e5;
int n,e,t,dp[maxn],x[maxn],bt[4*maxn];
void up(int u,int l,int r,int x,int y)
{
	if(r-l==1)
	{
		bt[u]=y;
		return ;
	}
	int md=(l+r)>>1;
	if(x<md)up(2*u,l,md,x,y);
	else up(2*u+1,md,r,x,y);
	bt[u]=min(bt[2*u],bt[2*u+1]);
}
int query(int u,int l,int r,int f,int s)
{
	if(l>=s||f>=r)return 1e18;
	if(f<=l&&r<=s)
	{
		return bt[u];
	}
	int md=(l+r)>>1;
	return min(query(2*u,l,md,f,s),query(2*u+1,md,r,f,s));
}
main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n>>e>>t;
    rep(i,1,n+1)cin>>x[i];
    int g=0;
    up(1,0,n+1,0,-2*x[1]);
    rep(i,1,n+1)
    {
        while(x[g+1]<=x[i]-t/2.0)g++;
        dp[i]=min(t+dp[g],2*x[i]+query(1,0,n+1,0,g));
        up(1,0,n+1,i,dp[i]-2*x[i+1]);
        //cout<<i<<' '<<g<<' '<<dp[i]<<' '<<2*x[i]<<'+'<<query(1,0,n+1,0,g)<<' '<<t+dp[g]<<endl;
    }
    cout<<dp[n]+e;
}


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

int main(){
  int N,M,r;
  cin >> N >> M;
  vector<int>cnt(N+1);
  for (int i=0; i<M*2; i++){
    cin >> r;
    cnt.at(r)++;
  }
  for (int i=1; i<=N; i++)
    cout << cnt.at(i) << endl;
}

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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

int main() {
  ll a, b;
  cin >> a >> b;
  string s = "", t = "";
  repi(b) s += (char)(a + '0');
  repi(a) t += (char)(b + '0');
  cout << min(s, t) << endl;
}


Measured memory_bytes: 3544