akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

func main() {
    sc.Split(bufio.ScanWords)
    n1 := nextInt()
    n2 := nextInt()

    if ( n1 * n2 ) % 2 == 0 {
        fmt.Println("Even")
    } else{
        fmt.Println("Odd")
    }
}


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

int main(){
 int p,q,r;

 cin>>p>>q>>r;

if(r>=q && r>=p){
    cout<<q+p;
    return 0;
}
if(q>=r && q>=p){
    cout<<r+p;
    return 0;
}
if(p>=q && p>=r){
    cout<<q+r;
    return 0;
}
    
 
}

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

using namespace std;

int main(){
	int n, max_votes=0;
	string s;
	vector<string> v;
	map<string, int> m;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i){
		cin>>s;
		m[s]++;
		if(m[s]>max_votes){
			v.clear();
			v.push_back(s);
			max_votes++; 
		}else if(m[s]==max_votes){
			v.push_back(s);
		}
	}

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

	for(auto i: v){
		cout<<i<<'\n';
	}
	
	return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int mi=INF,ma;
string s;
map<int,int> m;

signed main() {
    cin >> s;
    for(auto i : s) m[(int)(i-'a')]++;
    for(auto i : m) mi = min(mi, i.se), ma = max(ma, i.se);
    if ((m.size() == 3 && ma-mi <= 1) || (m.size() == 2 && s.size() == 2 && ma==mi) || (m.size()==1 && s.size()==1)) cout << "YES" << endl;
    else cout << "NO" << endl;
}





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

