akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B > C+ D)
    cout << "Left" << endl;
  else if (A + B < C + D){
    cout << "Right" <<endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 5;
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    if(k >= n) printf("0\n");
    else printf("%d\n",n-k);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 200010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define pp pop_back
#define mapiter map<int, int>::iterator
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 1; i <= n; ++i)
#define forr(i, n)	for(int i = n - 1; i >= 0; --i)
#define forr1(i, n)	for(int i = n; i >= 1; --i)
#define form(l, r, i)	for(int i = l; i <= r; ++i)
#define forv(r, l, i)	for(int i = r; i >= l; --i)
#define r0 return 0
#define barnarnar ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lld long double
#define elif else if
 
const int inf = 1e9 + 7;
const lld EPS = 0.00000001;
const ll modwdop = 998244353ll;
 
ll pp = 13337ll;
ll modw = 1e9 + 7;
 
using namespace std;

bool check(string s)
{
	forn(i, s.si / 2)	if(s[i] != s[s.si - 1 - i])	return 0;
	return 1;
}

int main()
{
	barnarnar
	string s;
	cin >> s;
	bool ans = check(s) & check(s.substr(0, s.si / 2)) & check(s.substr(s.si / 2 + 1, s.si / 2));
	if(ans)cout << "Yes";
	else	cout << "No";
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define c cout<<"#"<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 2000000000

const double EPS = 1e-10;
const double PI  = acos(-1.0);
////////////////////////////////////////////////
//?????????????????????????????????
SI s;//?¨?????????????????????????
int n;//??????????????°
int t;//??????
int d[101];//??????????????????????¨????????????????????????????????????????
int f[102];//??????????????£??\?????????????????????????????????????????????????????????
int a[101][101];//??£??\?????????
int p[101];//??£??\?????????????¨???????????????????????????????
int flag;//???
int main()
{
	cin>>n;
	FOR(i,1,n+1)//??£??\??????????????????
	{
		int k,m;cin>>k>>m;
		a[k][0]=m;
		FOR(j,1,m+1)
		{
			int x;cin>>x;
			a[k][j]=x;
		}
	}
	d[1]=1;int o=1;
	FOR(i,1,101)p[i]=1;//??£??\??????????????????????????????????????????1???????????????
	for(s.push(o),t=2;;t++)
	{
		//s.top()?????????????????????????????????
		if(a[s.top()][0]==0)
		{
			f[s.top()]=t;
			s.pop();
		}
		else
		{
			int next=a[s.top()][p[s.top()]];//next????¬?????¨?????????????????????????
			for(;d[next]!=0;)//???????????????????¨??????????????????¢???
			{
				p[s.top()]++;//????????????????????????????¬??????????????????????
				if(p[s.top()]>a[s.top()][0])//?????????????????£????????????????????????????¨??????????????????°
				{
					f[s.top()]=t;
					s.pop();//?¬?????¨????????????????????????????
					flag=1;//???????????????
					break;//????????????????????????
				}
				next=a[s.top()][p[s.top()]];//?¨????????????????????????´??°
			}
			if(flag==0)//?????????????????£???????????????????¨??????????????????°
			{
				s.push(next);//?¬?????¨??????????for???????????§??????????????????
				d[s.top()]=t;//???????????????????????????????????????????¨????????????????????????????????????????
			}
		}
		flag=0;//???????????????
		if(f[o]!=0)
		{
			int i;
			for(i=o;f[i]!=0;i++);
			if(i>n)break;
			o=i;t++;
			s.push(o);
			d[o]=t;
		}
	}
	FOR(i,1,n+1)cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
	return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
#define MOD 1e9 + 7
#define N 1e5 + 10
struct dish
{
	ll rem,t;
};
bool cmp(dish a,dish b)
{
	return(a.rem>b.rem);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,q;
	cin>>n>>q;
	string s;
	cin>>s;
	ll i=0;
	string str="AC";
	ll cv[n];
	string x="";
	for(i=0;i<n;i++)
	{
		if(i==0)
		{
			cv[i]=0;
			x=x+s[i];
		}
		else
		{
			x=x+s[i];
			if(x==str)
			{
				cv[i]=cv[i-1]+1;
			}
			else
			{
				cv[i]=cv[i-1];
			}
			x=x[1];
		}
		//cout<<cv[i]<<" ";
	}
	ll l,r;
	for(i=0;i<q;i++)
	{
		cin>>l>>r;
		cout<<cv[r-1]-cv[l-1]<<endl;
	}
}	

Measured memory_bytes: 1872
N,M=gets.chomp.split.map(&:to_i)
map=M.times.map { gets.chomp.split.map(&:to_i) }
a=gets.chomp.split.map(&:to_i)
ans=0
[0,1].repeated_permutation(N) {|q|
  r=Array.new(M,0)
  M.times do |i|
    z=0
    map[i][0].times do |j|
      j+=1
      z+=1 if q[map[i][j]-1]==1
    end
    r[i]=1 if z%2==a[i]
  end
  ans+=1 if r.all?{|h| h==1}
}
puts ans

Measured memory_bytes: 3836
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        int X = sc.nextInt();

        for(int i=X-K+1; i<X+K; i++){
            System.out.print(i + " ");
        }
    }
}

