akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
    public static void Main()
    {
        string[] s = Console.ReadLine().Split(' ');
        int x = int.Parse(s[0]);
        int y = int.Parse(s[1]);
        int z = int.Parse(s[2]);

        x = x - z;
        Console.WriteLine(x / (y + z));
    }
}


Measured memory_bytes: 13140
IDENTIFICATION DIVISION.
 PROGRAM-ID. TEST01.
 
 ENVIRONMENT DIVISION.

 DATA DIVISION.
 WORKING-STORAGE SECTION.
 
  01 INP.
    03 A      PIC 9(1).
    03 FILLER PIC X.
    03 B      PIC 9(1).
    03 FILLER PIC X.
    03 C      PIC 9(1).
  
  01 SW-KAWAISO PIC X(1).
 
 PROCEDURE DIVISION.

  ACCEPT INP.
  
  MOVE SPACE TO SW-KAWAISO.
  
  EVALUATE TRUE
   WHEN (A = B) AND (A NOT = C)
   WHEN (A = C) AND (A NOT = B)
   WHEN (B = C) AND (B NOT = A)
    MOVE '1' TO SW-KAWAISO  
   WHEN OTHER
    CONTINUE
  END-EVALUATE.
  
  IF SW-KAWAISO = '1'
    DISPLAY 'Yes'
  ELSE
    DISPLAY 'No'
  END-IF.
    
 STOP RUN.

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long lint;

lint ans[55];

int main(){
    lint K; cin >> K;

    for(int i=0;i<50;i++) ans[i] = i + K / 50;

    K %= 50;
    for(int i=0;i<K;i++){
        ans[i] += 50;
        for(int j=0;j<50;j++) if(i != j) ans[j]--;
    }

    cout << 50 << endl;
    for(int i=0;i<50;i++) cout << ans[i] << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k,q;
  cin>>n>>k>>q;
  vector<int> a(n);
  vector<long long> challenger(n,k);
  for(int i=0;i<q;i++){
    int a;
    cin>>a;
    a--;
    challenger[a]++;
  }
  for(int i=0;i<n;i++)challenger[i]-=q;
  for(int i=0;i<n;i++){
    if(challenger[i]>0){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4572
#include<iostream>
using namespace std;
long long int input;
int ans;

int main(){
	while(cin >> input, input){
		ans = 0 - input;
		for(int i=1; i*i <= input; i++){
			if(input % i == 0) ans += i + input/i;
			if(i == input/i && input % i == 0) ans -=i;
		}
		if(ans == input) cout << "perfect number" << endl;
		else if(ans < input) cout << "deficient number" << endl;
		else cout << "abundant number" << endl;
	}
}

Measured memory_bytes: 1156
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    auto a = make_vec<int>(3, 3);
    cin >> a[0][0] >> a[0][1] >> a[1][1];
    auto check = [&](int sum) {
                     int sum1 = 0, sum2 = 0;
                     rep(i, 3) sum1 += a[i][i];
                     rep(i, 3) sum2 += a[2][i];
                     return sum1 == sum && sum2 == sum;
                 };
    for (int x = -1000; x <= 1000; ++x) {
        a[0][2] = x;
        int sum = 0;
        rep(i, 3) sum += a[0][i];
        a[2][1] = sum - a[0][1] - a[1][1];
        a[2][0] = sum - a[0][2] - a[1][1];
        a[1][0] = sum - a[0][0] - a[2][0];
        a[1][2] = sum - a[1][0] - a[1][1];
        a[2][2] = sum - a[2][0] - a[2][1];
        if (check(sum)) {
            rep(i, 3) {
                rep(j, 3) {
                    cout << a[i][j] << (j == 2 ? '\n' : ' ');
                }
            }
        }
    }
}


Measured memory_bytes: 256
def solver(N,S):
    ACs = S.count("AC")
    WAs = S.count("WA")
    TLEs = S.count("TLE")
    REs = S.count("RE")
    print("AC x",ACs)
    print("WA x",WAs)
    print("TLE x",TLEs)
    print("RE x",REs)

N = int(input())
S = []
for i in [0] * N:
    S.append(input())
solver(N,S)

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

using namespace std;

int main(){
  int N,M; cin >> N >> M;
  int max_L = 0;
  int min_R = N;
  for(int i = 0; i < M; i++){
    int L,R;
    cin >> L >> R;
    if(L > max_L) max_L = L;
    if(R < min_R) min_R = R;
  }
  if(min_R >= max_L)
    cout << min_R - max_L + 1 << endl;
  else
    cout << 0 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001000
#define mod 1000000007
#define pi 3.1415926535
using namespace std;

int main(void){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ake = 0;
    ll toji = 0;
    rep(i,n){
        if(s[i] == '('){
            ake++;
        }
        else{
            if(ake > 0) ake--;
            else toji++;
        }
    }
    rep(i,toji) cout<<'(';
    cout<<s;
    rep(i,ake) cout<<")";
    cout<<endl;
}

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

map<int, int> o;
vector<int> v;
set<int> s;

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    o[x]++;
    o[x] %= 2;
    v.push_back(x);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (o[v[i]] == 1 && s.find(v[i]) == s.end()) {
      ans++;
      s.insert(v[i]);
    }
  }
  printf("%d", ans);
}

Measured memory_bytes: 9976
#define _USE_MATH_DEFINES // for C++  
#include "bits/stdc++.h"
#define NUM ((long long)1000000007)
#define int long long

using namespace std;

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

    int x;
    cin >> x;

    int tmp = 0;

    for (size_t i = 1; i <= x; i++)
    {
        for (size_t j = 2; j <= x + 1; j++)
        {
            auto tmpp = pow(i, j);
            if (tmpp <= x && tmpp > tmp)
            {
                tmp = tmpp;
            }
        }
    }
    cout << tmp << endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
	int w, num[31], n, a[31], b[31], i, temp;
	
	scanf("%d", &w);
	
		for(i=1;i<=w;i++){
		a[i]=i;
		b[i]=i;
		num[i]=i;
	}
	
	scanf("%d", &n);
	
	for(i=1;i<=n;i++){
		scanf("%d,%d", &a[i], &b[i]);
	    temp=num[a[i]];
	    num[a[i]]=num[b[i]];
	    num[b[i]]=temp;
	}
	
	for(i=1;i<=w;i++){
		printf("%d\n", num[i]);
	}
	
	return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  if (A == B)
    cout << C << endl;
  else if (B == C)
    cout << A << endl;
  else if (C == A)
    cout << B << endl;
  return 0;
}

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

