akhauriyash/Code-Regression huggingface dataset:
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u64 = read();
    let k: u64 = read();

    let r = n / k;
    let ans1 = n - k * r;
    let ans2 = k - ans1;

    let ans = if ans1 < ans2 {
        ans1
    } else {
        ans2
    };

    println!("{}", ans);
}


Measured memory_bytes: 4352
import math
def main():
    n,k = [int(i) for i in input().split()]
    ans = 0.0
    for i in range(1, n+1):
        # 出目
        if k <= i:
            # 出目がすでに k 以上の時
            ans += 1/n
        else:
            # それ以外
            ans += 1/n*(1/2)**math.ceil(math.log2(k/i))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
package main
import (
  "fmt"
  "math"
)
func main() {
  var q,a,b int
  fmt.Scan(&q)
  for k:=0;k<q;k++ {
    fmt.Scan(&a,&b)
    if a > b { a,b = b,a }
    if a == b || a+1 == b {
      fmt.Println(2*a-2)
    } else {
      var c int = int(math.Sqrt(float64(a)*float64(b)))
      if int64(c)*int64(c) == int64(a)*int64(b) { c-- }
      if int64(c)*int64(c+1) < int64(a)*int64(b) {
        fmt.Println(2*c-1)
      } else {
        fmt.Println(2*c-2)
      }
    }
  }
}

Measured memory_bytes: 512
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
for i in range(1001):
    i=str(i)
    if len(i)!=n:
        continue
    f=1
    for s,c in l:
        c=str(c)
        if len(i)<s:
            f=0
            break
        if not i[s-1]==c:
            f=0
            break
    if f:
        print(i)
        exit()
print("-1")

Measured memory_bytes: 9220
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC opatimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }

int main() {
//    freopen("in.txt","r", stdin);
//    cout << fixed << setprecision(15);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);


    long long a,b;
    cin >> a >> b;
    cout << a * b / __gcd(a,b) << endl;
}


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

using namespace std;

const int ms = 1e5 + 17;
int arr[ms];

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

    int a, b, x;
    cin >> a >> b >> x;

    if(x > a + b)
       return cout << "NO\n", 0;

    if(x >= a)
        cout << "YES\n";
    else
        cout << "NO\n";
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main{
    public static void main(String args[]){
	int i,j,n,q;
	Scanner scan = new Scanner(System.in);
	int a[] = new int[20];
	int m[] = new int[200];
	int s[] = new int[2000];

	n = scan.nextInt();
	for(i=0;i<n;i++){
	    a[i] = scan.nextInt();
	}
	q = scan.nextInt();
	for(j=0;j<q;j++){
	    m[j] = scan.nextInt();
	}
	for(j=0;j<q;j++){
	    if(solve(0,m[j],n,a)==true){
		System.out.println("yes");
	    }
	    else System.out.println("no");
	}
    }
    
    public static boolean solve(int i,int m,int n,int a[]){
	boolean res;
	if(m==0){
	    return true;
	}
	if(i>=n){
	    return false;
	}
	res = solve(i+1,m,n,a) || solve(i+1,m-a[i],n,a);
	return res;
    }
    
}



Measured memory_bytes: 26640
#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
 int H, W;
 while(scanf("%d %d", &H, &W), H!=0)
 {
  for (int i = 0; i < H; i++)
  {
   for (int j = 0; j < W; j++)
   {
    cout << "#";
   }
   cout << endl;
  }
  cout << endl;
 }
}


Measured memory_bytes: 3164
#ABC126D-EvenRelation.py

import sys
import collections
import numpy as np

def main():
    N = int(sys.stdin.readline())
    UVW = [[] for _ in range(N)]
    for _ in range(N-1):
        u, v, w = list(map(int, sys.stdin.readline().split()))
        UVW[u-1].append([v,w])
        UVW[v-1].append([u,w])
    answerList = [0] + [-1]*(N-1)
    edge = collections.deque([(1,0)])

    while edge:
        u, w1 = edge.pop()
        for v, w2 in UVW[u-1]:
            if answerList[v-1] == -1:
                answerList[v-1] = (w1 + w2) % 2
                edge.append((v,w1+w2))

    for answer in answerList:
        print(answer)



if __name__ == "__main__":
    main()


Measured memory_bytes: 54220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[300004];
int main() {
	// your code goes here
	ll n,k,g=0,m=-1;
	cin>>n>>k;
	for(int i=0;i<n;i++){cin>>a[i];m=max(m,a[i]);g=__gcd(g,a[i]);}
	if(m>=k and k%g==0)cout<<"POSSIBLE\n";else cout<<"IMPOSSIBLE\n";
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    string s;
    cin >> s;
    bool c = false, f = false;
    REP(i,s.size()){
        if(s[i] == 'C') c = true;
        if(c && s[i] == 'F') f = true;
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl; 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9+7);
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(10000) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

struct UnionFindTree {
    vector<int> par;
    vector<int> rank;
    vector<int> siz;

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        siz.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        siz[x] += siz[y];
    }
    bool is_same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        x = find(x);
        return siz[x];
    }
};