Measured memory_bytes: 23764
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix
 
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！
 
def main():
    ans=0
    a,b=map(int,input().split())
    for j in range(1,a+1):
        for i in range(10,b+1):
            c=str(i)
            if int(c[0])>=2 and int(c[1])>=2:
                if j==int(c[0])*int(c[1]):
                    ans+=1
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 5056
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef int64_t lint;
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using lb = long double;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define debug(x) cerr << #x << ": " << x << "\n"//手動デバッグ
#define YES(c) cout<<((c)?"YES\n":"NO\n"),0
#define Yes(c) cout<<((c)?"Yes\n":"No\n"),0
#define O(p) cout<<p<<"\n",0
#define OS(p) cout<<p<<" ",0
#define ON(p) cout<<p,0
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
#define endl "\n"//endlを置き換える
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定

const int dy[4]={1,0,-1,0};
const int dx[4]={0,1,0,-1};//^>v<

template<class T=int> T in(){
    T x;
    cin>>x;
    return (x);
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
//------------------------------------------------------------





//------------------------------------------------------------
int main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
//------------------------------------------------------------
    string s;cin>>s;
    int ans=0;
    bool ok=0;
    if(s[0]=='R'){ans++;}
    if(s[1]=='R'){ans++;}
    if(s[2]=='R'){ans++;}
    if(s=="RSR")ans--;
    O(ans);
    
    
    
    
    
//------------------------------------------------------------
	return 0;
}


Measured memory_bytes: 3648
# -*- coding: utf-8 -*-


def main():
    a, b, c = map(int, input().split())
    ans = 0

    # See:
    # https://www.youtube.com/watch?v=UHfTqvaD0pk
    if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
        print(0)
        exit()

    if b == c == a:
        print(-1)
        exit()

    for i in range(1, 31):
        twice = 2 ** i
        tmp = twice % 3

        x = twice // 3
        y = x
        z = x

        if tmp == 2:
            y += 1
            z += 1
        elif tmp == 1:
            x += 1

        takahashi = a * x + b * y + c * z
        aoki = a * y + b * x + c * z
        snuke = a * z + b * y + c * x

        if takahashi % twice == 0 and aoki % twice == 0 and snuke % twice == 0:
            ans += 1
        else:
            print(ans)
            exit()


if __name__ == '__main__':
    main()


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

int main()
{
	
	int H, W;
   	while(1)
   	{
		scanf("%d%d", &H, &W);
		if(H == 0 && W == 0)
		{
			break;
		}
		for(int i = 0; i < H; i++)
		{   
			if(i == 0 || i == H - 1)
			{
				for(int j = 0; j < W ; j++)
				{   
					printf("#");
				}
			}
			else
			{
				printf("#");
				for(int j = 0; j < W-2 ; j++)
				{   
					printf(".");
				}
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}




Measured memory_bytes: 1968
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] s = in.nextString().toCharArray();

			boolean ok = true;

			if (s[0] != 'A') {
				ok = false;
			}

			int count = 0;
			for (int i = 2; i < s.length - 1; i++) {
				if (s[i] == 'C') {
					count++;
				} else if (!('a' <= s[i] && s[i] <= 'z')) {
					ok = false;
					break;
				}
			}

			for (int i = s.length - 1; i < s.length; i++) {
				if (!('a' <= s[i] && s[i] <= 'z')) {
					ok = false;
				}
			}
			for (int i = 1; i < 2; i++) {
				if (!('a' <= s[i] && s[i] <= 'z')) {
					ok = false;
				}
			}

			if (count != 1) {
				ok = false;
			}

			out.println(ok ? "AC" : "WA");

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


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

int count(int i){
  int result=0;
  for(int j=1; j<i; j++){
    result += j;
  }
  return result;
}
int main(){
  
  int n, m; cin >> n >> m;
  
  cout << count(n)+count(m);
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());

        // 主処理
        long result = 0;
        for (int i = n - 1; 0 < i; i--) {
            result += i;
        }

        // 出力
        System.out.println(result);
        sc.close();
    }

}

Measured memory_bytes: 23764
#include <stdio.h>
#include <string.h>

int main()
{
  int a[5],i;

  for(i=0;i<5;i++)
    scanf("%d",&a[i]);

  int min = 10 ,num=0;

  for(i=0;i<5;i++)
    {
      num += a[i] / 10 ;
      if(a[i] % 10 != 0)
	num++;
      if(min > a[i]%10 && a[i]%10 != 0)
	min = a[i]%10;
    }

      num *=10;
           num += min-10;

      printf("%d\n",num);
  
  return 0;
  
}

