akhauriyash/Code-Regression huggingface dataset:
from collections import deque

k = int(input())
que = deque([i for i in range(1, 10)])
i = 0
while True:
    i += 1
    num = que.popleft()
    if i == k:
        print(num)
        exit()
    if num % 10 > 0:
        que.append(num * 10 + ((num % 10) - 1))
    que.append(num * 10 + (num % 10))
    if num % 10 < 9:
        que.append(num * 10 + ((num % 10) + 1))


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

typedef long long ll;
typedef unsigned long long ull;

ll gcd(int x, int y) {
    if (y == 0) return x;
    return gcd(y, x % y);
}

int main() {
    int N, X, x, ans;
    cin >> N >> X >> x;
    ans = abs(X - x);
    rep(i, N - 1) {
        cin >> x;
        ans = gcd(ans, abs(X - x));
    }
    cout << ans << "\n";
}

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

int main()
{
	string o, e;
	cin >> o >> e;

	string ans = "";

	for (int i = 0, j = 0; i < o.size() || j < e.size();)
	{
		if (i < o.size())
		{
			ans += o[i];
			i++;
		}

		if (j < e.size())
		{
			ans += e[j];
			j++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int a = sc.nextInt();
		System.out.println(n%500 <= a ? "Yes" : "No");
	}

}


Measured memory_bytes: 21716
import java.util.Scanner;


public class Main{
	
	public static void main(String[] args){
		int[] blood = new int[] {0, 0, 0, 0};	//A, B, AB, O
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()) {
			String line = sc.nextLine();
			Scanner scstr = new Scanner(line);
			scstr.useDelimiter(","); scstr.next();
			
			String b = scstr.next(); scstr.close();
			if(b.equals("end")) break;
			if(b.equals("A")) blood[0]++;
			else if(b.equals("B")) blood[1]++;
			else if(b.equals("AB")) blood[2]++;
			else blood[3]++;
		}
		sc.close();
		for(int n: blood) System.out.println(n);
	}
}

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

using namespace std;
using ll = long long;


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

    bool res = true;
    for(int i = 0; i < 3; i++)if(a[i] != b[2 - i])res = false;
    cout << (res ? "YES" : "NO") << endl;
}

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

double kaijyo(int n){
    int k(1);
    for(int i=n;i>0;i--){
        k *= i;
    }

    return k;
}

double distance(int x[],int y[],int i,int j){
    int dx = (x[i] - x[j]) * (x[i] - x[j]);
    int dy = (y[i] - y[j]) * (y[i] - y[j]);
    return sqrt(dx+dy);
}

int main(){
    string s,t;
    cin >> s >> t;
    cout << t << s << endl;

    return 0;
}

Measured memory_bytes: 3528
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
func kakunin(n int) []int{
	sum := make([]int,n)
	for i:= 0; i<n; i++ {
		sum[i] = 1
	}
	return sum
}
func main() {
	// 尺取り法
	// 計算量がO(N+M)早い
	/*
		例えば a=[10,20,30,40,50],b=[50,60,70,80,90] //sortは必須
	    とした時に, 100まででaIndex+bIndexの最大値を求める問題だとして
		1:
		a[0] = 10 + b[1~5] //可能
		a[1] = 20 + b[1~4] //可能
		a[2] = 30 + b[1~3] //可能
	    a[3] = 40 + b[1~2] //可能
	    a[4] = 50 + b[1] //可能となる
		最大値をもとめるので、 aを基準とした時,bは最大indexのみを知れれば良い
		そうすると可能値が変動する場合のみ動かす。とすると
		bのindexの動き方が n回しか行われない
		O(N+M)
	*/
	scan_init()
	n := scanInt()
	m := scanInt()
	k := scanInt()
	a := make([]int,n+1)
	b := make([]int,m+1)
	a[0] = 0
	for i:= 1; i<=n; i++ {
		a[i] = a[i-1]+scanInt()
	}
	b[0] = 0
	for i:= 1; i<=m; i++ {
		b[i] = b[i-1]+scanInt()
	}
	// aIndex := 0
	// inf := int(math.Pow(10,12))+1
	sum := 0
	siyakutoriB:= m
	for i:= 0; i<=n; i++ {
		// count := 0
		purser := k-a[i]
		if purser < 0 {
			break
		}
		for ;siyakutoriB >0 && purser<b[siyakutoriB]; siyakutoriB--{
		}
		// fmt.Println(siyakutoriB,purser,b[siyakutoriB],a[i],i)
		if sum < siyakutoriB+i {
			sum = siyakutoriB+i
		}
	}
	fmt.Println(sum)
}

var sc = bufio.NewScanner(os.Stdin)

func scan_init() {
	sc.Split(bufio.ScanWords)
	buf := make([]byte, 10000)
	sc.Buffer(buf,1000000000000)
}
func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func scan() string {
	sc.Scan()
	return sc.Text()
}

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