#define NIL -1

struct Node {
    int parent = NIL, left = NIL, right = NIL;
};
Node t[100010];
int n, d[100010];

void print(int u){
    int i,c;
    cout << "node " << u << ": ";
    cout << "parent = " << t[u].parent << ", ";
    cout << "depth = " << d[u] << ", ";

    if(t[u].parent == NIL) cout << "root, ";
    else if(t[u].left == NIL) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";

    for(int i=0, c=t[u].left; c!=NIL;i++, c=t[c].right){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;

    return;
}

void rec(int u,int p){
    d[u] = p;
    if(t[u].right != NIL) rec(t[u].right, p); //右の兄弟に同じ深さを設定
    if(t[u].left != NIL) rec(t[u].left, p+1); //最も左の子に自分の深さ+1を設定
    
    return;
}

int main() {
    int c,id,k,root,last;
    cin >> n;
    
    for(int i=0;i<n;i++){
        cin >> id >> k;
        for(int j=0;j<k;j++){
            cin >> c;
            if(j == 0)t[id].left = c;
            else t[last].right = c;
            last = c;
            t[c].parent = id;
        }
    }
    for(int i=0;i<n;i++){
        if(t[i].parent == NIL) root = i;
    }

    rec(root,0);

    for(int i=0;i<n;i++) print(i);
    return 0;
}


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

int main() {
    int n;
    cin>>n;
    int count=0,max=0,answer=0;

    rep(i,1,n+1){
        int x=i;
        while(x%2==0){
            x/=2;
            count++;
            }
        if(count>=max){
            max=count;
            answer=i;
        }
        count=0;
    }
    cout<<answer<<endl;
}

Measured memory_bytes: 256
import sys
import collections
input = sys.stdin.readline


def log(*args):
    print(*args, file=sys.stderr)


def main():
    n = int(input())
    a = map(int, input().rstrip().split())
    ans = 0
    candidates = collections.deque()
    for v in sorted(a, reverse=True):
        if not candidates:
            candidates.appendleft(v)
            continue
        if candidates[-1] > v:
            v2 = candidates.pop()
            ans += v2
            candidates.appendleft(v)
            candidates.appendleft(v)
        else:
            candidates.appendleft(v)
            ans += v
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32516
fn main() {
    let q = read::<u32>();
    let v = read_vec2::<usize>(q);
    let mut arr = [0;100001];
    let mut count = 0;
    arr[1] = 0;
    for i in 3..100001 {
        if i % 2 == 0 { continue; }
        if is_prime(i) && is_prime((i+1)/2) {
            count += 1;
        }
        arr[i as usize] = count;
    }

    for v in v {
        let l = v[0] as usize;
        let r = v[1] as usize;
        if l > 1 && arr[l] > arr[l-2] {
            println!("{}", arr[r]-arr[l]+1);
        } else {
            println!("{}", arr[r]-arr[l]);
        }
    }
}

fn is_prime(n:u32) -> bool {
    if n == 1 { return false; }
    let mx = (n as f64).sqrt().floor() as u32 + 1;
    for i in 2..mx {
        if n%i==0 {
            return false;
        }
    }
    true
}

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 read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}


Measured memory_bytes: 9212
import java.util.Scanner;
import java.util.TreeMap;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        String s = scanner.next();
        if (s.startsWith("S")) {
            System.out.println("Cloudy");
        } else if (s.startsWith("C")) {
            System.out.println("Rainy");
        } else {
            System.out.println("Sunny");
        }
    }
}



Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <string>
#include <unordered_map>
using namespace std;


int main() {

    string N;
    cin >> N;

    if (N[0] == '7' ||    N[1] == '7' ||    N[2] == '7' ) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }


    return 0;
}


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

