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

class Main{
    public static void main(String[] args){
        long mod=1_000_000_007l;
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        long[] x=new long[n+1];
        for(int i=1;i<=n;x[i++]=sc.nextLong());
        sc.close();
        long ans=0;
        for(int i=1;i<n;i++){
            ans+=((x[n]-x[i])*modinv(i, mod))%mod;
        }
        ans%=mod;
        for(int i=2;i<n;ans=(ans*i++)%mod);
        System.out.println(ans);
    }
    static long modinv(long a, long mod) {
        long b = mod;
        long u = 1, v = 0;
        while (b >= 1) {
            long t = a / b;
            a -= t * b;
            long tmp1 = a;
            a = b;
            b = tmp1;
            u -= t * v;
            long tmp2 = u;
            u = v;
            v = tmp2;
        }
        u %= mod;
        return u >= 0 ? u : u + mod;
    }
}


Measured memory_bytes: 57824
const main = (inputs) => {
  var num = inputs - 0;
  var sum = 0;

  for (var i = 1; i <= num; i++) {
    for (var j = 1; j <= num; j++) {
      for (var k = 1; k <= num; k++) {
        sum = sum + gcd(i, j, k);
      }
    }
  }

  console.log(sum);

}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


function gcd() {
  var f = (a, b) => b ? f(b, a % b) : a
  var ans = arguments[0]
  for (var i = 1; i < arguments.length; i++) {
    ans = f(ans, arguments[i]);
  }
  return ans
}

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

using namespace std;

