akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
const int inf = 1e8;
ll dp[3000][3000];
ll findansrec(int index, int n, ll ptr[]){
    if(index==n) return 0;
    if(dp[index][n-1]!=-1) return dp[index][n-1];
    if( (ptr[index] - findansrec(index+1,n,ptr)) >
        (ptr[n-1] - findansrec(index,n-1,ptr)) ){
            return dp[index][n-1] = (ptr[index] - findansrec(index+1,n,ptr));
    }else{
            return dp[index][n-1] = (ptr[n-1] - findansrec(index,n-1,ptr));
    }

}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    memset(dp,-1,sizeof(dp));
    ll ptr[n];
    for(int i = 0 ; i <n; i++) cin>>ptr[i];
    cout<<findansrec(0,n,ptr);
}

Measured memory_bytes: 74172
#幅優先探索


from queue import Queue

ans = 0
h,w = map(int, input().split())
maps = [input() for _ in range(h)]
for i in range(h):
    for j in range(w):
        if maps[i][j] == '.':
            visited = [[-1]*w for _ in range(h)]
            q = Queue()
            q.put([i,j])
            visited[i][j] = 0
            while not q.empty():
                y,x = q.get()
                for k,l in [[1,0],[-1,0],[0,1],[0,-1]]:
                    if 0 <= y+k < h and 0<= x+l < w:
                        new_y,new_x = y+k,x+l
                    else: continue
                    if visited[new_y][new_x]== -1 and maps[new_y][new_x]==".":
                        visited[new_y][new_x]=visited[y][x]+1
                        q.put([new_y,new_x])
   
          
        
            for ii in range(h):
                for jj in range(w):
                    ans = max(ans,visited[ii][jj])


print(ans)

Measured memory_bytes: 62164
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main() {
	int A, B;
	char op;

	cin >> A >> op >> B;

	if (op == '+') {
		cout << A + B << endl;
	} else {
		cout << A - B << endl;
	}
}

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