int func(int x)
{
    if(x%2==0)
    {
        return x/2;
    }
    else
    {
        return 3*x+1;
    }
}
int main()
{
    string s;
    cin>>s;
    bool flag = true;
    sort(s.begin(),s.end());
    for(int i=0;i<s.size();i++)
    {
        if(s[i]==s[i+1])
        {
            flag = false;
        }
    }

    if(flag)
    {
        cout<<"yes"<<endl;
    }
    else
    {
        cout<<"no"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(raw_input())



FORMAT = ('node {0.id}: parent = {0.parent}, sibling = {0.sibling}, degree = {0.degree}, depth = {0.depth}, height = {0.height}, {0.type}').format

class Node:
    def __init__(self):
        self.id = -1
        self.parent = -1
        self.left = -1
        self.right = -1
        self.sibling = -1
        self.degree = 0
        self.depth = 0
        self.height = 0
        self.type = 'leaf' if self.height == 0 else 'internal node'
        
    def setType(self):
        if self.height == 0 and self.parent != -1:
            self.type = 'leaf'
        elif self.parent == -1:
            self.type = 'root'
        else:
            self.type = 'internal node'

    def __str__(self):
        return FORMAT(self)

def setHeight(T,u):
    h1 = h2 = 0
    if T[u].right != -1:
        h1 = setHeight(T, T[u].right) + 1
    if T[u].left != -1:
        h2 = setHeight(T, T[u].left) + 1
    T[u].height = max(h1, h2)
    return T[u].height

def setDepth(u, d):#(0,0)
    T[u].depth = d
    if T[u].left == -1 and T[u].right == -1:
        return
    if T[u].left != -1 and T[u].right == -1:
        setDepth(T[u].left, d+1)
    elif T[u].left == -1 and T[u].right != -1:
        setDepth(T[u].right, d+1)
    else:
        setDepth(T[u].left, d+1)
        setDepth(T[u].right, d+1)

T = [Node() for _ in xrange(n)]

for i in xrange(n):
    a = map(int, raw_input().split())
    u = a[0]
    l = a[1]
    r = a[2]
    T[u].id = u
    T[u].left = l  #set child
    T[u].right = r  #set child
    if l != -1 and r != -1:
        T[l].parent = u  #set parent
        T[r].parent = u  #set parent
    elif l != -1 and r == -1:
        T[l].parent = u  #set parent
    elif l == -1 and r != -1:
        T[r].parent = u  #set parent

    if l != -1 and r != -1:
        T[u].degree = 2
        T[l].sibling = r
        T[r].sibling = l
    elif l != -1 and r == -1:
        T[u].degree = 1
    elif  l == -1 and r != -1:
        T[u].degree = 1

N = 0
for i in xrange(n):
    if T[i].parent == -1:
        N = T[i].id

setHeight(T, N)
setDepth(N, 0)


for i in xrange(n):
    T[i].setType()
    print T[i]

Measured memory_bytes: 6548
n = int(input())
al = [int(i) for i in input().split()]  
al.sort()
ma = al[-1]
from collections import Counter
c = Counter(al)

if n == 1:
  print(1)
else:
  sn = set()
  total = 0
  l = len(al)
  for num in al:
    if num in sn:
      continue
    if c[num] == 1:
      total += 1
    tmp = num
    while tmp <= ma:
      sn.add(tmp)
      tmp += num
  print(total)



Measured memory_bytes: 103264
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//Main
	static void Main(string[] args)
	{
		//読み込む
		string S = Console.ReadLine();
		int N = int.Parse(S);

		//バケツを用意
		int[] bucket = new int[N];

		//ループ計算（それぞれ高々10^2までで大丈夫）
		for(int i=1; i<=100; i++){
			for(int j=1; j<=100; j++){
				for(int k=1; k<=100; k++){
					int prod = i*i +  j*j + k*k + i*j + j*k + k*i;
					int idx = prod - 1;
					if(idx >= N){
						break;
					}
					else{
						bucket[idx]++;
					}
				}
			}
		}

		//出力
		//出力準備（AutoFlushを切る）
		var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
		Console.SetOut(sw);

		/*
		出力処理の開始
		*/
		foreach(int ans in bucket){
			Console.WriteLine(ans);
		}
		/*
		出力処理の完了
		*/

		//出力終了
		Console.Out.Flush();
	}
}



Measured memory_bytes: 17712
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>
 
#define rep(i,a,n) for(int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long
 
using namespace::std;
int main(){
 
  int N;
  cin>>N;
  if(N<10) cout<<N;
  else if(N<100) cout<<9;
  else if(N<1000) cout<<9+(N-99);
  else if(N<10000) cout<<9+900;
  else if(N<100000) cout<<9+900+(N-9999);
  else cout<<9+900+90000;
  
}
// int *p = new int[N];
 
// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));
 
//

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int a, b, c;
  int max = 0;

  scanf("%d %d %d", &a, &b, &c);

  if(a>max) max = a;
  if(b>max) max = b;
  if(c>max) max = c;

  if(max == a+b+c-max){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define VI vector<int> 
#define SI set<int>
#define QI queue<int> 
#define PB push_back
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define M 1000000007
using namespace std;

int main()
{
    FIO
    int a,b,c;
    cin>>a>>b>>c;
    if (a+b+c >= 22)
    {
        cout<<"bust";
    }
    else
        cout<<"win";
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void judge(int,int);

int num[3];

int main(){
  int i;
  
  for(i=0;i<3;i++) scanf("%d",&num[i]);
  
  judge(0,1);
  judge(1,2);
  judge(0,1);

  printf("%d %d %d\n",num[0],num[1],num[2]);

  return 0;
}

void judge(int a,int b){
  int tmp;
  if(num[a]>num[b]){
    tmp=num[a];
    num[a]=num[b];
    num[b]=tmp;
  }
}


Measured memory_bytes: 2076
#include<stdio.h>
int main()
{
int p,q,r,x,y,z;
scanf("%d%d%d",&p,&q,&r);
x=p+q;
y=q+r;
z=p+r;
if(x<=y && x<=z)
printf("%d",x);
else if(y<=x && y<=z)
printf("%d",y);
else
printf("%d",z);
return 0;
}


  
      

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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

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

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 1000001;

int X;
set<int> primes;
bitset<1000000> prime;

void sieve() {
    prime.set();
    FOR(i, 2, 1000000) {
        if(prime[i]) {
            primes.insert(i);
            for (int j = i * 2; j < 1000000; j += i) {
                prime[j] = 0;
            }
        }
    }
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    sieve();
    cin >> X;
    cout << *(primes.lb(X));
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007

int main() {
    int n, m, a[60], b[60], c[60], d[60];
    cin >> n >> m;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < m; ++i)
    {
        cin >> c[i] >> d[i];
    }
    for (int i = 0; i < n; ++i)
    {
        int mi = M, miid = -1;
        for (int j = 0; j < m; ++j)
        {
            if (mi > abs(a[i] - c[j]) + abs(b[i] - d[j]))
            {
                mi = abs(a[i] - c[j]) + abs(b[i] - d[j]);
                miid = j;
            }
        }
        cout << miid + 1 << "\n";
    }
    return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int x;
    cin >> x;
    cout << (x == 3 || x == 5 || x == 7 ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
def answer_143c():
    n = int(input())
    s = input()

    # aaa|bbb|ccが3であることを数えるには2つ方法がある。
    # (1)連続する文字を一つのグループとみなして、その境界を数える。
    # (2)隣り合ったものを本当に削除する→そういう関数があれば使う
    # 境界が二つあればグループは3つ。

    ans = 0

    # 境界は最後の要素の一つ前までチェックすればよい。
    for i in range(n-1):
        if s[i] != s[i + 1]:
            ans += 1
    print(ans + 1)
    
if __name__ == '__main__':
    answer_143c()

Measured memory_bytes: 3316
K = int(input())

if K%2 == 0 or K%5 == 0:
    print(-1)
else:
    if K%7 == 0:
        L = 9*K//7
    else:
        L = 9*K
    i = 1
    A = 10
    while i < 9000000:
        re = A%L
        if re == 1:
            print(i)
            break
        else:
            A = re*10
            i += 1
    else:
        print(-1)

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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int count{};
  for (int i{min(A, B)}; i >= 1; --i) {
    if (!(A % i) && !(B % i)) {
      if (++count == K) {
        cout << i << endl;
        break;
      }
    }
  }

  return 0;
}


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

struct P
{
    public bool y;
    public long l;
    public P(bool y,long l)
    {
        this.y=y;
        this.l=l;
    }
}

class Program
{
    private int W,H;
    private P[] PQ;
    
    private void Scan()
    {
        var l=Console.ReadLine().Split(' ');
        W=int.Parse(l[0]);
        H=int.Parse(l[1]);
        PQ=new P[H+W];
        for(int i=0;i<W;i++)
        {
            PQ[i]=new P(false,int.Parse(Console.ReadLine()));
        }
        for(int i=0;i<H;i++)
        {
            PQ[i+W]=new P(true,int.Parse(Console.ReadLine()));
        }
    }
    
    private void Calc()
    {
        Array.Sort(PQ,(aa,bb)=>aa.l.CompareTo(bb.l));
        long ans=0;
        long a=W+1;
        long b=H+1;
        foreach(var p in PQ)
        {
            if(!p.y)
            {
                ans+=b*p.l;
                a--;
            }
            else
            {
                ans+=a*p.l;
                b--;
            }
        }
        Console.WriteLine(ans);
    }
    
    public void Solve()
    {
        Scan();
        Calc();
    } 
    
    static void Main()
    {
        new Program().Solve();
    }
}

Measured memory_bytes: 18268
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>

int main(){
	long long n, p;
	long long ans=1;
	long long tp;

	std::vector<bool> isPrime(1000001, true);
	std::vector<long long> prime;
	std::vector<long long> numPrime;

	std::cin>>n>>p;
	tp=p;

	isPrime[0]=false;
	isPrime[1]=false;

	for(long long i=2; i<1000001; i++){
		if(!isPrime[i])
			continue;

		prime.push_back(i);

		for(long long j=2*i; j< 1000001; j+=i){
			isPrime[j]=false;
		}
	}

	numPrime.resize(prime.size(), 0);

	for(long long i=0; i<prime.size(); i++){
		if(p==1)
			break;

		while(p%prime[i]==0){
			p/=prime[i];
			numPrime[i]++;
		}
	}
	
	for(long long i=0; i<prime.size(); i++){
		if(numPrime[i]<n)
			continue;

		long long tmp= numPrime[i]/n;
		ans*= std::pow(prime[i], tmp);		
	}

	if(n==1)
		ans=tp;

	std::cout<<ans<<std::endl;

	return 0;
}

Measured memory_bytes: 1780
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
        int n = sc.nextInt();
        int count = 0;
        for(int i=0; i*r<=n; i++){
          if(i*r==n) {
            count++;
            //System.out.println("("+i+")");
            break;
          }
          for(int j=0; i*r+j*g<=n; j++){
            if(i*r+j*g==n){
              count++;
              //System.out.println("("+i+","+j+")");
              break;
            }
            if((n-(i*r+j*g))%b == 0){
              count++;
              //System.out.println("("+i+","+j+")");
            }
          }
        }
		System.out.println(count);
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
const long long INF = 1ll << 60;

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


int main() {
  int K,S;
  cin >> K >> S;

  int ans = 0;

  rep(i,K+1)rep(j,K+1){
    int t = i + j;
    if(S - t >= 0 && S - t <= K) ans++;

  }

  cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>
#include <stack>
#include <cassert>

// aliases
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

// graph
using Graph = Vvec<int>;
class Edge{
public:
    int to;
    long long cost;
    Edge(int v, long long c = 1): to(v), cost(c){}
    ~Edge(){}
    bool operator<(const Edge& e) const{return cost < e.cost;}
};
using WeightedGraph = Vvec<Edge>;

// for debug
template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

ll count(int& e, vector<int>& v){
    ll ret = 0;
    for(auto& f: v){
        if(e == f) ret++;
    }
    return ret;
}

// answer
int main()
{
    constexpr ll sz = 3e5+3;
    int H, W, M;
    cin >> H >> W >> M;
    vector<int> h(M), w(M), ch(sz), cw(sz);
    for(int i=0; i<M; i++){
        cin >> h[i] >> w[i];
        ch[h[i]]++;
        cw[w[i]]++;
    }

    int mh = *max_element(ch.begin(), ch.end());
    int mw = *max_element(cw.begin(), cw.end());
    ll c = count(mh, ch) * count(mw, cw);

    for(int i=0; i<M; i++){
        if(ch[h[i]] == mh && cw[w[i]] == mw){
            c--;
        }
    }
    
    cout << ((c == 0) ? mh+mw-1 : mh+mw) << "\n";
}

Measured memory_bytes: 7632
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

int main()
{
	int n, k;
	cin >> n >> k;
	int current = 1;

	REP(i, n){
		if (current + k < current * 2){
			current += k;
		}
		else current *= 2;

	}

	cout << current << endl;


}


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

#pragma warning(disable : 4996)

using namespace std;

int H, W, R[100][100];

const int dx0[6] = { 0, 1, 1, 1, 0, -1 };
const int dx1[6] = { -1, 0, 1, 0, -1, -1 };

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

int main()
{
	scanf("%d", &W);
	scanf("%d", &H);

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			scanf("%d", &R[i][j]);
		}
	}

	int count_ = 3;

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (R[i][j] == 0)
			{
				queue<pair<int, int> > que; que.push(make_pair(j, i));

				while (!que.empty())
				{
					pair<int, int> now = que.front(); que.pop();

					int x = now.first;
					int y = now.second;

					if (R[y][x] == 0)
					{
						R[y][x] = count_;

						for (int dir = 0; dir < 6; dir++)
						{
							int sx, sy = y + dy[dir];

							if (y % 2 == 0)
							{
								sx = x + dx0[dir];
							}
							else
							{
								sx = x + dx1[dir];
							}

							if (0 <= sx && sx < W && 0 <= sy && sy < H)
							{
								if (R[sy][sx] == 0)
								{
									que.push(make_pair(sx, sy));
								}
							}
						}
					}
				}

				bool ok = false;

				for (int k = 0; k < H; k++)
				{
					for (int l = 0; l < W; l++)
					{
						if (R[k][l] == count_)
						{
							for (int dir = 0; dir < 6; dir++)
							{
								int sx, sy = k + dy[dir];

								if (k % 2 == 0)
								{
									sx = l + dx0[dir];
								}
								else
								{
									sx = l + dx1[dir];
								}

								if (!(0 <= sx && sx < W && 0 <= sy && sy < H))
								{
									ok = true;
								}
							}
						}
					}
				}

				if (ok)
				{
					for (int k = 0; k < H; k++)
					{
						for (int l = 0; l < W; l++)
						{
							if (R[k][l] == count_)
							{
								R[k][l] = 2;
							}
						}
					}
				}

				count_++;
			}
		}
	}

	int ret = 0;

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			for (int dir = 0; dir < 6; dir++)
			{
				int sx, sy = i + dy[dir];

				if (i % 2 == 0)
				{
					sx = j + dx0[dir];
				}
				else
				{
					sx = j + dx1[dir];
				}

				if (0 <= sx && sx < W && 0 <= sy && sy < H)
				{
					if (R[i][j] == 2 && R[sy][sx] == 1)
					{
						ret++;
					}
				}
				else if(R[i][j] == 1)
				{
					ret++;
				}
			}
		}
	}

	printf("%d\n", ret);

	return 0;
}