bool dp[10001];
int main() {
  int n;
  cin >> n;
  dp[0] = true;
  for(int i = 0; i < n; i++) {
    int s;
    cin >> s;
    for(int j = 10000; j >= 0; j--) {
      if(!dp[j] || j + s > 10000) continue;
      dp[j + s] = dp[j];
    }
  }

  for(int i = 10000; i >= 0; i--) {
    if(i % 10 != 0 && dp[i]) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "0" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll K;
    cin >> K;

    cout << (K / 2) * (K / 2 + K % 2) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 5000000000000000
#define endl '\n'
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; }
using namespace std;

struct edge { int from, to, cost; };

signed main(){
    int L; cin>>L;
    vector<edge> ans;
    for(int i=19; i>=1; i--){
        if(L==1){
            edge e; e.from=i; e.to=i+1; e.cost=0;
            ans.push_back(e);
        }else{
            if(L%2==1){
                edge e; e.from=1; e.to=i+1; e.cost=L-1;
                ans.push_back(e);
            }
            edge e,f;
            e.from=i; e.to=i+1; e.cost=0;
            L/=2;
            f.from=i; f.to=i+1; f.cost=L;
            ans.push_back(e);
            ans.push_back(f);
        }
    }
    cout<<20<<' '<<ans.size()<<endl;
    rep(i,ans.size()){
        cout<<ans.at(i).from<<' '<<ans.at(i).to<<' '<<ans.at(i).cost<<endl;
    }
}

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

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int comp(const int *a,const int *b){
	return (*a - *b);
}

int main(int argc, char const *argv[])
{
	int n,x,a[107],b[107] = { 0 };
	int temp,cnt = 0;
	scanf("%d%d",&n,&x);
	for (int i = 0; i < n; ++i)	scanf("%d",&a[i]);
	qsort(a,n,sizeof(int),comp);
	for (int i = 0; i < n; ++i)
	{
		temp = (a[i] <= x) ? a[i] : x;
		b[i] += temp;
		x -= temp; 
	}
	if(x > 0) cnt = -1;
	for (int i = 0; i < n; ++i)
	{
		if(a[i] == b[i])	++cnt;
	}
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {

  static class Node {
    int n;
    int parent;
    List<Integer> neighbors;

    public Node(int n) {
      this.n = n;
      this.parent = 0;
      this.neighbors = new ArrayList<>();
    }

    public void addNeighbor(int n) {
      this.neighbors.add(n);
    }
  }

  static Scanner scan = new Scanner(System.in);

  public static void main(String[] args) {
    int n = scan.nextInt();
    int m = scan.nextInt();

    Node[] nodes = new Node[n + 1];
    for (int i = 0; i < n; i++) {
      nodes[i + 1] = new Node(i + 1);
    }

    for (int i = 0; i < m; i++) {
      int a = scan.nextInt();
      int b = scan.nextInt();

      nodes[a].addNeighbor(b);
      nodes[b].addNeighbor(a);
    }

    Queue<Node> queue = new LinkedList<>();
    Set<Integer> visited = new HashSet<>();
    visited.add(1);
    queue.offer(nodes[1]);

    while (queue.size() > 0) {
      Node node = queue.poll();
      for (int neighbor: node.neighbors) {
        if (!visited.contains(neighbor)) {
          visited.add(neighbor);
          nodes[neighbor].parent = node.n;
          queue.add(nodes[neighbor]);
        }
      }
    }

    StringBuffer ans = new StringBuffer();

    for (int i = 2; i <= n; i++) {
      if (nodes[i].parent == 0) {
        System.out.println("No");
        return;
      }

      ans.append(nodes[i].parent + "\n");
    }

    System.out.println("Yes");
    System.out.println(ans);
  }
}

Measured memory_bytes: 73956
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;


void solve(){
    int s; cin >> s;
    vi ans;
    map<int,int> m;
    vll v;
    v.PB(s);
    m[s]++;
    int i = 0;
    while(++i){
        int op = (v[i-1] & 1) ? (3*v[i-1] + 1) : (v[i-1]/2);
        if(m[op]){
            cout << i+1 << endl;
            return;
        }
        m[op]++;
        v.PB(op);
    }
}

int main(){
    //int t; cin >> t;
    //while(t--) solve();

    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>

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

string rotate(string t, int s, int e, int d) {
	string nt(t);
	for(int i=s; i<=e; i++) {
		nt[i] = '0' + (nt[i]-'0'+d)%10;
	}
	return nt;
}

int main()
{
next:
	for(;;) {
		int k;
		cin >> k;
		if(k==0) return 0;
		string from, to;
		cin >> from >> to;
		if(from==to) {
			printf("0\n");
			continue;
		}
		set<string> vi;
		queue<pair<int, string> > q;
		q.push(make_pair(0, from));
		vi.insert(from);
		while(!q.empty()) {
			int c = q.front().first;
			string v = q.front().second;
			q.pop();
			rep(i, k) if(v[i]!=to[i]) {
				for(int j=i; j<k; j++) {
					string nv = rotate(v, i, j, (to[i]-v[i]+10)%10);
					if(nv==to) {
						printf("%d\n", c+1);
						goto next;
					}
					if(vi.find(nv)!=vi.end()) continue;
					vi.insert(nv);
					q.push(make_pair(c+1, nv));
				}
				break;
			}
		}
	}
}

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

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    rep(i, n) cin >> s[i] >> t[i];
    string x;
    cin >> x;
    int ans = 0;
    int num = 0;
    rep(i, n) {
        if(s[i] == x) num = i;
    }
    for(int i = num + 1; i < n; i++) {
        ans += t[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define taskname "A"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 1e3 + 5;
const int mod = 1e9 + 7;
const ll inf = 1e18;

int f[maxn];
int n , a , b , c , d;
int fac[maxn] , rfac[maxn];
int Pow(int x , int y){
    if(y == 0)return 1;
    ll r = Pow(x , y / 2);
    if(y & 1)return r * r % mod * x % mod;
    return r * r % mod;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP" , "r")){
        freopen(taskname".INP","r",stdin);
        freopen(taskname".OUT","w",stdout);
    }
    cin >> n >> a >> b >> c >> d;
    fac[0] = 1;
    for(int i = 1 ; i <= n ; ++i){
        fac[i] = (ll)fac[i - 1] * i % mod;
        rfac[i] = Pow(fac[i] , mod - 2);
    }
    f[0] = 1;
    for(int i = a ; i <= b ; ++i){
        for(int t = n - 1 ; t >= 0 ; --t){
            for(int j = c ; t + j * i <= n && j <= d ; ++j){
                f[t + i * j] += (ll)f[t] * Pow(rfac[i],j) % mod * rfac[j] % mod;
                if(f[t + i * j] >= mod)f[t + i * j] -= mod;
            }
        }
    }
    cout << (ll)f[n] * fac[n] % mod;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define For(start,end) for(int i = (int)start;i<(int)end;i++)
using Int = long long int;
using TDim = vector<vector<int>>;
int main(){
    int N;cin>>N;
    vector<int>stick(N);
    if(N<=2)cout<<0<<endl;
    else
    {
        For(0,N)cin>>stick.at(i);
        sort(stick.begin(),stick.end());
    
    
        int front=0,midle=1,end=2;
        int sum=0;
        while(1){
            if(stick.at(end)<stick[front]+stick[midle]&&stick[end]!=stick[midle]&&stick[end]!=stick[front]&&stick[front]!=stick[midle])sum++;
            if(end==N-1)
            {
            
                if(midle==N-2){
                    if(front==N-3){
                        break;
                    }else
                    {
                        front++;
                        midle=front+1;
                        end=midle+1;
                    }
                    
                }
                else 
                {
                    midle++;
                    end=midle+1;
                }
            }else end++;
        }
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 3632
N,M= map(int,input().split())
LRlis = [list(map(int, input().split())) for i in range(M)]
maxL = 0
minR = 10**5
for i in range(M):
  maxL = max(LRlis[i][0],maxL)
  minR = min(LRlis[i][1],minR)

ans = minR-maxL    
if ans>=0:
  print(ans+1)
else:
  print(0)

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

int main() {
    string s;
    int n,k;

    cin >> n >> k;
    cin >> s;

    if (s.at(k-1)=='A') {
        s.at(k-1) = 'a';
    }
    if (s.at(k-1)=='B') {
        s.at(k-1) = 'b';
    }
    if (s.at(k-1)=='C') {
        s.at(k-1) = 'c';
    }
    cout << s << endl;

}

Measured memory_bytes: 256
n=int(input())
a = list(map(int, input().split()))
b = 0
c = 0
d = 0
e = 0
f = 0
g = 0
h = 0
k = 0
ans = 0
j=0
for i in range(n):
    col = a[i]
    if col <= 399 and b == 0:
        b = 1
        ans += 1
    elif 400 <= col <= 799 and c == 0:
        c = 1
        ans += 1
    elif 800 <= col <= 1199 and d == 0:
        d = 1
        ans += 1
    elif 1200 <= col <= 1599 and e == 0:
        e = 1
        ans += 1
    elif 1600 <= col <= 1999 and f == 0:
        f = 1
        ans += 1
    elif 2000 <= col <= 2399 and g == 0:
        g = 1
        ans += 1
    elif 2400 <= col <= 2799 and h == 0:
        h = 1
        ans += 1
    elif 2800 <= col <= 3199 and k == 0:
        k = 1
        ans += 1
    elif 3200<=col:
        ans += 1
        j += 1
if ans == j:
    print(1, "", ans)
else:
    print(ans-j,"",ans)


Measured memory_bytes: 3064
using System;

namespace A___RGB_Cards
{
    class Program
    {
        static void Main(string[] args)
        {
            var r_g_b = Console.ReadLine().Replace(" ", string.Empty);

            Console.WriteLine(int.Parse(r_g_b) % 4 == 0 ? "YES" : "NO");
        }
    }
}


Measured memory_bytes: 11092
//author:emre yazicioglu

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define fori(a,b,c) for(ll a = b;a < ll(c);a++)
#define ford(a,b,c) for(ll a = b;a >= ll(c);a--)
#define pb emplace_back

const int N = 2e6 + 7;
ll n,m,k,ans,cur,ar[N];
string str;
vector<ll> v;

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);

	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	

	cin >> str;

	ll ar[] = {0, 9, 0, 900, 0, 90000, 0};
	
	m = str.size();
	
	fori(i,0,m)
		ans += ar[i];

	if(m & 1){
		fori(i,0,m)
			k += pow(10,(m-i-1)) * (str[i] - '0');
	
		ans += k - pow(10,(m - 1)) + 1;
	}

	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << - 1 << endl;}
void unhap() {cout << ":(" << endl;}

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> city(m, vector<int>(3));
  for (int i = 0; i < m; i++) {
    cin >> city.at(i).at(0) >> city.at(i).at(1);
    city.at(i).at(2) = i;
  }
  sort(city.begin(), city.end());
  vector<string> ans(m);
  int cnt = 1;
  for (int i = 0; i < m; i++) {
    if (i > 0) {
      if (city.at(i).at(0) != city.at(i - 1).at(0)) cnt = 1;
      else cnt++;
    }
    for (int j = 0; j < 6 - to_string(city.at(i).at(0)).size(); j++)
      ans.at(city.at(i).at(2)).push_back('0');
    ans.at(city.at(i).at(2)) += to_string(city.at(i).at(0));
    for (int j = 0; j < 6 - to_string(cnt).size(); j++)
      ans.at(city.at(i).at(2)).push_back('0');
    ans.at(city.at(i).at(2)) += to_string(cnt);
  }
  for (int i = 0; i < m; i++) cout << ans.at(i) << endl;
}

Measured memory_bytes: 14080
def main():
    n,k = map(int,input().split())
    dests =[0 for _ in range(n)]
    telepos = list(map(int,input().split()))
    for i,t in enumerate(telepos):
        dests[i] = t-1
    print(solve(dests,k))




def solve(dests,k,here = 0):
    here = 0
    telepo_times = 0
    cycle_start = -1
    cycle_end = -1
    cycle_length = -1
    visited = dict()
    visited2 = []


    #循環検出！同じ町にいつ戻ってくるのか
    while telepo_times < k:
        #print("現在地は",here)
        if here in visited:
            cycle_start = visited[here]
            #print(cycle_start,"でループが始まった")
            cycle_end = telepo_times - 1
            #print(cycle_end,"でループが終わった")
            cycle_length = cycle_end - cycle_start + 1
            #print("サイクルの長さは",cycle_length,"だ")
            break
        #ids[here] = telepo_times

        visited[here] = telepo_times
        visited2.append(here)
        telepo_times += 1
        here = dests[here]
    if cycle_length == -1:
        return here + 1

    cycle_index = (k-cycle_start) % cycle_length
    return visited2[cycle_start + cycle_index] + 1




    #telepo_times = 0
    #while telepo_times < (k - cycle_start)%cycle_length:
    #    telepo_times += 1
    #    here = dests[here]







if __name__ == '__main__':
    main()


Measured memory_bytes: 116476
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let nr: Vec<i32> = read_vec();

    println!("{}", if nr[0] >= 10 { nr[1] } else { nr[1] + (100 * (10 - nr[0])) });
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<vector<int>> F(N, vector<int>(10)), P(N, vector<int>(11));

    rep(i, N) {
        rep(j, 10) {
            cin >> F[i][j];
        }
    }

    rep(i, N) {
        rep(j, 11) {
            cin >> P[i][j];
        }
    }

    ll ans = -INF;
    for (int bit = 1; bit < (1 << 10); bit++) {
        vector<int> cnt(N, 0);
        rep(i, 10) {
            if (bit & (1 << i)) {
                rep(j, N) {
                    if (F[j][i]) cnt[j]++;
                }
            }
        }
        ll tmp = 0;
        rep(i, N) {
            tmp += (ll)(P[i][cnt[i]]);
        }

        ans = max(ans, tmp);
    }

    cout << ans << endl;
    return 0;
}

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

using namespace std;

using ll = long long;

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

    ll h, w, n;
    cin >> h >> w >> n;

    vector<ll> cnt(10);
    set<pair<int, int>> pos, check;
    for (int i = 0; i < n; ++i) {
        int r, c;
        cin >> r >> c;
        pos.insert(make_pair(r, c));

        for (int y = max(1, r - 2); y <= r; ++y)
            for (int x = max(1, c - 2); x <= c; ++x) {
                if (y + 2 <= h && x + 2 <= w) check.insert(make_pair(y, x));
            }
    }

    for (const auto &p : check) {
        int num = 0;
        for (int r = p.first; r <= p.first + 2; ++r)
            for (int c = p.second; c <= p.second + 2; ++c)
                if (pos.count(make_pair(r, c))) ++num;
        ++cnt[num];
    }

    cout << (h - 2) * (w - 2) - accumulate(cnt.begin() + 1, cnt.end(), 0ll) << '\n';
    for (int i = 1; i < 10; ++i) cout << cnt[i] << '\n';

    return 0;
}


Measured memory_bytes: 47104
n = int(input())
h = list(int(i) for i in input().split())
ct = 0
query = [0]*n

for i in range(n):
 while h[i] !=0:
  flag = 0
  ct += 1
  for j in range(n):
   try:
    if h[i+j] >0:
     h[i+j] -= 1
    else:
     break
   except:
     break
print(ct)
 
    
 

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    ll N,K;
    ll n,k,len,cp;
    cin >> N >> K;

    vi A(N);
    vi r;
    vi odr(N+1,-1);
    rep(i,N) cin >> A[i];

    n = 1;
    while(odr[n] == -1){
        odr[n] = r.size();
        r.push_back(n);
        n = A[n-1];
    }

    cp = odr[n];
    len = r.size() - cp;
    if(K >= cp){
        K -= cp;
        k = (K % len) + cp;
    }else{
        k = K;
    }
    cout << r[k] << endl;

    return 0;
}

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

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			int[][] hoge = new int[4][];
			for(int i = 0; i < 4; i++)
			{
				hoge[i] = new int[4];
			}

			var input1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)-1).ToArray();
			var input2 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)-1).ToArray();
			var input3 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)-1).ToArray();

			hoge[input1[0]][input1[1]] += 1;
			hoge[input1[1]][input1[0]] += 1;
			hoge[input2[0]][input2[1]] += 1;
			hoge[input2[1]][input2[0]] += 1;
			hoge[input3[0]][input3[1]] += 1;
			hoge[input3[1]][input3[0]] += 1;

			int[] sum=new int[4];
			for(int i = 0; i < 4; i++)
			{
				sum[i] = hoge[i].Sum();
			}
			var temp = sum.OrderBy(x => x).ToArray();

			if(temp[0] == 1 && temp[1] == 1 && temp[2] == 2 && temp[3] == 2)
			{
				Console.WriteLine("YES");
			}
			else
			{
				Console.WriteLine("NO");
			}
			Console.ReadLine();
		}
	}
}

