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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

#define PI acos(-1.0)

struct point{
  ll x,y;
  long double arg;
};

ll n;
vector<point> ps;

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

  cin>>n;
  rep(i,n){
    ll x,y;
    cin>>x>>y;
    if(x==0&&y==0)continue;
    ps.push_back((point){x,y,atan2(y,x)});
  }
  n=ps.size();

  sort(all(ps),[](const point& a,const point& b){
    return a.arg < b.arg;
  });

  rep(i,n)ps.push_back(ps[i]);

  long double res=0;
  rep(i,n)rep(j,n){
    ll X=0,Y=0;
    repl(k,i,i+j+1){
      X+=ps[k].x;
      Y+=ps[k].y;
    }
    maxch(res,(long double)sqrt((long double)X*X+(long double)Y*Y));
  }
  printf("%.12Lf\n", res);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int x = 1;
  int y = 1;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  vector<int>c(n);
  vector<int>d(n);
  for(int i = 0;i<n;i++) cin >> a[i];
  for(int i = 0;i<n;i++) cin >> b[i];
  for(int i = 0;i<n;i++){
    c[i] = i+1;
    d[i] = i+1;
  }
  do{
    if(a!=c) x++;
    else break;
  }
while(next_permutation(c.begin(),c.end()));
do{
  if(b!=d) y++;
  else break;
}
while(next_permutation(d.begin(),d.end()));
cout << abs(x-y);
return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    lint ans=1;
    vector<lint> a(n);
    REP(i,n){
        cin >> a[i];
        if(a[i]==0){
            cout << 0 << "\n";
            return 0;
        }
    }
    lint pre = ans;
    REP(i,n){
        lint a2=a[i];
        ans *= a2;
        if(ans>(long long)1e18||a[i]>ceil(1e18/pre)){
            cout << -1 << "\n";
            return 0;
        }
        pre = ans;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4000
#include <iostream>
#include <cmath>
using namespace std;
long long BZ[35];
long long work(long long x1, long long y1, long long x2, long long y2, int bz){
	if(bz == 0)
        return abs(y1 - y2);
	long long Tempbz = BZ[bz - 1];
	if(x1 / Tempbz != x2 / Tempbz)
        return abs(x1 - x2) + abs(y1 - y2);
	if(x1 / Tempbz == 1 && abs(y1 / Tempbz - y2 / Tempbz) >= 2)
		return abs(y1 - y2) + min(x1 % Tempbz + x2 % Tempbz + 2, (Tempbz - (x1 % Tempbz)) + (Tempbz - (x2 % Tempbz)));
	return work(x1 % Tempbz, y1, x2 % Tempbz, y2, bz - 1);
}
int main(){
	BZ[0] = 1;
	for(int i = 1; i <= 29; i++)
        BZ[i] = BZ[i - 1] * 3;
	long long q, x1, y1, x2, y2;
	cin >> q;
    while(q--){
		cin >> x1 >> y1 >> x2 >> y2;
		x1--, y1--, x2--, y2--;
		if(abs(y1 - y2) < abs(x1 - x2))
            swap(x1, y1), swap(x2, y2);
		cout << work(x1, y1, x2, y2, 30) << endl;
	}
	return 0;
}


Measured memory_bytes: 384
N, M, K = map(int, input().split())

def main(N, M, K):
    for i in range(0, N+1):
        for j in range(0, M+1):
            if i * (M - j) + j * (N - i) == K:
                return True
    return False

res = main(N, M, K)

if res == True:
    print('Yes')
else:
    print('No')





Measured memory_bytes: 3060
function Main(input) {
	const row = input.split(" ");
	const X = parseInt(row[0], 10);
	const K = parseInt(row[1], 10);
	const D = parseInt(row[2], 10);
	const even = num => num % 2 === 0;
	const av_x = X < 0 ? X * -1 : X;

	if(av_x >= K * D) {
		console.log(av_x - K * D);
	} else {
		for (let i = 1; i <= K; i++) {
			if(av_x <= D * i) {
				if(even(K - i)){
					console.log(D * i - av_x);
				} else {
					console.log(av_x - D * (i - 1));
				}
				break;
			}
		}
	}
};

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


Measured memory_bytes: 32376
/*

Sviatoslav Bidzilia 2019
CF: anakib1

*/

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define int long long

template<typename A, typename B, typename C>
struct triple
{
	A X;
	B Y;
	C Z;
	triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0)
{
	return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b)
{
	if (a.X != b.X)
		return a.X < b.X;
	if (a.Y != b.Y)
		return a.Y < b.Y;
	return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p)
{
	ofs << "( " << p.F << " , " << p.S << " )";
	return ofs;
}
template<typename T>
void print(T a)
{
	for (auto i : a)
		cout << i << ' ';
	cout << '\n';
}
template<typename T>
T max(T a, T b, T c)
{
	return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c)
{
	return min(a, min(b, c));
}
struct custom_hash
{
	static uint64_t splitmix64(uint64_t x)
	{
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const
	{
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int d = 1; d < 10; d++)
		if (n % d == 0 && n / d < 10)
			return cout << "Yes\n", 0;
	cout << "No\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<stdlib.h>

using namespace std ;

int main()

{
    int a, b, k;

    cin>>a>>b ;

    k=(a+b)/2 ;

    if(abs(a-k)==abs(b-k))
    {
        cout<<abs(k)<<endl ;
    }
    else
    {
        cout<<"IMPOSSIBLE"<<endl ;
    }

    return 0;
}


Measured memory_bytes: 3624
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main{
    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
    public static void main(String[] args) throws IOException {
        FastReader in = new FastReader();
        String[] arr = new String[3];
        char[] ans = new char[3];
        for(int i = 0 ; i < 3 ; i++ ){
            arr[i] = in.next();
            ans[i] = arr[i].toUpperCase().toCharArray()[0];
        }
        String temp = new String(ans);
        System.out.println(temp);
    }
}



Measured memory_bytes: 22612
import java.util.*;
import java.io.*;

public class Main {
	private static void solve(){
		//Implement solution here.
		int A = ni();
		int B = ni();
		int C = ni();
		int K = ni();
		
		int cnt = 0;
		while(A >= B) {
			B *= 2;
			cnt ++;
		}
		while(B >= C) {
			C *= 2;
			cnt ++;
		}
		
		if(cnt > K) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}


	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 25388
#include <bits/stdc++.h>
using namespace std;
constexpr auto MOD = 1000000007;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;

string s;
int n, m;

int gcm(int a, int b){
  if (!a || !b)return -1;
  if (a < b){
    a = a ^ b;b = a ^ b;a = a ^ b;
    }if (!(a % b))return b;
  return gcm(a % b, b);
}
long long gcm(long long a, long long b){
  if (!a || !b)return -1;
  if (a < b){
    a = a ^ b;b = a ^ b;a = a ^ b;
  }if (!(a % b))return b;
  return gcm(a % b, b);
}


int main()
{

  cin >> n;
  cout<<360/gcm(n, 360)<<endl;
}


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

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

  int S = s.length();
  vector<int> num(S + 1);

  s = '>' + s + "<";
  rep(k, 2) {
    rep(i, S) {
      if (s.substr(i, 2) == "><") {
        num[i] = 0;
        int j = i + 1;
        while (s[j] == '<') {
          num[j] = max(num[j], num[j - 1] + 1);
          j++;
        }
        i = j - 1;
      }
    }
    reverse(s.begin(), s.end());
    int l = s.length();
    rep(i, l) s[i] = (s[i] == '<') ? '>' : '<';
    reverse(num.begin(), num.end());
  }
  ll ans = 0;
  rep(i, S + 1) ans += num[i];
  cout << ans << endl;
}


Measured memory_bytes: 6796
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
    int N; cin >> N;
    vector<int> height(N);
    for(int i = 0; i < N; i++) cin >> height[i];
    vector<int> dp(N);
    dp[0] = 0;
    dp[1] = abs(height[1] - height[0]);
    for(int i = 2; i < N; i++) dp[i] = min(dp[i - 1] + abs(height[i] - height[i - 1]), dp[i - 2] + abs(height[i] - height[i - 2]));
    
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 3984
using System;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        long n = sc.NextInt();
        long m = sc.NextInt();
        
        // 答えとしてありえる値は mの約数

        long ans = 1;
        for (long i = 1; i * i <= m; i++)
        {
            if (m % i == 0)
            {
                // 答えをiにできるか
                if(n * i <= m) ans = Math.Max(ans, i);
                // 答えをm/iにできるか
                long j = m / i;
                if(n * j <= m) ans = Math.Max(ans, j);
            }
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}



Measured memory_bytes: 13268
#include<stdio.h>
int main()
{
    int N,i,b=0;
    scanf("%d",&N);
    for(i=105; i<=N; i+=2)
    {
        if(factor(i)>=8)
            b++;
    }
    printf("%d\n",b);
    return 0;
}

int factor(int num)
{
    int j=0,i;
    for(i=1; i<=num; i++)
    {
        if(num%i==0)
            j++;
    }

    return j;
}



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

int main() {
  int n; cin >> n;
  string s = to_string(n);
  rep(i,2)if(s[i]=='9'){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
//#define mp make_pair
#define fi first
#define se second

int main()
{
    int m,n;
    while(cin>>m>>n,m) 
    {
        bitset<limit+1>dp;
        rep(i,m,limit+1)
        {
            if(!dp[i]) 
            {
                if(--n<0) 
                {
                    cout<<i<<endl;
                    break;
                }
                for(int j=i+i;j<=limit;j+=i)dp[j]=1;
            }
        }
    }
}



Measured memory_bytes: 3988
#include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;


#define all(collection) (collection).begin(), (collection).end()
#define loop(i, times) for(int i = 0; i < times; i++)
#define seloop(i, start_index, end_index) for(int i = start_index; i < end_index; i++)
#define eqseloop(i, start_index, end_index) for(int i = start_index; i <= end_index; i++)



class AGC031A
{
public:
	AGC031A()
	{
		ans_ = 0;
		char_count_collection_.resize(26);
	}
	void Run(void)
	{
		cin >> n_;
		cin >> s_;
		CharCount();
		AllCount();

		cout << ans_;
	}

private:
	int n_;
	string s_;
	unsigned long long ans_;
	vector<int> char_count_collection_;
	void CharCount(void)
	{
		for (const auto & e : s_)
			char_count_collection_[(int)(e)-97]++;

		for (auto & e : char_count_collection_)
		{
			if (e == 0)
				e = 1;
			else
				e++;
		}

	}
	void AllCount(void)
	{
		ans_ = 1;
		for (const auto & e : char_count_collection_)
		{
			ans_ = (ans_ * e) % 1000000007;
		}
		ans_--;
	}
};

int main()
{
	AGC031A agc031a;
	agc031a.Run();
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long int Mod=1e9+7;
int dp[2][100005];
int rec(long A[],long k,int ind,long n)
{
    long val = 1,i;
    for(i=0;A[i]<=k && i<n;i++)
    {
        if(dp[ind][k-A[i]]==-1)
            dp[ind][k-A[i]]=rec(A,k-A[i],ind^1,n);
        if(ind == 1 && dp[ind][k-A[i]]==1)
            val = 0;
        else if(ind ==0 && dp[ind][k-A[i]]==0)
            val = 0;
    }
    return(val^ind);
}
int main()
{
    long i,j,n,k,ans;
    cin>>n>>k;
    long A[n];
    for(i=0;i<n;i++)
        cin>>A[i];
    sort(A,A+n);
    
    for(i=0;i<=k;i++)
        dp[0][i]=dp[1][i]=-1;
    
    ans = rec(A,k,0,n);
    if(ans==1)
        cout<<"Second"<<endl;
    else
        cout<<"First"<<endl;
}



Measured memory_bytes: 10368
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var scan = bufio.NewScanner(os.Stdin)

func main() {
	scanWords()
	itemNum := readNextInt()
	list := make([]int, 0, itemNum)
	for i := 0; i < cap(list); i++ {
		list = append(list, readNextInt())
	}

	sort.Sort(sort.IntSlice(list))

	min := list[0]
	max := list[len(list)-1]
	sum := 0
	for _, value := range list {
		sum += value
	}

	fmt.Printf("%d %d %d\n", min, max, sum)
}

func scanWords() {
	scan.Split(bufio.ScanWords)
}

func readNextInt() int {
	scan.Scan()

	input, err := strconv.Atoi(scan.Text())
	if err != nil {
		panic(err)
	}
	return input
}



Measured memory_bytes: 1268
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt() * 2;
        int[] l = new int[n];
        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }
        Arrays.sort(l);
        int sum = 0;
        for (int i = 0; i < n; i++) {
            if (i + 1 >= n) {
                sum += l[i];
                break;
            } else {
                sum += Math.min(l[i], l[i+1]);
                i++;
            }
        }
        System.out.println(sum);
        
    }
    
}

Measured memory_bytes: 10068
using System;
using System.Linq;

class C
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(long.Parse).ToArray();

		var p = new long[n + 1];
		p[0] = 1 - a[0];
		for (int i = 0; i < n; i++)
			p[i + 1] = Math.Min(1L << 60, 2 * p[i] - a[i + 1]);
		p[n] = Math.Min(p[n], 0);
		for (int i = n - 1; i >= 0; i--)
			p[i] = Math.Min(p[i], p[i + 1] + a[i + 1]);

		Console.WriteLine(p.Take(n).Any(x => x <= 0) || p[n] < 0 ? -1 : a.Sum() + p.Sum());
	}
}


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

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int main() {
    int N, A, B;
    while (~scanf("%d %d %d", &N, &A, &B)) {
          if (A + B - 1 > N || (LL)A * B < (LL)N) puts("-1");
          else {
               while (N > 0) {
                     int now = min(A, N - (B - 1));
                     for (int i = N - now + 1; i <= N; i++) printf("%d ", i);
                     N -= now;
                     B--;
               }
               puts("");
          }
          puts("");
    }
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int ans=0, x[5]={};
    for(int z=0;z<5;z++){
        cin>>x[z];
        
        ans+=1;
        if(x[z]==0){
            cout<<ans<<endl;
        }
    }
}

Measured memory_bytes: 3124
#n=int(input())
n,m=map(int,input().split())
#al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(m)]

corl=[list(map(int,input().split())) for i in range(n)]
chkl=[list(map(int,input().split())) for i in range(m)]

for i in range(n):
    templ=[]
    a=corl[i][0]
    b=corl[i][1]
    for j in range(m):
        c=chkl[j][0]
        d=chkl[j][1]
        templ.append([j,abs(a-c)+abs(b-d)])
    templ.sort(key=lambda x:(x[1],x[0]))
    print(templ[0][0]+1)




Measured memory_bytes: 3064
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF=2e18;
ll N,M;

ll h[100010];
int main(){
    cin>>N;
    ll ma=0;
    for(int i=0;i<N;i++){
        cin>>h[i];
        if(h[i]<=ma-2){
            cout<<"No"<<endl;
            return 0;
        }
        ma=max(ma,h[i]);
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <vector>
#include <list>
#include <queue>
#include <stack>

using namespace std;


int main() {
	int n;
	long long int sum = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (i % 3 == 0 || i % 5 == 0)continue;
		sum += i;
	}
	cout << sum << endl;

	return 0;
}



Measured memory_bytes: 3636
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	N, A, B := readInt3()
	result := N / (A + B) * A
	remain := N % (A + B)
	if remain <= A {
		fmt.Println(result + remain)
		return
	}
	fmt.Println(result + A)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    int sum = 0;
    for( int i = 0; i < s.size(); ++i ) {
        if( s[i] == '+' ) ++sum;
        else --sum;

    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>

typedef long long ll;

using namespace std;

int main() {
    string s;
    cin >> s;
    int len = s.length();
    ll a[len] = {};
    int f[len] = {};
    for(int i=0; i<len-1; i++) {
        if(s[i]=='R' && s[i+1]=='L') f[i]=1;
    }

    int way;
    for(int i=0; i<len; i++) {
        int now = i;
        if(s[i]=='R') way = 1;
        else way = -1;

        while(!f[now]) now+=way;
//        cout << "i=" << i << ", now=" << now << endl;


        if(abs(now-i)%2) {
            a[now+1]++;
//            cout << "a[now+1]=" << a[now+1] << endl;
        } else {
            a[now]++;
//            cout << "a[now]=" << a[now] << endl;
        }

    }

    for(int i=0; i<len-1; i++) cout << a[i] << " ";
    cout << a[len-1] << endl;


    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,x,ans=1e9,sum;
bool dp[880][880];
main(){
	cin>>n;
	dp[0][0]=1;
	r(i,n){
		cin>>x;
		sum+=x;
		for(int j=879;j>=0;j--)
		  for(int k=879;k>=0;k--)
		    if(dp[j][k]){
		    	if(j+x<810)dp[j+x][k]=1;
		    	if(k+x<810)dp[j][k+x]=1;
		    }
	}
	r(i,880)r(j,880)if(dp[i][j])ans=min(ans,max(i,max(j,sum-i-j)));
    cout<<ans<<endl;
}

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

#define MOD 1000000007
typedef unsigned long long ull;

int N = 0;
string S = "";

int main() {
  cin >> N >> S;

  if (N % 2 == 1) {
      cout << "No" << endl;
      return 0;
  }

  if (S.substr(0, N / 2) == S.substr(N / 2, N / 2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <deque>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b&&b==c){
        cout << "No" << endl;
    }else if(a!=b&&b!=c&&a!=c){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}


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

int a(int& b, int c) {
	return c ? a(c, b % c) : b;
}

int main() {
	int x, y, b = 0;
	cin >> x >> y;
	for (int i = 1; i <= x; ++i) {
		for (int j = 1; j <= y; ++j) {
			if (i / a(i, j) == x / a(x, y) && j / a(i, j) == y / a(x, y)) ++b;
		}
	}
	cout << 1 + x + y - b << endl;
}


Measured memory_bytes: 3108
# -*- coding: utf-8 -*-
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
A = []
B = []
for _ in range(N):
    x, y = map(int, readline().split())
    A.append(x+y)
    B.append(x-y)

a = max(A)
b = min(A)
c = max(B)
d = min(B)

print(max(abs(a-b),abs(c-d)))

Measured memory_bytes: 86908
#include<stdio.h> 
#include<iostream> 
#include<string.h>
#include<cstring>
#include<string>
#include<math.h>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
#define cuttime ios::sync_with_stdio(false)
#define swap(x, y) x ^= y, y ^= x, x^= y
#define INF 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)
#define scan1(x) scanf("%d",&x)
#define scan2(x,y) scanf("%d%d",&x,&y)
#define scan3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scanll1(x) scanf("%lld",&x)
#define scanll2(x,y) scanf("%lld%lld",&x,&y)
#define scanll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define lowbit(x) (x&(-x))
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int N=2e5+20;
const int MAX=10000007;
inline ll read() {
    char c=getchar();ll 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;
}

inline void out(int x) {   
	if(x>9) out(x/10);   
	putchar(x%10+'0'); 
}   
double q[N];
char s[N];
int main(){
	int t;
	ll a,b,n;
	a=read(),b=read(),n=read();
	if(n<b)cout<<(a*n)/b-a*(n/b)<<endl;
	else{
		cout<<(a*(b-1))/b<<endl;
	}
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long double ll;

ll rr = 998244353;

int main(){
    ll ans = 0, perm = 1.; 
    int n;
    cin >> n;
    vector<vector<ll>> pos(n, {0,0}), distance(n, vector<ll> (n,0));
    vector<int> v(n);

    REP(i,n){
        int x,y;
        cin >> pos[i][0] >> pos[i][1];
        v[i] = i+1;
      perm *= i+1;
    }
    REP(i,n){
        REP(j,n){
            distance[i][j] = sqrt( (pos[i][0] - pos[j][0])*(pos[i][0] - pos[j][0]) + (pos[i][1] - pos[j][1])*(pos[i][1] - pos[j][1])  );
        }
    }

    do{
        for(int i=0; i<n-1; i++){
                ans += distance[v[i%n]-1][v[(i+1)]-1];
        }
    }while(next_permutation(v.begin(),v.end()));

    cout << std::setprecision(12) <<  ans/perm;
  	return 0;
}

//2.2761423749



Measured memory_bytes: 256
n=int(input())
a=[]
d=[]
for i in range(n):
  c=[]
  b=int(input())
  d.append(b)
  for j in range(b):
    c.append(list(map(int,input().split())))
  a.append(c)


count=0
for i in range(2**n):
  x=[0]*n
  pre=0
  for j in range(n):
    if ((i>>j)&1):
      x[n-1-j]=1 
      for l in range(d[j]):
        if ((i>>(a[j][l][0]-1))&1)!=a[j][l][1]:
          pre+=1
  if pre!=0:
    count=count
  else:
    count=max(count,x.count(1))
print(count)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

bool solve(const vector<int>& a, const vector<int>& b)
{
    if(5 <= a[0] && 5 <= a[1])
        return false;

    for(int i=0; i<2; ++i){
        for(int j=0; j<2; ++j){
            if(a[i] < 5 && b[j] < 5){
                vector<int> b2 = b;
                b2[j] += a[i];
                if(!solve(b2, a))
                    return true;
            }
        }
    }
    return false;
}

int main()
{
    vector<int> a(2), b(2);
    cin >> a[0] >> a[1] >> b[0] >> b[1];

    if(solve(a, b))
        cout << "ISONO" << endl;
    else
        cout << "NAKAJIMA" << endl;

    return 0;
}

Measured memory_bytes: 1204
k, n = list(map(int, input().split()))
houses = list(map(int, input().split()))
d = []

for i in range(0, n-1):
    d.append(houses[i+1] - houses[i])
d.append(k - houses[-1] + houses[0])
ans = sorted(d)
del(ans[-1])
print(sum(ans))

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

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

	if (a > b) {
		cout << "a > b" << endl;
	}
	else if (a < b) {
		cout << "a < b" << endl;
	}
	else if (a == b) {
		cout << "a == b" << endl;
	}
}



Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

bool solve(const vector<string>& W){
    const int n = W.size();
    // condition1
    for(int i = 0; i < n-1; ++i){
        if(W[i].back() != W[i+1].front()){
            return false;
        }
    }
    // condition 2
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            if(W[i] == W[j]){
                return false;
            }
        }
    }
    return true;
}

vector<string> input(){
    int n; cin >> n;
    vector<string> W(n);
    for(int i = 0; i < n; ++i){
        cin >> W[i];
    }
    return W;
}

int main(){
    const vector<string> W = input();
    if(solve(W)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
"use strict";

function main(input) {
  var inputs = input.split("\n");

  var N = parseInt(inputs[0], 10)
  var s = inputs.slice(1, N + 1);
  var M = parseInt(inputs[N + 1], 10);
  var t = inputs.slice(N + 2, N + 2 + M);

  var dic = {};
  s.forEach((v, i) => dic[v] = (dic[v] || 0) + 1);
  t.forEach((v, i) => dic[v] = (dic[v] || 0) - 1);

  var result = 0;
  for (var key in dic) {
    result = Math.max(result, dic[key]);
  }

  console.log(result);
}

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


Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n[5];
    for(int i=0; i<4; i++){
        cin>>n[i];
    }
    sort(n,n+4);
    if(n[0]==1 && n[1]==4 && n[2]==7 && n[3]==9) cout<<"YES"<<'\n';
    else cout<<"NO"<<'\n';
    return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define ll long long
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	priority_queue<int> que;
	ll sum = 0LL;

	for (int i = 0; i < n; i++) {
		int cost;
		cin >> cost;
		que.push(cost);
	}

	for (int i = 0; i < m; i++) {
		int tmp = que.top();
		que.pop();
		tmp /= 2;
		que.push(tmp);
	}

	while (!que.empty()) {
		sum += (ll)que.top();
		que.pop();
	}

	printf("%lld", sum);

	return 0;
}




Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long int

int power(int x,int y, int p) 
{ 
    int res = 1; // Initialize result 
  
    x = x % p; // Update x if it is more than or 
    // equal to p 
  
    while (y > 0) { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res * x) % p; 
  
        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % p; 
    } 
    return res; 
} 
  
// Returns n^(-1) mod p 
int modInverse(int n, int p) 
{ 
    return power(n, p - 2, p); 
} 
  
// Returns nCr % p using Fermat's little 
// theorem. 
int nCrModPFermat(int n,int r, int p) 
{ 
    // Base case 
    if (r == 0) 
        return 1; 
  
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    int fac[n + 1]; 
    fac[0] = 1; 
    for (int i = 1; i <= n; i++) 
        fac[i] = (fac[i - 1] * i) % p; 
  
    return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; 
} 
int32_t main()
{
	int n;cin>>n;
	int ans=0;

// 	cout<<"Im here"<<endl;
	for(int i=1;;i++){
		if(3*i >n)
			break;
		else
		{	
			int p1=(n-3*i)+i-1,p2=(n-3*i);
			int val=nCrModPFermat(p1,p2,mod);
// 			cout<<val<<endl;
			ans+=(val);
			ans%=mod;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

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

	int N,M;
	cin >> N >> M;
	int dig[5];
	bool udah[5];
	bool ok = true;

	memset(udah, false, sizeof(udah));

	for(int i=1; i<=M; i++){
		int s,c;
		cin >> s >> c;
		if(udah[s] && dig[s]!=c){
			ok = false;
		} else {
			udah[s] = true;
			dig[s] = c;
		}
	}

	if(N>1 && udah[1] && dig[1]==0) ok = false;

	if(!ok) {cout << -1 << "\n"; return 0;}

	for(int i=1; i<=N; i++){
		if(udah[i]) cout << dig[i];
		else {
			if(N>1 && i==1) cout << 1;
			else cout << 0; 
		}
	}

	cout << "\n";

}


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<iomanip>
#include<string>
using namespace std;

int main()
{
	int n,p;
	cin>>n>>p;
	if (n%3==0)
	{
		cout<<"Possible"<<endl;
	}
	else if (p%3==0)
	{
		cout<<"Possible"<<endl;
	}
	else if ((n+p)%3==0)
	{
		cout<<"Possible"<<endl;
	}
	else if (n%3!=0 && p%3!=0 && (n+p)%3!=0)
	{
		cout<<"Impossible"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

double dist(int x1, int y1, int x2, int y2) {
    int dx = x1 - x2, dy = y1 - y2; 
    return sqrt(dx*dx + dy*dy);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    vi perm(n);
    iota(perm.begin(), perm.end(), 0);
    double ans = 0;
    int cnt = 0;
    do {
        cnt++;
        double sum = 0;
        rep(i, n-1) {
            int j = perm[i], k = perm[i+1];
            sum += dist(x[j], y[j], x[k], y[k]);
        }
        ans += sum;
    } while(next_permutation(perm.begin(), perm.end()));
    ans /= cnt;
    cout << fixed << setprecision(10) << ans << endl;

}

Measured memory_bytes: 256
def solve(items)
  sorted = false
  count = 0
  until sorted
    sorted = true
    1.upto(items.size-1) do |i|
      if items[i-1] > items[i]
        items[i], items[i-1] = items[i-1], items[i]
        sorted = false
        count += 1
      end
    end
  end
  [items, count]
end
gets
items, count = solve(gets.split(" ").map(&:to_i))
puts "#{items.join(" ")}\n#{count}"



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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int N;
    cin >> N;
    
    int A[N][N - 1];
    vector<int> count(N, 0);
    vector<int> index(N, 0);
    rep(i, N) {
        rep(j, N - 1) cin >> A[i][j];
    }

    int goal = N * (N - 1) / 2;
    int cnt = 0;
    int res = 0;

    while (cnt < goal) {
        int tmp = cnt;
        rep(i, N) {
            if (index[i] >= N - 1) continue;
            int enemy = A[i][index[i]];
            enemy--;
            if (A[enemy][index[enemy]] == i + 1) {
                if (count[i] == count[enemy]) {
                    count[i]++;
                    count[enemy]++;
                }
                else {
                    int plus = max(count[i], count[enemy]);
                    count[i] = plus + 1;
                    count[enemy] = plus + 1;
                }
                index[enemy]++;
                index[i]++;
                cnt++;
            }
        }
        if (tmp == cnt) {
            res = -1;
            break;
        }
    }
    if (res != -1) {
        rep(i, N) {
            res = max(res, count[i]);
        }
    }

    cout << res << endl;
    return 0;
}

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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    string s, t; cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());

    if (s < t) {
        puts("Yes");
    } else {
        puts("No");
    }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

var abc [200][200]int

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	s1 := getNextString(scanner)
	s2 := getNextString(scanner)

	ans := solve(n, s1, s2)

	fmt.Fprintln(writer, ans)

	writer.Flush()
}

func solve(n int, s1, s2 string) int {
	d := 3
	s := 1
	if s1[0] != s2[0] {
		s++
		d = 6
	}
	for i := s; i < n; i++ {
		if s1[i] != s2[i] {
			if s1[i-1] == s2[i-1] {
				d *= 2
			} else {
				d *= 3
			}
			d %= int(1e9 + 7)
			i++
			continue
		}
		if s1[i-1] == s2[i-1] {
			d *= 2
		}
		d %= int(1e9 + 7)
	}
	return d
}


Measured memory_bytes: 640
// in the name of Allah

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

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))
#define all(x) (x).begin(), (x).end()

#define fr first
#define se second

const ll mod = 1000000007;

inline ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

inline ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

inline ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

const int N = 2e5 + 5;

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

	string s, t;
	cin >> s >> t;

	vector <int> g[26];
	for(int i=0; i<sz(s); i++) {
		g[s[i]-'a'].pb(i);
	}
	ll idx = 0;
	for(char e : t) {
		int n = e - 'a';
		if(sz(g[n]) == 0) {
			cout << -1 << endl;
			return 0;
		}
		int now = idx % sz(s);
		int pos = lower_bound(g[n].begin(), g[n].end(), now) - g[n].begin();
		if(pos == sz(g[n])) {
			pos = g[n][0];
		}
		else {
			pos = g[n][pos];
		}
		if(pos >= now) {
			idx = idx - now + pos + 1;
		}
		else {
			idx = idx - now + sz(s) + pos + 1;
		}
	}
	cout << idx << endl;

	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
int n,x,a;
int gcd(int o,int p){
    if(o<p)swap(o,p);
    if(o%p==0)return p;
    return gcd(p,o%p);
}
int main(void){
    cin>>n>>x>>a;
    a=abs(x-a);
    for(int i=1;i<n;i++){
        int b;
        cin>>b;
        a=gcd(a,abs(x-b));
    }
    cout<<a<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static long bignum = 1000000000+7;

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String s = sc.next();
		String[] ss = s.split("");
		long rsize = 0;
		int gsize = 0;
		int bsize = 0;
		for(int i =0;i<ss.length;i++) {
			if(ss[i].equals("R"))rsize++;
			if(ss[i].equals("G"))gsize++;
			if(ss[i].equals("B"))bsize++;
		}
		int counter = 0;
		for(int i =1;i<n/2+1;i++) {
			for(int j =0;j+i*2<n;j++) {
				if(!ss[j].equals(ss[j+i])) {
					if(!ss[j].equals(ss[j+i*2])) {
						if(!ss[j+i].equals(ss[j+i*2]))counter++;
					}
				}
			}
		}
		System.out.println(rsize*gsize*bsize-counter);
	}

	static int gcd(int a,int b,int c) {
		int ans = 1;
		int max = Math.max(Math.max(a, b),c);
		for(int i =max;i>0;i--) {
			if(a%i==0) {
				if(b%i==0) {
					if(c%i==0) {
						ans = i;
						break;
					}
				}
			}
		}
		return ans;
	}





}
/*
class City{
	int order;
	int prefecture;
	int year;
	int number;
	City(int order,int prefecture, int year){
		this.order = order;
		this.prefecture = prefecture;
		this.year = year;
	}
}
*/


Measured memory_bytes: 37016
// In the name of God

#include <bits/stdc++.h>

using namespace std;

#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define debug(x) cout << #x ": " << x << endl;

vector<pair<int, int>> vals;
int ans[10];
vector<pair<int, int>> res;

bool compare(pair<int, int> x, pair<int, int> y) {
	if(x.first == y.first) return x.second > y.second;
	return x.first < y.first;
}

bool compare2(pair<int, int> x, pair<int, int> y) {
	return x.second < y.second;
}

bool comp(vector< pair<int, int> > s, vector < pair<int, int> > ss) {
	if(s.size() == ss.size()) {
		sort(s.begin(), s.end(), compare2);
		sort(ss.begin(), ss.end(), compare2);
		for(int i=s.size()-1; i>=0; i--) {
			if(s[i].second > ss[i].second) return true;
			else if(s[i].second < ss[i].second) return false;
		}
		return false;
	}
	else return s.size() > ss.size();
}

void solve(int num, int index, vector<pair<int, int>> nums) {
	if( num==0 && comp(nums, res)) res = nums;
	else if(num >= vals[0].first && index < vals.size()) {
		vector<pair<int, int>> n1 = nums;
		n1.push_back(vals[index]);
		if(num-vals[index].first >=0) solve(num-vals[index].first, index, n1);
		solve(num, index+1, nums);
	}
}

int main() {
	IOS
	int n, m, sum=0;
	cin >> n >> m;
	int val[10];
	val[1] = 2;
	val[2] = 5;
	val[3] = 5;
	val[4] = 4;
	val[5] = 5;
	val[6] = 6;
	val[7] = 3;
	val[8] = 7;
	val[9] = 6;
	for(int i=0; i<m; i++) {
		int x;
		cin >> x;
		vals.push_back(make_pair(val[x], x));
	}
	sort(vals.begin(), vals.end(), compare);
	int tmpn = n;
	int tmp = n / vals[0].first;
	n -= tmp * vals[0].first;
	while(n <= min(30, n)) {
		n += vals[0].first;
		tmp--;
	}
	ans[vals[0].second] += tmp;
	vector<pair<int, int>> h;
	solve(n, 0, h);
	for(int i=0; i<res.size(); i++) {
		ans[res[i].second]++;
	}
	string s = "";
	for(int i=1; i<10; i++) {
		if(!ans[i]) continue;
		while(ans[i]--) {
			s += (char)(i+'0');
		}
	}
	reverse(s.begin(), s.end());
	cout << s;
	return 0;
}


Measured memory_bytes: 384
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		long sum = 0;
		Set<String> set = new HashSet<>();
		for( int i=0 ; i<n ; i++ ) {
			set.add(sc.next());
		}
		
		System.out.println(set.size());
		
	}
}