UnionFindTree g;

int main() {
    int n, h, w, ans;
    cin >> n >> w >> h;
    g.init(n+w+h);
    for(int i=n;i<n+w+h;i++){
        g.siz[i] = 0;
    }
    for(int i=0;i<n;i++){
        int x, y;
        cin >> x >> y;
        x--; y--;
        g.unite(i, n+x);
        g.unite(i, n+w+y);
    }
    ans = n-1;
    set<int> st;
    for(int i=0;i<n;i++){
        st.insert(g.find(i));
    }
    int wall = 0;  // 壁に隣接しているスライムがあるか
    wall = g.size(n)>0 || g.size(n+w-1)>0 || g.size(n+w)>0 || g.size(n+w+h-1)>0;
    if(st.size()>1) ans += max(0, int(st.size())-wall);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 6728
#include <iostream>
using namespace std;
int main(){
    string s1 , s2 , chosen;
    int n1 , n2;
    cin >> s1 >> s2 >> n1 >> n2 >> chosen;
    if (chosen == s1) n1--;
    else if (chosen == s2) n2--;
    cout << n1 << " " << n2;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;

long data[100040];
long sa[100040];

int main(void) {
	long n, x;
	cin >> n >> x;
	for (long i = 0; i < n; i++) {
		cin >> data[i];
	}
	long cnt = 0;
	for (long i = 0; i < n; i++) {
		sa[i] = abs(x - data[i]);
		cnt++;
	}

	sort(sa, sa + cnt);

	long tmp = sa[0];
	bool finish = false;
	int ans;
	while (tmp != 1) {
		if (sa[0] % tmp == 0) {
			for (long i = 1; i < cnt; i++) {
				if (sa[i] % tmp != 0) finish = true;
			}
			if (!finish) {
				ans = tmp;
				break;
			}

		}
		finish = false;
		tmp--;
	}
	
	cout << tmp << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define PI 3.1415926535897932384626433832795
using namespace std;

int main(){
    int m,n;
    cin>>n>>m;

    int ans = ((n * (n-1)) / 2)  + ((m *(m-1))/2);
    if(n > 1 || m> 1){
        cout<<ans;
    }
   
    else{
        cout<<0;
    }
 
   


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
//#include <cmath>
//#include <complex>
#include<queue>
#include<map>
#include <string>
#include<bits/stdc++.h>
//#define pi 3.141592654
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);
//#define x real()
//#define y imag()
using namespace std;
typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//template<typename T>T gcd(T x, T y) { if(y == 0)return x; else return gcd(y, x%y); }
//typedef bitset<30> mask;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
ll n,l,a[200020];
int main()
{

//cout<<Pow((ll)1000000,(ll)110);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//    char input[15];
//    scanf("%s", &input);  array of char
//  gets(c+1);  array of char
input;
cin>>n>>l;
forr(i,1,n)cin>>a[i];


forr(i,1,n-1)
{
    if(a[i]+a[i+1]>=l)
    {
        cout<<"Possible"<<endl;
        forr(j,1,i-1)cout<<j<<endl;
        for(int j=n-1;j>i;j--)cout<<j<<endl;
        cout<<i<<endl;
        return 0;
    }
}

cout<<"Impossible"<<endl;
return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

const char* possible = "POSSIBLE";
const char* impossible = "IMPOSSIBLE";

int n;
int p[252521];
vector<int> children[252521];

int cycle[252521];
int m = 0;
bool cycled[252521];

int calcorder[252521];
int calcorderhead = 0;
int calcordertail = 0;

int it = 0;

#define MAX_DEG 19
int val[252521];
bool deg[MAX_DEG+2];

void calc(int x){
    REP(i,children[x].size()){
        int v = val[children[x][i]];
        deg[v]=true;
    }
    REP(d,MAX_DEG+1)if(!deg[d]){
        val[x] = d;
        break;
    }
    REP(i,MAX_DEG+2)deg[i]=false;
}

int main(void){
    scanf("%d",&n);
    REP(i,n){
        scanf("%d",p+i);
        p[i]--;
        children[p[i]].push_back(i);
    }
    REP(i,n)it = p[it];
    do{
        cycle[m++] = it;
        cycled[it] = true;
        it = p[it];
    }while(cycle[0]!=it);
    REP(i,m){
        int x = cycle[i];
        REP(j,children[x].size()){
            int y = children[x][j];
            if(cycled[y])continue;
            calcorder[calcordertail++] = y;
        }
    }
    while(calcorderhead != calcordertail){
        int x = calcorder[calcorderhead++];
        REP(j,children[x].size()){
            calcorder[calcordertail++] = children[x][j];
        }
    }
    REP(i,n)val[i] = MAX_DEG+1;
    while(calcordertail--){
        int x = calcorder[calcordertail];
        calc(x);
    }
    // first challenge
    REP(i,m)calc(cycle[i]);
    int tst = val[cycle[0]];
    calc(cycle[0]);
    if(tst == val[cycle[0]]){
        puts(possible);
        return 0;
    }
    REP(i,m-1)calc(cycle[i+1]);
    tst = val[cycle[0]];
    calc(cycle[0]);
    if(tst == val[cycle[0]]){
        puts(possible);
    }else{
        puts(impossible);
    }
    return 0;
}


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

const long long mod=1000000007LL;
int main(int argc, char const *argv[])
{
	int n,m;
	cin>>n>>m;
	int x,y;
	set<int> a,b;
	for (int i = 0; i < n; ++i)
	{
		cin>>x;
		a.insert(x);
	}
	for (int i = 0; i < m; ++i)
	{
		cin>>y;
		b.insert(y);
	}
	if (a.size()!=n||b.size()!=m)
	{
		cout<<"0\n";
		return 0;
	}
	long long ans=1LL;
	set<int> c,d;
	for (int i = n*m; i > 0; --i)
	{
		if (a.count(i)==1)
		{
			c.insert(i);
			if (b.count(i)==1)
			{
				d.insert(i);
			}
			else
			{
				ans*=(long long)d.size();
				ans%=mod;
			}
		}
		else
		{
			if (b.count(i)==1)
			{
				d.insert(i);
				ans*=(long long)c.size();
				ans%=mod;
			}
			else
			{
				if (c.size()*d.size()-n*m+i<=0)
				{
					cout<<"0\n";
					return 0;
				}
				ans*=(long long)(c.size()*d.size()-n*m+i);
				ans%=mod;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
S=input()
P=[]
P.append(S[0])
S=S[1:]
while len(S)>0:
    for i in range(1,len(S)+1):
        if not S[0:i] == P[-1]:
            P.append(S[0:i])
            S=S[i:]
            break
    else:
        break
print(len(P))

Measured memory_bytes: 7916
N,M = map(int,input().split())
a = [0]*M
for i in range(M):
    a[i] = int(input())

step = [0]*(N+1)
step[0] = 1

for i in range(M):
    step[a[i]] = -1

if 1 in a:
    step[1] = 0
else:
    step[1] = 1

for i in range(2,N+1):
    if step[i] == -1:
        step[i] = 0
    else:
        step[i] = (step[i-1] + step[i-2])%(10**9+7)

print(step[N])

#再起関数供養
def count_step(a,n):
    if n == 0:
        return 1
    if n == 1 and 1 not in a:
        return 1
    if n in a:
        return 0
    return (count_step(a,n-1)+count_step(a,n-2))%(10**9+7)

Measured memory_bytes: 45144
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);
	    String s=gs();

	    //System.out.print(s.substring(s.length()-8));
	    if (s.contains("AC")) {
	    	System.out.print("Yes");
	    }else {
	    	System.out.print("No");
	    }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35656
/*#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
vector<vector<int>> g;
vector<bool> used;
vector<pair<int,int>> edges;
int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n>>
    }
}
*/
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    map<string,int> m;
    m.insert(pair<string,int>("AC",0));
    m.insert(pair<string,int>("WA",0));
    m.insert(pair<string,int>("TLE",0));
    m.insert(pair<string,int>("RE",0));
    while(n--){
        string s;
        cin>>s;
        m[s]++;
    }
    cout<<"AC x "<<m["AC"]<<endl;
    cout<<"WA x "<<m["WA"]<<endl;
    cout<<"TLE x "<<m["TLE"]<<endl;
    cout<<"RE x "<<m["RE"]<<endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000010;
constexpr ll INF= 2000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

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; }

ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}

// N^P mod M（ただしM == -1の時はmodを取らない）
template<typename T>
T RS(T N, T P, T M){
    if(P==0) return 1;
    if(P < 0) return 0;
    if(P%2==0){
        ll t = RS(N, P/2, M);
        if(M == -1) return t * t;
        return t * t % M;
    }
    if(M == -1) return N * RS(N,P - 1,M);
    return N * RS(N, P-1, M) % M;
}

int main() {
    ll N,K;
    cin >> N >> K;
    vector<ll> vec(N);
    for(int i = 0;i < N;i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(),vec.end());
    ll ng = -INF; //K未満
    ll ok = INF; //K以上
    ll mid;
    while(ok - ng > 1) {
        mid = (ng + ok) / 2;
        ll S = 0;
        ll T = 0;
        for(int i = 0;i < N;i++) {
            if(vec.at(i) > 0) {
                ll left = -1;
                ll right = N;
                ll mid2;
                while(right - left > 1) {
                    mid2 = (left + right) / 2;
                    if(vec.at(i) * vec.at(mid2) <= mid) {
                        left = mid2;
                    }
                    else {
                        right = mid2;
                    }
                }
                S += right;
            }
            else if(vec.at(i) < 0) {
                ll left = -1;
                ll right = N;
                ll mid2;
                while(right - left > 1) {
                    mid2 = (left + right) / 2;
                    if(vec.at(i) * vec.at(mid2) <= mid) {
                        right = mid2;
                    }
                    else {
                        left = mid2;
                    }
                }
                S += N - right;
            }
            else if(mid >= 0) {
                    S += N;
            }
            if(vec.at(i) * vec.at(i) <= mid) {
                T++;
            }
        }
        if((S - T) / 2 >= K) {
            ok = mid;
        }
        else {
            ng = mid;
        }
    }
    cout << ok << endl;
}

Measured memory_bytes: 4820
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

#[allow(dead_code)]
const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let q: usize = sc.cin();
    use std::collections::BTreeSet;
    let mut qs = vec![];
    for _ in 0..n {
        let s: i32 = sc.cin();
        let t: i32 = sc.cin();
        let x: i32 = sc.cin();
        qs.push((s-x, 1, x));
        qs.push((t-x, 0, x));
    }
    for _ in 0..q {
        let d: i32 = sc.cin();
        qs.push((d, 2, 0));
    }
    qs.sort();
    let mut xs = BTreeSet::new();
    for &q in qs.iter() {
        let (x, ty, val) = q;
        if ty == 1 {
            xs.insert(val);
        } else if ty == 0 {
            xs.remove(&val);
        } else {
            put!(match xs.iter().next() {
                Some(&y) => y,
                _ => -1
            });
        }
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 16128
#include <stdio.h>
#define N 100

int main(){
  int n,k,j,i,v;
  int A[N];
  
  
    scanf("%d",&n);

    for(k=0;k<n;k++){
    scanf("%d",&A[k]);
    }

    for(i=1;i<=n;i++){
      for(j=0;j<n;j++){
	if(j)printf(" ");
	printf("%d",A[j]);
      }
      printf("\n"); 
      
      v=A[i];
      j=i-1;
      
      while(j>=0 && A[j]>v){
	
	A[j+1]=A[j];
	j--;
      }
      A[j+1]=v;
     
    }

    return 0;    
}



Measured memory_bytes: 2080
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int mod = 1E9 + 7;
const int inf = 1 << 29;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  vector<bool> sieve(a[n - 1], true);
  int prev = -1;
  rep(i, n) {
    if (prev == a[i]) {
      sieve[a[i]] = false;
      continue;
    };
    int tmp = 2 * a[i];
    while (tmp <= a[n - 1]) {
      sieve[tmp] = false;
      tmp += a[i];
    }
    prev = a[i];
  }
  int cnt = 0;
  rep(i, n) {
    // cout << a[i] << ' ' << sieve[a[i]] << endl;
    if (sieve[a[i]]) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 4280
NOT_VISIT = 10**20
N, M = map(int,input().split())
graph = [[] for i in range(N)]

for i in range(M):
	L, R, D = map(int,input().split())
	graph[L-1].append((R-1,D))
	graph[R-1].append((L-1,-D))

visited = [NOT_VISIT for i in range(N)]

def dfs(start):
	global graph, visited

	if visited[start] != NOT_VISIT:
		return True

	stack = [start]
	visited[start] = 0
	while stack:
		label = stack.pop()
		for nextnode, distance in graph[label]:
			if visited[nextnode] == NOT_VISIT:
				stack.append(nextnode)
				visited[nextnode] = visited[label] + distance
			elif visited[nextnode] != visited[label] + distance:
				return False
	return True

res = True
for i in range(N):
	res &= dfs(i)

print("Yes" if res == True else "No")

Measured memory_bytes: 65976
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int n,m,k;
  cin >> n >> m >> k;
  vl sa(n+1,0);
  vl sb(m+1,0);
  rep(i,n) {
    ll a;
    cin >> a;
    sa.at(i+1)=sa.at(i)+a;
  }
  rep(i,m) {
    ll b;
    cin >> b;
    sb.at(i+1)=sb.at(i)+b;
  }
  int ans = 0;

  rep(i,n+1) {
    if(sa.at(i)>k) break;
    int t=i+upper_bound(rng(sb),k-sa.at(i))-sb.begin()-1;
    ans=max(ans,t);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6376
#include<iostream>
#include<cmath>
using namespace std;
struct Node{
	int x;
	int y;
	int t;
}N[100005];
int main()
{
 	int n,x,y,t,i,j;
 	N[0].x = N[0].y=N[0].t=0;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>N[i].t>>N[i].x>>N[i].y;
	}
	for(i=1;i<=n;i++){
		x = N[i].x-N[i-1].x;
		if(x<0){
			x = (-1)*x;
		}
		y = N[i].y-N[i-1].y;
		if(y<0){
			y = (-1)*y;
		}
		if( (((N[i].t-N[i-1].t)-x-y)<0) || (((N[i].t-N[i-1].t)-x-y)%2 !=0)){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
int main() {
    int n; cin >> n;
    int h[20];
    for (int i=0; i<n; i++) {
        cin >> h[i];
    }
    int res = 0;
    for (int i=0; i < n; i++) {
        bool flag = true;
        for (int j=0; j <= i; j++) {
            if (h[i] >= h[j]) continue;
            else {
                flag = false;
                break;
            }
        }
        if(flag == true) res++;
    }

    cout << res << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int n,a[100001],sum=0,len=1;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		if(a[i]==a[i+1])
		len++;
		else 
		{
			if(len<a[i])
			{
				sum=sum+len;
			  len=1;
			}
			else if(len>a[i])
			{
				sum=sum+len-a[i];
				len=1;
			}
			else 
			len=1;
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 888
import math
import queue

mod = 1e9+7

def swap(a,b):
    return (b,a)

def gcd(a,b):
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def divisors(a):
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def main():
    n = int(input())
    print(n**3)
    return

if __name__ == '__main__':
    main()

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

int main() {
    int ans = 700;
    string s;
    cin >> s;
    if (s[0] == 'o') {
        ans += 100;
    }
    if (s[1] == 'o') {
        ans += 100;
    }
    if (s[2] == 'o') {
        ans += 100;
    }

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

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RSORT(x) sort(x.begin(), x.end(), std::greater<int>())
#define swap(a, b) \
  do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
#define vi vector<int>
using namespace std;

const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main() {
  
  int N[4];
  REP(i,4)
    cin >> N[i];

  vi s;
  REP(i, 2)
    for(int j = 2; j < 4; j++)
      s.push_back(N[i] + N[j]);
  
  SORT(s);

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

#define int long long

#if defined(__GNUC__)
#define __int32 __int32_t
#endif // __GNUC__

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); (i)++)
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); (i)++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x))
#define RSORT(x, T) sort(ALL(x), greater<(T)>())
#define REVERCE(x) reverce(ALL(x))

itn main() {
	ios::sync_with_stdio(false);

	int n;

	cin >> n;

	string s;

	cin >> s;

	int cnt = 0;
	int j;

	REP(i, s.length()) {
		j = 1;
		while (s[i] == s[i + j]) {
			j++;
			if (j == n) {
				break;
			}
		}

		i += j - 1;
		cnt++;
	}

	cout << cnt;

	return 0;
}

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

using namespace std;

int main()
{
	int n; cin>>n;
	int arr[n];
	for(int i = 0; i<n; i++) cin>>arr[i]; 
	sort(arr,arr+n);
	int l = arr[0];
	int r = arr[n-1];
	
	int ans = INT_MAX;
	
	for(int i = l; i<=r; i++)
	{
		int cost = 0;
		
		for(int j = 0; j<n; j++)
			cost += (arr[j] - i)*(arr[j] - i);
		ans = min(ans,cost);
	}
	
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
h, w = map(int, input().split())
grid = []
bias_inf = 2000
for i in range(h):
    k = list(map(int, input().split()))
    grid.append(k)
for i in range(h):
    k = list(map(int, input().split()))
    for j in range(w):
        grid[i][j] = abs(grid[i][j] - k[j])

dp = [[[0 for i in range(-bias_inf,bias_inf)] for j in range(w)] for k in range(h)]
dp[0][0][0 - grid[0][0]] = 1
dp[0][0][0 + grid[0][0]] = 1
for i in range(h):
    for j in range(w):
        for k in range(-bias_inf,bias_inf):
            if i == h-1 and j == w-1:
                break
            if dp[i][j][k]:
                if i != h-1 and j != w-1:
                    dp[i][j+1][k + grid[i][j+1]] = 1
                    dp[i+1][j][k + grid[i+1][j]] = 1
                    dp[i][j+1][k - grid[i][j+1]] = 1
                    dp[i+1][j][k - grid[i+1][j]] = 1
                elif j == w-1:
                    dp[i+1][j][k - grid[i+1][j]] = 1
                    dp[i+1][j][k + grid[i+1][j]] = 1
                else:
                    dp[i][j+1][k - grid[i][j+1]] = 1
                    dp[i][j+1][k + grid[i][j+1]] = 1
ans = bias_inf
for i in range(-bias_inf,bias_inf):
    if dp[-1][-1][i]:
        ans = min(ans, abs(i))
print(ans)


Measured memory_bytes: 250760
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)
#define INF 1000000000
#define LINF (LL)INF * INF
#define pow10 tipa_pow10
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
int n , m , s , t;
vector<vector<pair<int , int> > > g1(100000) , g2(100000);
LL dist1[100000] , dist2[100000];
int main()
{
    cin >> n >> m >> s >> t;
    s--;t--;
    for(int i = 0; i < m; i++)
    {
        int u , v , a , b;
        cin >> u >> v >> b >> a;
        u--;v--;
        g1[u].pb({v , a});
        g1[v].pb({u , a});
        g2[v].pb({u , b});
        g2[u].pb({v , b});
    }
    memset(dist1 , -1 , sizeof dist1);
    memset(dist2 , -1 , sizeof dist2);
    priority_queue<pair<LL , int> > pq;
    pq.push({0 , t});
    dist1[t] = 0;
    while(!pq.empty())
    {
        int u = pq.top().second;
        LL d = -pq.top().first;
        pq.pop();
        if(d > dist1[u])
        {
            continue;
        }
        for(int i = 0; i < g1[u].size(); i++)
        {
            int v = g1[u][i].first , D = g1[u][i].second;
            if(dist1[v] == -1 || dist1[v] > dist1[u] + D)
            {
                dist1[v] = dist1[u] + D;
                pq.push({-dist1[v] , v});
            }
        }
    }


    pq.push({0 , s});
    dist2[s] = 0;
    while(!pq.empty())
    {
        int u = pq.top().second;
        LL d = -pq.top().first;
        pq.pop();
        if(d > dist2[u])
        {
            continue;
        }
        for(int i = 0; i < g2[u].size(); i++)
        {
            int v = g2[u][i].first , D = g2[u][i].second;
            if(dist2[v] == -1 || dist2[v] > dist2[u] + D)
            {
                dist2[v] = dist2[u] + D;
                pq.push({-dist2[v] , v});
            }
        }
    }
    vector<LL> ans;
    LL curAns = LINF;
    for(int i = n - 1; i >= 0; i--)
    {
        curAns = min(curAns , dist1[i] + dist2[i]);
        ans.pb(curAns);
    }
    LL val = (LL)INF * 1000000;
    for(int i = ans.size() - 1; i >= 0; i--)
    {
        cout << val - ans[i] << endl;
    }
  
}


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


bool palincheck(string &test, int i, int j)
{
  while(i<=j)
  {
    if(test[i] != test[j])
    {
      return false;
    }
    i++;
    j--;
  }
  return true;
}
int main()
{
  string test;
  cin>>test;
  int l = test.length();
  int i = 0;
  int j = test.length() - 1;
  if(palincheck(test,i,j) && palincheck(test,0,((l-1)/2)-1) && palincheck(test,(((l+3)/2) -1),(l-1)))
    {
       cout<<"Yes";
       return 0;
    }
    else
    {
        cout<<"No";
        return 0;
    }
         
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static System.Console;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C_Rally
{
    class Program
    {
        static void Main(string[] args)
        {
            int total = int.Parse(ReadLine());
            string input = ReadLine();
            string[] array = input.Split(' ');
            int[] n = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                n[i] = int.Parse(array[i]);
            }
            int count = 0;
            int check= 0 ;
            int result = n[0];
            int a = n[0];
            for (int i=0;i<total;i++) {
                for (int j = 0; j < a; j++) {
                    check = n[i] % 2;
                    n[i] = n[i] / 2;
                    
                    if (1 == check) {
                        check = 0;

                        if (count < result)
                        {
                            result = count;
                            count = 0;
                            break;
                        }
                        else
                        {
                            count = 0;
                            break;
                        }
                    }
                    count++;
                }
                
            
            }
            WriteLine("{0}", result);
            ReadKey();

        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n; ll w;
    ll wx, vx;
    map<ll, ll> dp = {{0, 0}}; // weight , value
    ll ans = 0;
    cin >> n >> w;
    for(int i = 0; i < n; i++) {
        map<ll, ll> new_dp;
        cin >> wx >> vx;
        for(auto it = dp.rbegin(); it != dp.rend(); ++it) {
            ll new_w = it->first + wx;
            new_dp[it->first] = max(new_dp[it->first], it->second);
            ans = max(ans, new_dp[it->first]);
            if (new_w <= w) {
                new_dp[new_w] = max(new_dp[new_w], it->second+vx);
                ans = max(ans, new_dp[new_w]);
            }
        }
        new_dp.swap(dp);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 640
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

N = int(input())
s = [0 for i in range(N)]
cnt = 0
chance = False
A_cnt = 0
B_cnt = 0
BA_cnt = 0
for i in range(N):
    s[i] = str(input())
    cnt += s[i].count("AB")
    if s[i][0] == "B" and s[i][-1]=="A":
        BA_cnt += 1
    elif s[i][0] == "B":
        B_cnt += 1
    elif s[i][-1] == "A":
        A_cnt += 1


if BA_cnt != 0 and A_cnt == 0 and B_cnt == 0:
    plus = BA_cnt - 1
elif BA_cnt != 0 and A_cnt == 0:
    plus = min(BA_cnt,BA_cnt+B_cnt)
elif BA_cnt != 0 and B_cnt == 0:
    plus = min(BA_cnt,BA_cnt+A_cnt)
else:
    plus = min(BA_cnt+A_cnt,BA_cnt+B_cnt)

cnt += plus

print(cnt)


Measured memory_bytes: 6992
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
  int a,b;
  cin >> a >> b;
  if(a%3 == 0 || b%3 == 0 || (a+b)%3 == 0)
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.text.*;


public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int r = sc.nextInt();

		double areaOne = Math.pow(r, 2);
		double areaTwo = Math.pow(1, 2);

		double answer = areaOne / areaTwo;

		System.out.println((int)answer);
	}
}

Measured memory_bytes: 23892
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
//#define INF 0x3f3f3f3f
#define INF 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//int arr[SIZE]={};
//ここまでテンプレ
signed main(){
	int N;
	cin>>N;
	vll a;
	for(int i=0;i<3*N;i++){
		ll c;
		cin>>c;
		a.pb(c);
	}
	priority_queue<ll,vector<ll>,greater<ll>> fro;
	priority_queue<ll> bac;
	ll fsum=0,bsum=0;
	for(int i=0;i<N;i++){
		fro.push(a[i]);
		fsum+=a[i];
	}
	for(int i=2*N;i<3*N;i++){
		bac.push(a[i]);
		bsum+=a[i];
	}
	ll f[3*SIZE]={},b[3*SIZE]={};
	f[N-1]=fsum,b[2*N]=bsum;
	for(int i=N;i<2*N;i++){
		fro.push(a[i]);
		fsum+=a[i];
		fsum-=fro.top();
		fro.pop();
		f[i]=fsum;
	}
	for(int i=2*N-1;i>=N;i--){
		bac.push(a[i]);
		bsum+=a[i];
		bsum-=bac.top();
		bac.pop();
		b[i]=bsum;
	}
	ll ans=-INF;
	for(int i=N-1;i<2*N;i++){
		ans=max(ans,f[i]-b[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11628
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solve()
{
   int x;int k;int d;cin>>x>>k>>d;
   x=abs(x);
   int kitna=x/d;
   
   
   if(k<=kitna)
   {
       x=x-k*d;
       cout<<x<<endl;
       return;
   }
   x=x%d;
   k=k-kitna;
   int rem=k%2;
   if(rem==1)
   {
       int temp1=x-d;
       int temp2=x+d;
       temp2=abs(temp2);
       temp1=abs(temp1);
       int ans=min(temp1,temp2);
       cout<<ans<<endl;
   }
   else
   cout<<x<<endl;
}
int32_t main()
{
    rapido;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    solve();
}


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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	int a=read(),b=read(),c=read(),k=read();
	if(k&1)swap(a,b);
	print(a-b);
}


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

void swap(int *x, int *y) {
	int fake;
	fake = *x;
	*x = *y;
	*y = fake;
}

int main()
{
	int a, b;
	
	int i = 0;
	while (i < 3000) {
		cin >> a >> b;

		if (a > b) {
			swap(a, b);
		}
		if (a == 0 && b == 0) {
			break;
		}
		cout <<  a << " " << b << "\n";
		i++;
	}
    return 0;
}




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

 int main(){
     int N, j = 0, k = 0, counter = 1;
     cin >> N;
     vector<int> a(N);
     for(int i = 0;i < N;i++){
         cin >> a.at(i);
     }
     for(;;){
         if(a.at(k) == 2){
             cout << counter << endl;
             break;
         }
         else if(a.at(k) == 0){
             cout << "-1" << endl;
             break;
         }
         j = k;
         k = a.at(k) -1;
         a.at(j) = 0;
         counter++;
     }
 }

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

using namespace std;

int main()
{
  int p, q;
  string str, buf;
  vector<string> vec;

  while(!cin.eof()){
    p = q = 0;
    buf = "";

    while(getline(cin, str) && str != "END_OF_TEXT") vec.push_back(str);
    while(getline(cin, str) && str != "-"){
      if(str == "a") q = 0;

      if(str == "e") q = vec[p].size();

      if(str == "p"){
	if(p > 0) --p;
	q = 0;
      }

      if(str == "n"){
	if(p < vec.size()-1) ++p;
	q = 0;
      }

      if(str == "f"){
	if(q < vec[p].size()) ++q;
	else if(q == vec[p].size() && p < vec.size()-1){
	  ++p;
	  q = 0;
	}
      }

      if(str == "b"){
	if(q > 0) --q;
	else if(q == 0 && p > 0){
	  --p;
	  q = vec[p].size();
	}
      }

      if(str == "d"){
	if(q == vec[p].size()){
	  if(vec.size()-1 > p){
	    vec[p] += vec[p+1];
	    vec.erase(vec.begin()+(p+1));
	  }
	} else if(q < vec[p].size()){
	  vec[p].erase(vec[p].begin()+q);
	}
      }

      if(str == "k"){
	if(q == vec[p].size()){
	  if(vec.size()-1 > p){
	    vec[p] += vec[p+1];
	    vec.erase(vec.begin()+(p+1));
	    buf = "\n";
	  }
	} else if(q < vec[p].size()){
	  buf = vec[p].substr(q);
	  vec[p] = vec[p].substr(0, q);
	}
      }

      if(str == "y" && buf.size()){
	if(buf == "\n"){
	  string s1 = vec[p].substr(0, q), s2 = vec[p].substr(q);
	  vec[p++] = s1;
	  vec.insert(vec.begin()+(p), s2);
	  q = 0;
	} else {
	  vec[p] = vec[p].substr(0, q)+buf+vec[p].substr(q);
	  q += buf.size();
	}
      }
    }

    for(int i = 0; i < vec.size(); ++i)
      cout << vec[i] << endl;
    
    buf.clear();
    vec.clear();
  }
  
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
class UnionFind {
private:
    int sz;
    vector<int> par, size_;
public:
    UnionFind(){}
    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x,int y){
        x = find(x), y = find(y);
        if(x == y) return;
        if(size_[x] < size_[y]) swap(x,y);
        par[y] = x;
        size_[x] += size_[y];
    }
    int size(int x){
        x = find(x);
        return size_[x];
    }
    bool same(int x,int y){
        return find(x) == find(y);
    }
};
struct edge{
    int to;
    ll cost;
};
vector<edge> g[5000];
int dp[5000][5000];
void dfs(const int s, int par,int t){
    for(auto &x : g[t]){
        if(x.to == par)continue;
        dp[s][x.to] = max(dp[s][t], (int)x.cost);
        dfs(s,t,x.to);
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<pair<ll,pii>>e;
    while(m--){
        int a,b;
        ll c;
        cin >> a >> b >> c;
        a--,b--;
        e.push_back({c,{a,b}});
    }
    sort(e.begin(),e.end());
    UnionFind uf(n);
    ll sum = 0;
    for(auto &x: e){
        if(!uf.same(x.second.first,x.second.second)){
            uf.unite(x.second.first,x.second.second);
            sum += x.first;
            int a = x.second.first;
            int b = x.second.second;
            ll c = x.first;
            g[a].push_back((edge){b,c});
            g[b].push_back((edge){a,c});
        }
    }
    show(sum);
    rep(i,n)dfs(i,-1,i);
    int q;
    cin >> q;
    while(q--){
        int s,t;
        cin >> s >> t;
        s--,t--;
        cout << sum - dp[s][t] << "\n";
    }
}

Measured memory_bytes: 89576
#include<iostream>
#include<string>
#include<cassert>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
#define el endl
int main(){
	int n;
	scanf("%d",&n);
	vector<int>x(n+1,0);
	for(int i=0;i<n-1;i++){
		int a;
		scanf("%d",&a);
		x[a]++;
	}
	for(int i=1;i<=n;i++)printf("%d\n",x[i]);
}

Measured memory_bytes: 4112
#include "bits/stdc++.h"
using namespace std;
int n;
int inp;
int cnt;
int main(){
    scanf("%d" , &n);
    cnt = 0;
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , &inp);
        cnt += (inp & 1);
    }
    if(cnt & 1){
        printf("NO\n");
    }
    else{
        printf("YES\n");
    }
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const ll INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(ll i=0;i<(ll)(s.size());++i) {
    cout << s[i];
    if(i == (ll)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  ll s, t, d; cin >> s >> t >> d;
  vi w(d);
  ll su = 0;
  ll mi = LINF;
  ll argmi = -1;
  for(ll i=0;i<d;++i) {
    cin >> w[i];
    su += w[i];
    if(mi > min(mi, su)) {
      mi = su;
      argmi = i;
    }
  }
  ll tmp1 = s - t;
  if(tmp1 + mi <= 0) {
    for(ll i=0;i<d;++i) {
      tmp1 += w[i];
      if(tmp1 <= 0) {
        cout << i + 1 << endl;
        break;
      }
    }
    return 0;
  }
  if(su >= 0) {
    cout << -1 << endl;
    return 0;
  }
  ll tmp2 = tmp1 + mi;
  ll cnt = (tmp2 - 1) / (-su) + 1;
  tmp2 = tmp1 + cnt * su;
  ll ans = cnt * d;
  for(ll i=0;i<d;++i) {
    ans++;
    tmp2 += w[i];
    if(tmp2 <= 0) {
      cout << ans << endl;
      return 0;
    }
  }
}



Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define MAX 100100


int main(void){
	int n;
	cin >> n;
	int p[MAX+10];

	for(int i = 0; i < MAX; i++){
		p[i] = 1;
	}
	p[0]=0; p[1]=0;
	for(int i = 2; i < sqrt(MAX); ++i){
		if(p[i]){
			for(int j = 2; j*i < MAX; ++j){
				p[j*i] = 0;
			}
		}
	}
	vector<int> rui(MAX);
	int count = 0;
	for(int j = 1; j <= MAX; j+=2){
		if(p[j]&&p[(j+1)/2]){
			count++;
		}
		rui[j] = count;
	}

	for(int i = 0; i < n; ++i){
		int l,r;
		cin >> l >> r;
		cout << rui[r] - rui[l-2] << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
fun solve(k: Int): Int {
    if (k % 2 == 0 || k % 5 == 0) {
        return -1
    }

    val d = IntArray(10)
    for (i in 1..10) {
        d[k * i % 10] = k * i
    }

    var cnt = 0
    var x = k
    while (x > 0) {
        if (x % 10 == 7) {
            cnt++
            x /= 10
            continue
        }

        x += d[(17 - x % 10) % 10]
    }
    return cnt
}

fun main() {
    val k = readLine()!!.toInt()
    println(solve(k))
}


Measured memory_bytes: 34556
s = input()

if s[0] == s[1] and s[2] == s[3] and s[1] != s[2]:
    print('Yes')
elif s[0] == s[2] and s[1] == s[3] and s[0] != s[1]:
    print('Yes')
elif s[0] == s[3] and s[1] == s[2] and s[0] != s[1]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064