akhauriyash/Code-Regression huggingface dataset:
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    ll g = x / d;
    if (g >= k) x -= d * k;
    else {
        x -= g * d;
        k -= g;
        if (k % 2) x = abs(x-d);
    } 
    cout << x;
    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>

int n;
int r;

int main(void)
{
	scanf("%d", &n);
	
	if(n % 2 == 0)
	{
		r = n / 2;
	}
	
	else
	{
		r = n / 2 + 1;
	}
	
	printf("%.7lf", (double)r / (double)n);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<set>
#include<string>
#include<algorithm>
using namespace std;
bool a[7368800];
int main() {
	int m=3,n=1;
	while (cin >>m>> n&&n != 0&&m!=0) {
		int sum = m, n2 = n;
		fill(a, a + 7368800, false);
		while (n2 != 0 || a[sum]) {
			if (!a[sum]) {
				a[sum] = true;
				int j = 2;
				while (sum*j < 7368800) {
					a[sum*j] = true;
					j++;
				}
				n2--;
			}
			sum++;
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 10292
<?php
$n = explode(" ",trim(fgets(STDIN)));
$s = $n[0];
$t = $n[1];
$n2= explode(" ",trim(fgets(STDIN)));
$a = $n2[0];
$b = $n2[1];
$u = trim(fgets(STDIN));
if ($s==$u) {
    print($a-1);
    echo " ";
    print($b);
    echo "\n";
}else {
    print($a);
    echo " ";
    print($b-1);
    echo "\n";
}
?>


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
int n,c[25],v[25],ans;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&c[i]);
	for(int i=1;i<=n;++i)
		scanf("%d",&v[i]);
	for(int i=1;i<=n;++i)
		ans+=(c[i]<v[i]?0:c[i]-v[i]);
	printf("%d\n",ans);
}

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

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

    int d5, d4, d2, d1;
    int cnt = 0;
    for (int i = a; i <= b; i++) {
        d5 = i / 10000;
        d4 = (i / 1000) % 10;
        d2 = (i / 10) % 10;
        d1 = i % 10;
        if (d5 == d1 && d4 == d2) {
            cnt++;
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
A, B = ri_()
print((A + B) % 24)

Measured memory_bytes: 63468
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {

	Scanner std = new Scanner(System.in);


	//List<Integer> list = new ArrayList<>();
	int N = std.nextInt();
	int L = std.nextInt();
	int Lsum = 0;
	int Ltemp = L;
	//String S = std.next();

	if(L <= 0 && Math.abs(L) < N) {
		for(int i = 0; i < N; i++) {
			Lsum = Lsum +L;
			L++;
		}
	}


	else if(L <= 0 && Math.abs(L) >= N) {
		for(int i = 0; i < N; i++) {
			Lsum = Lsum + L;
			L++;
		}
		Lsum = Lsum - L + 1;
	}

//-5,-4,-3=-12.
	else {
		for(int i = 0; i < N; i++) {
			Lsum = Lsum + L;
			L++;
		}
		Lsum = Lsum - Ltemp;
	}

	System.out.println(Lsum);


	  }


	}




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

#define ll long long
#define ld long double
using namespace std;

int  main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    ll answ = 0;
    for (auto i : s){
        if (i == '1')
            answ++;
    }
    cout << answ << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  int i,j;
  for(i=0;i<h;i++){
      cin >> s[i];
  }
  
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
        if(s[i][j] == '#'){
          if(j == 0){
            if(s[i][j+1] == '#'){
              continue;
            }
          }else if(j == w-1){
            if(s[i][j-1] == '#'){
              continue;
            }
          }else{
            if(s[i][j+1] == '#' || s[i][j-1] == '#'){
              continue;
            }
          }
          if(i == 0){
            if(s[i+1][j] == '#'){
              continue;
            }
          }else if(i == h-1){
            if(s[i-1][j] == '#'){
              continue;
            }
          }else{
            if(s[i+1][j] == '#'||s[i-1][j] == '#'){
              continue;
            }
          }
          cout << "No" << endl;
          return 0;
        }   
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int xy[600][600], xz[600][600], yz[600][600];
int X[600], Y[600];
int n, q, a, b; string S;
int main() {
	while (true) {
		for (int i = 0; i < 600; i++) {
			X[i] = 0; Y[i] = 0;
			for (int j = 0; j < 600; j++) {
				xy[i][j] = 0; xz[i][j] = 0; yz[i][j] = 0;
			}
		}
		cin >> n >> q; if (n == 0 && q == 0)break;
		for (int i = 0; i < q; i++) {
			cin >> S >> a >> b; a--; b--;
			if (S == "xy") { xy[a][b] = 1; }
			if (S == "xz") { xz[a][b] = 1; }
			if (S == "yz") { yz[a][b] = 1; }
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				X[i] += xy[i][j]; Y[j] += xy[i][j]; cnt += xy[i][j];
			}
		}
		int sum = 0;
		for (int i = 0; i < n; i++) {
			vector<int>XZ, YZ;
			for (int j = 0; j < n; j++) {
				if (xz[j][i] == 1) {
					XZ.push_back(j); sum += n - X[j];
				}
				if (yz[j][i] == 1) {
					YZ.push_back(j); sum += n - Y[j];
				}
			}
			sum += cnt;
			for (int j = 0; j < XZ.size(); j++) {
				for (int k = 0; k < YZ.size(); k++) {
					sum -= (1 - xy[XZ[j]][YZ[k]]);
				}
			}
		}
		cout << n*n*n - sum << endl;
	}
	return 0;
}

Measured memory_bytes: 5452
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let _c: i64 = read();
    let k: usize = read();

    println!("{}", if k % 2 == 0 { a - b } else { b - a });
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <stdio.h>

int main()
{
  int g,w,h=0,i,j;
  int A[10000],B[500];
  scanf("%d",&g);
  for(i=0; i<g; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&w);
  for(i=0; i<w; i++){
    scanf("%d",&B[i]);
  }
  for(i=0; i<w; i++){
    for(j=0; j<g; j++){
      if(B[i]==A[j]){
        h++;
        break;
      }
    }
  }
  printf("%d\n",h);
  return 0;
}



Measured memory_bytes: 2104
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
#include <cmath>
#include <cstdio>
#include <complex>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;

int main() {
  ll n;
  cin>>n;
  cout<<((n+1)/2)*(n/2)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#define maxd 400500
using std::string;
using std::cout;
using std::cin;
using std::endl;
using std::sort;
using std::map;
using std::min;
using std::max;
int main()
{
    long int n,a[110],ans=-1,p=-1,s;
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    for(int i=1;i<=100;i++)
    {
        if(ans==-1)
        ans=p;
        else
        ans=min(ans,p);
        p=0;
        for(int j=1;j<=n;j++)
        {
            s=i-a[j];
            s*=s;
            p+=s;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static long Mod = (long)1e9 + 7;
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }
        static void Solve()
        {
            var S = ReadLine();
            var N = S.Length;
            var U = 1L << (N - 1);
            var ans = 0L;
            for (var i = 0; i < U; ++i)
            {
                var lst = new List<char>();
                var t = i;
                for (var j = 0; j < N; ++j)
                {
                    lst.Add(S[j]);
                    if (0 != (t & 1))
                    {
                        ans += long.Parse(string.Join("", lst));
                        lst = new List<char>();
                    }
                    t >>= 1;
                }
                if (lst.Any())
                    ans += long.Parse(string.Join("", lst));
            }
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 28592
n=int(input())
s=str(input())
ans=0

for i in range(n-1):
    n=i+1
    if s[n]=='E':
        ans=ans+1

cnt=ans

for i in range(n):
    if s[i:i+2]=='WW':
        cnt=cnt+1
    elif s[i:i+2]=='EE':
        cnt=cnt-1
    else:
        0
        
    #print('i,s[i:i+2],ans,cnt',i,s[i:i+2],ans,cnt)
    ans=min(ans,cnt)
print(ans)


Measured memory_bytes: 42072
n = int(input())
s = str(input())

ans = ""
#print(ord("A")) 65
#print(ord("Z")) 90

for i in s:
    temp = ord(i)
    #print(temp)
    if int(ord(i)) + n > 90:
        temp = int(temp) -90 + 64
        temp = chr(temp+n)
        ans = ans + temp
    else:
        temp = chr(temp+n)
        ans = ans + temp


print(ans)


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


int main(){
    int n,m;
    cin >> n >> m;
    double s = 4*m;
    double r = 0;
    int cnt = 0;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        r += a[i];
    }
    r /= s;
    rep(i,n){
        if(a[i] >= r) cnt++;
    }
    if(cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <sstream>
#include <string>
#include <vector>

#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif
	std::string buf;;
	std::string tmp;
	std::vector<int> alpha_counter(26);	

#if INPUT_FROM_FILE
	while(std::getline(ifs, tmp)){
#else
	while(std::getline(std::cin, tmp)){
#endif
		buf.append(tmp);	
	}

	for(unsigned int i = 0; i < buf.size(); i++){
		char c = buf.at(i);
		if(c >=  'A' && c <= 'Z'){
			c -= 'A';	
		}
		else if(c >= 'a' && c <= 'z'){
			c -= 'a';	
		}
		else{
			continue;
		}
		alpha_counter[c]++;
	}

	for(unsigned int i = 0; i < alpha_counter.size(); i++){
		std::cout << char(i + 'a') << " : " << alpha_counter[i] << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3180
//B Ed 31
#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main()
{
	int a,b,c,d,e=0;
	cin>>a>>b>>c>>d;
	a--;

	int p= b-a;
	int q= b/c -a/c;
	int r= b/d -a/d;
	int s= (c*d)/ __gcd(c,d);
	int t= b/s - a/s;
	cout<<(p-q-r+t);
}

Measured memory_bytes: 3628
INF = 10**10

N,M,R = map(int,input().split())
r = list(map(int,input().split()))

dp = [[INF]*(N+1) for i in range(N+1)]
for i in range(N+1):
    dp[i][i]=0

for i in range(M):
    a,b,c=map(int,input().split())
    dp[a][b]=c
    dp[b][a]=c

for k in range(1,N+1):
    for i in range(1,N+1):
        for j in range(1,N+1):
            dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j])

ans = INF
import itertools
for it in itertools.permutations(r):
    tmpans = 0
    for i in range(1,R):
        tmpans+=dp[it[i-1]][it[i]]
    ans = min(ans,tmpans)
print(ans)


Measured memory_bytes: 74776
#include<tuple>
#include<map>
#include<algorithm> // sort,reverse,min,lower_bound
#include<vector>
#include<iostream>
using namespace std;
#define df 0
#define INF 1000000000
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

int main(){
  if(df) printf("*debug mode*\n");
  int n,m; cin >>n >>m;
  vector<pair<int,int>> d(n);
  rep(i,n){
    int x; cin >>x;
    d.at(i)=make_pair(x,i);
  }
  vector<vector<int>> adj(n);
  map<pair<int,int>,int> edge;
  rep(i,m){
    int u,v; cin >>u >>v; u--; v--;
    if(u>v)swap(u,v);
    edge[make_pair(u,v)]=i;
    adj.at(u).push_back(v);
    adj.at(v).push_back(u);
  }
  vector<int> col(n,-1),to(n,-1),w(m,INF);
  rep(i,n){
    if(to.at(i)!=-1)continue;
    for(int u:adj.at(i)){
      if(d.at(u).first>d.at(i).first) continue;
      to.at(i)=u;
      if(d.at(u).first==d.at(i).first){
	to.at(u)=i;
	if(col.at(u)==-1){
	  col.at(i)=0;
	  col.at(u)=1;
	}else{
	  col.at(i)=1-col.at(u);
	}
	if(df)printf("%d:0,%d:1\n",u,i);
	int j;
	if(u<i) j=edge[make_pair(u,i)];
	else  j=edge[make_pair(i,u)];
	w.at(j)=d.at(u).first;
      }
      break;
    }
    if(to.at(i)==-1){
      printf("-1");
      return 0;
    }
  }
  sort(d.begin(),d.end());
  if(df){
    for(auto x:d)printf("(%d,%d)",x.first,x.second);
    printf("\n");
  }
  rep(i,n){
    int u=d.at(i).second;
    if(col.at(u)!=-1)continue;
    int v=to.at(u);
    if(df)printf("%d->%d",u,v);
    col.at(u)=1-col.at(v);
    int j;
    if(u<v) j=edge[make_pair(u,v)];
    else  j=edge[make_pair(v,u)];
    w.at(j)=d.at(i).first;
    if(df)printf("%d\n",w.at(j));
  }
  rep(i,n) printf("%c",col.at(i)?'B':'W');
  printf("\n");
  rep(i,m){
    printf("%d\n",w.at(i));
  }
}

/// confirm df==0 ///


Measured memory_bytes: 23296
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>

typedef long long ll;
using namespace std;


int main(void){
  int n,i,t,a,cnt;
  t=1;
  cnt=0;

  cin>>n;
  for(i=0;i<n;i++){
    cin>>a;
    if(a!=t){
      cnt++;
    }
    else{
      t++;
    }
  }

  if(cnt==n){
    cout<<-1<<endl;
  }
  else{
    cout<<cnt<<endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	double n,max,min,s;
	
	s=-1.0;
	
	while(scanf("%lf",&n)!=EOF){
		if(s==-1.0){
			max=n;
			min=n;
			s=max-min;
			continue;
		}
		if(max<n)max=n;
		if(min>n)min=n;
		s=max-min;
	}
	
	printf("%.1lf\n",s);
	
	return 0;
}
		

Measured memory_bytes: 652
class SegmentTree:
    def __init__(self, n):
        size = 1
        while size < n:
            size *= 2
        self.size = 2*size - 1
        self.data = [0] * self.size

    def add(self, i, v):
        # assert 0 <= i <= self.size//2
        index = self.size // 2 + i
        self.data[index] += v
        while index > 0:
            index = (index-1) // 2
            self.data[index] = self.data[index*2 + 1] + self.data[index*2 + 2]

    def sum(self, lo, hi):
        def _sum(r, i, j):
            if j < lo or i > hi:
                return 0
            elif lo <= i and j <= hi:
                return self.data[r]
            else:
                mid = i + (j - i)//2
                return _sum(r*2 + 1, i, mid) + _sum(r*2 + 2, mid+1, j)

        # assert 0 <= lo <= self.size//2
        # assert 0 <= hi <= self.size//2
        # assert lo <= hi

        return _sum(0, 0, self.size//2)


def run():
    n, q = [int(i) for i in input().split()]

    t = SegmentTree(n)
    for _ in range(q):
        com, x, y = [int(i) for i in input().split()]
        if com == 0:
            t.add(x-1, y)
        else:
            print(t.sum(x-1, y-1))


if __name__ == '__main__':
    run()



Measured memory_bytes: 10744
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//最小公倍数を返す関数
int mcd(int n) {
	return 0;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}


int main() {
	int a, b;
	cin >> a >> b;
	if ((a*b) % 2 == 0)cout << "Even" << endl;
	else cout << "Odd" << endl;


	//system("pause");
	return 0;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  ll ans = k;
  
  rep(i,n-1) ans *= (k-1);
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string>

using namespace std;

int main(){
    string a;
    cin>>a;
    
    string b = {};
    for(int i=0;i<a.size();++i){
        if(a[i] == '0') b = b + '0';
        else if(a[i] == '1')b = b + '1';
        else if(a[i] == 'B')if(b.size() != 0)b.pop_back();
    }
    cout<<b;
}

Measured memory_bytes: 256
# coding: utf-8
class Case03

  def initialize
  end

  def show
    p self.instance_variables
        .map{ |sym| [sym, self.instance_variable_get(sym)] }
        .to_h
  end
  
  # 実行する
  def execute
    read
    solve
    output
  end

  def read
    @n = gets.chomp.to_i
    @a = gets.chomp.split.map(&:to_i)
  end

  def solve
    @a.sort!
    @result = 'YES'
    0.upto(@n-2) do |i|
      if @a[i] == @a[i+1] then
        @result = 'NO'
        break;
      end
    end
  end
  
  def output
    puts @result
  end

end

Case03.new.execute if $0 == __FILE__


Measured memory_bytes: 19464
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  std::vector<int> happiness[3];
  for (int i = 0; i < 3; i++) {
    happiness[i].resize(n, 0);
  }
  int a, b, c;
  cin >> a >> b >> c;
  happiness[0][0] = a;
  happiness[1][0] = b;
  happiness[2][0] = c;
  for (int i = 1; i < n; i++) {
    cin >> a >> b >> c;
    happiness[0][i] =
        std::max(happiness[1][i - 1] + a, happiness[2][i - 1] + a);
    happiness[1][i] =
        std::max(happiness[0][i - 1] + b, happiness[2][i - 1] + b);
    happiness[2][i] =
        std::max(happiness[1][i - 1] + c, happiness[0][i - 1] + c);
  }
  cout << std::max(
              {happiness[0][n - 1], happiness[1][n - 1], happiness[2][n - 1]})
       << endl;

  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    s64 d[n][n];
    s64 ans = 0;
    rep (i, n) rep (j, n) { cin >> d[i][j]; }

    rep (i, n) for (int j = i + 1; j < n; ++j)
    {
        bool ok = true;
        rep (k, n)
        {
            if (i == k || j == k) continue;
            if (d[i][j] > d[i][k] + d[k][j])
            {
                cout << "-1\n";
                return 0;
            }
            else if (d[i][j] == d[i][k] + d[k][j])
            {
                ok = false;
            }
        }
        if (ok) ans += d[i][j];
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
	string S;
	cin >> S;
	int c = 0;
	if (S == "RRR") c = 3;
	if (S == "RRS") c = 2;
	if (S == "RSR") c = 1;
	if (S == "RSS") c = 1;
	if (S == "SRR") c = 2;
	if (S == "SRS") c = 1;
	if (S == "SSR") c = 1;
	if (S == "SSS") c = 0;

	cout << c << endl;

	return(0);
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main(){
  int a[4];
  rep(i,4)cin >> a[i];
  cout << min(a[0],a[1])+min(a[2],a[3]) << endl;
}

Measured memory_bytes: 256
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

//Descrete Speed
public class Main{

	public static int n;
	public static int m;
	public static int start;
	public static int goal;

	public static double[][][] dist;
	public static int[][] r;
	public static int[][] limit;

	public static double dijkstra(){
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				for(int k=0;k<31;k++)
					dist[i][j][k] = Integer.MAX_VALUE;
			}
		}
		dist[start][0][0] = 0;
		PriorityQueue<int[]> q = new PriorityQueue<int[]>(n, new Comparator<int[]>(){
			public int compare(int[] a, int[] b) {
				return dist[a[0]][a[1]][a[2]]-dist[b[0]][b[1]][b[2]]<0?-1:dist[a[0]][a[1]][a[2]]-dist[b[0]][b[1]][b[2]]>0?1:0;
			}
		});
		q.add(new int[]{start,0,0});
		while(!q.isEmpty()){
			int[] uu = q.poll();
			int u = uu[0];
			int pre = uu[1];
			int v = uu[2];
			if(u==goal&&v==1)return dist[u][pre][v];
			for(int i=1;i<=n;i++){
				if(i!=pre && r[u][i]!=0){
					for(int x=v-1;x<=v+1;x++){
						if(x<=0)continue;
						if(x>limit[u][i])continue;
						double nc = dist[u][pre][v] + r[u][i]*1.0/x;
						if(nc < dist[i][u][x]){
							dist[i][u][x] = nc;
							q.add(new int[]{i, u, x});
						}
					}
				}
			}
		}
		return -1;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			n = sc.nextInt();
			m = sc.nextInt();
			if(n==0&&m==0)break;
			dist = new double[n+1][n+1][31];
			r = new int[n+1][n+1];
			limit = new int[n+1][n+1];
			start = sc.nextInt();
			goal = sc.nextInt();
			for(int i=0;i<m;i++){
				int u = sc.nextInt();
				int v = sc.nextInt();
				int d = sc.nextInt();
				int l = sc.nextInt();
				r[u][v] = r[v][u] = d;
				limit[u][v] = limit[v][u] = l;
			}
			double ans = dijkstra();
			if(ans==-1)System.out.println("unreachable");
			else System.out.printf("%.5f\n", ans);
		}
	}
}

Measured memory_bytes: 15000
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()    
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
const int MOD = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime MOD
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
ostream& operator<< (ostream& os, const mint& value) {
  os << value.x;
  return os;
}

#pragma endregion library
// Complexity: O(log n)
ll modpow(ll x, ll n, const ll mod){
    if(!n) return 1;
    ll res = modpow(x*x%mod, n/2, mod);
    if(n&1) res = res * x % mod;
    return res;
}
int main(){
    int n; cin >> n;
    mint ans = modpow(10, n, MOD);
    ans -= modpow(9, n, MOD);
    ans -= modpow(9, n, MOD);
    ans += modpow(8, n, MOD);
    cout << ans << '\n';
    
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a,b,c=0,d=0,e,f,g,h,m,n,ans=0;
  string s,t;
  cin>>n;
  int x[n];
  bool y=true;
  rep(i,0,n) cin>>x[i];
  rep(i,0,n){
    if(x[i]%2==0){
      if(x[i]%3!=0 && x[i]%5!=0) y=false;
    }
  }
  if(y==true) co("APPROVED");
  else co("DENIED");
    
  return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

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

	ll n;cin >> n;
	ll ans = n;

	for(ll i = 1;i * i <= n;i++){
		if(n % i)continue;
		ans = min(ans, i + (n/i) - 2);
	}

	cout << ans << endl;

	return 0;
}


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

int main()
{
  long long goukei = 0;
  int data[10000];
  int min = 0,max = 0;
  int n;
  
  cin >> n;

  for(int i = 0 ; i < n ; i++){
    cin >> data[i];
    goukei += data[i];
  }
      max = data[0];
      min = data[0];

  for(int k = 0;k < n;k++)
    {
      if(max < data[k]){
	max = data[k];
      }
      if(min > data[k]){
	min = data[k];
      }
    }
  cout << min << " " << max << " " << goukei << endl;
}


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

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

    vector<int> p(n);
    rep(i, 0, n) cin >> p[i];

    vector<double> data(1001, 0);
    data[1] = 1;
    rep(i, 2, 1001) {
        data[i] += data[i - 1] + i;
    }

    rep(i, 1, 1001) {
        data[i] /= (double)i;
    }

    vector<double> x(n);
    rep(i, 0, n) {
        x[i] = data[p[i]];
    }

    vector<double> left(n + 1, 0), right(n + 1, 0);
    left[0] = 0;
    rep(i, 0, n) {
        left[i + 1] = left[i] + x[i];
    }

    double cur = -1;
    for (int i = 0; i < n; i++) {
        if (i + k > n) continue;
        cur = max(cur, left[i + k] - left[i]);
    }

    cout << fixed << setprecision(10) << cur << endl;

    return 0;
}

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

using namespace std;

int main(){
 int a,b,c,d; 
  cin >> a >> b >> c >> d;
 
  int cnt[10]={0};
  
  cnt[a]++;
  cnt[b]++;
  cnt[c]++;
  cnt[d]++;
  
  if(cnt[1]==1&&cnt[9]==1&&cnt[7]==1&&cnt[4]==1) cout << "YES" << endl;
  else cout << "NO" << endl;
  

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/segtree.hpp>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
using namespace atcoder;

const int MAX_A = 3000005;

int op(int a, int b) {
  return max(a,b);
}

int e() {
  return 0;
}

signed main() {
  int n,k;
  cin >> n >> k;


  segtree<int, op, e> dp(MAX_A);

  vector<int> a(n);
  rep(i,n) cin >> a[i];

  rep(i,n) {
    int x = a[i];
    int l = max(0, x-k);
    int r = min(x+k+1, MAX_A);
    int ma = dp.prod(l,r);
    dp.set(x, ma+1);
  }

  int ans = dp.all_prod();

  cout << ans << '\n';

}




Measured memory_bytes: 47880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

int main() {

	int n,r;
	cin >> n >> r;
	int out;
	if (n <= 10) {
		out = r + 100 * (10 - n);
	} else {
		out = r;
	}
	cout << out << endl;
	return 0;
}

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

int main()
{
    int n; cin >> n;
    string s; cin >> s;
    string ans = "No";
    if(n % 2 == 0){
        string fir = s.substr(0,n/2);
        string sec = s.substr(n/2);
        if(fir == sec) ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	l := []int{a, b, c}
	sort.Ints(l)
	max := l[2]

	if max%2 != (a+b+c)%2 {
		max++
	}
	ans := (3*max - (a + b + c)) / 2
	fmt.Println(ans)
}


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

int main() {
  int k,n;cin>>k>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  a.push_back(a[0]+k);
  //円環の問題は１周＋αを考える
  int cnt=0;
  rep(i,n)cnt=max(cnt,a[i+1]-a[i]);
  cout<<k-cnt<<endl;
}

Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

template<int mod=1000000007>
class ModInt {
  int x;
public:
  ModInt() : x(0) {}
  ModInt(const ModInt &y): x(y.x) {}
  ModInt(int64_t y){ x = y % mod; if(x < 0) x += mod; }
  ModInt &operator += (const ModInt &p){ x += p.x; if(x >= mod) x -= mod; return *this; }
  ModInt &operator -= (const ModInt &p){ x -= p.x; if(x < 0) x += mod; return *this; }
  ModInt &operator *= (const ModInt &p){ x = (int) (1LL * x * p.x % mod); return *this; }
  ModInt &operator /= (const ModInt &p){ *this *= p.inverse(); return *this; }
  ModInt operator -() const { return ModInt(-x); }
  ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; }
  ModInt operator ^ (const int64_t y) const { return pow(y); }
  bool operator == (const ModInt &p) const { return x == p.x; }
  bool operator != (const ModInt &p) const { return x != p.x; }
  ModInt operator = (const int64_t y) { return *this = ModInt(y); }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0){
      t = a/b; a -= t*b; swap(a, b);
      u -= t*v; swap(u, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t y) const {
    if(x==0) return ModInt(0);
    int64_t r = 1, t = x;
    while(y > 0){
      if(y&1) r = r*t%mod;
      t = t*t%mod; y >>= 1;
    }
    return ModInt(r);
  }
  friend ostream &operator << (ostream &os, const ModInt<mod> &p) { return os<<p.x; }
  friend istream &operator >> (istream &is, ModInt<mod> &a) { int64_t x; is>>x; a = ModInt<mod>(x); return is; }
};
using Int = ModInt<>;

int main(){
  int n, k;
  cin>>n>>k;
  vector<int> a(n);
  rep(i,n) cin>>a[i];

  vector<Int> dp(k+1, 0);
  dp[0] = 1;
  rep(i,n){
    vector<Int> nxt(k+1, 0);
    Int acc = 0;
    rep(j,a[i]+1){
      acc += dp[j];
      nxt[j] = acc;
    }
    rep(j,a[i]+1,k+1){
      acc -= dp[j - a[i] - 1];
      acc += dp[j];
      nxt[j] = acc;
    }
    //dbg(nxt);
    swap(dp, nxt);
  }

  cout << dp[k] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
  int N, M;
  cin >> N >> M;
  int c[M];
  for(int i=0;i<M;i++){
    c[i] = 0;
  }
  //
  int K;
  int code;
  for(int i=0;i<N;i++){
    cin >> K;
    for(int j=0;j<K;j++){
      cin >> code;
      c[code-1]++;
    }
  }
  int ans = 0;
  for(int i=0;i<M;i++){
    if(c[i]==N){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
 char ss1[4],ss2[4],ss3[4];
 cin>>ss1;
  cin>>ss2 ;
  cin>>ss3;
cout<<ss1[0];
cout<<ss2[1];
cout<<ss3[2]<<'\n';



    return 0;




}


Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
# D - Lunlun Number
# モジュールのインポート
from collections import deque

# 標準入力の取得
K = int(input())

# 求解処理
# 空のQueueを一つ用意し、1, 2, ・・・, 9を順にEnqueue
que = deque(list(range(1, 10)))
lunlun_number = 0
for k in range(K):
    # Queueに対して、Dequeueを行う
    x = que.popleft()
    # x mod 10 ≠ 0なら、10x + (x mod 10) - 1をEnqueue
    if x % 10 != 0:
        que.append(10*x + (x%10) - 1)
    # 10x + (x mod 10)をEnqueue
    que.append(10*x + (x%10))
    # x mod 10 ≠ 9なら、10x + (x mod 10) + 1をEnqueue
    if x % 10 != 9:
        que.append(10*x + (x%10) + 1)

    # 上の操作をK回実施したときの値がLunlun Number
    lunlun_number = x

print(lunlun_number)

Measured memory_bytes: 11900
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

  int mx, mn;
  mn = max(a, c);
  mx = min(b, d);

  cout << max(mx - mn, 0) << ln;
}


Measured memory_bytes: 256
using System;


namespace QQ
{
    class Program
    {
        static void Main(string[] args)
        {
            int i, j;

            for(i =1; i<=9; ++i)
            {
                for(j=1; j<=9; ++j)
                {
                    Console.WriteLine("{0}x{1}={2}", i, j, i * j);
                }
            }
        }
    }
}

Measured memory_bytes: 9100
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  string s;
  int k, n;
  cin >> s >> k;
  n = s.length();
  for(int i = 0; i < n - 1; i++) {
    if(s[i] != 'a') {
      if(123 - (int)s[i] <= k) {
        k -= 123 - (int)s[i];
        s[i] = 'a';
      }
    }
  }
  k %= 26;
  while(k--) {
    s[n - 1]++;
    if(s[n - 1] == 123) {
      s[n - 1] = 97;
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3724
fun main(args: Array<String>) {
    val s = readLine()!!

    print(if (req1(s)&&req2(s)&&req3(s)) ("AC") else ("WA"))
}

fun req1(s: String): Boolean {
    return s[0] == 'A'
}

fun req2(s: String): Boolean {
    val len = s.substring(2 until s.length-1).filter{it == 'C'}.length
    return len == 1
}

fun req3(s: String): Boolean {
    return s.filter{c -> (c!='A' && c!='C')}.all{it.isLowerCase()}
}

Measured memory_bytes: 31872
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;

typedef pair<int, int> P;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int H, W, K, sx, sy, gx, gy;
    cin >> H >> W >> K >> sx >> sy >> gx >> gy;
	--sx; --sy; --gx; --gy;
    char s[H][W];
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            cin >> s[i][j];
        }
    }

    int dist[H][W];
    fill(dist[0], dist[H], INF);
    deque<P> que;
    dist[sx][sy] = 0;
    que.emplace_front(sx,sy);
    while(!que.empty()){
        P p = que.front();
        que.pop_front();
        int x = p.first;
        int y = p.second;
        
        for(int i = 0; i < 4; ++i){
			for(int j=1;j<=K;j++){
				int nx = x + dx[i]*j, ny = y + dy[i]*j;
				if(nx < 0 || nx >= H || ny < 0 || ny >= W)  break;
				if(s[nx][ny] == '@'){
					break;
				}
				if(s[nx][ny] == '.'){
					if(dist[nx][ny] > dist[x][y]+1){
						dist[nx][ny] = dist[x][y]+1;
						que.emplace_back(nx,ny);
					}
					else if(dist[nx][ny] == dist[x][y]+1){
						continue;
					}
					else{
						break;
					}
				}
			}
        }
        
    }
    if(dist[gx][gy] == INF) cout << -1 << endl;
	else cout << dist[gx][gy] << endl;
}

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

int main(){
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]=='1')cout<<9;
        else cout<<1;
    }
    cout<<endl;
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        double[] arr = Console.ReadLine().Split(' ').Select(v => double.Parse(v)).ToArray();
        double a = arr[0];
        double b = arr[1];
        double n = arr[2];
        double nMax = n < b ? n : b - 1;
        long ans = (long)(a * nMax / b) - (long)a *(long)(nMax / b);
        Console.WriteLine(ans);
    }




}





Measured memory_bytes: 19028
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(pair<int,int> a, pair<int,int> b) {
	return a < b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

int main() {
	int n;
	cin >> n;
	vint a(n);
	int one = 0;
	int p_o;
	rep(i, n) {
		cin >> a[i];
		if (a[i] > one) {
			one = max(one, a[i]);
			p_o = i;
		}
	}
	int two = 0;
	rep(i, n) {
		if (i != p_o) {
			two = max(two, a[i]);
		}
	}
	rep(i, n) {
		if (i == p_o) {
			cout << two << endl;
		}
		else {
			cout << one << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2432
n=int(input())
d,x=[int(i) for i in input().split()]
a=[]
for i in range(n):
    a.append(int(input()))
for j in range(n):
    for k in range(100):
        if a[j]*k+1<=d:
            x+=1
        else:
            break
print(x)

Measured memory_bytes: 2940
#include <stdio.h>

int main() {
    long long int n = 0, sum = 0;
    scanf("%lld\n", &n);
    for (long long int i=1; i*(i+1)+1 <= n; i++) {
        if ((n-i)%i == 0) sum += (n-i)/i;
    }
    printf("%lld\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

void Cal(int *myNum, int *yourNum) {
	int me = *myNum;
	int you = *yourNum;
	if (me % 2 == 1) {
		me--;
	}
	me = me / 2;
	you += me;
	*myNum = me;
	*yourNum = you;
}

int main() {
	int A, B, K;
	cin >> A >> B >> K;
	for (int i = 0; i < K; i++) {
		if (i % 2 == 0) {
			Cal(&A, &B);
		}
		else {
			Cal(&B, &A);
		}
	}
	cout << A <<' '<< B << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

const int inf = 1 << 30;

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

    int n;
    cin >> n;

    int a[n];
    int mx = -inf, mn = inf;
    int mx_idx = 0, mn_idx = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] > mx) {
            mx = a[i];
            mx_idx = i;
        }
        if (a[i] < mn) {
            mn = a[i];
            mn_idx = i;
        }
    }

    cout << 2 * n - 1 << '\n';
    if (mx > -mn) {
        for (int i = 0; i < n; i++) cout << mx_idx + 1 << " " << i+1 << "\n";
        for (int i = 1; i < n; i++) cout << i << " " << i+1 << "\n";
    } else {
        for (int i = 0; i < n; i++) cout << mn_idx + 1 << " " << i+1 << "\n";
        for (int i = n; i > 1; i--) cout << i << " " << i-1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define ll long long int
#define MOD1		1000000007
#define MOD2		998244353
#define BOOST		ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;


int main()
{
    ll a,b,c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int givenNumber = scanner.nextInt();
        scanner.nextLine();
        long[] strength = new long[givenNumber*3];
        for(int i=0; i<givenNumber*3; i++) {
            strength[i] = scanner.nextLong();
        }
        scanner.nextLine();
        Arrays.sort(strength);

        long targetStrength = 0;
        for(int i=1; i<=givenNumber; i++) {

            targetStrength += strength[strength.length-2*i];
        }
        System.out.println(targetStrength);
    }
}


Measured memory_bytes: 98052