class Program
{
	static void Main()
	{
		var t = Array.ConvertAll(Console.ReadLine().Split(new[] { ' ' }), number => int.Parse(number));

		var num = t[0] * 100 + t[1] * 10 + t[2];

		Console.WriteLine(num % 4 == 0 ? "YES" : "NO");

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 13140
#include <cstdio>
#include <cctype>
#include <cmath>
#define int long long

int read() {
    int ret, fl = 1;
    char ch;
    while(!isdigit(ch = getchar())) (ch == '-') && (fl = -1);
    for(ret = ch - '0'; isdigit(ch = getchar()); ret *= 10, ret += ch - '0');
    return ret * fl;
}

void print(int x) {
    if(x < 0) putchar('-'), x = -x;
    if(x > 9) print(x / 10);
    putchar(x % 10 + '0');
}

signed main() {
    int t = read();
    while(t--) {
        int a = read(), b = read(), mul = a * b;
        int base = (int)sqrt(mul), ans = (base << 1);
        // if(base == a && base == b) --ans;
        // // if(abs(a - b) == 1 && (base == a || base == b)) --ans;
        // if(base * base == mul - 1) --ans;
        // if(base * base == mul) ans -= 2;
        if(base * base == mul) {
            if(a == b) ans -= 2;
            else ans -= 3;
        }
        else if(base * (base + 1) < mul) ans -= 1;
        else ans -= 2;
        print(ans), putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

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

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	long long n;
	std::cin >> n;
	long long ans = 0;
	for(long long l = 1, r; l <= n; l = r + 1) {
		r = n / (n / l);
		// n - a * x == a
		// n == a + a * x
		// n - a == a * x
		// n / a - 1 == x
		long long a = n / l;
		long long pt = n % a == 0 ? n / a - 1 : -1;
		if(l <= pt && pt <= r) {
			ans += pt;
		}
	}
	std::cout << ans << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int solve(vector<vector<char>> vec,int h_start,int w_start,int h_end,int w_end){
	vector<int> nh = {1,0,-1,0};
	vector<int> nw = {0,1,0,-1};
	const int h_size = vec.size();
	const int w_size = vec[0].size();
	vector<vector<int>> depth(h_size,vector<int>(w_size,INT_MAX-1));
	depth[h_start][w_start] = 0;
	bool han[h_size][w_size] = {};
	queue<pair<int,int>> que;
	que.push(make_pair(h_start,w_start));
	while(que.size()){
		pair<int,int> now = que.front();
		que.pop();
		for(int i = 0;i < 4;i++){
			int next_h = now.first + nh[i];
			int next_w = now.second + nw[i];
			if(next_h < 0||next_w < 0||next_h >= h_size||next_w >= w_size)continue;
			if(vec[next_h][next_w] == 'X')continue;
			if(han[next_h][next_w] == true)continue;
			han[next_h][next_w] = true;
			depth[next_h][next_w] = depth[now.first][now.second] + 1;
			que.push(make_pair(next_h,next_w));
		}
	}
	return depth[h_end][w_end];
}
int main(){
	int h,w,n;
	cin >> h >> w >> n;
	vector<vector<char>> vec(h, vector<char>(w));
	for(int i = 0;i < h;++i){
		for(int j = 0;j < w;j++){
			cin >> vec[i][j];
		}
	}
	vector<int> basho_h(n + 1,0);
	vector<int> basho_w(n + 1,0);
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			if(vec[i][j] == 'S'){
				basho_h[0] = i;
				basho_w[0] = j;
				//cout << i << j << endl;
			}
			if ('1' <= vec[i][j] && vec[i][j] <= '9') {
				basho_h[vec[i][j] - '0'] = i;
				basho_w[vec[i][j] - '0'] = j;
			}
		}
	}
	//cout << basho_h[0] << basho_w[0] << endl;
	int ans = 0;
	for(int i = 0;i < n;i++){
		ans += solve(vec,basho_h[i],basho_w[i],basho_h[i+1],basho_w[i+1]);
		//cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 9676
#include<stdio.h>
#include<stdbool.h>

int main(void){
    int n,ans=0,cnt=0;
    scanf("%d",&n);
    char s[n+1];
    scanf("%s",s);
    for(int i=1;i<n;i++){
        int cnt=0;
        for(char c='a';c<='z';c++){
            bool left=false,right=false;
            
            for(int j=0;j<i;j++){  // 0からi-1まで
                if(s[j]==c){
                    left=true;
                    break;
                }
            }
            
            for(int j=i;j<n;j++){ //iからn-1まで
                if(s[j]==c){
                    right=true;
                    break;
                }
            }
            
            if(left&&right){
                cnt++;
            }
        }
        if(ans<cnt){
            ans=cnt;
        }
    }
    printf("%d\n",ans);
    return 0;
}


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

int main(void){
    int x,a,b;
    cin>>x>>a>>b;
    if(b<=a){
        cout<<"delicious"<<endl;
    }else if(b<=a+x){
        cout<<"safe"<<endl;
    }else{
        cout<<"dangerous"<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int gcd(int a, int b) {
  return b?gcd(b, a%b):a;
}
int main() {
  int x,y;
  scanf("%d %d", &x, &y);
  if (x < y) printf("%d\n", gcd(y,x));
  else printf("%d\n", gcd(x,y));
}



Measured memory_bytes: 2700
import collections

s = list(input())
k = int(input())
n = len(s)
ans = 0
if k == 1:
    for i in range(n - 1):
        if s[i] == s[i + 1]:
            ans += 1
            s[i + 1] = -1
    print(ans)
else:
    if collections.Counter(s).most_common()[0][1] == n:
        print(n * k // 2)
    else:
        ans1 = 0
        sd = s[:]
        for i in range(n - 1):
            if sd[i] == sd[i + 1]:
                ans1 += 1
                sd[i + 1] = -1
        s += s
        for i in range(n * 2 - 1):
            if s[i] == s[i + 1]:
                ans += 1
                s[i + 1] = -1
        ans -= ans1
        print(ans * (k - 1) + ans1)

Measured memory_bytes: 3444
H,W=map(int,input().split())

if H%3==0 or W%3==0:
  print(0)
  exit()

A=0
B=0
ans=H*W

if H%2==0:
  A=H//2
  B=H//2
else:
  A=H//2+1
  B=H-A
for i in range(1,W):
  S1=A*i
  S2=B*i
  S3=(W-i)*H
  SMaxMin=max(S1,S2,S3)-min(S1,S2,S3)
  ans=min(ans,SMaxMin)
if W%2==0:
  A=W//2
  B=W//2
else:
  A=W//2+1
  B=W-A;
for i in range(1,H):
  S1=A*i
  S2=B*i
  S3=(H-i)*W
  SMaxMin=max(S1,S2,S3)-min(S1,S2,S3)
  ans=min(ans,SMaxMin)
if H>=3:
  ans=min(ans,W)
if W>=3:
  ans=min(ans,H)
print(ans)


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

int main() { 
  string S;
  cin >> S;
  int w=0, s=0, n=0, e=0;
  for (int i=0; i<S.size(); i++) {
    if (S.at(i)=='W') w++;
    else if (S.at(i)=='S') s++;
    else if (S.at(i)=='N') n++;
    else if (S.at(i)=='E') e++;
  }
  if (w==0||s==0||n==0||e==0) {
    if ((w==0&&e==0&&s>0&&n>0)||(s==0&&n==0&&w>0&&e>0))
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  } else cout << "Yes" << endl;
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d %d\n" @@ fun h w ->
  let r = ref 0 in
  let c = ref 0 in
  for i = 0 to h - 1 do
    for j = 0 to w - 1 do
      Scanf.scanf "%s " @@ fun s ->
        if s = "snuke" then begin
          r := j;
          c := i
        end
    done
  done;
  Printf.printf "%c%d\n" (Char.chr (Char.code 'A' + !r)) (!c + 1)


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

using namespace std;

#define all(x) begin(x), end(x)

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

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

    int q;
    cin >> q;

    ll b = 0;
    multiset<int> leq, gt;
    ll left_sum = 0LL;
    ll right_sum = 0LL;

    while (q-- > 0) {
        int op;
        cin >> op;
        if (op == 1) {
            int a, bi;
            cin >> a >> bi;
            b += bi;

            if (!gt.empty() and a > *begin(gt)) {
                gt.insert(a);
                right_sum += a;
            } else {
                leq.insert(a);
                left_sum += a;
            }

            while (gt.size() > leq.size()) {
                int x = *begin(gt);
                gt.erase(begin(gt));
                right_sum -= x;
                left_sum += x;
                leq.insert(x);
            }

            while (leq.size() - 1 > gt.size()) {
                int x = *prev(end(leq));
                leq.erase(prev(end(leq)));
                left_sum -= x;

                right_sum += x;
                gt.insert(x);
            }
        } else {
            int x = *prev(end(leq));
            ll cost = b + 1LL * x * leq.size() - left_sum + right_sum - 1LL * x * gt.size();
            cout << x << ' ' << cost << '\n';
        }
    }
    
    return 0;
}


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

using namespace std;

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

int main(){
	ios_base::sync_with_stdio (false);
	cout << fixed;
	cout.precision(10);
	if(fopen("joke.in", "r")){
		freopen ("joke.in","r",stdin);
		freopen ("joke.out","w",stdout);
	}

	int n;
	cin >> n;
	vector<int> v(n);
	for(int i = 0; i < n; ++i){
		cin >> v[i];
	}
	vector<int> c(n);
	for(int i = 0; i < n; ++i){
		cin >> c[i];
	}

	int res = 0;
	for(int i = 0; i < n; ++i){
		res += max(0, v[i] - c[i]);
	}
	cout << res;
    return 0;
}


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

struct Node{
    int key;
    Node *parent,*left,*right;
};

Node *nil,*root=nil;

void insert(int key){
    Node *x=root; //挿入場所
    Node *y=nil; //親
    Node *z=new Node;
    z->key=key;
    z->left=nil;
    z->right=nil;
    while(x!=nil){
        y=x;
        if(z->key<x->key) x=x->left;
        else x=x->right;
    }
    if(y==nil) root=z;
    else{
        z->parent=y;
        if(z->key<y->key) y->left=z;
        else y->right=z;
    }
}

Node* find(int key){
    Node *x=root;
    while(x!=nil&&x->key!=key){
        if(key<x->key) x=x->left;
        else x=x->right;
    }
    return x;
}

void inorder(Node *u){
    if(u==nil) return;
    inorder(u->left);
    cout<<' '<<u->key;
    inorder(u->right);
}

void preorder(Node *u){
    if(u==nil) return;
    cout<<' '<<u->key;
    preorder(u->left);
    preorder(u->right);
}

Node* getSuccessor(Node* u){
    if(u->right!=nil){
        u=u->right;
        while(u->left!=nil){
            u=u->left;
        }
        return u;
    }
    else{
        Node *x,*y;
        x=u;
        y=u->parent;
        while(y!=nil&&y->left!=x){
            x=y;
            y=y->parent;
        }
        return y;
    }
}

void deleteNode(Node *u){
    Node *x,*y;
    if(u->left==nil||u->right==nil) y=u;
    else y=getSuccessor(u);

    if(y->left!=nil) x=y->left;
    else x=y->right;

    if(x!=nil) x->parent=y->parent;

    if(y->parent==nil) root=x;
    else if(y->parent->left==y) y->parent->left=x;
    else y->parent->right=x;

    if(u!=y) u->key=y->key;
    delete y;
}

int main(){
    int m,k;
    string com;
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>com;
        if(com=="insert"){
            cin>>k;
            insert(k);
        }
        else if(com=="find"){
            cin>>k;
            Node *n=find(k);
            if(n!=nil) cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
        else if(com=="delete"){
            cin>>k;
            deleteNode(find(k));
        }
        else{
            inorder(root);
            cout<<endl;
            preorder(root);
            cout<<endl;
        }
    }
}


Measured memory_bytes: 21800
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

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

#define REP(i,n) for(int i = 0; i < n; i++)
#define INF 1e9

int main(){
  int n;
  cin >> n;
  int t[n+1], x[n+1], y[n+1];
  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  REP(i,n)cin >> t[i+1] >> x[i+1] >> y[i+1];

  bool ans = true;

  REP(i,n){
    int dt = t[i+1] - t[i];
    int dx = abs(x[i+1] - x[i]);
    int dy = abs(y[i+1] - y[i]);
    if(dt < dx + dy || (dx + dy)%2 != dt%2){
      ans = false;
    }
  }

  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

int main()
{
    int d[100000];
    int alphabet_max = 26;
    long long N;
    const long long MOD = 1000000007;
    cin >> N;
    string S;
    cin >> S;
    long long kosuu[26];
    for (int i = 0; i < alphabet_max; i++)
    {
        kosuu[i] = 0;
        for (int j = 0; j < N; j++)
        {
            if (S.at(j) == 'a' + i)
            {
                kosuu[i]++;
            }
        }
        kosuu[i]++;
    }
    long long ans = 1;
    for (int i = 0; i < alphabet_max; i++)
    {
        ans *= kosuu[i];
        ans %= MOD;
    }
    if (ans == 0)
    {
        cout << MOD - 1 << endl;
        return 0;
    }
    cout << ans - 1 << endl;
}

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

double x[25],y[25];

inline double dist(int i,int j){
	double xx=x[j]-x[i];
	double yy=y[j]-y[i];
	return sqrt(xx*xx+yy*yy);
}

double area(double a,double b,double c){
	double s=(a+b+c)/2.0;
	return sqrt(s*(s-a)*(s-b)*(s-c));
}

int main(void){
	double s=0.0;
	int n=0;
	char tmp;
	while(cin >> x[n] >> tmp >> y[n]){
		if(cin.eof()) break;
		n++;
	}
	range(i,2,n){
		double a=dist(0,i-1);
		double b=dist(0,i);
		double c=dist(i-1,i);
		s+=area(a,b,c);
	}
	cout.precision(10);
	cout << fixed << s << endl;
	return 0;
}

Measured memory_bytes: 1288
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    h,w = LI()
    board = [["." for _ in range(w+2)]]
    for _ in range(h):
        s = S()
        s = list(s)
        s = ["."] + s + ["."]
        board.append(s)
    board.append(["." for _ in range(w+2)])

    exp = [[1,0],[0,1],[-1,0],[0,-1],[1,1],[1,-1],[-1,1],[-1,-1]]
    for y in range(1,h+1):
        for x in range(1,w+1):
            if board[y][x] == ".":
                cnt = 0
                for u,r in exp:
                    if board[y-u][x-r] == "#":
                        cnt += 1
                board[y][x] = str(cnt)

    for line in board[1:-1]:
        line = "".join(line[1:-1])
        print(line)
main()

Measured memory_bytes: 74888
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
using Graph = vector<vector<int>>;
 
vector<bool> seen;
void dfs(const Graph& G, int v) {
    seen[v] = true; // v を訪問済にする
 
    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}
signed main() {
    int L, R; cin >> L >> R;
    int M = 2019;
    bool J = false;
    if (L / 2019 == R / 2019 && L % 2019 != 0) {
        for (int X = L % 2019; X < R % 2019; X++) {
            for (int Y = L % 2019 + 1; Y <= R % 2019; Y++) {
                if ((X * Y) % 2019 < M) {
                    M = (X * Y) % 2019;
                    J = true;
                }
            }
        }
        if (J == true) {
            cout << M << endl;
        }
    }
    else {
        cout << 0 << endl;
        J=true;
    }
    if (L + 1 == R && J == false) {
        cout << ((L % 2019) * (R % 2019))%2019 << endl;
    }
}


Measured memory_bytes: 3632
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String c = sc.next();
        if(c.charAt(0)=='a'||c.charAt(0)=='i'||c.charAt(0)=='e'||c.charAt(0)=='o'||c.charAt(0)=='u'){
            System.out.println("vowel");
        }else{
            System.out.println("consonant");
        }

    }
}


Measured memory_bytes: 21972
K, A, B = map(int, input().split())
CNT = K - A + 1     # 最初、A枚になるまでビスケットを増やす
# 残り回数でできるだけAとBを行う
# 残り回数が1余ったならビスケットを増やす
print(max(A + CNT // 2 * (B - A) + CNT % 2, K + 1))

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

int main() {
    int n;
    vector<int> v;
    cin>>n;
    int temp;
    rep(i,n) {
        cin>>temp;
        v.push_back(temp);
    }
    sort(v.begin(),v.end());
    double ans=v[0];
    rep(i,n-1) ans = (ans+v[i+1])/(double)2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())

ans = float("inf")
for i in range(h):
    p1 = i * w
    p2 = ((h - i) // 2) * w
    p3 = (h - i - ((h - i) // 2)) * w

    ans = min(ans, max(p1, p2, p3) - min(p1, p2, p3))

    p1 = i * w
    p2 = (h - i) * (w // 2)
    p3 = (h - i) * (w - (w // 2))

    ans = min(ans, max(p1, p2, p3) - min(p1, p2, p3))

w, h = h, w
for i in range(h):
    p1 = i * w
    p2 = ((h - i) // 2) * w
    p3 = (h - i - ((h - i) // 2)) * w

    ans = min(ans, max(p1, p2, p3) - min(p1, p2, p3))

    p1 = i * w
    p2 = (h - i) * (w // 2)
    p3 = (h - i) * (w - (w // 2))

    ans = min(ans, max(p1, p2, p3) - min(p1, p2, p3))

print(ans)


Measured memory_bytes: 73668
#include <stdio.h>
#include <stdlib.h>

int main()
{
    unsigned short *attkVals;
    unsigned int i, numOfAttks; 
    signed int health; 
    scanf("%i %u", &health, &numOfAttks);
    
    attkVals = (short*) malloc (numOfAttks* sizeof(short));
    
    for (i=0; i<numOfAttks ; i++)
    {
        scanf("%hu", &attkVals[i]);
        health -= attkVals[i];
    }
    
    if (health > 0)
    {
        printf("No");
    }
    else
    {
        printf("Yes");
    }
    
    return 0;
}


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

int main()
{
    ll h;
    cin >> h;

    ll ans = 0;
    ll rate = 1;

    while (h > 0)
    {
        ans += rate;
        rate <<= 1;
        h >>= 1;
    }
    cout << ans << endl;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    string bef,aft;
    cin>>bef>>aft;
    map<char,char> befmp;
    map<char,char> aftmp;
    int cnt=bef.size();
    int cntsm=0;
    rep(i,cnt){
        if(befmp.find(bef[i])==befmp.end()&& aftmp.find(aft[i])==aftmp.end()){
            befmp[bef[i]]=aft[i];
            aftmp[aft[i]]=bef[i];
        }else if(befmp[bef[i]]!=aft[i] || aftmp[aft[i]]!=bef[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i=0; i<N; i++) {
    cin >> a.at(i);
  }
  // fが最大の時のmは{a(N)}の最小公倍数-1
  // このときfの最大値は各Nに対してa(N)-1の和
  int answer = accumulate(a.begin(), a.end(), 0)-N;
  cout << answer << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>

using namespace std;

#define MAXN 100005
#define fi first
#define se second

typedef pair<int, int> pii;

int A[MAXN], B[MAXN];
bool C[MAXN];
vector<pii> ed[MAXN];
bool chk[MAXN];
int num[MAXN], nn;
int cnt[MAXN], dep[MAXN], par[MAXN], pe[MAXN];

void dfs(int x) {
	//printf("dfs(%d)\n", x);
	num[nn++] = x;
	chk[x] = true;
	for(int i = 0; i < ed[x].size(); i++) {
		pii a = ed[x][i];
		if(A[a.se] == x) cnt[x]++;
		if(a.fi == par[x]) pe[x] = a.se;
		if(!chk[a.fi]) {
			dep[a.fi] = dep[x] + 1;
			par[a.fi] = x;
			dfs(a.fi);
		}
	}
}

int main() {
	int N, M;
	int u, v;

	scanf("%d%d", &N, &M);
	for(int i = 0; i < M; i++) scanf("%d%d", A + i, B + i);

	for(int i = 0; i < M; i++) {
		ed[A[i]].push_back(make_pair(B[i], i));
		ed[B[i]].push_back(make_pair(A[i], i));
	}

	if(M % 2) {
		printf("-1");
		return 0;
	}
	dfs(1);
	//for(int i = 1; i <= N; i++) printf("%d ", par[i]);
	//printf("\n");
	int l = -1;
	for(int i = 0; i < N; i++) if(cnt[num[i]] % 2) {
		if(l == -1) l = num[i];
		else {
			int a = l, b = num[i];
			//printf("%d, %d\n", a, b);
			if(dep[a] < dep[b]) swap(a, b);
			while(dep[a] > dep[b]) {
				C[pe[a]] ^= true;
				a = par[a];
			}
			while(a != b) {
				C[pe[a]] ^= true;
				C[pe[b]] ^= true;
				a = par[a];
				b = par[b];
			}
			//printf("%d\n", a);
			l = -1;
		}
	}

	//for(int i = 1; i <= N; i++) for(auto a : ed[i]) printf("%d %d %d\n", i, a.fi, (int)a.se);
	for(int i = 0; i < M; i++) {
		if(C[i]) swap(A[i], B[i]);
		printf("%d %d\n", A[i], B[i]);
	}
	return 0;
}


Measured memory_bytes: 14464
n = gets.to_i
a = gets.split.map(&:to_i).sort
ans = 0
for i in 0...n-2
  for j in i+1...n-1
    for k in j+1...n
      if a[i]+a[j]>a[k]&&a[i]!=a[j]&&a[j]!=a[k]
        ans += 1
      end
    end
  end
end
puts ans


Measured memory_bytes: 14328
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  ll ans=0;
  ll N,M;
  cin>>N>>M;
  if(N==1&&M==1){
    ans=1;


  }else if(N==1){
    ans=M-2;
  }else if(M==1){
    ans=N-2;
  }else{
    ans=(N-2)*(M-2);
  }



cout<<ans<<endl;
return 0;

}
 


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



int main() {
  int n;
  cin >>n;
  vector<int> g={},h={};
  rep(i,n){
    int q;
    cin >>q;
    if(i%2==0){h.push_back(q);}else{g.push_back(q);}
  }
  if(n%2==1){
    for(int i=h.size()-1;i>=0;i--){
      cout << h[i] << " ";
    }
    for(int i=0;i<g.size();i++){
      cout << g[i] << " ";
    }
  }else{
    for(int i=g.size()-1;i>=0;i--){
      cout << g[i] << " ";
    }
    for(int i=0;i<h.size();i++){
      cout << h[i] << " ";
    }
  }
  cout << endl;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
 
const ll MOD  = 1e9+7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

int main(){
    ll n;
    string s;
    cin >> n >> s;

    vector<vector<ll>> pos(10);
    rep(i, s.size()){
        pos[s[i]-'0'].push_back(i);
    }

    ll ans = 0;

    rep(i, 1000){
        int keta[3];
        keta[0] = i / 100;
        keta[1] = (i%100) / 10;
        keta[2] = i % 10;

        if(pos[keta[0]].empty() || pos[keta[1]].empty() || pos[keta[2]].empty()){
            continue;   
        }

        ll p = pos[keta[0]][0];

        auto itr = upper_bound(ALL(pos[keta[1]]), p);
        if(itr == pos[keta[1]].end())continue;
        p = pos[keta[1]][itr - pos[keta[1]].begin()];

        itr = upper_bound(ALL(pos[keta[2]]), p);
        if(itr == pos[keta[2]].end())continue;

        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  
  int n, d;
  
  cin>>n>>d;
  
  int c = 0;
  
  while(n != 0){
  	n /= d;  
    c++;
  }
  cout<<c;
 return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    ll K, A, B, ans = 0;
    cin >> K >> A >> B;
    ans = max(K + 1, ((K - A + 1) / 2) * (B - A) + A);
    if (ans != K + 1 and (K - A + 1) % 2 == 1)
        ans++;
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define ii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
#define output(x) for (auto a:x) cout<<a<<" ";cout<<endl;
#define output2(x) for (auto a:x) cout<<a.fi<<" "<<a.se<<endl;
#define PI 3.14159265

// DEBUG TEMPLATE
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
  *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
  
// DEBUG TEMPLATE ENDS

#define MOD 1000000007
int power(int x,int y,int mod = MOD) 
{ 
  int ret = 1;
  x = x % mod;
  while (y){
    if(y&1) ret = (ret*x)%mod;
    y = y>>1;
    x = (x*x)%mod;
    } 
    return ret%mod; 
}

void solve()
{ 
  for (int i=0;i<5;i++){
    int x;
    cin>>x;
    if (x==0) {
      cout<<i+1<<endl;
      return;
    }
  }
}


/*
  
*/
signed main(){
  // int t;
  // cin>>t;
  // while (t--)
  solve();
}
// Check MOD values plox :(


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

int main(){
    int N,M;cin>>N>>M;
    int cnt;
    cnt=100*(N-M)+1900*M;
    cnt*=pow(2,M);
    cout<<cnt<<endl;
}

Measured memory_bytes: 4100
#include<iostream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<tuple>
#include<queue>
#define LL long long
#define TT std::tuple<LL,LL,LL>
#define PP std::pair<LL,LL>
LL A, B, C, X, Y;
LL ans;
int main() {
	std::cin >> A >> B >> C >> X >> Y;
	if (X < Y) {
		std::swap(X, Y);
		std::swap(A, B);
	}
	if (A + B > C * 2) {
		ans += Y*C*2;
		X -= Y;
		Y = 0;
	}
	if (A > C * 2) {
		ans += X * C * 2;
		X = 0;
	}
	ans += X * A;
	ans += Y * B;
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
R = S.count('R')
G = S.count('G')
B = N-R-G
ans = R*G*B
for d in range(1,N//2+1):
    for i in range(N):
        if i + d*2 >= N: break
        a,b,c = S[i],S[i+d],S[i+d+d]
        if a!=b and b!=c and c!=a:
            ans -= 1
print(ans)

Measured memory_bytes: 9220
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cassert>
using namespace std;

typedef long long LL;
const int MAX_N = 15;
const LL INF = 1e15 + 6;

LL adj[MAX_N][MAX_N];
LL cost[(1<<MAX_N)];
LL dp[(1<<MAX_N)][MAX_N];
int arr[MAX_N];

inline LL Cost(LL mask1,LL mask2) {
    assert((mask1 & mask2)==0);
    return cost[(mask1|mask2)] - cost[mask1] - cost[mask2];
}

int main() {
    int n,m;
    scanf("%d %d",&n,&m);
    int tot=0;
    for (int i=1;m>=i;i++) {
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        a--;
        b--;
        adj[a][b] = adj[b][a] = c;
        tot += c;
        for (int mask=0;(1<<MAX_N)>mask;mask++) {
            if (((1<<a)&mask) != 0 && ((1<<b)&mask) != 0) cost[mask] += c;
        }
    }
    /*
Define dp(S, t) as the minimum cost required to achieve the condition ”There is a unique path from 1 to t that only uses vertices
in S”.
(Here, cost(S, T) denotes the sum of costs of all edges between two sets S and T.)
• Let u /∈ S be a vertex. If there is an edge between t and u, we can reach dp(S ∪ {u}, u)
with cost dp(S, t) + cost(S \ {t}, {u}).
• Let T be a set of vertices that is disjoint with S. We can reach dp(S ∪ T, t) with cost
(dp(S, t) + cost(S \ {t}, T).
    */
    for (int i=0;(1<<n)>i;i++) {
        for (int j=0;n>j;j++) {
            dp[i][j] = INF;
        }
    }
    dp[1][0] =0 ;
    LL ans=INF;
    for (int mask=1;(1<<n)>mask;mask++) {
        for (int j=0;n>j;j++) {
            if (dp[mask][j] != INF && (((1<<j)&mask) != 0)) {
                //deal with 1 first
                int id=0;
                for (int k=0;n>k;k++) {
                    if (((1<<k)&mask) == 0) arr[id++]=(1<<k);
                    if (((1<<k)&mask) == 0) {
                        //cout<<"haha"<<endl;;
                        if (adj[j][k] != 0) dp[ (1<<k)|mask ][k] = min(dp[ (1<<k)|mask ][k],dp[mask][j] + Cost(mask-(1<<j),(1<<k)));
                    }
                }
                //deal with second
                for (int k=0;(1<<id)>k;k++) {
                    int mask2=0;
                    for (int l=0;id>l;l++) {
                        if (((1<<l)&k) != 0) mask2+=arr[l];
                    }
                    //cout<<"hehe"<<endl;
                    dp[mask | mask2][j] = min(dp[mask | mask2][j],dp[mask][j] + Cost(mask-(1<<j),mask2));
                }
            }
        }
    }
    printf("%lld\n",dp[(1<<n)-1][n-1]);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main()
{

	int n;
	while(~scanf("%d",&n))
	{
			int a[1000]={0};
			for(int  i=0;i<n;i++)
			scanf("%d",&a[i]);
			int num=0;
			for(int i=1;i<n-1;i++)
			{
				if((a[i]>a[i-1]&&a[i]<a[i+1])||(a[i]<a[i-1]&&a[i]>a[i+1]))
				num++;
			}
			printf("%d\n",num);
	}
 } 

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main() {
    int cnt = 0;
    string S;
    cin >> S;
    for (int i = 1; i < S.size(); i++) {
        if (S[i] == S[i-1]) {
            cnt++;
            S[i] = (S[i] == '0' ? '1' : '0');
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
n = int(input())

r = []

ac = 0
wa = 0
tle = 0
re = 0

for _ in range(n):
  s = input()
  
  if s == 'AC':
    ac += 1
  elif s == 'WA':
    wa += 1
  elif s == 'TLE':
    tle += 1
  else:
    re += 1

print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))


Measured memory_bytes: 9108
N = int(input())
t0 = x0 = y0 = 0
OK = True
for _ in range(N):
  t, x, y = map(int, input().split())
  dt = t-t0
  d = abs(x-x0) + abs(y-y0)
  OK *= dt>=d and dt%2==d%2
  t0 = t
  x0 = x
  y0 = y
print('Yes' if OK else 'No')

Measured memory_bytes: 3064
n = int(input())
s = list(input())
f = 0

if n%2 == 0:
    l = int(n/2)
    for i in range(l):
        if s[i] != s[i+l]:
            break
        if i == l-1:
            f = 1

if f == 1:
    print("Yes")
else:
    print("No")

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

int main() {
  int H, W, N;
  cin >> H >> W;
  vector<char> sharp(W + 2, '#');
  vector<char> img(W + 2, '#');
  
  for (int i = 0; i < sharp.size(); i++) cout << sharp.at(i);
  
  cout << "\n";
  
  for (int i = 0; i < H; i++) {
    for (int j = 1; j <= W; j++) cin >> img.at(j);
    
    for (int j = 0; j < img.size(); j++) cout << img.at(j);
    
    cout << "\n";
  }
  
  for (int i = 0; i < sharp.size(); i++) cout << sharp.at(i);
  
  cout << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    ll u=1000000000000000000,y=1;
    rep(i,n){
        if (a[i]==0){
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i,n){
        if (y>u/a[i]+1){
            cout << -1 << endl;
            return 0;
        }
        y*=a[i];
    }
    if (y<=u) cout << y << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

using P = pair<ll, ll>;

ll X;
int K, Q;
vector<P> events;

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

    cin >> X;
    cin >> K;
    rep(i, K) {
        int t;
        cin >> t;
        events.emplace_back(t, -1);
    }
    cin >> Q;
    rep(i, Q) {
        ll t, x;
        cin >> t >> x;
        events.emplace_back(t, x);
    }
    sort(ALL(events));

    bool inc = 0;
    ll pt = 0;
    ll a = 0, b = X, c = 0;
    for(P p : events) {
        ll t = p.first;
        ll x = p.second;

        if(inc) {
            c += t - pt;
            if(b + c > X) b = X - c;
            if(a > b) a = b;
        } else {
            c -= t - pt;
            if(a + c < 0) a = -c;
            if(a > b) b = a;
        }
        if(x == -1) {
            inc = !inc;
        } else {
            cout << max(a, min(b, x)) + c << endl;
        }
        pt = t;
    }

    return 0;
}

Measured memory_bytes: 6512
const input = require("fs").readFileSync("/dev/stdin", "utf8").trim();

const lines = input.split('\n');
const [_, text, ...indexes] = lines;

const acMap = new Array(text.length);
let count = 0, prev = '', char = '', i = 0;
for (; i < text.length; i++) {
    if (text[i-1] === 'A' && text[i] === 'C') {
        count++;
    }
    acMap[i] = count;
}

indexes.forEach((line) => {
    const [i, j] = line.split(' ').map(Number);
    console.log(acMap[j - 1] - acMap[i - 1]);
});


Measured memory_bytes: 35796
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define pye cout << "yes" << endl
#define pno cout << "no" << endl
#define pYe cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pYE cout << "YES" << endl
#define pNO cout << "NO" << endl
#define prin(num) cout << num << endl
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1000000000
#define MOD 1000000007LL
#define MAX 10005
#define MAX_E 30005
#define NIL -1
#define WHITE 0
#define BLACK 1
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
ll a[40], b[40], c[40];
ll dp[41][401][401];

int main(void) {
    ll N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    ll i;
    ll suma=0, sumb=0;
    ll ca, cb;
    
    for(i=0; i<N; i++) {
        cin >> a[i] >> b[i] >> c[i];
        suma+=a[i];
        sumb+=b[i];
    }
    
    for(i=0; i<=N; i++) {
        for(ca=0; ca<=suma; ca++) {
            for(cb=0; cb<=sumb; cb++) {
                dp[i][ca][cb]=INF;
            }
        }
    }
    
    dp[0][0][0]=0;
    
    for(i=0; i<N; i++) {
        for(ca=0; ca<=suma; ca++) {
            for(cb=0; cb<=sumb; cb++) {
                dp[i+1][ca][cb]=min(dp[i+1][ca][cb], dp[i][ca][cb]);
                dp[i+1][ca+a[i]][cb+b[i]]=min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb]+c[i]);
            }
        }
    }
    
    ll ans=INF;
    for(ca=1; ca<=suma; ca++) {
        for(cb=1; cb<=sumb; cb++) {
            if(Ma*cb==Mb*ca)
                ans=min(ans, dp[N][ca][cb]);
        }
    }
    
    if(ans==INF) prin(-1);
    else prin(ans);
    
}

Measured memory_bytes: 50944
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#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};
template<typename T>
T gcd(T a, T b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
int main(){
    int ans = 0;
    int K;
    cin >> K;
    for(int i = 1; i <= K; i++)for(int j = 1; j <= K; j++) for(int k = 1; k <= K; k++){
        ans += gcd(gcd(i, j), k);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3604
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
using namespace std;
//**********************************************DO IT NOW***************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
signed main()
{   
    fastio();
    int t=1;
  // cin>>t;
    while(t--)
    {    
       string s1,s2;
       cin>>s1>>s2;
       int n,m;
       cin>>n>>m;
       string s;
       cin>>s;
       if(s==s1)
       cout<<n-1<<" "<<m;
       else
       cout<<n<<" "<<m-1;
    }
}
    
// 🍪 🍪 🍪


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

const int maxn = 2e5 + 10;

int n,k;
double p[maxn];

int main()
{
	
	//std::ios::sync_with_stdio(false);cin.tie(0);
	scanf("%d %d",&n,&k);
	for(int i = 1; i <= n; i++){
		scanf("%lf",&p[i]);
		p[i] = (1.0 + p[i]) / 2.0;
	}	
	double ans = 0, now = 0;
	for(int l = 1, r = 0; l <= n; l++){
		while(r - l < k - 1 && r < n) now += p[++r];
		//cout << now << endl;
		if(r - l == k - 1) {
			ans = max(ans,now);
			now -= p[l];
		}
		
	}
	printf("%.6f",ans);
	return 0;
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x) cerr << "  (L" << __LINE__ << ") " << #x << " = " << (x) << endl;
#define dumpv(x) cerr << "  (L" << __LINE__ << ") " << #x << " = "; REP(q,(x).size()) cerr << (x)[q] << " "; cerr << endl;
template<typename T1, typename T2>
ostream& operator<<(ostream& s, const pair<T1, T2>& d) {return s << "(" << d.first << "," << d.second << ")";}


const int INF = 1e9;

int solve(int N, VVI& land, VVI& sea, VI& z) {
  // bellman-ford
  REP(k, N) REP(i, N) REP(j, N) {
    land[i][j] = min(land[i][j], land[i][k] + land[k][j]);
    sea[i][j] = min(sea[i][j], sea[i][k] + sea[k][j]);
  }

  // dp[i][j]: i個目の配達を終えた時に船が町jにあるときの最短時間
  VVI dp(z.size(), VI(N, INF));
  dp[0][z[0]-1] = 0;
  REP(i, z.size()-1) {
    int from = z[i]-1;
    int to = z[i+1]-1;
    REP(j, N) {
      REP(k, N) {
        // z[i]からz[i+1]までの移動中に、船をjからkまで移動させる
        if (land[from][j] != INF && sea[j][k] != INF && land[k][to] != INF) {
          dp[i+1][k] = min(dp[i+1][k], 
              dp[i][j] + land[from][j] + sea[j][k] + land[k][to]);
        }
      }
      // 陸路のみで、港に立ち寄らない場合
      dp[i+1][j] = min(dp[i+1][j], dp[i][j] + land[from][to]);
    }
  }

  return *min_element(dp[z.size()-1].begin(), dp[z.size()-1].end());
}

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

  while (true) {
    int N, M; cin >> N >> M;
    if (N == 0 && M == 0) break;

    VVI land(N, VI(N, INF)), sea(N, VI(N, INF));
    REP(i, N) {
      land[i][i] = 0;
      sea[i][i] = 0;
    }
    REP(i, M) {
      int x, y, t; string sl;
      cin >> x >> y >> t >> sl;
      if (sl == "L") {
        land[x-1][y-1] = t;
        land[y-1][x-1] = t;
      } else {
        sea[x-1][y-1] = t;
        sea[y-1][x-1] = t;
      }
    }
    int R; cin >> R;
    vector<int> z(R);
    REP(i, R) cin >> z[i];

    int ans = solve(N, land, sea, z);
    cout << ans << endl;
  }
}

Measured memory_bytes: 2044
#include <stdio.h>
int main(){
    int n,h,w,a,b,c;
    scanf("%d",&n);
    scanf("%d",&h);
    scanf("%d",&w);
    a=n-h+1;
    b=n-w+1;
    c=a*b;
    printf("%d",c);
    return 0;
}
    



Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    cout << (a%b == 0 ? -1 : a) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define v vector<ll> 
#define vv vector<v>
#define p pair<ll,ll>
#define arrayinput int n; int m; cin>>n>>m; v arr (n+1,-1); for (int i=0; i<n; i++){int temp; cin>>temp;arr[i]=temp;}
#define vp vector<pair<int,p> >
int LIM=2e5+10;
ll MOD=1e9+7;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    v arr(n+1,-1);
    for (int i=1; i<=n; i++)
        cin>>arr[i];
    v last(LIM,0);
    v previous(n+1,-1);
    for (int i=1; i<=n; i++)
    {
        previous[i]=last[arr[i]];
        last[arr[i]]=i;
    }
    v dp(n+1,0);
    dp[1]=1;
    for (int i=2; i<=n; i++)
    {
        dp[i]=dp[i-1];
        if (i>1 && arr[i]!=arr[i-1])
            dp[i]=(dp[previous[i]]+dp[i])%MOD;
    }
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 6528