Measured memory_bytes: 3272
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1},
};
use std::collections::VecDeque;

const INF: usize = 999999999;

fn dfs(cur: usize, prev: usize, v: &Vec<Vec<usize>>, res: &mut Vec<usize>) {
   let mut dq = VecDeque::new();
   dq.push_front((0, 0));
   while dq.len() != 0 {
      let (pr, pop) = dq.pop_back().unwrap();
      if res[pop] != INF {
         continue;
      }
      res[pop] = pr;
      for i in &v[pop] {
         if *i == pr {
            continue;
         }
         dq.push_front((pop, *i));
      }
   }
}

fn main() {
   input! {
      n:usize,m:usize,
      r:[(Usize1,Usize1);m]
   }
   let mut v = vec![vec![]; n];
   for &(a, b) in &r {
      v[a].push(b);
      v[b].push(a);
   }
   let mut ans = vec![INF; n];
   dfs(0, 0, &v, &mut ans);
   println!("Yes");
   for i in ans.iter().skip(1) {
      println!("{}", *i + 1);
   }
}


Measured memory_bytes: 20032
package main

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

var (
	sc      = bufio.NewScanner(os.Stdin)
	n, m    int
	arr     = make([]bool, 101010)
	dp      = make([]int64, 101010)
	visited = make([]bool, 101010)
)

