akhauriyash/Code-Regression huggingface dataset:
import java.io.PrintWriter;
//import java.util.Arrays;
import java.util.Scanner;
//import java.util.stream.IntStream;

public class Main {
	static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		// 入力
		final String s;	// 2≦|s|≦10^5		s は小文字のアルファベットのみからなる。
		try(Scanner scan = new Scanner(System.in)) {
			s = scan.next();
		}
		
		// 部分文字列が「アンバランス」というのは、連続する2文字が同じ文字でその前後に違う文字が存在すれば、
		// 3文字で「アンバランス」な文字列になる。
		// 全て同じ文字でも良いから2文字で「アンバランス」な文字列になる。
		
		// s.length == 2でもそれは当てはまる。
		
		// それ以外でも離れていても「アンバランス」があるから		
		//IntStream.range(0, s.length()).filter(i -> s.charAt(i) == s.charAt(i + 1)).findFirst(); は使えない。
		
		// 1個飛ばしで存在していても良い。
		// 逆に2個飛ばしで存在していた場合、「アンバランス」なら、
		// そこまでを切り落としても「アンバランス」なはずである。
		
		int start = -1;
		int end = -1;
		
		for (int i = 0; i < s.length(); i++) {
			if (i + 1 < s.length() && s.charAt(i) == s.charAt(i + 1)) {
				start = i + 1;	// i は1オリジン
				end = i + 1 + 1;
				break;				
			} else if (i + 2 < s.length() && s.charAt(i) == s.charAt(i + 2)) {
				start = i + 1;
				end = i + 2 + 1;
				break;
			}
		}
		
		
		// 各文字について検討する
		// 過半数を占めるためには文字Aから次の文字Aまでのm文字で区切った時、
		// その間の文字m/2以上文字Aがあればよい。
		// 逆に、その区間過半数ない場合は、さらに次の文字Aまで集計するにあたって
		// 過半数を取る助けにならないので破棄してよい。
		
		/* 各文字について検討する 方法は取らなくても良さそう。
		for (char c = 'a'; c <= 'z'; c++) {
			
			int start = 0;
			int count = 0;
			
			for (int i = 0; i < s.length(); i++) {
				
			}
		}*/
		
		
		
		// 出力
		out.println(start + " " + end);
		out.close();
	}

}


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

int main() {
    int a, b, c;  cin >> a >> b >> c;
    cout << a + b + c + 9*max({a, b, c}) << endl;
}

Measured memory_bytes: 384
n=int(input())
w = list(map(int,input().split()))
midw = sum(w)/2
tempw = 0
mid = 0
for i in range(0,n):
    tempw += w[i]
    if tempw >= midw:
        mid = i
        break

res1 = abs(sum(w[0:mid])-sum(w[mid:]))
res2 = abs(sum(w[0:mid+1])-sum(w[mid+1:]))

print(min(res1,res2))

Measured memory_bytes: 3064
#include <cstdio>


int n;

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

    int a, b, ans = 0;
    for(int i = 0; i < n; i++){
        scanf("%d %d", &a, &b);
        ans += b - a + 1;
    }

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

    return 0;
}


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

typedef long long int ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t,n,m,k,i,b,j;
	cin >> n;
	ll arr[n+2],a[n+2]={0};
	for(i=1;i<=n;i++)
	{
		cin >> arr[i];
	}
	a[1]=0;
	a[2]=a[1]+abs(arr[1]-arr[2]);
	for(i=3;i<=n;i++)
	{
		a[i]=min(a[i-1]+abs(arr[i-1]-arr[i]),a[i-2]+abs(arr[i-2]-arr[i]));
	}
	cout << a[n] << "\n";
	return 0;
}

Measured memory_bytes: 5176
n = int(input())
s = input()
max_cnt = 0

for i in range(1,n):
    a = set(s[:i])
    b = set(s[i:])
    cnt = 0
    for a_ in a:
        cnt += 1 if a_ in b else 0
    max_cnt = max(cnt,max_cnt)

print(max_cnt)


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;


int R, C;
VII a;

int solve(int n) {
	if (n == R) {
		int ret = 0;
		for (int j = 0; j < C; j++) {
			int cnt = 0;
			for (int i = 0; i < R; i++) {
				if (a[i][j]) cnt++;
			}
			ret += max(cnt, R - cnt);
		}
		return ret;
	}

	int tmp1 = solve(n + 1);
	rep(i, C) {
		a[n][i] = !a[n][i];
	}
	int tmp2 = solve(n + 1);

	return max(tmp1, tmp2);
}

int main() {
	while (cin >> R >> C, R)
	{
		a = VII(R, VI(C));
		rep(i, R) rep(j, C) cin >> a[i][j];

		cout << solve(0) << endl;
	}


	return 0;
}



Measured memory_bytes: 3324
#include <stdio.h>
int row[8],col[8],dpos[2*8-1],dneg[2*8-1],x[8][8];