Measured memory_bytes: 128
#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  long long int arr[n], max = 1e18, prod = 1, flag = 0, zero = 0;
  
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i]);
    flag = (arr[i] > max) ? 1 : flag;
    prod *= arr[i];
    (arr[i]) ? max /= arr[i] : zero = 1;
  }

  (zero) ? puts("0") : ((flag) ? puts("-1") : printf("%lld\n", prod));
  return 0;
}

Measured memory_bytes: 2484
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int preT = 0;
        int preX = 0;
        int preY = 0;
        for (int i=0; i<N; i++) {
            int t = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            if(judgeValidMove(t - preT, x - preX, y - preY) == false) {
                System.out.println("No");
                return;
            }
            preT = t;
            preX = x;
            preY = y;
        }
        System.out.println("Yes");
        sc.close();
    }

    public static boolean judgeValidMove(int t,int x,int y){
        final int minDist = Math.abs(x) + Math.abs(y);
        final int difDist = t - minDist;
        // 到達可能な距離か
        if(difDist < 0){
            return false;
        }
        // 最短でたどり着いた時間と予定時間の差が偶数なら到達可能
        if(difDist % 2 == 0){
            return true;
        } else {
            return false;
        }
    }
}

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

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define fo(i, a, b, k) for(int i = a; i <= b; i += k)
#define _fo(i, a, b, k) for(int i = a; i >= b; i -= k)
#define foa(i, a) for (auto &i : a)
#define fod(i, a) for(int i = 1; i*i <= a; i++)
#define sz(a) ((int) a.size())
#define all(a) begin(a), end(a)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mk(x, y) make_pair(x, y)  
#define log2i(x) (31-__builtin_clz(x))
#define log2ll(x) (63-__builtin_clzll(x)) 
#define msz(x) __builtin_popcount(x) 
#define mszll(x) __builtin_popcountll(x) 
#define fom(i, a, b) for(int i = a; i < (1<<b); i++)
#define ifon(i, mask) if(mask&(1<<i))
#define ss(i, mask) while(i=(i-mask)&mask)
#define ifss(i, mask) if(i > (mask^i)) 

typedef int64_t ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 1e5+1;
const int MOD = 1e9+7;
const ll INF = INT_MAX;
const ll _INF = INT_MIN;

string s;
vi l, r;
int ans[N];

void solve() {
	int s = sz(l), curr = 0;
	fo(i, 1, s-1, 1) {
		int pr = curr+r[i], pl = pr+1, ar, al, temp = (r[i]+l[i]);
		curr += temp;
		ar = temp/2;
		al = temp-ar;
		if(r[i] > l[i]) swap(ar, al);
		if((max(r[i], l[i])-1) % 2 == 1) swap(ar, al);
		ans[pr] = ar;
		ans[pl] = al;
	}
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> s;
	char temp = ' ';
	int len = sz(s);
	l.pb(0);
	r.pb(0);
	fo(i, 0, len-1, 1) {
		if(s[i] == 'L') {
			if(s[i] != temp) l.pb(1);
			else l.back()++;
		}
		if(s[i] == 'R')	{
			if(s[i] != temp) r.pb(1);
			else r.back()++;
		}	
		temp = s[i];
	}
	
	solve();
	fo(i, 1, len, 1) cout << ans[i] << " ";
}

Measured memory_bytes: 1612
#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);
  }
  sort(A.begin(),A.end());
  cout << A.at(N - 1) - A.at(0) << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(3*N);
    FOR(i, 0, 3*N){
        cin >> A.at(i);
    }

    sort(ALL(A), greater<ll>());
    
    ll sum = 0;
    FOR(i, 0, N){
        sum += A[2*i+1];
    }

    p(sum);
    
    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner input = new Scanner(System.in);
		int num = input.nextInt();
		for(int i = 0 ; i < num ; i++){
			double x1 = input.nextDouble();
			double y1 = input.nextDouble();
			double x2 = input.nextDouble();
			double y2 = input.nextDouble();
			double x3 = input.nextDouble();
			double y3 = input.nextDouble();
			double x4 = input.nextDouble();
			double y4 = input.nextDouble();
			if((y2-y1)/(x2-x1) == (y4-y3)/(x4-x3)){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
		input.close();
	}
}

Measured memory_bytes: 20564
#include <bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vl vector<long long>
#define fin(ar,k,n) for(int i=k;i<n;i++) cin>>ar[i]
#define fout(ar,k,n) for(int i=k;i<n;i++) cout<<ar[i]<<' '
#define vs vector<string>
#define mx INT_MAX
#define mn INT_MIN
#define all(z) z.begin(),z.end()
#define mcc 1000000007
#define mcf 998244353
#define mi map<int,int>
#define mem(a,n) memset(a,n,sizeof(a))
using namespace std;

//ll maxl(ll a,ll b) {return (a>b)? a:b;}
//ll minl(ll a,ll b) {return (a<b)? a:b;}
//ll gcdl(ll a,ll b) {return b ? gcdl(b,a%b):a;}
//bool sortc(const vi &v1,const vi &v2) {return v1[0]>v2[0];}