Measured memory_bytes: 13524
$<.gets.to_i.times do |co|
  $<.gets
  field = Array.new(8) {$<.gets.chomp.chars.map(&:to_i)}
  xi, yi = $<.gets.to_i, $<.gets.to_i
  
  blast = ->(x, y) {
    field[y][x] = 2
    3.times do |i|
      [[1, 0], [0, -1], [-1, 0], [0, 1]].each do |dx, dy|
        x1, y1 = x + dx * (i + 1), y + dy * (i + 1)
        next if x1 < 0 or x1 >= 8 or y1 < 0 or y1 >= 8
        if field[y1][x1] == 1
          blast.(x1, y1)
        else
          field[y1][x1] = 2
        end
      end
    end
  }
  blast.(xi - 1, yi - 1)
  
  puts "Data #{co + 1}:"
  puts field.map {|line| line.map {|x| x == 2 ? 0 : x}.join}
end


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

const int maxV = 1e5 + 10;
const long long oo = 1e18;

int n, m, v[110], w[110];
long long f[110][maxV];

int main()
{
 //   freopen("input.txt", "r", stdin);
    
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        scanf("%d%d", &w[i], &v[i]);
        
    for (int i = 0; i <= n; ++i)
        for (int j = 0; j < maxV; ++j)
            f[i][j] = oo;
    f[0][0] = 0;
    
    for (int i = 1; i <= n; ++i)
        for (int j = 0; j < maxV; ++j)
        {
            f[i][j] = f[i - 1][j];
            if (j - v[i] >= 0)
                f[i][j] = min(f[i][j], f[i - 1][j - v[i]] + w[i]);
//            cout << i << ' ' << j << ' ' << f[i][j] << endl;
        }
    
    for (int j = maxV - 1; j >= 0; --j)
        if (f[n][j] <= 1LL*m)
        {
            printf("%d", j);
            return 0;
        }
}