const mod = 1000000007

func init() {
	sc.Split(bufio.ScanWords)
}

func input() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func dfs(node int) int64 {
	if arr[node] {
		return 0
	}

	if visited[node] {
		return dp[node]
	}

	if node > n {
		return 0
	}

	if node == n {
		return 1
	}

	var ans int64
	ans += dfs(node + 1)
	ans += dfs(node + 2)
	ans %= mod

	visited[node] = true
	dp[node] = ans
	return ans
}

func main() {
	fmt.Scan(&n, &m)
	for i := 0; i < m; i++ {
		arr[input()] = true
	}
	fmt.Println(dfs(0))
}

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

int main() {
  int N;
  int a[110];
  cin >> N;
  for (int i = 0; i<N; ++i) cin >> a[i];
  
  sort(a,a+N,greater<int>());
  int Alice = 0;
  int Bob = 0;
  for (int i = 0; i<N;++i) {
    if (i%2 == 0) {
      Alice += a[i];
    }
    else {
      Bob += a[i];
    }
  }
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
 
class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size
 
        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod
 
    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod
 
    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod
 
    def nhr(self, n, r):  # 重複組合せ
        return self.ncr(n + r - 1, n - 1)
 
    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]
 
    def factInvN(self, n):
        if n < 0:
            return 0
        return self.factInv[n]
 