void solve()
{
    int k;
    ll sum=0;
    cin>>k;
    for (int i=1;i<=k;i++)
    {
        for (int j=1;j<=k;j++)
        {
            for (int l=1;l<=k;l++)
            {
                sum+=__gcd(i,__gcd(j,l));
            }
        }
    }
    cout<<sum;
}


#if 1
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}
#endif

//------------------------Google-------------------
#if 0
int main()
{
    #ifdef __WIN32
    freopen("input.txt","r",stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t,ct=0;
    cin>>t;
    while(t--)
    {
        cout<<"Case #"<<++ct<<": ";
        solve();
    }
    return 0;
}
#endif


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  multiset<int> st;
  rep(i, n) {
    cin >> a[i];
    auto it = st.lower_bound(a[i]);
    if (it != st.begin()) {
      it--;
      st.erase(it);
    }
    st.insert(a[i]);
  }
  cout << st.size() << endl;
}

Measured memory_bytes: 5376
#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;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int par[250000];
int rank1[250000];
const int Nmax = 100000;
void init(int n)
{
    for(int i = 0; i < n; i++){
        par[i] = i;
        rank1[i] = 0;
    }
}

int find(int x)
{
    if(par[x] == x){
        return x;
    } else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if(x == y){
        return ;
    }
    if(rank1[x] , rank1[y]){
        par[x] = y;
    } else {
        par[y] = x;
        if(rank1[x] == rank1[y]){
            rank1[x]++;
        }
    }
}

bool same(int x, int y)
{
    return find(x) == find(y);
}

int main() {
    //cout.precision(10);
    long long n, m;
    cin >> n >> m;
    init(240000);
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        unite(a, b + Nmax);
        unite(a + Nmax, b);
    }
    for(int i = 0; i <= 2 * Nmax; i++){
        find(i);
    }
    bool checker = true;
    for(int i = 1; i <= n; i++){
        if(!same(1, i)){
            checker = false;
        }
    }
    if(checker){
        cout << n * (n - 1) / 2 - m << endl;
        return 0;
    }
    long long number[2];
    number[0] = 0;
    number[1] = 0;
    for(int i = 1; i <= n; i++){
        if(same(1, i)){
            number[0]++;
        } else {
            number[1]++;
        }
    }
    cout << number[0] * number[1] - m << endl;
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using PQ = priority_queue<lint, vector<lint>, greater<lint>>;

struct UnionFind {
    vector<int> data;
    UnionFind(int n) { data.assign(n, -1); }