Measured memory_bytes: 67464
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 200005
using namespace std;
typedef long long ll;

ll n, ans, a[N], d[N][3];
int main() {
	int i;
	memset(d, 0xc0, sizeof(d));
	cin >> n;
	for(i=1; i<=n; i++) scanf("%lld", &a[i]);
	d[1][0] = a[1];
	d[2][1] = a[2];
	d[3][0] = a[1] + a[3];
	d[3][2] = a[3];
	for(i=4; i<=n; i++) {
		d[i][0] = d[i-2][0] + a[i];
		d[i][1] = max(d[i-3][0], d[i-2][1]) + a[i];
		d[i][2] = max({d[i-4][0], d[i-3][1], d[i-2][2]}) + a[i];
	}
	if(n&1) cout << max({d[n-2][0], d[n-1][1], d[n][2]});
	else cout << max(d[n-1][0], d[n][1]);
	return 0;
}

Measured memory_bytes: 10024
X, Y, A, B, C = map(int, input().split())
p = sorted(list(map(int, input().split())))
q = sorted(list(map(int, input().split())))
r = sorted(list(map(int, input().split())))[::-1]

pq = sorted(p[-X:] + q[-Y:])
ans = sum(pq)

if pq[0] < max(r):
    left = 0
    right = len(r)
    while left < right - 1:
        mid = (left + right) // 2
        if pq[mid] >= r[mid]:
            right = mid
        else:
            left = mid
    ans = ans + sum(r[:right]) - sum(pq[:right])

print(ans)


Measured memory_bytes: 22720