Measured memory_bytes: 80128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define MOD 30000000000000000
#define inf -100000000
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define MAXN 500005
using namespace __gnu_pbds; 
ll int power(ll int x,ll int y) 
{ 
    ll int res = 1;     // Initialize result 
   
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = res*x; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = x*x;  // Change x to x^2 
    } 
    return res; 
}
//set<ll int> s;
bool prime[500005];
void SieveOfEratosthenes(ll int n) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
     
    memset(prime, true, sizeof(prime)); 
  
    for (ll int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    
} 

int main()
{
    fast;
    ///#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#endif
    ll int n;

    cin>>n;
    ll int k;
    cin>>k;
    ll int a[n+1];
    ll int i;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    
    ll int z,last,start,cycle,dest;
    map<ll int,ll int> mp;
    z=1;
    //cout<<"dkdk";
    if(k>n)
    {
    for(i=1;i<=n;i++)
    {
        if(mp[z]!=0)
        {
            last=i;
            break;

        }
        
        mp[z]=i;
        z=a[z];
    }
    start=z;
    k=k-mp[z]+1;
   // cout<<k<<endl;
    cycle=last-mp[z];
    k=k%cycle;
    for(i=1;i<=k;i++)
    {
        start=a[start];
    }
    cout<<start<<endl;
    }
    else
    {//cout<<"sjsj";
        start=1;
        for(i=1;i<=k;i++)
        {
            start=a[start];
        }
        cout<<start;
    }
}


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