    bool unite(int x, int y) {
        x = root(x), y = root(y);
        if(x == y) return true;
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int root(int x) {
        return (data[x]<0 ? x : data[x]=root(data[x]));
    }

    int size(int x) {
        return -data[root(x)];
    }
};

int main() {
  lint N, M;
  cin >> N >> M;

  vector<lint> a(N);
  for(auto& elem : a) cin >> elem;

  UnionFind uf(N);
  for(lint i=0; i<M; i++) {
    lint x, y;
    cin >> x >> y;
    uf.unite(x, y);
  }

  map<lint, PQ> mp;
  for(lint i=0; i<N; i++) {
    mp[uf.root(i)].push(a[i]);
  }
  vector<PQ> que;
  for(auto [key, value] : mp) que.push_back(value);
  sort(que.begin(), que.end(), [](PQ &q1, PQ &q2) {
    return q1.size() > q2.size();
  });

  lint ans = 0;
  lint k = que.size();
  PQ S = que[0];
  for(lint i=1; i<k; i++) {
    if(S.empty()) {
      cout << "Impossible" << endl;
      return 0;
    }
    lint ai = S.top(); S.pop();
    lint aj = que[i].top(); que[i].pop();
    ans += ai + aj;
    while(que[i].size()) {
      S.push(que[i].top());
      que[i].pop();
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 21676
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    string s; cin >> s;
    int len = s.length();
    int firstA = 0;
    for (int i = 0; i < len; ++i) {
		if (s[i] == 'A') {
			firstA = i;
			break;
		}
	}
	int lastZ = 0;
	for (int i = len - 1; i >= 0; --i) {
		if (s[i] == 'Z') {
			lastZ = i;
			break;
		}
	}
	cout << (lastZ - firstA) + 1 << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3792
import sys
input = sys.stdin.readline

n, w = map(int, input().split())
wv = [list(map(int, input().split())) for _ in range(n)]

dp=[[0]*(w+1) for _ in range(n+1)]

for i in range(n):
    for sum_w in range(w+1):
        if sum_w-wv[i][0]>=0:
            dp[i+1][sum_w]=max(dp[i][sum_w], dp[i][sum_w-wv[i][0]]+wv[i][1])
        else:
            dp[i+1][sum_w]=dp[i][sum_w]

print(dp[n][w])


Measured memory_bytes: 120044
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> a(N);
	int mx1=0, mx2=0;
	for(int i=0; i<N; ++i){
	    cin >> a[i];
	    if(mx1<=a[i]){
	        mx2=mx1;
	        mx1=a[i];
	    }else if(mx2<=a[i]){
	        mx2=a[i];
	    }
	}
	for(int i=0; i<N; ++i){
	    if(a[i]<mx1) cout << mx1 << endl;
	    else cout << mx2 << endl;
	}
	return 0;
}


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

int main(){
	int A, B, C, X, i, j, k, ans = 0;
	scanf("%d%d%d%d", &A, &B, &C, &X);
	for(i = 0; i <= A; i++){
		for(j = 0; j <= B; j++){
			for(k = 0; k <= C; k++){
				if(500 * i + 100 * j + 50 * k == X){
					ans++;
				}
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

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

const int NMAX = 2005;
const int INF = 1000000000;

int n, a[NMAX], b[NMAX], mma[2 * NMAX][NMAX], mmb[2 * NMAX][NMAX], dp[NMAX][NMAX];
int main()
{
	cin >> n;
	for (int i = 1; i <= 2 * n; i++)
    {
        char c;
        int x;
		cin >> c >> x;
		c == 'W' ? a[x] = i : b[x] = i;

		for (int j = 0; j < n; j++)
        {
			mma[i][j] = mma[i - 1][j];
            mmb[i][j] = mmb[i - 1][j];
			c == 'W' ? mma[i][j] += x > j : mmb[i][j] += x > j;
		}
	}

	for (int j = 1; j <= n; j++)
        dp[0][j] = INF;

	for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
        {
            if (i)
                dp[i][j] = dp[i - 1][j] + mma[a[i]][i] + mmb[a[i]][j];
            if (j)
                dp[i][j] = min(dp[i][j], dp[i][j - 1] + mma[b[j]][i] + mmb[b[j]][j]);
        }
	cout << dp[n][n];
	return 0;
}


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


void solve(long long N, long long K, std::vector<long long> x){
    long long ans = 0;
    for(long long i = 0; i < N; ++i){
        ans = ans + min(2 * abs(x[i]), 2 * abs(K - x[i]));
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> x(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
    }
    solve(N, K, std::move(x));
    return 0;
}


Measured memory_bytes: 256
using System;

namespace AIDU {
    class AIDU0016
    {
        public static void Main(){
            string s;
            string[] ss;
            double x=0,y=0,r=0,th=90;
            const double p=180/Math.PI;
            do {
                s=Console.ReadLine();
                ss=s.Split(',');

                r=int.Parse(ss[0]);
                x+=Math.Cos(th/p)*r;
                y+=Math.Sin(th/p)*r;
                th-=int.Parse(ss[1]);
            } while (r!=0||int.Parse(ss[1])!=0);

            Console.WriteLine(Math.Truncate(x));
            Console.WriteLine(Math.Truncate(y));
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 9044
#include<bits/stdc++.h>
using namespace std;
bool A[200],B[200];
int N;
void change(bool *C,int &c,int &fld){
    for(int i=fld+1;i<2*N;i++){
        if(C[i]){
            C[i]=false;
            c--;
            fld=i;
            return;
        }
    }
    fld=-1;
}
void solve(){
    int a,b,fld=-1;
    a=b=N;
    for(int i=0;i<N;i++){
        int x;
        scanf("%d",&x);
        A[--x]=true;
        B[x]=false;
    }
 
    for(int i=0;a&&b;i++){
        if(i%2)change(B,b,fld);
        else change(A,a,fld);
    }
    printf("%d\n%d\n",b,a);
}
 
int main(){
    while(scanf("%d",&N),N){
        fill_n(A,2*N,false);
        fill_n(B,2*N,true);
        solve();
    }
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }

int main()
{
	string S;
	int count[100000];
	int Rs, Re, Ls, Le;
	bool L = false;
	memset(count, 0, sizeof(count));
	Rs = Re = Ls = Le = 0;


	cin >> S;

	rep(i, S.size() - 1)
	{
		if (S[i] != S[i + 1])
		{
			if (!L)
			{
				L = true;
				Re = i;
				Ls = i + 1;
			}
			else
			{
				L = false;
				Le = i;
				count[Re] = (int)((Re - Rs) / 2) + 1 + (int)((Le - Re) / 2);
				count[Ls] = (int)((Ls - Rs) / 2) + 1 + (int)((Le - Ls) / 2);
				Rs = i + 1;
			}
		}
	}

	Le = S.size() - 1;
	count[Re] = (int)((Re - Rs) / 2) + 1 + (int)((Le - Re) / 2);
	count[Ls] = (int)((Ls - Rs) / 2) + 1 + (int)((Le - Ls) / 2);


	rep(i, S.size())
		cout << count[i] << " ";

	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, intmax_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, intmax_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t N; string s;
    cin >> N >> s;

    for (auto &si: s) {
        size_t tmp = si - 'A';
        (tmp += N) %= 26;
        si = 'A' + tmp;
    }

    cout << s << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include<algorithm>
using namespace std;
const int maxn = 100;

int n,q;
int a[maxn],m,num;

bool solve(int i,int m)
{
    bool res;
    if(m == 0) return true;
    if(i >= n) return false;

   // cout << i << " " << m << " " <<res <<endl;
    res = solve(i+1,m) || solve(i+1,m-a[i]);
    return res;
}

int main()
{
    scanf("%d",&n);
    fill(a,a + n, 0);
    for(int i = 0; i < n; ++i) scanf("%d",&a[i]);
    scanf("%d",&q);
    sort(a,a+n);
    for(int i = 0; i < q; ++i){
        scanf("%d",&m);
        if(solve(0,m)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}

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

int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	
	if (a[a.length()-1] == b[0] && b[b.length()-1] == c[0])
		cout << "YES";
	else
		cout << "NO";
	
	return 0;
}

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

#define int long long

#define endl '\n'
#define pb push_back
#define pi acos(-1)
#define fi first
#define se second
#define si signed
#define sc(x) scanf("%lld",&(x));
#define  P pair<int,int>
int A[200005];
vector<int> v;
signed main()
{
    string s;
    cin>>s;

    int n =s.length();
    int t =0,ans=0;
    for(int i=n-1; i>=0; i--)
    {
        if((s[i]-'0'+t)<5)
        {
            ans+=s[i]-'0'+t;
            t =0;
        }
        else if((s[i]-'0'+t)==5)
        {
            if(i>0&&s[i-1]-'0'>=5)
            {
                ans+=10-s[i]+'0'-t;
                t=1;
            }
            else
            {
                ans+=s[i]-'0'+t;
                t=0;
            }
        }
        else
        {
            ans+=10-s[i]+'0'-t;
            t=1;
        }
        //out.print(i+" "+ans+"\n");
    }
    ans+=t;
    cout<<ans<<'\n';
}


Measured memory_bytes: 1412
// HEADERS //
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

// MISCELLANEOUS //
#define fast_IO() ios_base::sync_with_stdio(false),cin.tie(NULL)
#define gcd __gcd
#define cnt_1s __buitlin_popcount
#define ll long long
#define endl "\n"
#define test(t) cin >> t; while(t--)
#define mem(v, x) memset(v, x, sizeof(v))

// LOOPS //
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define irep(i, a, b) for(int i = (a)-1; i >= (b); i--)
#define srep(i, v) for(decltype(v.begin())i = v.begin(); i != v.end(); i++)

// CONTAINERS //
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ii pair<int,int>
#define ff first
#define ss second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define all(v) (v).begin(), (v).end()
#define present(v, x) (v).find(x) != (v).end()

// DEBUGGING //
#define dbg() printf("\n**DEBUG**\n")
#define chk(a) cerr << endl << #a << ":" << a << endl
#define chk2(a, b) cerr << endl << #a << ":" << a << "\t" << #b << ":" << b << endl

// CONSTANTS //
#define M 1000000007

// MAIN //
// using namespace __gnu_pbds;
using namespace std;
int main() {
    fast_IO();
    int t, n, m, x, y;
    cin >> n >> m;
    map<int, int> mp;
    stack<int> temp;
    vi G[n], dp(n);
    rep(i, 0, m) {
        cin >> x >> y;
        x--, y--;
        G[x].eb(y); mp[y]++;
    }
    rep(i, 0, n) if(!mp[i]) temp.push(i);
    while(!temp.empty()) {
        int v = temp.top(); temp.pop();
        for(int i: G[v]) {
            dp[i] = max(dp[i], dp[v]+1);
            mp[i]--;
            if(!mp[i]) temp.push(i);
        }
    }
    int ans = 0;
    for(int i: dp) ans = max(ans, i);
    cout << ans;
}

Measured memory_bytes: 10752
def insertionSort(A, N):
	print(*A)
	for i in range(1, N):
		value = A[i]
		j = i - 1
		while j >= 0 and A[j] > value:
			A[j + 1] = A[j]
			j -= 1
		A[j + 1] = value
		print(*A)

if __name__ == "__main__":
	n = int(input())
	a = list(map(int, input().split()))
	insertionSort(a, n)


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

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

const long long MOD = 1000000007;

int main(){
  int n;
  string s;
  cin >> n >> s;
  int r;
  int ans=0;
  rep(i,n){
    if(s.at(i)=='R') r++;
  }
  rep(i,r){
    if(s.at(i)=='W') ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3756
#include <stdio.h>

int main (void) {
    int a, b;

    scanf("%d %d", &a, &b);
    if (a < b) {
        printf("a < b\n");
    } else if (a > b) {
        printf("a > b\n");
    } else {
        printf("a == b\n");
    }

    return 0;
}


Measured memory_bytes: 2104
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int> >;
using vii = vector<pair<int, int> >;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	int all = 0;

	int t[4][4];
	Rep(i, 4) {
		Rep(j, 4) {
			int val; cin >> val;
			t[i][j] = val;
			all += val;
		}
	}

	bool check[6];

	check[0] = (abs(t[1][1] - t[1][2])) == (abs(t[2][1] - t[2][2]));

	check[1] = (abs(t[1][2] - t[1][3])) == (abs(t[2][2] - t[2][3]));

	check[2] = (abs(t[2][1] - t[2][2])) == (abs(t[3][1] - t[3][2]));

	check[3] = (abs(t[2][2] - t[2][3])) == (abs(t[3][2] - t[3][3]));

	check[4] = (abs(t[1][1] + t[3][3])) == (abs(t[1][3] + t[3][1]));

	check[5] = all % 3 == 0;

	if (t[1][1] + t[2][2] + t[3][3] == t[1][3] + t[2][2] + t[3][1]) {
		if (t[2][2] - t[1][2] + t[1][3] == t[2][3]) {
			if (check[0] && check[1] && check[2] && check[3] && check[4] && check[5]) {
				ANS("Yes");
				return 0;
			}
		}
	}
	ANS("No");
	return 0;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	int chara,now=-1,page=0;
	int index[26][100001];
	string s,t;
	cin>>s>>t;
	for(int i=s.length();i>=0;i--){
		for(int j=0;j<26;j++){
			index[j][i]=-1;
		}
	}
	for(int i=0;i<s.length();i++)index[s[i]-'a'][i]=i;
	for(int i=s.length()-2;i>=0;i--){
		for(int j=0;j<26;j++){
			if(index[j][i]==-1)index[j][i]=index[j][i+1];
		}
	}
	for(int i=0;i<t.length();i++){
		chara = t[i]-'a';
		if(index[chara][0]==-1){cout<<"-1";return 0;}
		if(index[chara][now+1]>=0)now = index[chara][now+1];
		else{
			now=-1;
			page++;
			i--;
		}
	}
	cout<<(long long int)(page*s.length()+now+1);
	return 0;
}

Measured memory_bytes: 10752
#include<stdio.h>

int main(){
  int n,i,g[1000000],m,a[1000000],v,cnt=0,j,k,maxg=1;
  g[0]=1;
    scanf("%d",&n);
  for(i=0;maxg<n;i++){
    m=i+1;
    maxg=3*maxg+1;
  }
  if(i==0){m=1;}
  for(j=1;j<=m-1;j++){
     g[j]=3*g[j-1]+1;
  }
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(k=m-1;k>=0;k--){
  for(i=g[k];i<=n-1;i++){
    v=a[i];
    j=i-g[k];
    while(j>=0 && a[j] >v){
      a[j+g[k]]=a[j];
      j=j-g[k];
      cnt++;
      a[j+g[k]]=v;
    }
  }
  }
  printf("%d\n",m);
  for(i=m-1;i>=0;i--){
    if(i==0)printf("%d\n",g[i]);
    else printf("%d ",g[i]);
  }
  printf("%d\n",cnt);
  for(i=0;i<n;i++){
    printf("%d\n",a[i]);
  }
  return 0;
}
    



Measured memory_bytes: 5676
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val N, Q = sc.nextInt
    val S = sc.next
    val l = new Array[Int](Q)
    val r = new Array[Int](Q)
    val sums = new Array[Int](N)
    for (i <- 0 until Q) {
      l(i) = sc.nextInt
      r(i) = sc.nextInt
    }
    var count = 0
    for (i <- 1 until N) {
      if (S(i - 1) == 'A' && S(i) == 'C') {
        count += 1
      }
      sums(i) = count
    }

    for (i <- 0 until Q) {
      println(sums(r(i) - 1) - sums(l(i) - 1))
    }

  }
}

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

int num;
int a[21][21];

int retcost(int Island){
	int x=0;
	for(int i=1;i<=num;i++){
		if(a[Island][i]){
			a[i][Island]=0;
			x=max(x,a[Island][i]+retcost(i));
		}
	}
	return x;
}

int main(void){
	while(cin>>num,num){
		int I1,I2,t,ans,I[num+1],Cost=0;
		memset(a,0,sizeof(a));
		memset(I,0,sizeof(I));
		for(int i=1;i<num;i++){
			cin>>I1>>I2>>t;
			a[I1][I2]=a[I2][I1]=t;
			I[I1]++,I[I2]++;
			Cost+=t*2;
		}
		for(int i=1;i<=num;i++){
			for(int j=1;j<=num;j++){
				if((I[i]==1||I[j]==1)&&!((i==1&&I[i]==1)||(j==1&&I[j]==1))){
					Cost-=a[i][j]*2;
					a[i][j]=a[j][i]=0;
				}
			}
		}
		ans=Cost-retcost(1);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3048
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

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

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n;
  int a, b;
  cin >> n;
  cin >> a >> b;
  int p[n];
  for(int i = 0; i < n; i++) cin >> p[i];

  int ca = 0, cb = 0;
  for(int i = 0; i < n; i++){
    if(p[i] <= a) ++ca;
    else if(p[i] <= b) ++cb;
  }

  int ans = min(ca, min(cb, n - (ca + cb)));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 888
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
#include <bits/stdc++.h>
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<22,stdin),p1 == p2)?EOF:*p1++)
using namespace std ;
//char buf[(1 << 22)] , *p1 = buf , *p2 = buf ;
inline int read ()
{
    char c = getchar () ; int x = 0 , f = 1 ;
    while (c < '0' || c > '9') { if (c == '-') f = -1 ; c = getchar () ; }
    while (c >= '0' && c <= '9'){ x = x * 10 + c - '0' ; c = getchar () ; }
    return x * f ;
}
int n , a[55] , ans ;
int main ()
{
//    freopen (".in" , "r" , stdin) ; freopen (".out" , "w" , stdout) ;
	cin >> n ;
	for (int i = 1 ; i <= n ; i ++) scanf ("%d" , &a[i]) ;
	for (int i = 1 ; i <= n ; i ++)
		for (int j = i + 1 ; j <= n ; j ++)
			ans += a[i] * a[j] ;
	cout << ans ;
}




Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int x,a,b;
int main(){
	cin>>x>>a>>b;
	int t1=abs(x-a);
	int t2=abs(x-b);
	if(t1>t2){
		cout<<"B"<<endl;
	}
	else{
		cout<<"A"<<endl;
	}
	return 0;
}

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

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll a,b;
  string s;
  cin >> a >> b >> s;

  bool ok=true;
  for(ll i=0;i<a;i++){
    if('0'<=s[i] && s[i]<='9');
    else ok=false;
  }
  if(s[a]=='-');
  else ok=false;
  for(ll i=a+1;i<a+b+1;i++){
    if('0'<=s[i] && s[i]<='9');
    else ok=false;
  }

  if(ok)cout << "Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T=ll>
using v =vector<T>;
template<typename T=ll>
using vv = vector<v<T>>;
using p = pair<ll,ll>;
const ll INF = (ll)1e9;
template<typename T> T chmin(T &a,T b){a=min(a,b);}
template<typename T> T chmax(T &a,T b){a=max(a,b);}

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    auto dp = vv<>(2,v<>(3,0));
    dp[0][0]=a;
    dp[0][1]=b;
    dp[0][2]=c;

    rep(i,1e9){
        if(dp[i&1][0]%2||dp[i&1][1]%2||dp[i&1][2]%2){
            cout << i << endl;
            return 0;
        }
        if(dp[i&1][0]==dp[i&1][1]&&dp[i&1][1]==dp[i&1][2]){
            cout << -1 << endl;
            return 0;
        }
        
        int j = (i+1)&1;
        dp[j][0] = dp[i&1][1]/2 + dp[i&1][2]/2;
        dp[j][1] = dp[i&1][0]/2 + dp[i&1][2]/2;
        dp[j][2] = dp[i&1][0]/2 + dp[i&1][1]/2;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  char s[11];
  
  int c[10],m,i;
  m=999;
  scanf("%s",s);
  
  for (i=0;i<10;i++){
    
    if(s[i+2]=='\0')
      break;
    
    c[i]=abs((s[i]-48)*100+(s[i+1]-48)*10+(s[i+2]-48)-753);
    
    if(m>c[i])
      m=c[i];
    
  }
  printf("%d",m);
}

Measured memory_bytes: 128
S = input()
T = input()

def hoge(text):
    assign = {}
    result = []
    for c in text:
        if c not in assign:
            assign[c] = len(assign)
        result.append(assign[c])
    return result

if hoge(S) == hoge(T):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 6832
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  while(n--){
    string q,s;
    cin>>q>>s;
    for(int i=q.size()-1;0<=i;i--){
      if(q[i]=='C')s=s.substr(1,s.size()-1)+s[0];
      if(q[i]=='J')s=s[s.size()-1]+s.substr(0,s.size()-1);
      if(q[i]=='E')
	for(int j=0;j<s.size()/2;j++)swap(s[j],s[(s.size()+1)/2+j]);
      if(q[i]=='A')reverse(s.begin(),s.end());
      if(q[i]=='P')
	for(int j=0;j<s.size();j++)
	  if(isdigit(s[j]))s[j]=((s[j]-'0'+10)-1)%10+'0';
      if(q[i]=='M')
	for(int j=0;j<s.size();j++)
	  if(isdigit(s[j]))s[j]=((s[j]-'0')+1)%10+'0';
    }
    cout<<s<<endl;
  }
  return 0;
}

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

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

  int cnt1=0, cnt2=0, cnt3=0;
  for(int X=0; X<=n; X++){
    for(int Y=0; Y<=n-X; Y++){
      if((y-10000*X-5000*Y)%1000==0&&X+Y+(y-10000*X-5000*Y)/1000==n){
        cnt1=X;
        cnt2=Y;
        cnt3=n-X-Y;
        printf("%d %d %d\n", cnt1, cnt2, cnt3);
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
}

Measured memory_bytes: 256