void init(){
  int i,j;
  for(i=0;i<8;i++) {
    row[i]=-1;
    col[i]=-1;
  }
  for(i=0;i<2*8-1;i++){
    dpos[i]=-1;
    dneg[i]=-1;
  }
}
void print(){
  int i,j;
  for(i=0;i<8;i++){
    for(j=0;j<8;j++){
      if(x[i][j]==1){
        if(row[i]!=j)return;
      }
    }
  }
  for(i=0;i<8;i++){
    for(j=0;j<8;j++){
      if(row[i]==j){printf("Q");}
      else printf(".");
    }
    printf("\n");
  }
}

void recursive(int i){
  int j;
  if(i==8){
    print();
    return;
  }
  for(j=0;j<8;j++){
    if(col[j]==1||dpos[i+j]==1||dneg[i-j+8-1]==1)continue;
    row[i]=j;
    col[j]=1;
    dpos[i+j]=1;
    dneg[i-j+8-1]=1;
    recursive(i+1);
    row[i]=-1;
    col[j]=-1;
    dpos[i+j]=-1;
    dneg[i-j+8-1]=-1;
  }
}

int main()
{
  int i,j,k,r,c;
  init();

  for(i=0;i<8;i++){for(j=0;j<8;j++){x[i][j]=0;}}
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d %d",&r,&c);
    x[r][c]=1;
  }
  recursive(0);

  return 0;
}