N = int(input())
MOD = 10**9 + 7
comb = Combination(N + 100)
 
edges = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    fr, to = map(int, input().split())
    edges[fr].append(to)
    edges[to].append(fr)
 
order = []
parent = [0] * (N + 1)
st = [1]
while st:
    now = st.pop()
    order.append(now)
    for to in edges[now]:
        if to == parent[now]:
            continue
        st.append(to)
        parent[to] = now
 
size = [1] * (N + 1)
for v in order[::-1]:
    size[parent[v]] += size[v]
 
dpLeaf = [1] * (N + 1)
for v in order[:: -1]:
    pr = parent[v]
    dpLeaf[v] = dpLeaf[v] * comb.fact[size[v] - 1] % MOD
    dpLeaf[pr] = dpLeaf[pr] * dpLeaf[v] * comb.factInv[size[v]] % MOD
 
ans = [0] * (N + 1)
ans[1] = dpLeaf[1]
for v in order[1:]:
    pr = parent[v]
    ans[v] = ans[pr] * comb.inv[N - size[v]] * size[v] % MOD
 
print(*(ans[1:]), sep='\n')


Measured memory_bytes: 86616
# Dinic's algorithm
# https://tjkendev.github.io/procon-library/python/max_flow/dinic.html
from collections import deque
class Dinic:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def bfs(self, s, t):
        self.level = level = [None]*self.N
        deq = deque([s])
        level[s] = 0
        G = self.G
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        return level[t] is not None

    def dfs(self, v, t, f):
        if v == t:
            return f
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        INF = 10 ** 9 + 7
        # G = self.G
        while self.bfs(s, t):
            *self.it, = map(iter, self.G)
            f = INF
            while f:
                f = self.dfs(s, t, INF)
                flow += f
        return flow


n = int(input())
dinic = Dinic(2 * n + 2) # (始点, 終点) = (2n, 2n + 1)
AB = [list(map(int, input().split())) for _ in range(n)]
CD = [list(map(int, input().split())) for _ in range(n)]
# 条件を満たすノード同士を繋ぐ
for i in range(n):
    a, b = AB[i]
    dinic.add_edge(2 * n, i, 1)
    for j in range(n):
        if i == 0:
            dinic.add_edge(n + j, 2 * n + 1, 1)
        c, d = CD[j]
        if a < c and b < d:
            dinic.add_edge(i, n + j, 1)