int main()
{
  int N;
  cin >> N;
  int a[3 * N];
  
  for (int i = 0; i < 3 * N; i++) {
    cin >> a[i];
  }
  sort(a, a+3*N);
  
  long ans = 0;
  for (int i = 0; i < N; i++){
    ans += a[N+2*i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    ll n;
    cin >> n;
    vector<ll> dic;
    dic.push_back(10000000000);
    rep(i, n){
        ll a;
        cin >> a;
        ll pos = lower_bound(ALL(dic), a)-dic.begin();
        if(pos==0)dic.insert(dic.begin(), a);
        else if(dic[pos]>=a)pos--;
        dic[pos]=a;
    }
    // rep(i, dic.size())cout << dic[i] << ", ";cout << endl;
    cout << dic.size()-1 << endl;
}

Measured memory_bytes: 1400
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

#define ll long long
#define ld long double

constexpr double EPS = 1e-16;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

int n;
int q;

string s;
string t = "AC";

vector<int> sum;

int l;
int r;

void input() {
  cin >> n >> q >> s;

  sum.resize(n);
}

void input1() {
  cin >> l >> r;

  --l;
  --r;
}

void solve1() {
  for (int i = 0; i < n; ++i) {
    if (i > 0)
      sum[i] = sum[i - 1];

    if (s.substr(i, t.size()) == t)
      sum[i]++;
  }
}

void solve2() {
  int cur = r - (int)t.size() + 1;

  int ans = 0;

  if (cur >= l) {
    int back = 0;

    if (l > 0)
      back = sum[l - 1];

    ans = sum[cur] - back;
  }

  cout << ans << '\n';
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve1();

  while (q--) {
    input1();
    solve2();
  }
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define Vsort(a) sort(a.begin(), a.end())
#define rep(i,n) for(int i = 0; i < (n); i++)
#define Srep(i,a,n) for(int i = (a); i < (n); i++)
using namespace std;

int main(){
  string s,t,u;
  int a,b;
  cin >> s >> t >> a >> b >> u;
  s==u ? cout << a-1 << " " << b << endl : cout << a << " " << b-1 << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
int main(){
  ll n;
  cin>>n;
  vector<ll>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  ll cnt=0;
  ll cnta=0;
  ll saihu=1000;
  ll maxsaihu=1000;
  for(int i=0;i<n-1;i++){
    if(a[i]>a[i+1]){saihu=saihu+cnt*a[i];cnt=0;}
    else{cnta=cnt+saihu/a[i];saihu=saihu-a[i]*(cnta-cnt);cnt=cnta;}
    maxsaihu=max(maxsaihu,saihu);
    //    cout<<saihu<<endl;
  }
  if(a[n-1]>=a[n-2]){saihu=saihu+cnt*a[n-1];maxsaihu=max(maxsaihu,saihu);}
  cout<<maxsaihu<<endl;

  
  //cout<<cnt<<endl;
  return 0;
  }
  


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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll P,Q,R;cin>>P>>Q>>R;
  cout<<P+Q+R-max({P,Q,R})<<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
	ios::sync_with_stdio(false);
	ll n, p;
	cin >> n >> p;

	map<ll, int> primeFactorization;
	ll tmp = p;
	for (ll i = 2; i * i <= p; i++)
	{
		while (tmp % i == 0)
		{
			primeFactorization[i]++;
			tmp /= i;
		}
	}
	if (tmp != 1)
		primeFactorization[tmp]++;

	ll result = 1;
	for (const auto& p : primeFactorization)
		if (p.second >= n)
		{
			int cnt = p.second / n;
			while (cnt != 0)
			{
				result *= p.first;
				cnt--;
			}
		}
	cout << result << endl;
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
a_list = []
b_list = []
for _ in range(n):
  a, b = map(int, input().split())
  a_list.append(a)
  b_list.append(b)

a = np.array(a_list)
b = np.array(b_list)
indices = b.argsort()
a = a[indices]
b = b[indices]
if np.all(np.cumsum(a) <= b):
  print('Yes')
else:
  print('No')

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
  FAST();

  int n, i;
  cin >> n;
  vi p(n), q(n);
  REP(i, 0, n)  cin >> p[i];
  REP(i, 0, n)  cin >> q[i];

  vi arr(n);
  REP(i, 0, n)  arr[i] = i + 1;

  int a = 0, b = 0;

  i = 0;
  do{
    if(arr == p)
        a = i;
    if(arr == q)
        b = i;
    if(a != 0 && b != 0)
        break;
    i++;
  }while(next_permutation(all(arr)));

  cout << abs(a - b) << endl;
  return 0;
}












Measured memory_bytes: 256
import java.util.Scanner;

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

        Scanner scan = new Scanner(System.in);
        String[] str = new String[2];
        
        for(int i = 0; i < str.length; i++){
		    str[i] = scan.nextLine();
        }
        
        if(str[1].matches(str[0] + "\\w{1}")){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}

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

int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long int s , c;
    cin >> s>> c;
    c/=2;
    long long int a ;
    if (s >= c){
        cout << c;
    }
    else{
        a = c-s;
        cout << s+(a/2);
    }
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	
	//for(int i=0;i<N;i++) {}
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		int N=sc.nextInt();
		int H=sc.nextInt();
		
		int a[]=new int[N];
		int b[]=new int[N];
		int b_2[]=new int[N];
		long bSum=0;
		
		
		int maxA=0;
		for(int i=0;i<N;i++) {
			a[i]=sc.nextInt();
			b[i]=sc.nextInt();
			b_2[i]=b[i]*-1;
			
			maxA=Math.max(maxA, a[i]);
		}
		
		Arrays.sort(b_2);
		int ctn=0;
		boolean v=true;
		for(int i=0;i<N;i++) {
			
			if(b_2[i]*-1>maxA) {
				bSum+=b_2[i]*-1;
				ctn++;
			}
			if(bSum>=H) {
				v=false;
				break;
			}
			
		}
		
		if(v)ctn+=Math.ceil((double)(H-bSum)/maxA);
		
	//	p(bSum+" "+maxA);
		
		
		p(ctn);
	}
	

	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 89080
L, R = map(int, input().split())

ans = 2018**2
if R-L >= 2019:
    ans = 0
else:
    l, r = L % 2019, R % 2019
    for i in range(l, r):
        for j in range(i+1, r+1):
            ans = min(ans, i*j % 2019)
print(ans)


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

int main(){
    using namespace std;
    constexpr long double eps = 0.000000001;
    using real = long double;
    using point = complex<real>;
    using circle = pair<point, real>;
    unsigned long N;
    cin >> N;
    vector<point> p(N);
    for(auto& i : p){
        real im, re;
        cin >> im >> re;
        i.imag(im);
        i.real(re);
    }
    {
        mt19937_64 mt{random_device{}()};
        shuffle(p.begin(), p.end(), mt);
    }
    const auto& circle_from_diameter = [](const point& a, const point& b) -> circle {
        auto center = (a + b) / 2.0L;
        return {center, norm(a - center)};
    };
    const auto& circle_from_triangle = [](const point& a, const point& b, const point& c) -> circle {
        if(abs(((a - b) / (a - c)).imag()) < eps)return {0, 0};
        auto center = ((a - b) * norm(c) + (b - c) * norm(a) + (c - a) * norm(b)) / ((a - b) * conj(c) + (b - c) * conj(a) + (c - a) * conj(b));
        return {center, norm(a - center)};
    };
    const auto& is_included = [](const circle& c, const point& a) -> bool {
        return norm(a - c.first) <= c.second + eps;
    };
    const auto& is_all_include = [&p, &is_included](const circle& c) -> bool {
        return all_of(p.begin(), p.end(), [&c, &is_included](const point& a){return is_included(c, a);});
    };
    auto c = circle_from_diameter(p[0], p[1]);
    for(unsigned long i{2}; i < N; ++i)if(!is_included(c, p[i])){
            c = circle_from_diameter(p[0], p[i]);
            for(unsigned long j{1}; j < i; ++j)if(!is_included(c, p[j])){
                    c = circle_from_diameter(p[i], p[j]);
                    for(unsigned long k{0}; k < j; ++k)if(!is_included(c, p[k]))c = circle_from_triangle(p[i], p[j], p[k]);
                }
        }
    cout << setprecision(15) << sqrt(c.second) << endl;
    return 0;
}

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

#define zero(a) memset(a,0,sizeof(a))
#define inff(a,n) fill(a,a+n+1,inf)
#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define write(x) printf("%d\n",x)
long long  N;
long long a[100010];
long long T;
long long dp[100010];
int main(void)
{
	//freopen("C:\\Users\\YuXiaoKang\\Desktop\\test.txt","r",stdin);
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>N>>T;
    for(int i=1;i<=N;i++)
    {
        cin>>a[i];
    }
    long long min_num=a[1];
    dp[1]=0;
    for(int i=2;i<=N;i++)
    {
        if(a[i]>=min_num)
        {
            dp[i]=(T/2)*(a[i]-min_num);
        }
        else
        {
            min_num=a[i];
            dp[i]=0;
        }
    }
    sort(dp+1,dp+N+1);
    cout <<upper_bound(dp+1,dp+N+1,dp[N])-lower_bound(dp+1,dp+N+1,dp[N])<<endl;
	return 0;
}


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

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int A, B;
/*==================================================*/
/*function*/

/*==================================================*/

int main() {

    cin>>A>>B;

    REP(i,0,16){

    }

    if(A <= 8 && B <= 8){
        cout<<"Yay!"<<endl;
    } else{
        cout<<":("<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.io.*;


public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String args[]) {
        int n = sc.nextInt();
        int ans = 0;
        for(int i = 1; i <= n; i++) {
            if(String.valueOf(i).length() % 2 == 1) ans++;
        }
        System.out.println(ans);
    } 
}

Measured memory_bytes: 28244
using System;
using System.IO;
using System.Text;

namespace Contest
{

    class Program
    {

        public void Solve()
        {
            var sc = new Scanner();
            int N = sc.NextInt();
            var b = new bool[N + 1, N + 1];
            if (N % 2 == 0)
            {
                for (int i = 1; i <= N; i++)
                {
                    b[N - i + 1, i] = true;
                }
            }
            else
            {
                for (int i = 1; i <= N - 1; i++)
                {
                    b[N - i, i] = true;
                }
            }

            var sb = new StringBuilder();
            int cnt = 0;
            for (int i = 1; i < N; i++)
            {
                for (int j = i + 1; j <= N; j++)
                {
                    if (!b[i, j])
                    {
                        sb.AppendLine($"{i} {j}");
                        cnt++;
                    }
                }
            }
            Console.WriteLine(cnt);
            Console.Write(sb.ToString());
        }

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

    class Scanner
    {
        private char _separator = ' ';
        private StreamReader _stream = new StreamReader(Console.OpenStandardInput());
        private int _pos = 0;
        private string[] _line = new string[0];
        public string Next()
        {
            if (_pos >= _line.Length)
            {
                _line = _stream.ReadLine().Split(_separator);
                _pos = 0;
            }
            return _line[_pos++];
        }
        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public string[] Array()
        {
            if (_pos >= _line.Length)
                _line = _stream.ReadLine().Split(_separator);
            _pos = _line.Length;
            return _line;
        }
        public int[] IntArray()
        {
            var arr = Array();
            var res = new int[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = int.Parse(arr[i]);
            }
            return res;
        }
        public long[] LongArray()
        {
            var arr = Array();
            var res = new long[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = long.Parse(arr[i]);
            }
            return res;
        }
        public double[] DoubleArray()
        {
            var arr = Array();
            var res = new double[arr.Length];
            for (int i = 0; i < arr.Length; i++)
            {
                res[i] = double.Parse(arr[i]);
            }
            return res;
        }
    }
}


Measured memory_bytes: 13260
#!/usr/bin/env python
# encoding: utf-8


class Solution:

    @staticmethod
    def bubble_sort():
        # write your code here
        array_length = int(input())
        array = [int(x) for x in input().split()]

        flag, count, cursor = 1, 0, 0
        while flag:
            flag = 0
            for j in range(array_length - 1, cursor, -1):
                if array[j] < array[j - 1]:
                    array[j], array[j - 1] = array[j - 1], array[j]
                    flag = 1
                    count += 1
        cursor += 1
        print(" ".join(map(str, array)))
        print(str(count))


if __name__ == '__main__':
    solution = Solution()
    solution.bubble_sort()

Measured memory_bytes: 7708
#include<iostream>
using namespace std;
int main(){
  int n,coin[4]={10,50,100,500};
  bool flag = false;
  while(cin >>n,n){
    if(flag) cout <<endl;
    flag = true;
    int a[4],ans[4],ii[4],b[4],xx=1000;
    for(int i=0; i<4; i++) cin >>a[i];
    for(ii[0]=0; ii[0]<=a[0]; ii[0]++){
      for(ii[1]=0; ii[1]<=a[1]; ii[1]++){
	for(ii[2]=0; ii[2]<=a[2]; ii[2]++){
	  for(ii[3]=0; ii[3]<=a[3]; ii[3]++){
	    int sum = 0,r=0;
	    for(int i=0; i<4; i++) sum+=coin[i]*ii[i];
	    if(sum<n) continue;
	    sum-=n;
	    for(int i=3; i>=0; i--){b[i] = sum/coin[i];sum%=coin[i];}
	    bool f = false;
	    for(int i=0; i<4; i++) if(b[i]*ii[i]!=0) f = true;
	    if(f) continue;
	    for(int i=0; i<4; i++) r+=(a[i]-ii[i]+b[i]);
	    if(r<xx){
	      for(int i=0; i<4; i++) ans[i] = ii[i];
	      xx = r;
	    }
	  }
	}
      }
    }
    for(int i=0; i<4; i++) if(ans[i]!=0) cout <<coin[i]<<" "<<ans[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

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

    vector<int> vec;
    int sum = 0;
    vec.push_back(sum);
    rep(i, N) {
        if (S[i] == 'I') sum++;
        else sum--;
        vec.push_back(sum);
    }

    print(*max_element(all(vec)));

}




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

int main( void )
{
	int bi[13][2] = {
		{ 0, 2 },
		{ -1, 1 }, { 0, 1 }, { 1, 1 },
		{ -2, 0 }, { -1, 0 }, { 0, 0 }, { 1, 0 }, { 2, 0 },
		{ -1, -1 }, { 0, -1 }, { 1, -1 },
		{ 0, -2 }
	};
	int me[9][2] = {
		{ -1, 1 }, { 0, 1 }, { 1, 1 },
		{ -1, 0 }, { 0, 0 }, { 1, 0 },
		{ -1, -1 }, { 0, -1 }, { 1, -1 }
	};
	int sm[5][2] = {
		{ 0, 1 },
		{ -1, 0 }, { 0, 0 }, { 1, 0 },
		{ 0, -1 }
	};

	vector < vector <int> > V(10, vector<int>(10, 0));
	int max_value = 0;
	while ( !cin.eof() )
	{
		int x, y, size;
		char c1, c2;
		cin >> x >> c1 >> y >> c2 >> size;
		if ( cin.eof() )
			break;

		if ( size == 1 )
		{
			for ( int i = 0; i < 5; i++ )
			{
				int nx = x + sm[i][0];
				int ny = y + sm[i][1];

				if ( ( nx >= 0 && nx < 10 ) && ( ny >= 0 && ny < 10 ) )
				{
					V[ny][nx]++;
					max_value = max( V[ny][nx], max_value );
				}
			}
		}
		else if ( size == 2 )
		{
			for ( int i = 0; i < 9; i++ )
			{
				int nx = x + me[i][0];
				int ny = y + me[i][1];

				if ( ( nx >= 0 && nx < 10 ) && ( ny >= 0 && ny < 10 ) )
				{
					V[ny][nx]++;
					max_value = max( V[ny][nx], max_value );
				}
			}
		}
		else if ( size == 3 )
		{
			for ( int i = 0; i < 13; i++ )
			{
				int nx = x + bi[i][0];
				int ny = y + bi[i][1];

				if ( ( nx >= 0 && nx < 10 ) && ( ny >= 0 && ny < 10 ) )
				{
					V[ny][nx]++;
					max_value = max( V[ny][nx], max_value );
				}
			}
		}
	}

	int emp = 0;
	for ( int i = 0; i < 10; i++ )
	{
		for ( int j = 0; j < 10; j++ )
		{
			if ( V[i][j] == 0 )
				emp++;
		}
	}

	cout << emp << endl;
	cout << max_value << endl;

	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int gcd(int, int);

int main(){
  int a, b;

  scanf("%d%d", &a, &b);
  printf("%d\n", gcd(a, b));

  return 0;
}

int gcd(int a, int b){
  int r;
  
  if(a < b) {
    r = a;
    a = b;
    b = r;
  }
 
  while(b > 0){
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

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

int main(void){
	map<string,int> ans;
	char a[40];
	string best,high;
	while(!cin.eof()){
		cin>>a;
		string kari(a);
		if(ans.count(kari))
			ans[kari]++;
		else
			ans[kari]=1;
		if(ans[best]<ans[kari])
			best=kari;
		if(high.size()<kari.size())
			high=kari;
	}
	cout<<best.c_str()<<" "<<high.c_str()<<endl;
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    rep2(i, K, N) {
        if (A[i] > A[i-K]) {
            cout << "Yes" << '\n';
        }else {
            cout << "No" << '\n';
        }
    }

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  LL kk;
  cin >> n >> kk;
  vector<vector<LL>> e(n,vector<LL>(n)),ans(n,vector<LL>(n,0)),nans(n,vector<LL>(n,0));
  for(int i=0;i<n;i++) ans[i][i]=1;
  vector<vector<vector<LL>>> rui(64,vector<vector<LL>>(n,vector<LL>(n,0)));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin >> rui[0][i][j];
    }
  }
  for(int i=1;i<64;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
        for(int l=0;l<n;l++){
          rui[i][j][k]=(rui[i][j][k]+rui[i-1][j][l]*rui[i-1][l][k]%MOD)%MOD;
        }
      }
    }
  }
  for(int i=0;i<64;i++){
    if(kk&(1ll<<i)){
      // for(int j=0;j<n;j++){
      //   for(int k=0;k<n;k++){
      //     cout << rui[i][j][k];
      //   }
      //   cout << endl;
      // }
      for(int j=0;j<n;j++){
        for(int k=0;k<n;k++){
          nans[j][k]=0;
          for(int l=0;l<n;l++){
            nans[j][k]=(nans[j][k]+ans[j][l]*rui[i][l][k]%MOD)%MOD;
            // cout << j SP k SP l SP ans[j][l]*rui[i][l][k]  << endl;
          }
        }
      }
      // for(int i=0;i<n;i++){
      //   for(int j=0;j<n;j++){
      //     cout << nans[i][j];
      //   }
      //   cout << endl;
      // }
      for(int j=0;j<n;j++){
        for(int k=0;k<n;k++){
          ans[j][k]=nans[j][k];
        }
      }
    }
  }
  LL answer=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      answer=(answer+ans[i][j])%MOD;
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    int n, k, s;
    cin >> n >> k >> s;

    int i = 0;
    for (; i < k; ++i) {
        cout << s << " ";
    }
    for (; i < n; ++i) {
        int t = s == 1e9 ? s-1 : s+1; 
        cout << t << " ";
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
long long n;
long long ans=0;
long long nw,cnt;
long long dmg=0;
int main(){
	scanf("%lld",&n);
	nw=n; cnt=1;
	while(dmg<n){
		dmg+=(nw%2)*cnt;
		ans+=cnt;
		nw/=2;
		cnt*=2;
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;

#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define R(i,n) for(int i=0;i<(n);++i)
#define fill(a,b) memset(a,b,sizeof(a))

const int mod = 1e9 + 7;
const int p2 = 500000004;
const int maxn = 5010;
int d[2][maxn];
char s[maxn];
int n;

void add(int& a,int b)
{
	a += b;
	if(a > mod) a -= mod;
}

int main()
{
	//freopen("test.txt","r",stdin);
	scanf("%d %s",&n,s);
	int m = strlen(s);
	int p = 1;
	d[p][0] = 1;
	R(i,n)
	{
		p ^= 1;
		fill(d[p],0);
		F(j,0,i)
		{
			add(d[p][max(j-1,0)],d[p^1][j]);
			add(d[p][j+1],2*d[p^1][j] %mod);
		}
	}
	LL ans = d[p][m];
	R(i,m) ans = ans*p2%mod;
	printf("%lld\n",ans);
	return 0;
}




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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<ll> D(N);
  for (auto &d : D)
    cin >> d;
  int M;
  cin >> M;
  vector<ll> T(M);
  for (auto &t : T)
    cin >> t;
  map<ll, int> mp;
  for (auto &d : D)
    mp[d]++;
  bool can = true;
  for (auto &t : T)
  {
    auto itr = mp.find(t);
    if (itr == mp.end() || itr->second == 0)
      can = false;
    itr->second--;
  }
  (can) ? cout << "YES" << endl : cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 15872
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
double pie=3.14159265358979;
long long mod=998244353;
//
int main(){
	int x,y;
	cin>>x>>y;
	for(int i=0;i<=x;i++){
		if(i*2+(x-i)*4==y){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

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

string to_string(string s) { return '"' + s + '"'; }
string to_string(char c) { string s = "'"; s += c; return s + "'"; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } 
template <typename A>
string to_string(A v) {
    bool first = true; 
    string res = "{";
    for (const auto &x : v) {
        if (!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}"; 
    return res;
}
istream_iterator<string> eos;
void dbg_out(istream_iterator<string> it) { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(istream_iterator<string> it, Head H, Tail... T) {
    cerr << *it << " = " << to_string(H);
    if(++it != eos) cerr << ", ";
    dbg_out(it, T...);
}
#ifdef LOCAL
    #define dbg(...) { string _s = #__VA_ARGS__; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); dbg_out(_it, __VA_ARGS__); }
#else
    #define dbg(...)
#endif

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define MP make_pair
#define sz(v) ((int)(v).size())
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

const int inf = (1LL << 60), mod = 1e9+7, nn = 2e5+5;

void solve(){
    int n, m;
    cin >> n >> m;
    cout << n * (n-1)/2 + m * (m - 1)/2 << nl;
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll long long
using namespace std;
const int N = 405;
ll dp[N][N], sum[N], a[N], n;
ll f(int l, int r){
    return sum[r] - sum[l - 1];
}
ll calc(int l, int r){
    if(dp[l][r])return dp[l][r];
    if(l == r)return 0;
    ll ans = 1e18;
    for(int i = l + 1; i <= r; i++){
        ll L = calc(l, i - 1);
        ll R = calc(i, r);
        ans = min(ans, L + R);
    }
    return dp[l][r] = ans + f(l, r);
}
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
    }
    cout << calc(1, n) << endl;
}    

Measured memory_bytes: 1536
import java.util.*;

public class Main {                   
    
  public static void main(String[] args) {                     
      
      Scanner sc = new Scanner(System.in);
      
      long N = sc.nextLong();
      long A = sc.nextLong();
      long B = sc.nextLong();
      
     if(A > B || (N == 1 && A != B)){
         System.out.println(0);
         return;
     }
  
     System.out.println((N-2)*(B-A) + 1);
     
      
  }   
   
}
        
        

Measured memory_bytes: 23124
#include<cstdio>
#include<stack>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

ll n, ed[20], ans[1<<16], I;
char s[20];

ll search(ll st, ll e, ll a, ll b, ll c, ll d) {
  vector<ll> v, v2;
  for (ll i = st; i <= e; i++) {
    if (s[i] == '(') v.push_back(search(i+1, ed[i]-1, a, b, c, d)), i = ed[i];
    else if (s[i] == '0') v.push_back(0);
    else if (s[i] == '1') v.push_back(1);
    else if (s[i] == 'a') v.push_back(a);
    else if (s[i] == 'b') v.push_back(b);
    else if (s[i] == 'c') v.push_back(c);
    else if (s[i] == 'd') v.push_back(d);
    else if (s[i] == '-') v.push_back(-1);
    else if (s[i] == '^') v.push_back(-2);
    else if (s[i] == '*') v.push_back(-3);
  }
  bool flag = false;
  for (ll i = 0; i < v.size(); i++) {
    if (v[i] == -1) flag = !flag;
    else {
      if (flag) v2.push_back(!v[i]), flag = false;
      else v2.push_back(v[i]);
    }
  }
  if (v2.size() != 1 && v2.size() != 3) printf("!");
  if (v2.size() == 1) return v2[0];
  if (v2[1] == -2) return v2[0] xor v2[2];
  return v2[0] & v2[2];
}

int main() {
  for (ll i = 0; i < (1<<16); i++) ans[i] = 16;
  I = (1<<16) - 1;
  ll now = 0;
  vector<ll> v;
  ans[0] = 1;
  v.push_back(0);
  ans[(1<<16) - 1] = 1;
  v.push_back((1<<16) - 1);
  for (ll i = 0; i < 4; i++) {
    ll temp = 0;
    for (ll j = 0; j < 16; j++) {
      temp *= 2;
      if (j & (1<<i)) temp++;
    }
    ans[temp] = 1;
    v.push_back(temp);
  }
  while (now < v.size()) {
    if (ans[I xor v[now]] > ans[v[now]] + 1) ans[I xor v[now]] = ans[v[now]] + 1, v.push_back(I xor v[now]);
    if (ans[v[now]] >= 14) { now++; continue; }
    for (ll i = 0; i <= now; i++) {
      ll temp = ans[v[now]] + ans[v[i]] + 3;
      if (ans[v[now] xor v[i]] > temp) ans[v[now] xor v[i]] = temp, v.push_back(v[now] xor v[i]);
      if (ans[v[now] & v[i]] > temp) ans[v[now] & v[i]] = temp, v.push_back(v[now] & v[i]);
    }
    now++;
  }
  //printf("%lld\n", (ll)v.size());

  while (scanf("%s", s), s[0] != '.') {
    n = 0;
    while (s[n] != 0) n++;
    stack<ll> stc;
    for (ll i = 0; i < n; i++) {
      if (s[i] == '(') stc.push(i);
      if (s[i] == ')') ed[stc.top()] = i, stc.pop();
    }
    ll num = 0;
    for (ll i = 0; i < 16; i++) {
      num *= 2;
      num += search(0, n-1, (i&8) ? 1 : 0, (i&4) ? 1 : 0, (i&2) ? 1 : 0, (i&1) ? 1 : 0);
    }
    printf("%lld\n", ans[num]);
  }
}



Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    ll n,k;
    cin>>n>>k;
    n--;
    int x=n/2,y=n/2;
    if(n%2)
        x++;
    int can=x*y;
    can+=(x*(x-1))/2;
    can+=(y*(y-1))/2;
    n++;
    if(can<k)
    {
        cout<<"-1"<<endl;
    }
    else
    {
        int mid=(n+1)/2;
        vector<int>g[200];
        for(int i=1; i<mid; i++)
            g[i].push_back(mid);
        for(int i=mid+1; i<=n; i++)
            g[i].push_back(mid);
        for(int i=1; i<mid; i++)
        {
            if(can==k)
                break;
            for(int j=mid+1; j<=n; j++)
            {
                if(can==k)
                    break;
                g[i].push_back(j);
                can--;
            }
        }
        for(int i=1; i<mid; i++)
        {
            if(can==k)
                break;
            for(int j=i+1; j<mid; j++)
            {
                if(can==k)
                    break;
                g[i].push_back(j);
                can--;
            }
        }
        for(int i=mid+1; i<=n; i++)
        {
            if(can==k)
                break;
            for(int j=i+1; j<=n; j++)
            {
                if(can==k)
                    break;
                g[i].push_back(j);
                can--;
            }
        }
        int sz=0;
        for(int i=1; i<=n; i++)
        {
            sz+=g[i].size();
        }
        cout<<sz<<endl;
        for(int i=1; i<=n; i++)
            for(auto it:g[i])
                cout<<i<<" "<<it<<endl;

    }


    return 0;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  int n,r;
  cin>>n>>r;
  if(n>=10){
    cout<<r<<endl;
  }else{
    cout<<r+100*(10-n)<<endl;
  }

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

signed main() {
	int n, x;
	cin >> n >> x;

	int ans = 0;
	int a = x, b = n - x;
	while (b) {
		if (a > b)swap(a, b);
		int c = b / a;
		ans += a * 3 * c;
		b -= a * c;
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

bool g[55][55];
bool c[55];

void dfs(int p) {
    if (c[p]) {
        return;
    } else {
        c[p] = true;
    }

    for (int i = 0; i < 55; ++i) {
        if (g[p][i]) {
            dfs(i);
        }
    }
}

int main() {

    int n, m; cin >> n >> m;

    vector<int> a(m);
    vector<int> b(m);

    for (int i = 0; i < 55; ++i) {
        for (int j = 0; j < 55; ++j) {
            //隣接行列を一度全てfalseにする
            g[i][j] = false;
        }
    }

    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];

        --a[i]; --b[i];

        //隣接行列
        g[a[i]][b[i]] = true;
        g[b[i]][a[i]] = true;
    }

    int ans = 0;

    //橋かどうか調べる
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < 55; ++j) {
            c[j] = false;
        }

        g[a[i]][b[i]] = false;
        g[b[i]][a[i]] = false;

        //dfsを使って調べる
        dfs(a[i]);

        if (!c[b[i]]) {
            ++ans;
        }

        //元に戻す
        g[a[i]][b[i]] = true;
        g[b[i]][a[i]] = true;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
/*
    ????????°??§???????????¨????????????
*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#define LLU unsigned long long int
#define LL long long int
#define LD long double
using namespace std;
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vLL vector<long long int>
#define vLLU vector<unsigned long long int> 
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debug printf("asd\n")
#define debugd(a) printf("--%d\n",a)
#define debugdd(a,b) printf("--%d %d\n",a,b)
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forde(a,b,c) for(int a=b ; a<c ; a--)


inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void scd(int &a){scanf("%d",&a);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void scdlld(long int &a,long int &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(long long int &a){scanf("%I64d",&a);}

#define scarrd(a,b) for(int i=0 ; i<b ; i++)scanf("%d",&a[i])
#define prdlld(a,b) printf("%I64d %I64d",a,b)
#define prdd(a,b) printf("%d %d",a,b)
#define prd(a) printf("%d",a)
#define prarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i])
#define iniarr(a,b) for(int i=0 ; i<b ;i++)a[i]=0
#define arr(a,b) int *a=(int *)malloc(b*sizeof(int))
#define llarr(a,b) long long int *a=(long long int *)malloc(b*sizeof(long long int))
#define st(a,b) char *a=(char *)malloc(b*sizeof(char))
#define grav 9.8
#define pi 3.14159265

int main()
{
	int w,h,x,y,r;
	scdd(w,h);
	sctd(x,y,r);
	if((x+r)>w || (y+r)>h)
	printf("No\n");
	else if ((x-r)<0 || (y-r)<0)
	printf("No\n");
	else
	printf("Yes\n");
	
	return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <set>

using namespace std;

using PII = pair<int, int>;

using GRAPH = vector<vector<PII>>;  // next, coin)


void show(set<int> s) {
	for (auto x: s) {
		cout << x << " ";
	}
	cout << endl;
}

void show(GRAPH g) {
	for (int i = 1; i < g.size(); i++) {
		printf("%2d: ", i);
		for (auto p: g[i]) {
			printf("(%2d, %3d), ", p.first, p.second);
		}
		printf("\n");
	}
}

set<int> get_arrivals(int st, const GRAPH &g) {
	set<int> arrivals;
	queue<int> que;

	que.push(st);

	while (!que.empty()) {
		auto x = que.front();
		que.pop();

		if (arrivals.count(x) == 0) {
			arrivals.insert(x);

			for (auto y: g[x]) {
				que.push(y.first);
			}
		}
	}

	return arrivals;
}

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

	GRAPH g1(n + 1), g2(n + 1);
	for (int i = 0; i < m; i++) {
		cin >> a >> b >> c;

		g1[a].emplace_back(make_pair(b, c - p));
		g2[b].emplace_back(make_pair(a, c - p));
	}

	auto arrivals_from_1 = get_arrivals(1, g1);
	auto arrivals_from_n = get_arrivals(n, g2);

	set<int> arrivals;
	for (auto x: arrivals_from_1) {
		if (arrivals_from_n.count(x) > 0) {
			arrivals.insert(x);
		}
	}


	// cout << "-----" << endl;
	// show(g1);
	// cout << "-----" << endl;
	// show(g2);
	// cout << "-----" << endl;
	// show(arrivals_from_1);
	// show(arrivals_from_n);
	// show(arrivals);

	auto g = g1;

	for (int i = 0; i < g.size(); i++) {
		if (arrivals.count(i) == 0) {
			g[i].clear();
		} else {
			vector<PII> v;
			for (auto p: g[i]) {
				if (p.first == i) {
					if (p.second > 0) {
						// 正の循環
						cout << -1 << endl;
						return 0;
					}
				} else if (arrivals.count(p.first) > 0) {
					v.emplace_back(p);
				}
			}
			g[i] = v;
		}
	}

	// cout << "-----" << endl;
	// show(g);

	vector<int> scores(n + 1, -1e9);
	queue<PII> que; // pos, score
	que.push(make_pair(1, 0));

	int cnt = 0;
	int limit = m * m;

	while (!que.empty()) {
		auto p1 = que.front();
		que.pop();

		if (cnt > limit) {
			// 正の循環 を雑に検出
			cout << -1 << endl;
			return 0;
		}

		if (p1.second < scores[p1.first]) {
			continue;
		}

		for (auto p2: g[p1.first]) {
			cnt++;
			int tmp = p2.second + p1.second;
			// printf("(%d, %d) -> (%d, %d)\n", p1.first, p1.second, p2.first, tmp);

			if (tmp > scores[p2.first]) {
				scores[p2.first] = tmp;
				que.push(make_pair(p2.first, tmp));
			}
		}
	}

	int ans = max(0, scores[n]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;
 
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

ll dp[405][405];
ll psum[405];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    rep1(i, n) {
        cin >> psum[i];
        psum[i] += psum[i-1];
    }
    memset(dp, 0x3f, sizeof dp);
    for(int l=n; l>=1; l--)
        iter(r, l, n+2) {
            if(r == l || r == l+1) { dp[l][r] = 0; continue; }
            ll s = psum[r-1] - psum[l-1];
            iter(spl, l+1, r) dp[l][r] = min(dp[l][r], dp[l][spl] + dp[spl][r] + s);
        }
    cout << dp[1][n+1] << endl;
}



Measured memory_bytes: 1536
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <sstream>
using namespace std;
set<string> s;
set<string> visit;
map<string,vector<string> >m;
void solve(string &key){
	int i;
	vector<string> &z=m[key];
	for(i=0;i<z.size();i++)
		if(m.find(z[i])!=m.end()){
			if(visit.find(z[i])==visit.end()){
				visit.insert(z[i]);
				solve(z[i]);
			}
		}else
			s.insert(z[i]);
}
main(){
	string str,group,g1,arg;
	int n,i,j;
	for(;cin>>n,n;printf("%d\n",s.size())){
		m.clear();
		s.clear();
		visit.clear();
		for(i=0;i<n;i++){
			cin>>str;
			for(j=0;j<str.length();j++){
				if(str[j]==':'||str[j]==','||str[j]=='.')str[j]=' ';
			}
			istringstream is(str);
			vector<string> v;
			is >> group;
			if(!i)g1=group;
			for(;is>>arg;)v.push_back(arg);
			m[group]=v;
		}
		visit.insert(g1);
		solve(g1);
	}
}

Measured memory_bytes: 0