Measured memory_bytes: 2112
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		sc.nextLine();
		LOOP: for (int i = 0; i < n; i++)
		{
			String str = sc.nextLine();
			for (int a = 3; true; a++)
			{
				for (int b = 0; b < 26; b++)
				{
					if (a % 2 == 0 || a % 13 == 0) continue;
					StringBuffer buf = new StringBuffer(str);
					for (int j = 0; j < buf.length(); j++)
					{
						if (Character.isLowerCase(buf.charAt(j)))
							buf.setCharAt(j, affineCipher(a, b, buf.charAt(j)));
					}
					if (buf.indexOf("that") != -1 || buf.indexOf("this") != -1)
					{
						System.out.println(buf.toString());
						continue LOOP;
					}
				}
			}
		}
	}
	private static char affineCipher(int a, int b, char y)
	{
		int n = y - 'a';
		int f = (a * y + b) % 26;
		return (char) (f + 'a');
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
int main(void)
{
	int n,x;
	int i,j,k,ans;
	while(1){
		scanf("%d %d",&n,&x);
		ans = 0;
		if(n == 0&&x == 0){
			break;
		}
		for(i = 1;i <= n - 2;i++){
			for(j = 2;j <= n - 1;j++){
				for(k = 3;k <= n;k++){
					if(i + j + k == x && i < j && j < k){
						ans++;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 600
N, A, B = map(int, input().split())
X = list(map(int, input().split()))
sx = sorted(X)
ans = 0
for i in range(N-1):
  d = sx[i+1]-sx[i]
  if d*A < B:
    ans += d*A
  else:
    ans += B
print(ans)

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

typedef long long int int64;
static const int64 mod = 998244353LL;
int64 exgcd(int64 a,int64 b,int64 &c,int64 &d)
{
	if(b == 0) {
		c = 1, d = 0;
		return a;
	}
	int64 k = exgcd(b, a % b, d, c);
	d -= c * (a / b);
	return k;
}
int64 finv(int64 v)
{
	int64 c,d;
	exgcd(v,mod,c,d);
	if(c < 0) c += mod;
	return c;
}
int64 f[4][262144];
int n;
int main()
{
	scanf("%d",&n);
	int64 sum = 0;
	for(int i = 0;i < (1<<n);++i) {
		scanf("%lld",&f[0][i]);
		sum += f[0][i];
	}
	sum = finv(sum);
	for(int i = 0;i < (1<<n);++i) {
		f[0][i] = f[0][i] * sum % mod;
		f[1][i] = mod-1;
	}
	--f[0][0];
	if(f[0][0] < 0) f[0][0] += mod;
	f[1][0] = (1<<n)-1;
	for(int i = 0;i < n;++i) {
		for(int j = 0;j < (1<<n);++j) if((j&(1<<i))==0) {
			int64 p = f[0][j], q = f[0][j|(1<<i)];
			f[0][j] = (p+q)%mod;
			f[0][j|(1<<i)] = (p-q+mod)%mod;
			p = f[1][j], q = f[1][j|(1<<i)];
			f[1][j] = (p+q)%mod;
			f[1][j|(1<<i)] = (p-q+mod)%mod;
		}
	}
	for(int i = 0;i < (1<<n);++i) {
		f[0][i] = finv(f[0][i]) * f[1][i] % mod;
	}
	int64 inv2 = finv(2);
	for(int i = 0;i < n;++i) {
		for(int j = 0;j < (1<<n);++j) if((j&(1<<i))==0) {
			int64 p = f[0][j], q = f[0][j|(1<<i)];
			f[0][j] = (p+q)%mod*inv2%mod;
			f[0][j|(1<<i)] = (p-q+mod)%mod*inv2%mod;
		}
	}
	for(int i = 0;i < (1<<n);++i) {
		int64 val= (f[0][i]-f[0][0])%mod;
		if(val < 0) val += mod;
		printf("%lld\n", val);
	}
}


Measured memory_bytes: 8960
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt(); // infomation amount
	
		int[][] b1 = new int[4][11];
		int[][] b2 = new int[4][11];
		int[][] b3 = new int[4][11];
		int[][] b4 = new int[4][11];
		
		for(int i = 0; i < n; i++){
			
			int b = scan.nextInt(); // tou
			int f = scan.nextInt(); // flor
			int r = scan.nextInt(); // room
			int v = scan.nextInt(); // ninzu
		
			if(b == 1){
				b1[f][r] += v;
				}else if(b == 2){
					b2[f][r] += v;
				}else if(b == 3){
					b3[f][r] += v;
				}else if(b == 4){
					b4[f][r] += v;
				}
		}
		
		for(int i = 1; i <= 3; i++){
			for(int j = 1; j <= 10; j++){
				System.out.print(" " + b1[i][j]);
			}
			System.out.println();
		}
		
		System.out.println("####################");
		
		for(int i = 1; i <= 3; i++){
			for(int j = 1; j <= 10; j++){
				System.out.print(" " + b2[i][j]);
			}
			System.out.println();
		}
		
		System.out.println("####################");
		
		for(int i = 1; i <= 3; i++){
			for(int j = 1; j <= 10; j++){
				System.out.print(" " + b3[i][j]);
			}
			System.out.println();
		}
		
		System.out.println("####################"); 
		
		for(int i = 1; i <= 3; i++){
			for(int j = 1; j <= 10; j++){
				System.out.print(" " + b4[i][j]);
			}
			System.out.println();
		}
		
		
		
		
	}

}

Measured memory_bytes: 30292
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    
    vector<int> vec(N);
    for(int i = 0; i < N; i++){
        cin >> vec.at(i);
    }

    //sort algorithm
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(vec.at(i) > vec.at(j)){
                int A = vec.at(i);
                int B = vec.at(j);
                vec.at(j) = A;
                vec.at(i) = B;
            }
        }
    }
    
    int sum = 0;
    for (int i = 0; i < N; i+=2){
        sum += vec.at(i);
    } 
    for (int i = 1; i < N; i+=2){
        sum -= vec.at(i);
    } 

    cout << sum << endl;



}

Measured memory_bytes: 3588
public class Main {

    /**
     * ????????????
     *
     * @param args
     */
    public static void main(String[] args) {
        for (int i = 1; i < 10; i++) {
            for (int j = 1; j < 10; j++) {
                System.out.println(i + "x" + j + "=" + i * j);
            }
        }
    }
}

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

int main()
{
    string S;
    cin >> S;
    char tmp = '*';
    ll cnt = 0;

    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] == tmp)
        {
            tmp = '*';
            i++;
            if (i != S.length())
            {
                cnt++;
            }
        }

        else
        {
            tmp = S[i];
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 640
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    n,k = readInt()
    r,s,p = readInt()
    rsp = {"s":r,"p":s,"r":p}
    t = input()
    ans = 0
    u = []
    for i in range(n):
        if i<k:
            ans += rsp[t[i]]
            u.append(t[i])
        else:
            if t[i]!=u[i-k]:
                ans += rsp[t[i]]
                u.append(t[i])
            else:
                u.append("f")
    print(ans)
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 4212
n, w=gets.split.map(&:to_i)
wei, val=[], []
n.times do
  a, b=gets.split.map(&:to_i)
  wei<< a
  val<< b
end

item=Array.new(4){[]}
r=wei[0]
n.times{|i| item[wei[i]-r]<< val[i]}
item.each{|v| v.sort!{|a, b| b<=>a}}

sum=Array.new(4){[]}
4.times do |i|
  item[i].size.times do |j|
    if j.zero?
      sum[i]<< item[i][0]
    else
      sum[i]<< sum[i][j-1]+item[i][j]
    end
  end
end

ans=0
(item[0].size+1).times do |i|
  (item[1].size+1).times do |j|
    (item[2].size+1).times do |k|
      (item[3].size+1).times do |l|
        _w, _v=0, 0
        _w=r*i+(r+1)*j+(r+2)*k+(r+3)*l
        _v+=sum[0][i-1] if i.nonzero?
        _v+=sum[1][j-1] if j.nonzero?
        _v+=sum[2][k-1] if k.nonzero?
        _v+=sum[3][l-1] if l.nonzero?
        if _w<=w
          ans=[ans, _v].max
        end
      end
    end
  end
end

puts ans


Measured memory_bytes: 1788
n = int(input("")) #รับจำนวนข้อมูลในบรรทัดแรก
ns = list(map(int,input().split())) #รับข้อมูลในบรรทัดที่2 split และเก็บไว้ใน int 
c = 0
for i in range(n-1): #วน n-1 เพราะไม่นับรวมครั้งแรกที่ทำ
    for j in range(n-1-i): #วน loop 
        if ns[j] > ns[j+1]: #ถ้าข้อมูลในตำแหน่งที่ j > ข้อมูลตำแหน่งที่ j+1
            ns[j],ns[j+1]=ns[j+1],ns[j]
            #ทำการสลับตำแหน่ง j ไปที่ j+1 เหมือนฟองอากาศที่ลอยขึ้นไปเรื่อยๆ
            c+=1 # นับครั้งการ swap
print(" ".join(map(str,ns)))
print(c)




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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(min(a,b) < c && c < max(a,b)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 768
#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;
  string s;
  cin>>n>>s;

  map<char,int> cnt;
  for(char c : s) cnt[c]++;

  Int ans = 1;
  for(auto p : cnt) ans *= p.second + 1;

  cout << ans - 1 << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28; // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19
constexpr static double EPS = 1e-10;

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

    int preB = 0;
    ll ans = 0;
    int i = 0;
    while (true) {
        if (preB > 0) {
            if (preB > as[i]) {
                ans += as[i];
                as[i] = 0;
            } else {
                ans += preB;
                as[i] -= preB;
            }
        }

        if (i == n) {
            break;
        }

        int b;
        cin >> b;
        if (as[i] > b) {
            ans += b;
            preB = 0;
        } else {
            ans += as[i];
            preB = b - as[i];
        }

        i++;
    }

    cout << ans << endl;
}


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

int main() {
int n,k;
cin >> n >> k;
long double ans=0;
for(int i=1;i<=n;i++){
    long double tmp=ceil(log2(k)-log2(i));
  if(k<=i)tmp=0;
    long double tmpw=pow(0.5,tmp);
    ans+=tmpw/n;
}
cout <<fixed << setprecision(15) << ans << endl;
}


Measured memory_bytes: 384
#!ruby -nal
a=$F.sort
c||={a=>0}
q||=[a]
l=[[1],*[[1,-1]]*2,[-1]]*2
(l[t=(m=q.shift).index(?0)]+[-4]).map{|i|d=m.dup
d[t]=d[t+i]
d[t+i]=?0
c[d]||(c[d]=c[m]+1)&&q<<d
}until n=c[$F]
p n

Measured memory_bytes: 16980
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int a, b, c;

signed main() {
	cin >> a >> b >> c;
	cout << (c / a)*b << endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

unordered_map<ll, ll> mp;

ll n, a, b;
vector<ll> x;

void solve() {
    ll ans = 0;
    repone(i, n - 1) {
        if ((x[i] - x[i - 1]) * a > b) {
            ans += b;
        } else {
            ans += (x[i] - x[i - 1]) * a;
        }
    }
    cout << ans << endl;
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = unordered_map<ll, ll>();
#pragma clang diagnostic pop
#endif

        cin >> n >> a >> b;
        x.resize(n);
        rep(i, n) cin >> x[i];
        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return a % 1000000007;
}


int main(){
  ll n; cin >> n; vl via(100001); vl vib(100001); ll a = 0; ll b = 0;
 
  for(ll i=1; i <= n; i++){
    ll x; cin >> x;
    
    if(i % 2 == 0) via[x]++;
    else vib[x]++;
  }
  
  
  ll ai = -1; ll bi = -1;
  for(ll i=1; i <= 100000; i++){
    if(via[i] > a){
      a = via[i]; ai = i;
    }
    if(vib[i] > b){
      b = vib[i]; bi = i;
    }
  }
  
  if(ai == bi){
    sort(all(via)); sort(all(vib));
    cout << min(n - a - vib[99999], n - b - via[99999]) << endl;
  }
  else cout << n - a - b << endl;
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}


template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};




template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}


vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.pb(buffer);
    }
    return v;
}