print(dinic.flow(2 * n, 2 * n + 1))

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_b() {
	ll n, m;
	//ll x, y;
	//ll a, b, c;
	//ll k;
	string s;
	ll l_ans = 0;
	float f_ans = 0;
	string s_ans;

	cin >> s;

	ll start = -1;
	rep(i, s.size()) {
		if (s[i] == 'A' && start == -1) {
			start = i;
		}
		else if (s[i] == 'Z' && start != -1) {
			l_ans = i - start + 1;
		}
	}

	cout << l_ans << "\n";
}

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

	solve_abc_b();

	return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    FOR(i, k, n) {
        // debug(i, i-k);
        if (a[i]>a[i-k]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
    int f = 0, ch = 0; x = 0;
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    if(f) x = -x;
}
#define int ll
#define par pair<int, int>
#define fi first
#define se second
par f[(1<<19)+105]; 
main(){
	int n; read(n);
	for(int i = 0; i < (1 << n); i++) read(f[i].fi);
	for(int j = 0; j < n; j++)
		for(int i = 1; i < (1 << n); i++){
			if(i & (1 << j)){
				par now = f[i^(1<<j)];
				if(now.fi > f[i].fi){
					f[i].se = Max(f[i].fi, now.se);
					f[i].fi = now.fi;
				}
				else f[i].se = Max(f[i].se, now.fi);	
			}
		}
	for(int i = 1; i < (1 << n); i++){
		//cout << i << " " << f[i].fi << " " << f[i].se << endl;
		par now = f[i-1];
		if(now.fi + now.se > f[i].fi + f[i].se) f[i] = now;
		printf("%lld\n", f[i].fi + f[i].se);
	}
	return 0;
}


Measured memory_bytes: 9216
N,K = map(int,input().split())
A = list(map(int,input().split()))
x = 1
step = 0
count = [0]*N
count[0] += 1
memo = [-1]*N
memo[0] = 0
M = K
flag = 0
for i in range(M):
    x = A[x-1]
    count[x-1] += 1
    step += 1
    K -= 1
    if memo[x-1] != -1:
        s = memo[x-1]
        t = step-s
#        print(s,t)
        flag = 1
        break
    memo[x-1] = step
#    print(step,x,count,memo)
if flag == 0:
    print(x)
else:
    if t>= 1:
        K %= t
    else:
        K = 1
    for i in range(K):
        x = A[x-1]
    print(x)

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

int main() {
	int n, q;
	while (cin >> n >> q, n) {
		vector<pair<pair<int, int>, string>> v;
		for (int i = 0; i < n; i++) {
			string s;
			int a, b;
			cin >> s >> a >> b;
			v.push_back(make_pair(make_pair(b - a, b), s));
		}
		for (int i = 0; i < q; i++) {
			int a;
			cin >> a;
			bool f = false;
			for (auto it = begin(v); it != end(v); it++) {
				if (it->first.first < a && a <= it->first.second) {
					cout << it->second << " " << a - it->first.first << endl;
					f = true;
					break;
				}
			}
			if (!f) {
				cout << "Unknown" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3208
#include <stdio.h>
#include <string.h>
int main(){
  char	s[100+1]={0}, f[2]={0}, e[2]={0}, buff[8]={0};
  int	len;
  scanf("%s",s);
  
  len=strlen(s);
  strncpy(f, s, 1);
  strncpy(e, &s[len-1], 1);
  
  sprintf(buff, "%s%d%s", f, len-2, e);
  printf("%s\n", buff);
  
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int>P;

#define INF INT_MAX;
#define F first
#define S second

int n;
int h[100005];
int dp[100005];

int main(){

  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&h[i]);
  }

  dp[1]=abs(h[1]-h[0]);
  for(int i=2;i<n;i++){
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
  }

  printf("%d\n",dp[n-1]);

  return 0;
}


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

int h,n,a[1010],b[1010],dp[10010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>h>>n;
	for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
	for(int i=1;i<=h;i++) dp[i]=INF;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=n;j++){
			if(i-a[j]<0) dp[i]=min(dp[i],b[j]);
			else dp[i]=min(dp[i],dp[i-a[j]]+b[j]);
		}
	}
	cout<<dp[h]<<endl;
	return 0;
}

Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0: 
        break
    a, smin, smax=0, 1001, -1
    for i in range(n):
        s = int(input())
        a += s
        if s < smin:
            smin = s
        if s > smax:
            smax = s
        
    print((a-smin-smax)//(n-2))


Measured memory_bytes: 5604
#include<stdio.h>
int main(void)
{
    int t,s,f,i,x,y,n,z;
	
    while(1){
	    scanf("%d",&t);
		if(t==0){
        	break;
		}
		scanf("%d",&n);
		x=0;
		for(i=1;i<=n;i++){
			scanf("%d %d",&s,&f);
			x=f-s+x;
		}
//		printf("%d\n",x);
		if(t<=x){
			printf("OK\n");
		}
		else{
			y=t-x;
			printf("%d\n",y);
		}
	}
	return 0;
}

Measured memory_bytes: 2744
# B - Acrostic
# https://atcoder.jp/contests/soundhound2018-summer-qual/tasks/soundhound2018_summer_qual_b

# 指定した文字数ずつ分割　chunk

S = input()
w = int(input())

sp = [S[i: i+w] for i in range(0, len(S), w)]

ans = "".join(s[0] for s in sp)

print(ans)


Measured memory_bytes: 2940
// https://atcoder.jp/contests/agc039/tasks/agc039_b

#include "algorithm"
#include "iostream"
#include "set"
#include "vector"
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

ll N;
V<V<ll>> G;
V<ll> colors;  // 0: 未着色
V<V<ll>> ds;
V<ll> group_ids;

// 後の group 判定でいずれにせよ矛盾判定されそうなので不要？
bool check_bio(ll v, ll color) {
  colors[v] = color;

  for (auto to : G[v]) {
    if (colors[to] == color) {
      return false;
    }

    if (colors[to] == 0 && !check_bio(to, -color)) {
      return false;
    }
  }

  return true;
}

bool satisfied(ll v, ll group_id) {
  if (group_ids[v] != -1 && group_ids[v] != group_id) {
    return false;
  }

  if (group_ids[v] == group_id) {
    return true;
  }

  group_ids[v] = group_id;

  for (auto to : G[v]) {
    if (group_ids[to] != -1) {
      if (group_ids[to] == group_id - 1 || group_ids[to] == group_id + 1) {
        continue;
      } else {
        return false;
      }

      ll next_group_id = group_id + 1;

      if (!satisfied(to, next_group_id)) {
        return false;
      }
    }
  }

  return true;
}

void solve() {
  cin >> N;
  G.assign(N, V<ll>());

  rep(i, 0, N) {
    string e;
    cin >> e;

    rep(j, 0, N) {
      if (e[j] == '1') {
        G[i].push_back(j);
      }
    }
  }

  {
    colors.assign(N, 0);

    if (!check_bio(0, 1)) {
      drop(-1);
    }
  }

  {
    ll INF = 1 << 30;
    ds.assign(N, V<ll>(N, INF));
    rep(i, 0, N) ds[i][i] = 0;
    rep(i, 0, N) {
      for (auto to : G[i]) {
        ds[i][to] = 1;
        ds[to][i] = 1;
      }
    }

    // ワーシャルフロイド
    rep(k, 0, N) rep(i, 0, N) rep(j, 0, N) {
      ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]);
    }
  }

  auto max_d = 0;
  auto max_pair = pair<ll, ll>();
  rep(i, 0, N) rep(j, 0, N) {
    if (ds[i][j] > max_d) {
      max_pair = pair<ll, ll>(i, j);
      max_d = ds[i][j];
    }
  }

  // group_ids.assign(N, -1);
  // if (!satisfied(0, 0)) {
  //   drop(-1);
  // }

  cout << max_d + 1 << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, 0, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll INF = 1e18;
ll n, m, l, a, b, c, q, dist[305][305], dis[305][305];
vector<pi> adj[305];

int main() {
	fastio; cin >> n >> m >> l;
	FOR(i, 1, n) FOR(j, 1, n) dist[i][j] = INF;
	FOR(i, 1, n) dist[i][i] = 0;
	FOR(i, 1, m) {
		cin >> a >> b >> c;
		dist[a][b] = c;
		dist[b][a] = c;
	}
	FOR(k, 1, n) FOR(i, 1, n) FOR(j, 1, n) {
		if (dist[i][k] != INF and dist[j][k] != INF) {
			dist[i][j] = min(dist[i][j], dist[i][k] + dist[j][k]);
		}
	}
	FOR(i, 1, n) FOR(j, 1, n) {
		if (dist[i][j] <= l) dis[i][j] = 1;
		else dis[i][j] = INF;
	}
	FOR(i, 1, n) dis[i][i] = 0;
	FOR(k, 1, n) FOR(i, 1, n) FOR(j, 1, n) {
		if (dis[i][k] != INF and dis[j][k] != INF) {
			dis[i][j] = min(dis[i][j], dis[i][k] + dis[j][k]);
		}
	}
	cin >> q; while (q--) {
		cin >> a >> b;
		if (dis[a][b] == INF) cout << "-1\n";
		else cout << dis[a][b] - 1 << "\n";
	}
}


Measured memory_bytes: 2048
program name
    implicit none
    integer(4):: n,ni,dsum

    read*, n
    dsum=0
    ni=n
    do while(ni>0)
        dsum=dsum+mod(ni,10)
        ni=ni/10
    end do

    if (mod(n,dsum)==0) then
        print*, 'Yes'
    else
        print*, 'No'
    end if
    
end program name

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

int main() {
  int N, a;
  bool x=true;
  
  cin >>N;
  
  for (int i=0;i<N;i++){
      cin>>a;
      
      if(a%2==0){
          if(a%3!=0&&a%5!=0){
          x=false;
          }
      }
  }

  if(x){
      cout <<"APPROVED"<< endl;
  }
  
  else{
      cout <<"DENIED"<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

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

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(ll, N);
    CIN(ll, X)
    vector<ll> d(N, 0);

    for (int i = 0; i < N; i++) {
        ll temp;
        cin >> temp;
        d[i] = abs(X - temp);
    }
    sort(d.begin(), d.end());
    if (d[0]==d[N-1]) {
        cout << d[0] << "\n";
        return 0;
    }

    for (int t = 0; t < N; t++) {
        for (int i = 1; i < N; i++) {
            d[i] = d[i] % d[0];
            if (d[i] == 0) d[i] = d[0];
        }
        sort(d.begin(), d.end());
        if (d[0] == d[N-1]) {
            break;
        }
    }

    cout << d[0] << "\n";
    return 0;
}

Measured memory_bytes: 1024