#define mod 1000000007

int a[22][22];
long mem[22][(1<<22)-1];

long rec(int curr, int mask, int n)
{
  if(curr==n)
    return mask==0;
  if(mem[curr][mask]!=-1)
    return mem[curr][mask];
  long ans=0;
  for(int j=0;j<n;j++)
  {
    bool available=mask&(1<<j);
    if(available&&a[curr][j])
      ans=(ans%mod+rec(curr+1,mask-(1<<j),n)%mod)%mod;
  }
  mem[curr][mask]=ans;
  return ans;
  
}

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<n;j++)
      cin>>a[i][j];
  }
  memset(mem,-1,sizeof(mem));
  
  cout<<rec(0,(1<<n)-1,n);
  
  
  

}

Measured memory_bytes: 721152
N = int(input())
D = [list(map(int,input().split())) for n in range(N)]
count = 0
ans = "No"

for d1,d2 in D:
  if d1==d2:
    count+=1
    if count==3:
      ans = "Yes"
      break
  else:
    count = 0

print(ans)

Measured memory_bytes: 9172
#include <stdio.h>

int main(void)
{
	int i[9];
	int c, n, s;
	
	while (scanf("%d %d", &n, &s), n + s != 0){
		c = 0;
		for (i[0] = 0; i[0] <= 9; i[0]++){
			if (n > 1){
				for (i[1] = i[0] + 1; i[1] <= 9; i[1]++){
					if (n > 2){
						for (i[2] = i[1] + 1; i[2] <= 9; i[2]++){
							if (n > 3){
								for (i[3] = i[2] + 1; i[3] <= 9; i[3]++){
									if (n > 4){
										for (i[4] = i[3] + 1; i[4] <= 9; i[4]++){
											if (n > 5){
												for (i[5] = i[4] + 1; i[5] <= 9; i[5]++){
													if (n > 6){
														for (i[6] = i[5] + 1; i[6] <= 9; i[6]++){
															if (n > 7){
																for (i[7] = i[6] + 1; i[7] <= 9; i[7]++){
																	if (n > 8){
																		for (i[8] = i[7] + 1; i[8] <= 9; i[8]++){
																			if (i[0] + i[1] + i[2] + i[3] + i[4] + i[5] + i[6] + i[7] + i[8] == s){
																				c++;
																			}
																		}
																	}
																	else {
																		if (i[0] + i[1] + i[2] + i[3] + i[4] + i[5] + i[6] + i[7] == s){
																			c++;
																		}
																	}
																}
															}
															else {
																if (i[0] + i[1] + i[2] + i[3] + i[4] + i[5] + i[6] == s){
																	c++;
																}
															}
														}
													}
													else {
														if (i[0] + i[1] + i[2] + i[3] + i[4] + i[5] == s){
															c++;
														}
													}
												}
											}
											else {
												if (i[0] + i[1] + i[2] + i[3] + i[4] == s){
													c++;
												}
											}
										}
									}
									else {
										if (i[0] + i[1] + i[2] + i[3] == s){
											c++;
										}
									}
								}
							}
							else {
								if (i[0] + i[1] + i[2] == s){
									c++;
								}
							}
						}
					}
					else {
						if (i[0] + i[1] == s){
							c++;
						}
					}
				}
			}
			else {
				if (i[0] == s){
					c++;
				}
			}
		}
		printf("%d\n", c);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int n, m;
	cin >> n >> m;
    vector<int> a(m), dp(n+2);
    dp[0] = 0, dp[1] = 1;
    rep(i,m) {
        cin >> a[i];
        if (i && a[i] == a[i-1] + 1) {
            cout << 0 << endl;
            return 0;
        }
        dp[a[i]+1] = -1;
    }
    rep(i,n) {
        if (dp[i+2] != -1) {
            dp[i+2] = max(dp[i+1],0) + max(dp[i],0);
            dp[i+2] %= MOD;
        }
    }
	cout << dp[n+1] << endl;
	return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

void store(vvint &d, int y, int x, int wide) {
	for (int j = x; j < x+wide; j++) d[y][j] = 1;
}

void Main() {
	int H, W, A, B; cin >> H >> W >> A >> B;
	
	vvint ans(H, vint(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << ((i < B) ^ (j < A));
		}
		cout << el;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

int solve() {
    int x;
    cin >> x;
    cout << 1 - x << endl;
    return 0;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    while(t--) {
        solve();
    }
    return 0;
}


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

using namespace std;
#define ll long long int

int main()
{
   ll t;
   t = 1;
   // cin t;
   while (t--)
   {
      ll n, k;
      cin >> n >> k;
      vector<int> temp;
      temp.push_back(1);
      temp.push_back(1);
      ll a[n + 1];
      int visited[n + 1];
      for (int i = 1; i <= n; i++)
      {
         cin >> a[i];
         visited[i] = 0;
      }
      int start = 1;
      int count = 1;
      visited[1] = 1;
      while(visited[a[start]] == 0)
      {
         start = a[start];
         count++;
         visited[start] = count;
         temp.push_back(start);
      }
      int end = a[start];
      count -= (visited[end] - 1);
      
      if(k < visited[end])
      {
         cout << temp[k + 1] << endl;
      }
      else
      {
         cout << temp[visited[end] + ( k - visited[end] + 1 ) % count] << endl;
      }
      
   }
}


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

int main(){
    // 引数の受け取り
    int A[3];
    scanf("%d %d %d", &A[0],&A[1],&A[2]);

    // ----------------------
    //  メイン処理
    // ----------------------
    //
    sort(A, A+3);
    if (A[0] == 5 && A[1] == 5 && A[2] == 7 ){
        printf("YES");
    } else {
        printf("NO");
    };
    return 0;
}


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

using namespace std;

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

	int d = a / b;
	int r = a % b;
	auto f = d + 1.0*r / b;

	cout << d << ' ' << r << ' ' << fixed << setprecision(17) << f << endl;
}


Measured memory_bytes: 3264
package main

import "fmt"

func main() {
	var S string
	fmt.Scan(&S)

	var tmp, r string
	for _, v := range S {
		switch string(v) {
		case "A", "C", "G", "T":
			tmp += string(v)
			if len(tmp) > len(r) {
				r = tmp
			}
		default:
			tmp = ""
		}
	}
	fmt.Println(len(r))
}

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

int compress(int x){
    while(x > 9){
        int tmp = 0;
        while(x > 0)    tmp += x % 10, x /= 10;
        x = tmp;
    }
    return x;
}

int n, m;
string s;
vector<int> bias, use;
int sum = 0, cnt = 0, ans = 0;

void dfs(int pos, int accum){
    if(pos == cnt){
        if(accum % 10 == 0) ans++;
        return;
    }

    for(int i = 0; i < m; i++){
        dfs(pos+1, accum + compress(bias[pos] * use[i]));
    }
}

int main(){
    cin >> n >> s >> m;
    reverse(s.begin(), s.end());
    
    for(int i = 0; i < n; i++){
        if(s[i] == '*') bias.push_back(1 + i%2), cnt++;
        else            sum += compress((1+i%2)*(s[i]-'0'));
    }

    int a;
    for(int i = 0; i < m; i++){
        cin >> a;
        use.push_back(a);
    }

    dfs(0, sum);

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3320
def sieve(n: int) -> set: #返り値はset
    if n < 2:
        return set()
    
    num = [True]*n
    num[0] = num[1] = False
    for i in range(3,int(n**0.5)+1,2):
        if num[i]:
            num[i * i:: 2 * i] = [False] * ((n - i ** 2 - 1) // (2 * i) + 1)
    return {2}|{i for i in range(3,n,2) if num[i]}

primelist = sieve(10**5+100)
l = [0]+list(sorted(primelist))
X = int(input())
for i in range(len(l)):
    if l[i]>=X:
        print(l[i])
        break

Measured memory_bytes: 5156
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
ll mod = 1000000007;
int INF = 0x3f3f3f3f;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v(n+1);

    int u1 = 1+m;
    int d1 = 1;
    int u2=  n;
    int d2 = n - m + 1;

    int c = 0;

    while (u1 > d1 && c < m) {
        cout << u1 << " " << d1 << endl;
        d1++; u1--;
        c++;
    }
    while (u2 > d2 && c < m) {
        cout << u2 << " " << d2 << endl;
        d2++; u2--;
        c++;
    }
}



Measured memory_bytes: 3976
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, AB[18][2];
int dp[1 << 18][51];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> AB[i][0];
	rep(i, 0, N) cin >> AB[i][1];

	rep(msk, 0, 1 << N) rep(lst, 0, 51) dp[msk][lst] = inf;

	dp[0][0] = 0;
	rep(msk, 0, 1 << N) rep(lst, 0, 51) if(dp[msk][lst] != inf) {
		int done = 0;
		rep(i, 0, N) if (msk & (1 << i)) done++;

		int top = 0;
		rep(i, 0, N) {
			if (msk & (1 << i)) {
				top++;
				continue;
			}

			int d = top;
			int p = abs(done - i) % 2;
			int c = 0;
			rep(j, 0, i) if (!(msk & (1 << j))) c++;

			if (AB[i][p] < lst) continue;

			chmin(dp[msk | (1 << i)][AB[i][p]], dp[msk][lst] + c);
		}
	}

	int ans = inf;
	rep(lst, 0, 51) chmin(ans, dp[(1 << N) - 1][lst]);

	if (ans == inf) ans = -1;
	cout << ans << endl;
}







Measured memory_bytes: 52480
#include<bits/stdc++.h>
using namespace std;
priority_queue<int >q;
vector<int > a[1000001];
int main(){
    int o;
	int n,m;
	cin>>n>>m;
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		int x,y;
		cin>>x>>y;
		if(x>m)
		{
			continue;
		}
		a[m-x+1].push_back(y);
	}
	for(int i=1;i<=m;i++)
	{
		for(int j=0;j<a[i].size();j++)
		{
			q.push(-a[i][j]);
			ans+=a[i][j];
		}
		while(q.size()>i)
		{
			ans+=q.top();
			q.pop();
		}
	}
	cout<<ans<<endl;
}


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

#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main()
{
    int N = 0;
    int W = 1;
    string s;
    while (cin >> s) {
        if (s == "#") break;
        vector<int> vec;
        loop(s.size(), i) {
            if (s[i] == 'n') {
                vec.push_back(N);
                i+=4;
            } else {
                vec.push_back(W);
                i+=3;
            }
        }
//        for(auto i : vec) cout << i;
//        cout << endl;
        vector<pair<int,int>> rs;
        if (vec.back()==N) { 
            rs.push_back({0,1});
        } else {
            rs.push_back({90,1});
        }
        if (vec.size() == 1) {
            cout << rs[0].first << endl;
            continue;
        }
        vec.pop_back();
        int den_max = 0;
        int exp = 1;
        while(vec.size()) {
            if (vec.back() == N) {
                rs.push_back({-90, pow(2,exp++)});
            } else {
                rs.push_back({90, pow(2,exp++)});
            }
            den_max = max(den_max, (int)pow(2,exp-1));
            vec.pop_back();
        }
        int ans_num=0;
        for(auto r:rs) {
            //cout << r.first << ',' << r.second << endl;
            int k = den_max/r.second;
            ans_num += r.first*k;
        }
        int f = gcd(ans_num, den_max);
        //cout << ans_num << ' ' << f << ' ' << den_max << endl;
        cout << ans_num/f;
        if (den_max == f) cout << endl;
        else cout << '/' << den_max/f << endl;
    }
}

Measured memory_bytes: 3128
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define gcd __gcd
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define mp make_pair
#define pb push_back
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define sbits(a) __builtin_popcount(a)
#define lcm(a, b) ((a * b) / gcd(a, b))
#define nani(x) cerr << #x << " is " << x << endl;
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

typedef long long ll;

const int N = 1e5 + 5;

int A[N];

int main()
{
    fast;

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, k;
    cin >> n >> k;
    cout << max(0, n - (k << 1));
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cassert>
using namespace std;
typedef long long ll;

#ifdef _MSC_VER
#pragma warning(disable: 4996) // Disable deprecation
#endif 

char cbuf1[10000];
char cbuf2[10000];
char cbuf3[10000];

int main()
{
	scanf("%s %s %s", cbuf1, cbuf2, cbuf3);
	int l1 = strlen(cbuf1);
	int l2 = strlen(cbuf2);
	int l3 = strlen(cbuf3);
	if (cbuf1[l1 - 1] == cbuf2[0] && cbuf2[l2 - 1] == cbuf3[0])
		printf("YES\n");
	else
		printf("NO\n");

	fclose(stdout);
	return 0;
}


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

vector<int> H(int m){
	vector<int> h;
	for(int i = 0; i < m; i++){
		int g;
		cin >> g;
		h.push_back(g);
	}
	return h;
}

string Shuffle(string Previous, vector<int> h, int m, int n){
	char after[200];
	string After;
	for(int i = 0; i < m; i++){
		for(int j = h[i]; j < n; j++) after[j-h[i]] = Previous[j];
		for(int j = 0; j < h[i]; j++) after[n-h[i]+j] = Previous[j];
		for(int j = 0; j < n; j++) Previous[j] = after[j];
	}
	for(int i = 0; i < n; i++){
		After.push_back(after[i]);
	}
	return After;
}

int main(){
	while(1){
		string Previous;
		cin >> Previous;
		if(Previous == "-") break;
		
		int m;
		cin >> m;
		vector<int> h = H(m);
		
		string After;
		int n = Previous.size();
		After = Shuffle(Previous, h, m, n);
		
		cout << After << endl;
	}
		
	return 0;
}	

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

int main(){
	int X, i, j;
	scanf("%d", &X);
	vector<int> dp(X + 110, 0);
	dp[0] = 1;
	for(i = 0; i < X; i++){
		for(j = 0; j <= 5; j++){
			dp[i + 100 + j] |= dp[i];
		}
	}
	printf("%d\n", dp[X]);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
static const int INFTY = (1 << 29);
static const int MAX = 100000;

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;

void dfs(int u)
{
    V[u] = true;
    for (int i = 0; i != G[u].size(); ++i)
    {
        int v = G[u][i];
        if (V[v] == false) dfs(v);
    }
    out.push_front(u);
}

void tsort()
{
    for (int i = 0; i != N; ++i)
    {
        V[i] = false;
    }
    for (int i = 0; i != N; ++i)
    {
        if (V[i] == false) dfs(i);
    }
    for (list<int>::iterator it = out.begin(); it != out.end(); ++it)
    {
        cout << *it << endl;
    }
}

int main()
{
    int M, s, t;
    cin >> N >> M;
    for (int i = 0; i != M; ++i)
    {
        cin >> s >> t;
        G[s].push_back(t);
    }
    tsort();
    return 0;
}




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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int a,b,c;cin>>a>>b>>c;
  int k;cin>>k;

  int sum=a+b+c;
  int ma=max(a,max(b,c));
  sum-=ma;

  rep(i,0,k){
    ma*=2;
  }
  out(sum+ma);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

const ll INF = 1LL<<60;

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

    ll ans = INF;
    for(int i = 0; i <= max(x, y); i++) {
        int j, k;
        if(x - i < 0) j = 0; else j = x - i;
        if(y - i < 0) k = 0; else k = y - i;
        ll tmp = a * j + b * k + c * i * 2;
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

//gcdをユークリッド互除法で求める。O(log n)
ll euclid(ll x, ll y){
    if(min(x, y) ==  0) return max(x, y);
    else return euclid(max(x, y)% min(x, y) , min(x, y));
}
//

int main() {
	ll ans = 0;
	ll tmp;
	int n; cin >> n;
	ll a, b, c, d;
	REP(i, n){
		cin >> a >> b >> c >> d;
		
		if (a>=b && b<=d){
			if(c >= b) cout << "Yes" << endl;
			else {
				ll g = euclid(d, b);
				if(b - g + a % g <= c) cout << "Yes" << endl;
				else cout << "No" << endl;
			}
		}
		else cout << "No" << endl;
	}
	//cout << ans << endl;
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int K = sc.nextInt();

            int ans = 0;
            while (N > 0) {
                N /= K;
                ans++;
            }

            System.out.println(ans);
        }
    }

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

int n;
int a[111111];
int cnt2,cnt4;

int main(){
	cin.sync_with_stdio(false);
  cin>>n;
  rep(i,n)cin>>a[i];
  rep(i,n){
    if(a[i]%2==0&&a[i]%4!=0)cnt2++;
    if(a[i]%4==0)cnt4++;
  }
  if(n<=cnt4*2+1||n<=cnt4*2+cnt2)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int a[1000];
int main() {
	int n;
	cin>>n;
	int q = 1;
	for(int i = 0; i < n; ++i) q *= 3;
	int ans = 1;
	for(int i = 0; i < n; ++i) {
		cin>>a[i];
		if(a[i] % 2 == 0) {
			ans *= 2;
		}
	}
	cout<<q-ans<<'\n';

}


Measured memory_bytes: 256