int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string x;
    cin >> x;

    stack<char> s;
    rep(i, x.size()){
        if(s.empty()) s.push(x[i]);
        else if(x[i] == 'T' and s.top() == 'S')
            s.pop();
        else
            s.push(x[i]);
    }

    ppp(s.size());



    return 0;
}


Measured memory_bytes: 720
function Main(input) {
    var lines = input.split('\n');
    var R = +lines[0];
    var ans;
    if (R < 1200) {
        ans = 'ABC';
    } else if (R < 2800) {
        ans = 'ARC';
    } else {
        ans = 'AGC';
    }
    console.log(ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

a=x2-x1
b=y2-y1
x3 = x2 - b
y3 = y2 + a
x4 = x3 - a
y4 = y3 - b
print(x3, y3, x4, y4)





Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef vector< pii > vii;

#define ll          long long
#define ff          first
#define ss          second
#define pb          push_back
#define mkp         make_pair
#define sz          size()

#define forf(a,b,c)    for(int i=a;i<=b;i+=c)
#define forr(a,b,c)    for(int i=a;i>=b;i-=c)
#define all(a)      a.begin(),a.end()
#define mem(a,b)    memset(a,b,sizeof(a))
#define pi          2*acos(0.0)
#define End         return 0;

#define scan1(a)    scanf("%d",&a)
#define scan2(a,b)  scanf("%d %d",&a,&b)
#define scan3(a,b,c)  scanf("%d %d %d",&a,&b,&c)
#define scanl(a)    scanf("%lld",&a)
#define scanll(a,b) scanf("%lld %lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)

#define print1(a)    printf("%d",a)
#define print2(a,b)  printf("%d %d",a,b)
#define print3(a,b,c)  printf("%d %d %d",a,b,c)
#define printl(a)    printf("%lld",a)
#define printll(a,b) printf("%lld %lld",a,b)
#define printlll(a,b,c) printf("%lld %lld %lld",a,b,c)

#define MAXN        100000007
#define INF 0x3f3f3f3f
//int dx[]={+1,-1,+0,+0};///Four Directions
//int dy[]={+0,+0,+1,-1};///Four directions
//int dx [] = {+1,-1,+0,+0,-1,-1,+1,+1};///Eight Directions
//int dy [] = {+0,+0,+1,-1,+1,-1,-1,+1};///Eight Directions

//int mark[10007];vi prime;void seive(){for(int i=2;i<10000;i++){if(mark[i]==0){prime.pb(i);for(int j=i+i;j<=10000;j+=i)mark[j]=1;}}}

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

int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll k,n;
    cin>>k>>n;

    vll v(n);
    for(int i=0;i<n;i++) cin>>v[i];

    sort(all(v));
    ll dis=0,mx=-1;
    for(int i=1;i<n;i++){
        dis+=abs(v[i]-v[i-1]);
        mx=max(mx,abs(v[i]-v[i-1]));
    }
    ll t=k-v[n-1]+v[0];
    mx=max(mx,t); dis+=t;
    cout<<dis-mx<<endl;
    End;
}


Measured memory_bytes: 1920
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	

	static class Point implements Comparable<Point> {
		int x,y;
		public Point (int x,int y) {
			this.x = x;
			this.y = y;
		}
		@Override
		public int compareTo(Point o) {
			if (this.x == o.x) {
				return this.y - o.y;
			}
			return this.x - o.x;
		}
	}
	public static void main(String[]args) throws Throwable {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Point red[] = new Point[n];
		Point blue[] = new Point[n];
		for (int i = 0 ; i < n ; ++i) {
			red[i] = new Point(sc.nextInt(),sc.nextInt());
		}
		for (int i = 0 ; i < n ; ++i) {
			blue[i] = new Point(sc.nextInt(),sc.nextInt());
		}
		int ans = 0;
		boolean done[] = new boolean[n];
		Arrays.sort(red);
		Arrays.sort(blue);
		for (int i = n - 1 ; i >= 0 ; --i) {
			
			int ind = -1, ret = 1 << 30;
			for (int j = 0 ; j < n ; ++j) {
				if (done[j]) {
					continue;
				}
				if (red[i].x >= blue[j].x) {
					continue;
				}
				if (blue[j].y > red[i].y) {
					if (ret > blue[j].y) {
						ret = blue[j].y;
						ind = j;
					}
				}
			}
			if (ind != -1) {
				done[ind] = true;
				++ans;
			}
		}
		System.out.println(ans);
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}


Measured memory_bytes: 21460
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

############
############
############

r, D, x = l_inpl()

for i in range(10):
    x = r*x - D
    print(x)

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

int n;
bool ary[100100];
vector<int> v;

void count(){
	int cnt = 1;
	for (int i = 1; i < n; i++){
		if(ary[i] == ary[i-1])cnt++;
		else
		{
			v.push_back(cnt);
			cnt = 1;
		}
	}

	v.push_back(cnt);
}

int main(){
	int Max = 0;

	cin >> n;

	for (int i = 0; i < n; i++) cin >> ary[i];

	for (int i = 0; i < n; i += 2) ary[i] = !ary[i];

	count();

	if (v.size() == 1) {
		cout << v[0] << endl;
		return 0;
	}

	if (v.size() == 2) {
		cout << v[0] + v[1] << endl;
		return 0;
	}

	for (auto i = 0; i < v.size() - 2; i++) {
		int val = v[i] + v[i+1] + v[i+2];
		Max = max(Max, val);
	}

	cout << Max << endl;

	return 0;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

using i32 = int;
using i64 = long long;
using ll = long long;

using namespace std;

template<class T> class Dinic{
private:
    struct edge{
        int to; T cap; int rev;
        edge(int to,T cap,int rev):to(to),cap(cap),rev(rev){}
    };
    int N,M;
    vector<vector<edge>> G;
    vector<T> level;
    vector<int> iter;
public:
    Dinic(int N,int M):N(N),M(M),G(N),level(N,0),iter(N,0){}
    void add_edge(int from,int to,T cap);
    void bfs(int s);
    T dfs(int v,int t,T f);
    T max_flow(int s,int t);
};

template<class T>
void Dinic<T>::add_edge(int from, int to, T cap) {
    G[from].emplace_back(to,cap,G[to].size());
    G[to].emplace_back(from,0,G[from].size() - 1);
}
template<class T>
void Dinic<T>::bfs(int s){
    for(auto &i : level) i = -1;
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
        int v = que.front();que.pop();
        for(int i = 0;i < G[v].size();i++){
            edge &e = G[v][i];
            if(e.cap > 0 && level[e.to] < 0){
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

template<class T>
T Dinic<T>::dfs(int v, int t, T f) {
    if(v == t) return f;
    for(int &i = iter[v];i < G[v].size();i++){
        edge &e = G[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            T d = dfs(e.to,t,min(f,e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

template<class T>
T Dinic<T>::max_flow(int s, int t) {
    T flow = 0;
    for(;;){
        bfs(s);
        if(level[t] < 0) return flow;
        for(auto& i : iter) i = 0;
        T f;
        while((f = dfs(s,t,(1LL << 55))) > 0){
            flow += f;
        }
    }
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin >> n >> m;
    Dinic<int64_t> D(n,m);
    REP(i,m){
        int u,v;
        int64_t c;
        cin >> u >>v >> c;
        D.add_edge(u,v,c);
    }
    cout << D.max_flow(0,n-1) << '\n';
}


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

using namespace std;

int main(){
    long long int n;
    cin >> n;
    long long int a[n];

    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int count = 0;
    for(int i=0; i<n; i++){
        if(i%2==0 && a[i]%2!=0){
            count = count + 1;
        }
    }
    cout << count << endl;
    return 0;
}


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

#define fi                      first
#define se                      second
#define pb                      push_back
#define endl                    '\n'
#define all(x)                  x.begin(),x.end()
#define pii                     pair<int,int>
#define pll                     pair< long long int, long long int> 
#define fast                    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define SZ(x)                   ((int)x.size())

#define FOR(i,a,b)              for(int i = a; i < b; ++i)
#define REV(i,a,b)              for(int i = a; i >= b; --i)
#define FORE(i,a,b)             for(int i = a; i <= b; ++i)

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

void solve();

int32_t main()
{
        fast;
        int t = 1;
        // cin >> t;
        for(int i = 1; i <= t; ++i)
                solve();
        cerr << "Time taken: " << ((clock() * 1000) / CLOCKS_PER_SEC) << "ms\n";
}

void solve() {
        int n;
        cin >> n;
        set<int> s;
        int cnt = 0;
        FOR(i,0,n) {
        	int temp;
        	cin >> temp;
        	if(i == 0) {
        		s.insert(temp);
        		cnt++;
        		continue;
        	}
        	if(*s.begin() > temp) {
        		cnt++;
        		s.insert(temp);
        	}
        }
        cout << cnt << endl;
}

Measured memory_bytes: 9600
def check(x):
    ret = 0
    for e in a:
        ret += max((e - 1) // x, 0)

    return ret <= k


n, k = map(int, input().split())
a = list(map(int, input().split()))

l = 0
r = 10 ** 9
while r - l > 1:
    m = (l + r) // 2
    if check(m):
        r = m
    else:
        l = m

print(r)


Measured memory_bytes: 30780
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
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;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int n;
	cin >> n;
	int ans = 0;
	ans = 1000 - n % 1000;
	if(ans == 1000) ans = 0;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3648
def res(n):
    pos = n
    cnt = 1
    while 1:
        pos = P[pos]-1
        if pos == n:
            break
        cnt += 1

    tmp = 0
    ans = -float("inf")
    pos = n

    for _ in range(min(K,cnt)):
        pos = P[pos]-1
        tmp += C[pos]
        ans = max(ans,tmp)
    
    ##ループして0以上なら(K//cnt)回ループしてあまりをシミュレーション
    if tmp > 0 and K > cnt:
        pos = n
        d = K%cnt
        tmp = (K//cnt-1)*tmp
        ans = max(ans,tmp)
        for _ in range(d+cnt):
            pos = P[pos]-1
            tmp += C[pos]
            ans = max(ans,tmp)

    return ans

N,K = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = -float("inf")
for i in range(N):
    ans = max(ans,res(i))

print(ans)


Measured memory_bytes: 74572
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto &i : c)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define fill(a)  memset(a, 0, sizeof (a))
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }
int mul(int a, int b, int c){lli res=(lli)a*b;return (int)(res>=c?res%c:res);}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}


int main(){
    // #ifndef ONLINE_JUDGE
	// 	freopen("test", "r", stdin);
	// #endif
    fastio;
    
    lli N, M;
    cin >> N >> M;

    lli sum = 0;
    int temp;
    rep(i, M){
        cin >> temp;
        sum += temp;
    } 

    if(sum > N){
        cout << -1 << endl;
    }else{
        cout << N - sum << endl;
    }

    return 0;
}


Measured memory_bytes: 3692
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int N;
long long ans;

int main(){
	cin >> N;
	for (int i = 0; i < N; i++){
		ans += i;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 true; }
  return false;
}

template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return true;}
  return false;
}

vector<vector<long long>> h(100010, vector<long long>(3, 0));
vector<vector<long long>> dp(100010, vector<long long>(3, 0));

int main() {
  int N;
  cin >> N;
  
  rep(i,N) rep(j,3) cin >> h.at(i).at(j);
  
  rep(i, N) {
    rep(j, 3){
      rep(k, 3){
        if(j == k) continue;
        chmax(dp.at(i+1).at(k), dp.at(i).at(j) + h.at(i).at(k));
      }
    }
  }
  
  long long ans = 0;
  rep(i, 3) chmax(ans, dp.at(N).at(i));
  cout << ans << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

int num(ll n)
{
	ll ans = 0;
	while (n != 0)
	{
		n /= 10;
		ans++;
	}
	return ans;
}

int main()
{
	ll N;
	cin >> N;
	ll sq = (int)(sqrt(N)) + 1;
	int min = 11;
	FOR(i, sq + 1, 1)
	{
		if (N%i != 0)continue;
		min = std::min(min, num(N / i));
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long int LL;
int main(){
    LL A, B, C, x, y;
    scanf("%lld%lld%lld%lld%lld", &A, &B, &C, &x, &y);
    if(A+B > 2*C){
        LL z = min(x, y);
        LL ans = 2*C*z + A*(x-z) + B*(y-z);
        ans = min(ans, C*2*max(x, y));
        printf("%lld", ans);
    }
    else{
        printf("%lld", A*x+B*y);
    }
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
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 MOD7 1000000007
#define LL_INF 1LL << 60
#define LL_MINF -1LL << 60
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const long double PI = (acos(-1));

int gdig_sum(string s){
  int ans = 0;
  for(char c : s){
    ans += c - '0';
  }
  return ans;
}

int main(){
    vector<int> ans;
    while(true){
        string s;
        cin >> s;

        if(s == "0") break;
        ans.push_back(gdig_sum(s));
    }
    for(int a : ans) cout << a << endl;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int ctoi(const char c) {
    if ('0' <= c && c <= '9') return (c - '0');
    return -1;
}
vector<int> input(int n) {
    vector<int> vec(n);
    for (int i = 0; i < n; i++) {
        cin >> vec.at(i);
    }
    return vec;
}
void output(vector<int> vec) {
    for (int i = 0; i < vec.size(); i++) {
        cout << vec[i] << " ";
    }
    return;
}
vector<vector<int>> input(int n, int m) {
    vector<vector<int>> table(n, vector<int>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> table. at(i).at(j);
        }
    }
    return table;
}
void output(vector<vector<int>> table) {
    for (int i = 0; i < table.size(); i++) {
        for (int j = 0; j < table.at(0).size(); j++) {
            cout << table.at(i).at(j) << " ";
        }
        cout << endl;
    }
}
long long perm(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long perm = 1;
    for (int i = n; i > n - r; i--) {
        perm *= i;
    }
    return perm;
}
long long comb(int n, int r) {
    if (n < r) {
        cout << "error" << endl;
        return 0;
    }
    long long comb = perm(n,r);
    for (int i = r; i > 0; i--) {
        comb /= i;
    }
    return comb;
}
long long homo(int n, int r) {
    return comb(n + r - 1, n - 1);
}
long long fact(int n) {
    long long fact = 1;
    for (int i = n; i > 0; i--) {
        fact *= i;
    }
    return fact;
}
int gcd(int a, int b)
{
    if (a % b == 0)
    {
        return(b);
    }
    else
    {
        return(gcd(b, a % b));
    }
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int main() {
  string s;  
  cin >> s;
  int x=s.size();
  for(int i=0;i<=x;i++){
    s.pop_back();
    s.pop_back();
    string s1=s.substr(0,s.size()/2);
    string s2=s.substr(s.size()/2);
    if(s1==s2){
      cout << s.size() << endl;
      break;
    }
  }
}

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

int X[8002][20000] = {};
int Y[8002][20000] = {};

int main()
{
	vector<int> vX, vY;
	string s;
	int x, y;
	cin >> s;
	cin >> x >> y;

	int i = 0;
	int init_x = 0;
	while (s[i]=='F' && i<s.size())
	{
		init_x++;
		i++;
	}
	//0:Y,1:X
	int state = 1;
	for(;i<s.size();i++)
	{
		if (s[i] == 'T')
		{
			if (state == 0)
			{
				state = 1;
			}
			else
			{
				state = 0;
			}
		}
		else
		{
			int value=0;
			while (s[i] == 'F' && i<s.size())
			{
				value++;
				i++;
			}
			if (state == 0)vY.push_back(value);
			else vX.push_back(value);
			i--;
		}
	}

	X[0][10000+init_x] = 1;
	Y[0][10000] = 1;

	int index = 1;
	int index_x = 0;
	int index_y = 0;
	while (true)
	{
		if (index_y < vY.size())
		{

			//yの処理
			if (!vY.empty())
			{
				for (i = -10000; i < 10000; i++)
				{
					if (Y[index - 1][10000 + i] != 0)
					{
						if (10000 + i + vY[index_y] < 20000)Y[index][10000 + i + vY[index_y]] = 1;
						if (10000 - i + vY[index_y] >= 0)Y[index][10000 + i - vY[index_y]] = 1;
					}
				}

				index_y++;
			}
		}

		if (index_x < vX.size())
		{
			//xの処理
			for (i = -10000; i < 10000; i++)
			{
				if (X[index - 1][10000 + i] != 0)
				{
					if (10000 + i + vX[index_x] < 20000)X[index][10000 + i + vX[index_x]] = 1;
					if (10000 - i + vX[index_x] >= 0)X[index][10000 + i - vX[index_x]] = 1;
				}
			}
			index_x++;
		}
		if (index_y >= vY.size() && index_x >= vX.size())break;

		index++;
	}

	if (X[vX.size()][10000 + x] == 1 && Y[vY.size()][10000 + y] == 1)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 313856
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; ( iter = $ iter : ident , $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut $ iter = s . split_whitespace ( ) ; input_inner ! { $ iter , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let s = { use std :: io :: Read ; let mut s = String :: new ( ) ; std :: io :: stdin ( ) . read_to_string ( & mut s ) . unwrap ( ) ; s } ; let mut iter = s . split_whitespace ( ) ; input_inner ! { iter , $ ( $ r ) * } } ; }
macro_rules ! input_inner { ( $ iter : expr ) => { } ; ( $ iter : expr , ) => { } ; ( $ iter : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , mut $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , mut $ var : usize $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ iter , $ t ) ; input_inner ! { $ iter $ ( $ r ) * } } ; ( $ iter : expr , $ var : ident $ ( $ r : tt ) * ) => { input_inner ! { $ iter , $ var : usize $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ iter : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ iter , $ t ) ) ,* ) } ; ( $ iter : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ iter , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ iter : expr , { chars : $ base : expr } ) => { read_value ! ( $ iter , String ) . chars ( ) . map ( | c | ( c as u8 - $ base as u8 ) as usize ) . collect ::< Vec < usize >> ( ) } ; ( $ iter : expr , { char : $ base : expr } ) => { read_value ! ( $ iter , { chars : $ base } ) [ 0 ] } ; ( $ iter : expr , chars ) => { read_value ! ( $ iter , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ iter : expr , char ) => { read_value ! ( $ iter , chars ) [ 0 ] } ; ( $ iter : expr , usize1 ) => { read_value ! ( $ iter , usize ) - 1 } ; ( $ iter : expr , $ t : ty ) => { $ iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) } ; }
use std::cmp::max;
fn main() {
    input! { n, k, a: [i64; n] };
    let mut vl = vec![0; n + 1];
    let mut vr = vec![0; n + 1];
    let mut sum = vec![0; n + 1];
    for i in 0..n {
        vl[i + 1] = vl[i] + max(0, a[i]);
        sum[i + 1] = sum[i] + a[i];
    }
    for i in (0..n).rev() {
        vr[i] = vr[i + 1] + max(0, a[i]);
    }
    let mut ans = 0;
    for i in 0..n - k + 1 {
        let x = vl[i] + vr[i + k] + max(0, sum[i + k] - sum[i]);
        ans = max(ans, x);
    }
    println!("{}", ans);
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){ 
    string S;
    cin >>S;
    bool frag = 1;
    for(int i = 0;i < S.size();i++){
        if((i + 1)%2 == 1){
            if(S[i] == 'L') frag = 0;
        }else{
            if(S[i] == 'R') frag = 0;
        }
    }
    if(frag) cout << "Yes" << endl;
    else cout << "No" << endl;
}   


Measured memory_bytes: 256