int main() {
    string S;
    cin >> S;
    vector<string> A(7);
    A.at(0) = "SUN";
    A.at(1) = "MON";
    A.at(2) = "TUE";
    A.at(3) = "WED";
    A.at(4) = "THU";
    A.at(5) = "FRI";
    A.at(6) = "SAT";
    int ans;
    for (int i = 0; i < 7; i++){
        if(S == A.at(i)){
            ans = 7-i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define DESCEND greater<int>()  // sort 降順 大きい順
#define UNIQUE(vec) (vec).erase(unique(ALL((vec))), (vec).end());  // 必ずsortを行なってから
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1000000007;  // 1 000 000 007


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

    // input
    int K, S;
    cin >> K >> S;
    
    // 0 ~ K
    int cnt = 0;
    for (int i = 0; i <= K; ++i) {
        for (int j = 0; j <= K; ++j) {
            int tmp = S - (i + j);
            if (0 <= tmp && tmp <= K) cnt++;
        }
    }
    cout << cnt << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL n,m;
  cin >> n >> m;
  vector<int> l(m),r(m),c(m);
  REP(i,m) cin >> l[i] >> r[i] >> c[i];
  vector<vector<pair<int,int>>> nei(n+1);
  REP(i,m) {
    nei[l[i]].emplace_back(r[i], c[i]);
  }
  FOR(i,1,n) {
    nei[i+1].emplace_back(i,0);
  }

  priority_queue<pair<LL,LL>> q;
  set<LL> already;
  // negc, pos
  q.emplace(0,1);
  while(!q.empty()) {
    LL negc,pos;
    tie(negc,pos) = q.top();
    q.pop();
    if(!already.insert(pos).second) continue;
    if(pos == n) {
      cout << -negc << endl;
      return 0;
    }
    for(auto pa:nei[pos]) {
      q.emplace(negc - pa.second, pa.first);
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 12784
#include <stdio.h>

void main(void){
  int n;
  char s[3];
  
  scanf("%s",s);
  
  if(s[0]=='R'){
    if(s[1]=='R'){
      if(s[2]=='R')n=3;
      else n=2;
    }
    else n=1;
  }
  else{
    if(s[1]=='R'){
      if(s[2]=='R')n=2;
      else n=1;
    }
    else{
      if(s[2]=='R')n=1;
      else n=0;
    }
  }
  printf("%d",n);
}

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

// 辺に重みをつける場合
/* 
struct Edge{
  int to;
  int weight;
  Edge(int t,int w) : to(t). weight(w) { }
};
*/

using Graph = vector<vector<int>>;
// using Graph = vector<vector<Edge>>;

int res = 0;

//深さ優先探索
vector<bool> seen;
void dfs(const Graph &G, int v){
  bool end = true;
  for (int i = 0; i < seen.size(); ++i) if (!seen[i] && i != v) end = false;
  if (end) {
      ++res;
      return;
  }

  seen[v] = true; // v を訪問済みにする

  // vから行ける各頂点 next_v について
  for(auto next_v : G[v]){
    if (seen[next_v]) continue; // next_v が探索済みだったらスルー
    dfs(G, next_v); // 再帰的に探索
  }
  seen[v] = false;
}

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

  int N, M; cin >> N >> M;
  
  Graph G(N);
  for(int i=0;i<M;i++){
    int A, B;
    cin >> A >> B;
    A--, B--;
    G[A].push_back(B);
    G[B].push_back(A);
  }

  seen.assign(N, false); // 全頂点を「未訪問」にして初期化
  dfs(G, 0);

  cout << res << endl;

}

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

int main() {
  string s;
   cin>>s;
  int ans=0;
  for(int i=0;i<s.size()/2;i++){
      
    if(s[i]!=s[s.size()-i-1])
            ans++;
    
  }
  cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;
using ll = long long;

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

int main()
{
    int n,k;
    int d[101];
    int a[101][101];
    set<int> S;
    
    cin >> n >> k;
    rep(i,k){
        cin >> d[i];
        rep(j,d[i]){
            cin >> a[i][j];
            S.insert(a[i][j]);
        }
    }
    cout << n-S.size() << endl;
    
}


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

int main() {

  int A, B;
  cin >> A >> B;

  if (0 < A && A < 10 && 0 < B && B < 10) {
    cout << A * B << endl;
  } else {
    cout << "-1" << endl;
  }

}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<int, int> pii;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<pii> vpii;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas

namespace IO {
    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
        return out;
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve() {
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    int q;
    cin >> q;
    map<int, int> cnt;
    rep(i, 0, n) ++cnt[a[i]];
    int s = 0;
    rep(i, 0, n) s += a[i];
    while (q--) {
        int b, c;
        cin>> b >> c;
        s -= cnt[b] * b;
        s += cnt[b] * c;
        cnt[c] += cnt[b];
        cnt[b] = 0;
        put(s);
    }
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(30);
//    freopen("input.txt", "r", stdin);
//    freopen("input.txt", "r", stdin);
    int q = 1;
//    cin >> q;

    while (q--) solve();
}





Measured memory_bytes: 9416
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int R[n];
    for(int i=0;i<n;i++)
    {
        scanf("%d",&R[i]);
    }
    for(int k=0;k<n-1;k++)
    {
        printf("%d ",R[k]);
    }
    printf("%d\n",R[n-1]);
    
    for(int i=1;i<n;i++)
    {
        int x=R[i];
        int j=i-1;
        while(j>=0&&R[j]>x)
        {
            R[j+1]=R[j];
            j--;
        }
        R[j+1]=x;
        for(int k=0;k<n-1;k++){
            printf("%d ",R[k]);
        }
        printf("%d\n",R[n-1]);
    }
    return 0;
}


Measured memory_bytes: 2672
#include <iostream>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
using namespace std;
void init();
#ifdef DEBUG_BUILD
#define DBG(expr) cout << #expr << " = " << expr << endl;
#endif
#define ECHO(expr) cout << expr << endl;
#define REP(var, num) for(ll var = 0; var < num; var++)
#define REP_FROM(var, from, num) for(ll var = from; var < num; var++)
#define MAX_OF(type) numeric_limits<type>::max()
#define MIN_OF(type) numeric_limits<type>::min()
#define SORT(vec) sort(vec.begin(), vec.end())
#define REVERSE(vec) reverse(vec.begin(), vec.end())
#define ALL(vec) vec.begin(), vec.end()
typedef signed long long ll;
typedef unsigned long long ull;

void solve() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    vector<ll> chars(26, 1);
    for (char& c: s) {
        chars[c - 'a']++;
    }

    ll ans = 1;
    REP(i, 26) {
        ans = (ans * chars[i]) % 1000000007;
    }

    ans -= 1;
    ECHO(ans);
}

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

#ifdef INPUT_FILE
    if (!freopen(INPUT_FILE, "r", stdin)) {
        perror("freopen");
        exit(1);
    }
#endif

    solve();
    return 0;
}

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

int gcd(int x, int y) {
  return y ? gcd(y, x % y) : x;
}

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  int gmin = a[0], gminp;
  for (int i = 1; i < n; i++) {
    int tmp = gcd(a[0], a[i]);
    if (tmp <= gmin) {
      gmin = tmp;
      gminp = i;
    }
  }
  int ans = 0;
  int g = a[0];
  for (int i = 1; i < n; i++) {
    if (gminp != i) {
      g = gcd(g, a[i]);
    }
  }
  if (g > ans) {
    ans = g;
  }
  g = a[1];
  for (int i = 2; i < n; i++) {
    g = gcd(g, a[i]);
  }
  if (g > ans) {
    ans = g;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>


int main(void){

	char n;
	int count[26];
	int i;
	for(i=0;i<26;i++){
		count[i]=0;
	}
	
	while(scanf("%c",&n)!=EOF){
	
		if(n=='a'||n=='A'){
			count[0]++;
		}else if(n=='b'||n=='B'){
			count[1]++;
		}else if(n=='c'||n=='C'){
			count[2]++;
		}else if(n=='d'||n=='D'){
			count[3]++;
		}else if(n=='e'||n=='E'){
			count[4]++;
		}else if(n=='f'||n=='F'){
			count[5]++;
		}else if(n=='g'||n=='G'){
			count[6]++;
		}else if(n=='h'||n=='H'){
			count[7]++;
		}else if(n=='i'||n=='I'){
			count[8]++;
		}else if(n=='j'||n=='J'){
			count[9]++;
		}else if(n=='k'||n=='K'){
			count[10]++;
		}else if(n=='l'||n=='L'){
			count[11]++;
		}else if(n=='m'||n=='M'){
			count[12]++;
		}else if(n=='n'||n=='N'){
			count[13]++;
		}else if(n=='o'||n=='O'){
			count[14]++;
		}else if(n=='p'||n=='P'){
			count[15]++;
		}else if(n=='q'||n=='Q'){
			count[16]++;
		}else if(n=='r'||n=='R'){
			count[17]++;
		}else if(n=='s'||n=='S'){
			count[18]++;
		}else if(n=='t'||n=='T'){
			count[19]++;
		}else if(n=='u'||n=='U'){
			count[20]++;
		}else if(n=='v'||n=='V'){
			count[21]++;
		}else if(n=='w'||n=='W'){
			count[22]++;
		}else if(n=='x'||n=='X'){
			count[23]++;
		}else if(n=='y'||n=='Y'){
			count[24]++;
		}else if(n=='z'||n=='Z'){
			count[25]++;
		}
		
	}
	
	printf("a : %d\n",count[0]);
	printf("b : %d\n",count[1]);
	printf("c : %d\n",count[2]);
	printf("d : %d\n",count[3]);
	printf("e : %d\n",count[4]);
	printf("f : %d\n",count[5]);
	printf("g : %d\n",count[6]);
	printf("h : %d\n",count[7]);
	printf("i : %d\n",count[8]);
	printf("j : %d\n",count[9]);
	printf("k : %d\n",count[10]);
	printf("l : %d\n",count[11]);
	printf("m : %d\n",count[12]);
	printf("n : %d\n",count[13]);
	printf("o : %d\n",count[14]);
	printf("p : %d\n",count[15]);
	printf("q : %d\n",count[16]);
	printf("r : %d\n",count[17]);
	printf("s : %d\n",count[18]);
	printf("t : %d\n",count[19]);
	printf("u : %d\n",count[20]);
	printf("v : %d\n",count[21]);
	printf("w : %d\n",count[22]);
	printf("x : %d\n",count[23]);
	printf("y : %d\n",count[24]);
	printf("z : %d\n",count[25]);
	
	
	return 0;
}

Measured memory_bytes: 540
#include<stdio.h>

using namespace std;
int main(){
    while(true){
        int h,w;
        scanf("%d %d",&h,&w);
        if(h == 0 && w == 0) break;
        for(int i = 0;i < h;i++){
            for(int j = 0;j <w;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2532
#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() {
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll ans = LLONG_MAX*-1;
    if (a<=0 && b>=0 && c<=0 && d>=0) ans = 0;
    chmax(ans, a*c);
    chmax(ans, a*d);
    chmax(ans, b*c);
    chmax(ans, b*d);
    cout << ans << endl;
}

Measured memory_bytes: 3664
#include <iostream>
#include <string>

using namespace std;

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

    //昇順に並べる
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(a[i] < a[j]){
                int tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
    }

    int alice = 0, 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
#include <stdio.h>
int main(){
    int A,B;
    int ret;
    scanf("%d %d",&A,&B);
    if (A < 6){
        printf("0\n");
        return 0;
    }
    if(A < 13){
        printf("%d\n",B/2);
        return 0;
    }
    printf("%d\n",B);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int n; cin >> n;
    vector<pair<int, int>> v(n);
    for(int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        v[i] = make_pair(a, b);
    }

    sort(v.begin(), v.end());

    int ans = 0;
    ans += v[0].first + v[n - 1].first - v[0].first + v[n - 1].second; 

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


Measured memory_bytes: 1792
maze = []
h, w = map(int,input().split())
for _ in range(h):
    maze.append(list(input()))
#print(maze)
x,y = 0,0
while True:
    maze[y][x] = "."
    if x == w-1 and  y == h-1:
        break
    if x != w-1 and maze[y][x+1]== "#":
        x += 1
        continue
    if y != h-1 and maze[y+1][x]=="#":
        y += 1
        continue
    break
from pprint import pprint
#pprint(maze)
f= True
for i in range(h):
    if maze[i].count("#") != 0:
        f = False
print("Impossible" if not f else "Possible")


Measured memory_bytes: 3572
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>

#define N 60

using namespace std;

static int d[ N * 2 + 1 ][ N * 2 + 1 ];
#define D(X,Y) \
  d[ N + (X) ][ N + (Y) ]

struct Cell
{
  int x;
  int y;
  int t;
};
typedef struct Cell Cell;

static Cell
cons (
  int x,
  int y,
  int t
  )
{
  Cell res = { x, y, t };

  return ( res );
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  queue<Cell> lis;

  for ( ; ; )
  {
    int x, y;
    int t, n;
    int res = 0;

    scanf ( "%d%d", &t, &n );
    if ( !( t | n ) ) break ;

    memset ( d, 0, sizeof ( d ) );
    while ( n-- )
    {
      scanf ( "%d%d", &x, &y );
      D( x, y ) = 1;
    }

    scanf ( "%d%d", &x, &y );
    lis.push ( cons ( x, y, t + 1 ) );
    while ( !lis.empty ( ) )
    {
      const Cell c = lis.front ( );
      lis.pop ( );

      if ( !( c.t )
        || c.x < -N || c.x > N
        || c.y < -N || c.y > N
        || D( c.x, c.y ) ) continue ;
      ++res;

      D( c.x, c.y ) = 1;
      lis.push ( cons ( c.x + 1, c.y    , c.t - 1 ) );
      lis.push ( cons ( c.x + 1, c.y + 1, c.t - 1 ) );
      lis.push ( cons ( c.x    , c.y + 1, c.t - 1 ) );
      lis.push ( cons ( c.x - 1, c.y    , c.t - 1 ) );
      lis.push ( cons ( c.x - 1, c.y - 1, c.t - 1 ) );
      lis.push ( cons ( c.x    , c.y - 1, c.t - 1 ) );
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}

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

using namespace std;

int findInt(int query, vector<int> ints) {
	for (int i = 0; i < ints.size(); i++) {
		if (ints.at(i) == query) {
			return i;
		}
	}
	return -1;
}


int main() {
	int X, N;
	cin >> X >> N;
	vector<int> p;
	for (int i = 0; i < N; i++) {
		int pi;
		cin >> pi;
		p.push_back(pi);
	}
	int diff = 0;
	while (findInt(X + diff, p) != -1) {
		if (diff < 0) {
			diff *= -1;
		} else if (diff >= 0) {
			diff *= -1;
			diff--;
		}
	}
	cout << X + diff << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1e9+7;

int H,W;
vector<string> vec;
ll dp[1010][1010]; 
signed main(){
    cin>>H>>W;
    rep(i,H){
        string s;
        cin>>s;
        vec.push_back(s);
    }

    dp[0][0]=1;


    rep(i,H){
        rep(j,W){
            if(i+1<H&&vec[i+1][j]=='.'){
                if(dp[i][j]>0)dp[i+1][j]+=(dp[i][j])%mod;
            }

            if(j+1<W&&vec[i][j+1]=='.'){
                if(dp[i][j]>0)dp[i][j+1]+=(dp[i][j])%mod;
            }
        }
    }

    // rep(i,H){
    //     rep(j,W){
    //         cout<<dp[i][j];
    //     }
    //     cout<<endl;
    // }

    cout<<dp[H-1][W-1]%mod<<endl;


 
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define data_type long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    unordered_map<string,int> ball;
    string s,t,u;
    data_type a,b;
    cin>>s>>t>>a>>b>>u;
    ball[s]=a,ball[t]=b;
    ball[u]-=1;
    cout<<ball[s]<<" "<<ball[t]<<endl;



    return 0;
}


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

int myGcd(int first, int second, int third){
    vector<int> data{first, second, third};
    // 小さい順になる
    sort(data.begin(), data.end());

    int withNom = data.at(1) % data.at(0);
    int withMax = data.at(2) % data.at(0);

    if(withNom == 0 && withMax == 0){
        return data.at(0);
    }else if(withNom == 0){
        return myGcd(data.at(0), data.at(1), withMax);
    }else if(withMax == 0){
        return myGcd(data.at(0), withNom, data.at(2));
    }else {
        return myGcd(data.at(0), withNom, withMax);
    }
}

int howManyAppear(int first, int second, int third){
    if(first == third){
        // 全部同じ
        return 1;
    }else if(first == second || second == third){
        return 3;
    }else{
        return 6;
    }
}

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

    int result = 0;

    for(int m=1; m<=k; m++){
        for(int n=m; n<=k; n++){
            for(int l=n; l<=k; l++){
                result += myGcd(m, n, l) * howManyAppear(m, n, l);
            }
        }
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 3644
input = defined?(DATA) ? DATA : STDIN
n = input.gets.to_i
list = input.gets.split(' ').map(&:to_i)

xor_all = 0
list.each do |x|
  xor_all ^= x
end

result = []
list.each do |x|
  result << (xor_all ^ x)
end

puts result.join(' ')


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)


void func(long long r){
    cout<<3*r*r<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long r;
    scanf("%lld",&r);
    func(r);
    return 0;
}


Measured memory_bytes: 256
// Problem : B - Frog 2
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

#define ff first
#define fs second
#define lb lower_bound
#define ub upper_bound

#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector< vi >
#define vpii vector< pii >
#define vb vector<bool>
#define si set<int>
#define mii map<int, int>
#define mci map<char, int>
#define md 1000000007
#define pb push_back
#define eb emplace_back
#define fio ios_base::sync_with_stdio (false); cin.tie (NULL);  cout.tie (NULL);
#define qw1(x) cerr<<#x<<": "<<x<<" "<<endl
#define qw2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define qw3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define qw4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl


#define f(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define rl(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define all(x) x.begin(),x.end()
#define endl '\n'
void printv(vector<int>  v){ for(int i=0;i<v.size();i++) cout<<v[i]<<' '; cout<<endl;   }
int bem(int m , int n, int mod) { int res=1; while(n){
	     			        if(n%2!=0) { res*=m; res%=mod; }
	    			        m*=m;   m%=mod;   n/=2;
			                          }
				return res;	}
int be(int a, int b) { int res=1; 	while(b){
				if(b%2!=0) res*=a;
				a*=a; b/=2;
				}
			return res;	}
void sieve(int n, vb &prime){
    prime[0]=false;     prime[1]=false;
    for(int i=2;i*i<=n;i++){
         if(prime[i]==true){
              for(int j=i*i;j<=n;j+=i)    prime[j]=false;
             	  }
    	 }
	}
vi v, dp;
int fun(int n, int k)
{
	if(dp[n]!=-1) return dp[n];
	if(n==0) return dp[n]=0;
	if(n==1) return dp[n]=abs(v[1]-v[0]);
	dp[n]=fun(n-1, k)+abs(v[n]-v[n-1]);
	f(i, max(n-k,(int) 0), n-2){
		
	  dp[n]=min(dp[n], fun(i, k)+abs(v[i]-v[n]));
	}
	return dp[n];
	
		
}
void solve()
  {
int n, k; cin>>n>>k;
v.resize(n); f(i, 0, n-1) cin>>v[i];
dp.resize(n, -1);
cout<<fun(n-1, k);
 
  }

int32_t main ()
{
//fio
int t=1; 
//cin>>t; 
while(t--){
	solve();
}
 
}








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

ll N, M;

int main() {
    cin >> N >> M;
    ll ans;
    if (N >= 3 && M >= 3) {
        ans = (N-2)*(M-2);
    }else if (min(N,M) == 2) {
        ans = 0;
    }else if (max(N,M) >= 2) {
        ans = max(N,M)-2;
    }else{
        ans = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

int main()
{
  int k;
  while (scanf("%d", &k) != EOF)
  {
    lli ans = 0;
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++)
        for (int m = 1; m <= k; m++)
          ans += gcd(i, gcd(j, m));
    printf("%lld\n", ans);
  }
  return 0;
}

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

using namespace std;

int n,k;
int d[10] = {};

int cheak(){
    string s = to_string(n);

    for(int i = 0;i< 10;i++){
        if(d[i] == 1 && s.find('0'+ i) != -1){
            return 0;
        }
    }
    return 1;
}
int main(){
    
    cin >> n >> k;
    for(int i = 0;i< k;i++){
        int a;
        cin >> a;
        d[a] = 1;
    }

    while(1){
        if(cheak() == 1)break;
        n++;
    }

    cout << n <<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c = sc.nextInt();
        int[][] d = new int[c][c];
        int[][] g = new int[3][c];
        for (int i = 0; i < c; i++) {
            for (int j = 0; j < c; j++) {
                d[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int x = sc.nextInt()-1;
                g[(i+j)%3][x]++;
            }
        }
        int ans = Integer.MAX_VALUE;
        for (int i = 0; i < c; i++) {
            int c1 = 0;
            for (int b = 0; b < c; b++) {
                c1 += d[b][i] * g[0][b];
            }
            for (int j = 0; j < c; j++) {
                if(i == j) continue;
                int c2 = 0;
                for (int b = 0; b < c; b++) {
                    c2 += d[b][j] * g[1][b];
                }
                for (int k = 0; k < c; k++) {
                    if(i == k || j == k) continue;
                    int c3 = 0;
                    for (int b = 0; b < c; b++) {
                        c3 += d[b][k] * g[2][b];
                    }
                    int tmp = c1 + c2 + c3;
                    if(tmp < ans) ans = tmp;
                }
            }
        }
        System.out.println(ans);
        sc.close();

    }

}


Measured memory_bytes: 80296
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  int n;cin>>n;
  set<int> s;
  rep(i,n){
    int a;cin>>a;
    s.insert(a);
  }
  cout<<(s.size()==n?"YES":"NO");
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int roop;
  cin >> roop;
  int sum =0;
  for(int i=1;i <= roop;i++){
    int start;
    int end;
    cin >> start >> end;
    sum = sum + 1 + end - start;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
/*
    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;

#include <atcoder/all>
using namespace atcoder;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    FOR(i,1,n) cout << "ACL";
    return 0;
}


Measured memory_bytes: 3600
fun main(){
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toLong() }

    for (i in k until n){

        if (a[i] > a[i - k]){
            println("Yes")
        } else {
            println("No")
        }

    }
}

Measured memory_bytes: 71236
#include <stdio.h>

#define SIZE 2000000

int main() {
  setvbuf(stdout, NULL, _IOFBF, 8000);
  int A[SIZE];
  int H=0;
  int i, l, largest, tmp, n;
  char com[21], buf[20];
  buf[19]='\n';
  char *p,*c1,*c2;
  c1 = com+1;
  c2 = com+2;
  do {
    fgets(com, 20, stdin);
    if (*com == 'i') {
      n = 0;
      p = com+7;
      while (*p!='\n') {
        n = n*10+*p-'0';
        p++;
      }
      A[++H] = n;
      for (i=H; i>1 && A[i>>1]<A[i];i>>=1) {
        tmp = A[i>>1];
        A[i>>1] = A[i];
        A[i] = tmp;
      }

    } else if (*c1=='x') { // extract
      n = A[1];
      for (i=18; n>0; n/=10) buf[i--]=(n%10)+'0';
      fputs(buf+i+1, stdout);
      A[1] = A[H];
      i = 1;
      while (1) {
        l = i<<1;
        if (l < H && A[l] > A[i])        largest = l;
        else         largest = i;
        if (l+1 < H && A[l+1] > A[largest])  largest = l+1;
        if (largest == i) break;
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        i = largest;
      }
      H--;
    }
  } while (*c2!='d');
  return 0;
}


Measured memory_bytes: 5460
#include <bits/stdc++.h>
using namespace std;
string S;
int main() {
    cin >> S;
    int slen = S.length();
    int half = slen / 2;
    int max = 0;
    for(int i = 1; i < half; ++i) {
        int flg = 0;
        for(int j = 0; j < i; ++j) {
            if(S.at(j) != S.at(i+j)) {
                flg = 1;
                break;
            }
        }
        if(!flg) {
            max = i*2;
        }
    }
    cout << max << endl;
}

Measured memory_bytes: 256
N, M = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

CB = []
for _ in range(M):
    b,c = [int(x) for x in input().split()]
    CB.append((c,b))
CB = sorted(CB,reverse=True)

for c,b in CB:
    A.extend([c] * b)
    if len(A) >= 2*N:
        break

A.sort(reverse=True)

ans = sum(A[:N])
print(ans)


Measured memory_bytes: 23644
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

signed main(){
  string s;cin>>s;int ans = 0;
  rep(i,(int)(s.length())/2){
    if(s[i] != s[s.length()-i-1])ans++;
  }
  cout << ans << endl;
}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  double ans = 0;
  vector<double> x(n);
  vector<string> u(n);

  for(int i = 0; i < n; ++i){
    cin >> x.at(i) >> u.at(i);
  }

  for(int i = 0; i < n; ++i){
    if(u.at(i) == "JPY"){
      ans += x.at(i);
    } else {
      ans += x.at(i) * 380000;
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
#define IOS std::ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
const int N = 1e4+20;
const ll Mod = 1e5;
const int INF = 0x3f3f3f3f;
int a[N] = {0};
int b[N] = {0};
int g[N][N] = {0};
int main(){
  int a,b;
  cin>>a>>b;
  if(a >= 13){
    cout<<b<<endl;
  }else if( a >= 6){
    cout<<b/2<<endl;
  }else{
    cout<<0<<endl;
  }
	return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
/*
多倍長整数, cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//#pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 998244353;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	ll h1, m1, h2, m2, k;
	scanf("%lld%lld%lld%lld%lld", &h1, &m1, &h2, &m2, &k);
	printf("%lld\n", (m2 + h2 * 60 - h1 * 60 - m1 - k));

	Please AC;
}

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

int main() {
    ll n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    ll dis = llabs(a-b);
    n -= 1;
    if (dis > n*d) {
        cout << "NO" << endl;
    } else if (dis >= n*c && dis <= n*d) {
        cout << "YES" << endl;
    } else {
        ll min_diff = llabs(c-d);
        ll use_low = dis / c;
        ll remain_dis = dis % c;
        ll remain_step = n - use_low;
        // printf("remain step = %lld, remain_dis = %lld\n",
        //        remain_step, remain_dis);
        bool odd_time = false;
        if (remain_step % 2 == 1) {
            remain_step -= 1;
            remain_dis = c - remain_dis;
            odd_time = true;
        }
        //printf("mid_diff %lld\n", min_diff);
        //printf("remain_dis %lld \n", c-remain_dis);
        //printf("remain step = %lld, remain_dis = %lld\n",
            //remain_step, remain_dis);
        ll max_bias = ((remain_step / 2)) * min_diff;
        if (odd_time == false)
            max_bias += use_low * min_diff;
        // cout << max_bias << endl;
        if (max_bias >= remain_dis) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }

    }
    return 0;
}




Measured memory_bytes: 256
n=int(input())
old=[0,0,0]
new=[0,0,0]
for i in range(n):
    a,b,c=map(int,input().split())
    new[0]=a+max(old[1],old[2])
    new[1]=b+max(old[2],old[0])
    new[2]=c+max(old[0],old[1])
    old=new[:]

print(max(new))

Measured memory_bytes: 47960
x1, y1, x2, y2 = map(int, input().split())

xdif = x2 - x1
ydif = y2 - y1

x3 = x2 - ydif
y3 = y2 + xdif
x4 = x3 - xdif
y4 = y3 - ydif

print(x3,y3,x4,y4)

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
  int n,i,a,b,c,d,e;
  int sum;
  int max,min;
  while(1){
    cin >>n;
    if(n==0) break;
    sum=0;
    max=0;
    min=999;
    for(i=0;i<n;++i){
      cin >>a>>b>>c>>d>>e;
      sum=a+b+c+e+d;
      if(sum>max) max=sum;
      if(sum<min) min=sum;
    }
    cout << max <<" " <<min <<endl;
  }
  return 0;
}

Measured memory_bytes: 3064
from fractions import gcd
N=int(input())
A=list(map(int,input().split()))
n=0
i=0
while(n<N):
    i+=1
    n=2**i
INF=0
dat=[INF]*(2*n-1)
def update(i,x):
    i+=n-1
    dat[i]=x
    while(i>0):
        i=(i-1)//2
        dat[i]=gcd(dat[i*2+1],dat[i*2+2])
def find(a,b,k,l,r):
    if r<=a or b<=l:
        return INF
    if a<=l and r<=b:
        return dat[k]
    else:
        vl=find(a,b,k*2+1,l,(l+r)//2)
        vr=find(a,b,k*2+2,(l+r)//2,r)
        return gcd(vl,vr)
for i in range(N):
    update(i,A[i])
ans=0
for i in range(N):
    f=find(0,i,0,0,n)
    g=find(i+1,N,0,0,n)
    ans=max(gcd(f,g),ans)
print(ans)


Measured memory_bytes: 113376
import java.util.Scanner;

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

    Scanner scan = new Scanner(System.in);

    String str = scan.next();
    int a = Integer.parseInt(str);

    str = scan.next();
    int b = Integer.parseInt(str);
    if(a<b) System.out.println("a < b");
    else if(a>b) System.out.println("a > b");
    else if(a==b) System.out.println("a == b");
  }
}


Measured memory_bytes: 26028
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

map<char,int> hyo;

main(){
	hyo['I']=1;
	hyo['V']=5;
	hyo['X']=10;
	hyo['L']=50;
	hyo['C']=100;
	hyo['D']=500;
	hyo['M']=1000;
	
	string in;
	while(cin>>in){
		int i=0;
		int sum=0;
		for(int i=0;i<in.size();i++){
			if(i+1==in.size()){
				sum+=hyo[in[i]];
				continue;
			}
			if(hyo[in[i]]<hyo[in[i+1]]){
				sum+=hyo[in[i+1]]-hyo[in[i]];
				++i;
			}else{
				sum+=hyo[in[i]];
			}
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>

int main()
{
    std::ios_base::sync_with_stdio(0);
    int64_t n,d,sum=0,result = 0;
    std::cin >> n;
    for (int i=0;i<n;++i)
    {
        std::cin >> d;
        result += sum*d;
        sum += d;
    }
    std::cout << result;
    return 0;
}

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

long long dig_sum(long long x) {
  long long sum=0;
  while (x>0) {
    sum += x%10;
    x = x/10;
  }
  return sum;
}

int main() {
  long long N;
  cin >> N;
  
  long long min=1000000;
  for (long long i=1;i<=N/2;i++) {
    if (min > dig_sum(i) + dig_sum(N-i)) {
      min = dig_sum(i) + dig_sum(N-i);
    }
  }

  cout << min << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
typedef long long ll;
const int maxn=100+5;
ll a[maxn];

/*gcd*/
ll gcd(ll a,ll b){  
    return b>0?gcd(b,a%b):a;  
}
/************************/

/*lcm*/
/*先除再乘，否则先乘可能会爆掉*/ 
ll lcm(ll x,ll y){
	return x/gcd(x,y)*y;
} 


int main(){
	 int n;
	 ll ans=1;
	 scanf("%d",&n);
	 for(int i=1;i<=n;i++){
	 	ll x;
	 	scanf("%lld",&x);
	 	ans=lcm(x,ans);
	 }
	 printf("%lld\n",ans);
	return 0;
} 
/*
B
int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a<=c&&b>=d) printf("%d\n",d-c);
	else if(a<=c&&b<=d&&b>=c) printf("%d\n",b-c);
	else if(a>=c&&b>=d&&a<=d) printf("%d\n",d-a);
	else if(a>=c&&b<=d) printf("%d\n",b-a);
	else if(b<=c) printf("0\n");
	else if(d<=a) printf("0\n");
	return 0;
}

*/

/*
A
int main(){
	int a;
	scanf("%d",&a);
	if(a<=99){
		if(a/10==a%10) printf("Yes\n");
		else printf("No\n");
	}
	else if(a<=999){
		if(a/100==a%10) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
} 
*/


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define all(a)  (a).begin(),(a).end()

int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}

signed main(){
  int n;
  cin>>n;
  int sum=0;
  int a;
  for(int i=1; i<=n; i++){
    sum+=i;
    if(sum>=n){
      a=i;
      break;
    }
  }
  int b=sum-n;
  for(int i=1; i<=a; i++){
    if(i==b)
      continue;
    cout<<i<<endl;
  }
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s, t;
	cin >>s >>t;
	
	set<char> st;
	rep(i, sz(t)) st.insert(t[i]);
	for(auto x: st){
		if( s.find(x) == -1){
			puts("-1");
			return 0;
		}
	}
	
	vector<VI> ic(30);
	rep(i, sz(s)){
		ic[s[i]-'a'].push_back(i);
	}
	
	ll cr = -1, sh=0, zn=0;
	VI v(sz(t), -1), zm(30, 0);
	rep(i, sz(t)){
		int w= t[i] - 'a';
		auto it= lower_bound(all(ic[w]), cr+1);
		if(it == ic[w].end()) {
			sh++;
			cr=-1;
			it= lower_bound(all(ic[w]), cr+1);
		}
		{
			cr = *it; 
			//dbg(i,t[i],cr,sh,"hh");
		} 
	}
	//dbg(sh, sz(s), cr);
	cout << sh * sz(s) + cr +1<<"\n";
	return 0;
}


Measured memory_bytes: 1488
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// ここにコードを挿入
		Scanner s = new Scanner(System.in);
		String[] str = s.nextLine().split(" ");
		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		int c = Integer.parseInt(str[2]);
		int x = a % b;
		boolean ans = false;
		for(int i = 1; i <= b; i++) {
			if((x * i) % b == c) {
				ans = true;
				break;
			}
		}
		if(ans) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 23764