akhauriyash/Code-Regression huggingface dataset:
import math
def dis(x1,y1,x2,y2):
    return(((x1-x2)**2+(y1-y2)**2)**(1/2))

N = int(input())
cord = []
tem = 0

for i in range(N):
    cord.append(list(map(int,input().split())))

for i in range(N):
    x1,y1 = cord[i]
    for j in range(0,i):
        x2,y2 = cord[j]
        tem += dis(x1,y1,x2,y2)    
    for j in range(i+1,N):
        x2,y2 = cord[j]
        tem += dis(x1,y1,x2,y2)

print(tem*math.factorial(N-1)/math.factorial(N))

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  REP(i,N) cin >> a[i];

  int cost = INF;
  for(int i = -100; i <= 100; ++i) {
    int tmp = 0;
    REP(j,N) tmp += (a[j] - i) * (a[j] - i);
    cost = min(cost, tmp);
  }
  cout << cost << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
 
using std::cin;
using std::cout;
using std::endl;

static unsigned long const MODULO = 1e9 + 7;

static inline unsigned long
mmul(unsigned long a, unsigned long b)
{
  unsigned long ret = a * b;
  return ret < MODULO ? ret : ret % MODULO;
}

int
main()
{
  unsigned int N;
  cin >> N;
  unsigned long p = 1;
  for (unsigned int i = 1; i <= N; i++)
  {
    p = mmul(p, i);
  }
  cout << p;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

bool ok(const vecint& a, const int th, vecint& v) {
  ll n = a.size();
  v.assign(n*3, 0);
  int offset = n*1.5;
  ll cnt = 0;
  ll sum = 0;
  REP(i,n) {
    v[offset] += 1;
    if (a[i] >= th) {
      offset -= 1;
      sum -= v[offset];
    } else {
      sum += v[offset];
      offset += 1;
    }
    cnt += sum;
  }
  ll m = n * (n+1) / 2;
  ll mid = m/2 + 1;
  return cnt >= mid;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vecint a(n);
  string tmp;
  getline(cin, tmp);
  string line((istreambuf_iterator<char>(cin)), istreambuf_iterator<char>());
  int i = 0;
  int num = 0;
  for (char c : line) {
    if ('0' <= c && c <= '9') {
      num *= 10;
      num += c - '0';
    } else {
      a[i] = num;
      ++i;
      num = 0;
    }
  }
  vecint b = a;
  b.push_back(0);
  b.push_back(1000000007);
  sort(ALL(b));
  b.erase(unique(ALL(b)), end(b));
  int hi = b.size() - 1;
  int lo = 0;
  vecint v(n*4);
  while ((hi - lo) > 1) {
    int mid = (hi + lo) / 2;
    if (ok(a, b[mid], v)) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  cout<<b[lo]<<endl;
  return 0;
}


Measured memory_bytes: 4100
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int num=1e9+7;
int main(){
    int n,m;
    cin >> n >> m;
    vector<bool> flag(n+1,true);
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        flag[a]=false;
    }
    vector<int> dp(n+1,0);
    dp[0]=1;
    for(int now=0; now<n; now++){
        for(int next=now+1; next<=min(n,now+2); next++){
            if(flag[next]){
                dp[next]+=dp[now];dp[next]%=num;
            }
        }
    }
    cout << dp[n] <<endl; 
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "No";
    return 0;
  }
  cin >> n;
  if (n % 2 == 0) {
    cout << "No";
    return 0;
  }
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int i,j,n,c=0,d=0,h,w,e=0;
   cin>>h>>w>>n;
   c=max(h,w);
   d=n%c;
   e=n/c;
   if(d==0)
   {
       cout<<e;
   }
   else
   {
       cout<<e+1;
   }
}


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

using namespace std;

using ll = long long;
using ld = long double;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    int n;
    cin >> n;

    int sum = 0;
    vector<int> w(n);
    for (int &w_i : w) {
        cin >> w_i;
        sum += w_i;
    }

    int min_abs = sum;
    for (int i = 0, s = 0; i < n; ++i) {
        s += w[i];
        min_abs = min(min_abs, abs(s - (sum - s)));
    }

    cout << min_abs << endl;

    return 0;
}


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

const long long MOD = 5;
const string YES = "YES";
const string NO = "NO";

auto solve(long long A, long long B, long long C){
    for(long long i = 1; i <= B; i++) {
        if((A * i) % B == C){
            return YES;
        }
    }

    return NO;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    auto result = solve(A, B, C);
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    mod = 10**9 + 7

    def extgcd(a, b):
        if b == 0:
            return a, 1, 0
        else:
            d, x, y = extgcd(b, a % b)
            x -= (a // b) * y
            return d, y, x
        
    def modinv(a, mod): 
        return extgcd(a, mod)[1] % mod

    def modcomb(n, k, mod):
        q, a = 1, 1
        for i in range(n-k+1, n+1):
            q = (q * i) % mod
        for i in range(2, k+1):
            a = (a * i) % mod
        return int(q * modinv(a, mod) % mod)

    n,k = map(int, input().split())
    #k個ある青のボールをi個に分ける
    for i in range(1, k+1):
        if i > n-k+1:
            print(0)
        else:
            print((modcomb(k-1, k-i, mod) * modcomb(n-k+1, i, mod))% mod)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int a;
	cin >> a;
	cout << ( a/2 ) * ( a/2 + a%2 ) << endl;
	return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
	final boolean DEBUG = false;

	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		Tree tree = new Tree();
		for (int i = 0; i < n; i++) {
			String inst = scan.next();

			switch(inst) {
			case "insert":
				int key = scan.nextInt();
				if (DEBUG)
					System.out.println("insert: " + key);
				tree.insert(new Node(key));
				break;
			case "print":
				if (DEBUG)
					System.out.println("print");
				tree.print();
				break;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

class Tree {
	Node root;

	void insert(Node node) {
		Node parent = null;
		Node child = root;
		while (child != null) {
			parent = child;
			if (node.key < child.key) child = child.left;
			else					  child = child.right;
		}
		node.parent = parent;

		if(parent == null)		   		this.root    = node;
		else if (node.key < parent.key) parent.left  = node;
		else					   		parent.right = node;
	}

	void print() {
		this.inorder(this.root);
		System.out.println();
		this.preorder(this.root);
		System.out.println();
	}

	void preorder(Node node) {
		if (node == null) return;
		System.out.print(" " + node.key);
		this.preorder(node.left);
		this.preorder(node.right);
	}
	void inorder(Node node) {
		if (node == null) return;
		this.inorder(node.left);
		System.out.print(" " + node.key);
		this.inorder(node.right);
	}
}

class Node {
	int key;
	Node parent, left, right;
	Node(int key) {
		this.key = key;
	}
}


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

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

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

  int break_flag = 0;
  int counter = 0;
  while(break_flag == 0){

    for(int i=0; i<n ;i++){

      if(a[i] % 2 == 1){
        break_flag = 1;
        break;
      }

      a[i] /= 2;
    }

    if(break_flag == 0){
      counter++;
    }
  }

  cout << counter << endl;

  return 0;
}


Measured memory_bytes: 256
/*
      author : nishi5451
      created: 11.08.2020 23:14:26
*/

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


int main(){
    string s;
    cin >> s;	
    if(s=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}


Measured memory_bytes: 3560
#include<cstdio>
#include<iostream>
#define RI register int
#define CI const int&
using namespace std;
long long n,a,b;
int main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	if ((b-a)%2==0) return printf("%lld",(b-a)/2),0;
	long long res=min(b-1,n-a); res=min(res,min((a+b)/2,(2*n-a-b+1)/2));
	return printf("%lld",res),0;
}

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



int main(){
    ios_base::sync_with_stdio(false);
    //freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    int size; cin >> size;
    bool flag = true;
    while(size--){
        ll a; cin >> a;
        if( a % 2 == 0){
            if(a % 3 > 0 && a % 5 > 0){
                flag = false;
            }
        }
    }
    if(flag) cout << "APPROVED";
    else cout << "DENIED";

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int n,x,k;
int main(){
    scanf("%d",&n);
	int ans=0;
    for(int i=1;i<=n;i++){
        scanf("%d%d",&x,&k);
        while(x%k>0)
			x-=((x%k-1)/(x/k+1)+1)*(x/k+1);
        ans^=x/k;
    }
    if(ans)puts("Takahashi");
    else puts("Aoki");
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.solveA();
	}

	private void solveA() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		int NA = N * A;

		if(NA>B){
			System.out.println(B);
		}else{
			System.out.println(NA);
		}
	}

	private void solveB() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveC() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveD() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveE() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

	private void solveF() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		System.out.println(N);
	}

}

Measured memory_bytes: 21972
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("Ofast")
// #pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>

using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T>
// using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// #define sfind(i) (*find_by_order(i))
// #define ord(i) order_of_key(i)
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define mod 1000000007
#define rep(i, a, b) for(ll i = a; i < b; i++)
#define repc(i, a, b, c) for (ll i = a; (c > 0 ? i < b : i > b) and c != 0; i += c)
#define vi vector<int>
#define vl vector<ll>
#define _max(vec) (*max_element(all(vec)))
#define _min(vec) (*min_element(all(vec)))
#define fi first
#define si second
#define pb push_back
#define all(name) name.begin(), name.end()
#define ral(name) name.rbegin(), name.rend()
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod)
#define mod_in(a) power(a, mod - 2)
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%mod))%mod):0LL)
#define deb(x) cerr << "[" << #x << " " << x << "]" << endl;
#define endl '\n'  //....????
// #define int ll
vector<ll> ft(1, 1LL);

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


void solve(){
    string s;
    cin >> s;
    for(auto i : s)cout << (i=='?'?'D':i);
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3780
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<-1<<endl;return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
//20:00~
const int mod=1e9+7;
const llint big=1e16+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int main(void){
	int n,m;
	cin>>n>>m;
	cout<<(1<<m)*(100*(n-m)+1900*m)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#include <bitset>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n,d;
    cin >> n >> d;
    int ans=0;
    for(int i=0;i<n;i++){
        ll x,y;
        cin >> x >> y;
        if(sqrt(x*x+y*y)<=d) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3696
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
  int i,j,k,N,s1=0,s2=0,min=120,d;
   scanf("%d",&N);
  int w[N];
  
  for(i=0;i<N;i++)
    scanf("%d",&w[i]);
  
  for(i=1;i<N;i++){
  /*  for(j=0,k=i;j<i,k<N;j++,k++){
      s1+=w[j];s2+=w[k];
      d=abs(s1-s2);
    }*/
    
    for(j=0;j<i;j++)
      s1+=w[j];
    for(k=i;k<N;k++)
      s2+=w[k];           
    
    d=abs(s1-s2);
      s1=0;  //ここの二つが重要
      s2=0;   //s1,s2が全体の変数なので0を入れて初期化しないと足され続けてしまう
   // printf("%d %d\n",s1,s2);
   if(min>d)
     min=d;
  }
  printf("%d",min);
}

Measured memory_bytes: 128
import copy


args = input().split()
N, M = int(args[0]), int(args[1])
args_list = [list(map(lambda x: int(x), input().split())) for i in range(M)]
p_list = list(map(lambda x: int(x), input().split()))

count = 0
for i in range(2**N):
  continue_state = True
  args_i = copy.deepcopy(args_list)
  bin_str = format(i, "0{}b".format(N))
  bin_list = [int(bin_str[i]) for i in reversed(range(N))]
  bin_list = [i+1 for i, bit in enumerate(bin_list) if bit == 1]
  for j, current_list in enumerate(args_i):
    on_switchs = 0
    del current_list[0]
    for bin in bin_list:
      if bin in current_list:
        on_switchs += 1
    if on_switchs % 2 != p_list[j]:
      continue_state = False
      break
  if continue_state is False:
    continue
  count += 1
print(count)


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

int main() {
  int k, a, b;

  cin >> k >> a >> b;

  int tmp = k;

  while (tmp <= b) {
    if (tmp >= a) {
      cout << "OK";
      return 0;
    }
    tmp += k;
  }

  cout << "NG";

  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#define ll long long
#define mp make_pair
using namespace std;
int main(){
	int n;
	double cnt=0,x;
	cin>>n;
	for(int i=1;i<=n;++i)cin>>x,cnt+=1.0/x;
	cout<<fixed<<setprecision(6)<<1.0/cnt<<endl;
}

Measured memory_bytes: 888
a,b,c=map(int,input().split())
num1=max(a,b,c)
if num1==a:
    num2=a-b
    num3=a-c
elif num1==b:
    num2=b-a
    num3=b-c
else:
    num2=c-a
    num3=c-b
num4=abs(num2-num3)
if num4%2==0:
    print((num2+num3)//2)
else:
    print((num2+num3)//2+2)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    
    for(int i=1;i<s.size();i++){
        if(s[i]==s[i-1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
 return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine());
            int happy = 0;
            happy += num / 500 * 1000;
            happy += num % 500 / 5 * 5;
            Console.WriteLine(happy);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]
import itertools
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

if (p == q):
    print(0)
    exit()

seq = []
for i in range(1,n+1):
    seq.append(i)

t = list(itertools.permutations(seq))

ans = []
for i in range(len(t)):
    if list(t[i]) == p or list(t[i]) == q:
        ans.append(i)

print(ans[1]-ans[0])


Measured memory_bytes: 13856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=3005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;
const ll mod=1000000007;
const double pi=acos(-1);


int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b) cout<<c;
	else if (a==c) cout<<b;
	else cout<<a;
	return 0;
}












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

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

vector <ll> v;

ll fep(ll x, ll y, ll mod)
{ll res=1;while(y>0){if(y&1)res=(res*x)%mod;
    y=y>>1;x=(x*x)%mod;}return res%mod;}

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

	ll n,i,m,j,k,x,y,a,b,t,d;
	string s;
	
	cin >> x >> k >> d;
	x=abs(x);
	a=x/d;
	if(a>=k)
	{
		cout << x-k*d;
		return 0;
	}
	if((k-a)%2)
		cout << abs(x-(a+1)*d);
	else
		cout << x-a*d;
	return 0;
}


Measured memory_bytes: 3648
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
    int N, M; cin >> N >> M;
    cout << ((M*1900 + (N-M)*100) << M) << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

vector<int> prime(int N) {
  vector<bool> a(N, true);
  for(int i=1; i<sqrt(N); i++) {
    if(a[i]) for(int k=2; (i+1)*k-1<N; k++) a[(i+1)*k-1] = false;
  }
  vector<int> p;
  rep(i, N) if(a[i]) p.push_back(i+1);
  p.erase(p.begin());
  return p;
}

signed main() {
  int Q; cin >> Q;
  vector<int> p = prime(100000);
  
  unordered_map<int,int> m;
  for(int n : p) m[n]++;
  
  vector<int> v(100000, 0);
  rep(i, 100000-1) {
    v[i+1] = v[i];
    if(m[i+1] > 0 && m[(i+2)/2] > 0) v[i+1]++;
  }
  
  rep(i, Q) {
    int l, r; cin >> l >> r;
    cout << v[r] - v[l-1] << endl;
  }
    

}

Measured memory_bytes: 8152
#include<iostream>
#include <bits/stdc++.h>
#include<utility>
#include<algorithm>
#define int long long int
int mod=1e9+7;
#define p_b push_back
#define p_f push_front
#define P_f pop_front
#define P_b pop_back
#define m_p make_pair
#define m_t make_tuple
#define len() length()
#define sz() size()
#define u_b upper_bound
#define l_b lower_bound
#define ins insert
#define str string 
#define bitcount __builtin_popcount
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define ld long double
#define db double
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define F first
#define S second
#define T third
#define endl "\n"
#define done return 0;
#define Fill(a,n,x) fill(a,a+n,x);
// #define fill(a,val) memset(a,val,sizeof(a))
using namespace std;
typedef map<int,int> Map;
typedef pair<int,int> pr;
typedef vector<int> vec;
const int INF = 1e18;
const int MAX =1e18;
int power(int a,int b)
{   
    if(b==0)
    return 1;
    int num=1;
    int m=mod+2;
    while(b!=1)
    { 
        if(b%2==0)
        { 
            a*=a;
            a%=m;
            b/=2;
        }
        else
        { 
            num*=a;
            num%=m;
            b--;
        }
        
    }
    return (a*num)%m;
}
void solve()
{
	 int n;
     cin>>n;
     int a[n],alp=0;
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
         if(a[i]==0)
         alp=1;
     }
     if(alp)
         {
             cout<<0<<endl;
             return ;
         }
     int prod=1;
     for(int i=0;i<n;i++)
     {    
         
         if((MAX/a[i])<prod&&a[i]>(MAX/prod))
         {
             cout<<-1<<endl;
            //  cout<<prod<<" "<<MAX/prod<<endl;
             return ;
         }
         prod*=a[i];
     }
    cout<<prod<<endl;

}
int32_t main()
{
    fio;
    int t;
    t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
    done;
}

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

#define ll long long

int main(void){

    int n;
    string s;
    cin>>n>>s;

    int x=0;
    int ans = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='I')x++;
        else x--;
        ans = max(ans,x);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int h,w,i,j;

    while(1)
    {
        scanf("%d %d",&h,&w);
        for(i=1; i<=h; i++)
        {
            if(i==1 || i==h)
            {
                for(j=1; j<=w; j++)
                {
                    printf("#");
                }
                printf("\n");
            }
            else
            {
                if(w!=1)
                {
                    printf("#");
                    for(j=1; j<=w-2; j++)
                    {
                        printf(".");
                    }
                    printf("#\n");
                }
                else
                {
                    printf("#\n");
                }
            }
        }
        if(h==0 && w==0)
        {
            break;
        }
        printf("\n");
    }
}




Measured memory_bytes: 2056
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef long double ld;

int MOD=1000000007;

int main(){
  ll M,N;
  ld ans=0.0;
  bool an=true;
  cin >> N >> M;
  ll A[N+10];
  for(ll i=0; i<N; i++){ cin >> A[i]; ans+=A[i];}
  sort(A,A+N,greater<ll>());
  //cout << endl;
  ans=ans/(4*M);
  //cout << ans << endl;
  //if(ans <276) cout << "a" <<endl;
  //if(ans <275) cout << "b" << endl;
  for(ll i=0; i<M; i++){
    if(ans>A[i])
    an=false;
  }
  if(an) cout << "Yes" << endl;
  else cout << "No" << endl;


}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Fri Jun 15 11:27:37 2018

@author: Yuya

問題
3×3 のグリッドがあります. 上から i 番目で左から j 番目のマスを (i,j) で表すとき, マス (i,j) には数 ci,j が書かれています.
高橋君によると, 整数 a1,a2,a3,b1,b2,b3 の値が決まっており, マス (i,j) には数 ai+bj が書かれているらしいです.
高橋君の情報が正しいか判定しなさい. 

c1,1 c1,2 c1,3
c2,1 c2,2 c2,3
c3,1 c3,2 c3,3

入力
1 0 1
2 1 2
1 0 1

出力
Yes

"""

C = [list(map(int,input().split())) for i in range(3)]

flag = 0

for a1 in range(C[0][0]+1):
    b1 = C[0][0]-a1
    b2 = C[0][1]-a1
    b3 = C[0][2]-a1
    a2 = C[1][0]-b1
    a3 = C[2][0]-b1
    if a2+b2 == C[1][1] and a3+b2 == C[2][1] and a2+b3 == C[1][2] and a3+b3 == C[2][2]:
        flag = -1

if flag < 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main() {
	int N;
	int A;
	string input;
	getline(cin, input);
	N = stoi(input);
	getline(cin, input);
	A = stoi(input);

	int masu;
	masu = N * N;
	int blackmasu;
	blackmasu = masu - A;

	cout << blackmasu << endl;
	return 0;
}

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


using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, a, b) for (int i = a; i < b; i++)

#define INF 1050000000




int main() {

	int N,D;

	cin >> N >> D;

	int ans=0;

	for (int i=0; i < 20; i++) {

		N -= D * 2 + 1;
		ans++;
		if (N <= 0)break;
		
	}

	cout <<ans  << endl;


	return 0;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    string s;
    ll k;
    cin >> s >> k;

    int tmp = -1;
    int idx = -1;
    bool f = false;
    for (int i = 0; i < s.size(); i++)
        if (s[i] != '1')
        {
            idx = i;
            tmp = s[i];
            f = true;
            break;
        }

    // cout << idx << "," << k << endl;
    if (!f)
        cout << "1" << endl;
    else
    {
        if (k <= idx)
            cout << "1" << endl;
        else
            cout << (char)tmp << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define loop(i, a, b) for(li i=a; i<=b; i++)
#define stuff ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<li, li> lii;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ii> vii;
typedef vector<lii> vlii;
li mod = 1e9+7;
li expo(li base, li exponent)
{
	li ans=1;
	while(exponent)
	{
		if(exponent&1) ans = (ans*base)%mod;
		base = (base*base)%mod;
		exponent >>= 1;
	}
	return ans;
}
li gcd(li x, li y)
{
	if(y==0) return x;
	return gcd(y, x%y);
}


typedef tree<li, null_type, less<li>,
rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int main()
{
	stuff;
	// #ifndef ONLINE_JUDGE 
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("error.txt", "w", stderr);
	// #endif

	string s;
	cin >> s;
	if(s=="ABC") cout << "ARC";
	else cout << "ABC";	
	return 0;
}


Measured memory_bytes: 3528
n, m = map(int, input().split())

a = [list(map(int, input().split())) for _ in range(n)]
b = [int(input()) for _ in range(m)]


for i in range(n):
    c = 0
    for j in range(m):
        c += a[i][j]*b[j]
    print(c)


Measured memory_bytes: 6016
#include <iostream>
using namespace std;
int main() 
{
	int a, b, c, d, e, f, g, h, A, B;
	cin >> a >> b >> c >> d;
	cin >> e >> f >> g >> h;
	A = a + b + c + d;
	B = e + f + g + h;
	if (A >= B) {
		cout << A << endl;
	}
	else
		cout << B << endl;
	return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, A, B;
  cin >> N >> A >> B;
  string S;
  cin >> S;
  int count = 0;
  int count_b = 0;
  for(int i=0; i<S.size(); i++){
    string ans = "No";
    if(S.at(i) == 'a' && count < A+B){
      ans = "Yes";
      count++;
    }
    else if(S.at(i) == 'b' && count < A+B && count_b < B){
      ans = "Yes";
      count++;
      count_b++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 896
N,M,C=gets.split.map &:to_i
B=gets.split.map &:to_i
c=0
N.times{
    a=gets.split.map &:to_i
    t=C
    M.times{|i|
       t+=a[i]*B[i] 
    }
    if t>0 then c+=1 end
}
p c

Measured memory_bytes: 1788
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

ab = []
for ai in a:
    for bi in b:
        ab.append(ai + bi)
ab.sort(reverse=True)
if k < len(ab):
    ab = ab[:k]

ans = []
for abi in ab:
    for ci in c:
        ans.append(abi + ci)
ans.sort(reverse=True)
for i in range(k):
    print(ans[i])


Measured memory_bytes: 151512
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

 int main(){

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

  int n = s.size();
  map<char,char>ms,mt;

  for(int i=0;i<n;i++){
    ms[s[i]]++;
    mt[t[i]]++;
  }

  if(ms.size() == mt.size()){

     for(int i=0;i<n;i++)
     {
        if(ms[s[i]] == mt[t[i]])
            continue;
        else {
            cout<<"No"<<endl;
            return 0;
           }
     }
       cout<<"Yes"<<endl;
       return 0;
  }

  cout<<"No"<<endl;

 return 0;
 }


Measured memory_bytes: 3916
using System;

class ITP1_6_D
{
  static void Main()
  {
    string[] inputs = Console.ReadLine().Split(' ');
    int n = int.Parse(inputs[0]);//行
    int m = int.Parse(inputs[1]);//列
    int[,] A = new int[n, m];
    int[] b = new int[m];
    for (int i = 0; i < n; i ++)
    {
      string[] elementsA = Console.ReadLine().Split(' ');
      for (int j = 0; j < m; j ++)
      {  
        A[i, j] = int.Parse(elementsA[j]);
      }
    }
    for (int i = 0; i < m; i ++)
    {
      int elementsB = int.Parse(Console.ReadLine());
      b[i] = elementsB;
    }
    for (int i = 0; i < n; i ++)
    {
      int c = 0;
      for (int j = 0; j < m; j ++)
      {
        c += A[i, j] * b[j];
      }
      Console.WriteLine(c);
    }
  }
}



Measured memory_bytes: 17984
#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cerr<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

const ll mod = 1e9+7;


const double pi = acos(-1);

void solve(){
	int m,n;
	cin>>m>>n;
	int sum = 0;
	for(int i=0;i<n;i++){
		int tt;
		cin>>tt;
		sum += tt;
	}
	if(sum > m)cout<<-1;
	else cout<<(m-sum);
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    
    if (a >= 13) {
        cout << b << endl;
    } else if (a >= 6) {
        cout << b / 2 << endl;
    } else {
        cout << 0 << endl;
    }
}

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

class Program
{
    static void Main(string[] args)
    {
        long limit = 1000000000000000000;
        long sum = 1;
        long n = long.Parse(Console.ReadLine());
        long[] arr = Console.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
        if (arr.Contains(0))
        {
            Console.WriteLine(0);
            return;
        }
        for(int i = 0; i < n; i++)
        {
            if (sum  > limit / arr[i])
            {
                sum = -1;
                break;
            }
            sum *= arr[i];
        }
        Console.WriteLine(sum);
    }

   

}




Measured memory_bytes: 39368
import sys
input=sys.stdin.readline
from random import seed, randint

def calc(d,C,S,T):
    Last=[0]*26
    score=0
    for day,t in enumerate(T):
        t-=1
        Last[t]=day+1
        score+=S[day][t]
        for i,c in enumerate(C):
            score-=c*(day+1-Last[i])
    return score

def main():
    d=int(input())
    C=tuple(map(int,input().split()))
    S=[tuple(map(int,input().split())) for _ in range(d)]
    T=[(i%26)+1 for i in range(d)]
    score=calc(d,C,S,T)
    Ans=T[:]
    #print(score)
    m=10000
    for i in range(m):
        seed(i)
        d_idx=randint(0,d-1)
        q=randint(1,26)
        #print(d_idx,q)
        T[d_idx]=q
        tmp=calc(d,C,S,T)
        if tmp>score:
            score=tmp
            Ans=T[:]
    #print(score)
    print(*Ans,sep='\n')
    
if __name__=='__main__':
    main()

Measured memory_bytes: 79968
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
int main(){
	ll n,x,m;
	cin>>n>>x>>m;
	ll sum=0,temp=x,rep_sum,extra,i=0,len;
	unordered_map<ll,ll> ma,ma2;
	ma[x]=0;ma2[x]=1;i++;
	while(true){
		i++;
		sum+=temp;
		temp=(temp%m*temp%m)%m;
		if(ma.count(temp)){
			rep_sum=sum-ma[temp];
			extra=ma[temp];
			len=i-ma2[temp];
			break;
		}
		else ma[temp]=sum,ma2[temp]=i;
	}
	ll ans=extra+rep_sum*((n-ma2[temp]+1)/len);
	ll t=temp;
	for(int j=0;j<((ll)(n%len-ma2[t]%len+1%len+len)%len);j++){
		ans+=temp;
		temp=(temp%m*temp%m)%m;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 7256
#include <bits/stdc++.h>
#define int long long
using namespace std;
 
int32_t main(){
 	int n,d,a,b,nr=0;
  cin>>n>>d;
  for (int i=0; i<n; i++){
   	cin>>a>>b;
    if (sqrt(a*a+b*b)<=d) nr++;
  }
  cout<<nr;
}

Measured memory_bytes: 3640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const int N = 1e5 + 10;
ll mod, dp[N][2], ans[N];
VI e[N];

void dfs(int now, int past){
    dp[now][0] = dp[now][1] = 1;
    for (int next : e[now]){
        if (next == past) continue;
        dfs(next, now);
        dp[now][0] = (dp[now][0] * dp[next][0]) % mod;
        dp[now][1] = (dp[now][1] * (dp[next][0] + dp[next][1])) % mod;
    }
}

void dfs2(int now, int past, ll s){
    VL tmp;
    for (int next : e[now]){
        if (next == past) continue;
        tmp.push_back((dp[next][0] + dp[next][1]) % mod);
    }
    int m = tmp.size();
    VL pl(m + 1, 1), pr(m + 1, 1);
    REP(i,m){
        pl[i + 1] = (pl[i] * tmp[i]) % mod;
    }
    FORR(i,m-1,0){
        pr[i] = (pr[i+1] * tmp[i]) % mod;
    }
    int i = 0;
    REP(j,e[now].size()){
        int next = e[now][j];
        if (next == past) continue;
        ll ss = s;
        ss = (ss * pl[i]) % mod;
        ss = (ss * pr[i + 1] + 1) % mod;
        ans[next] = (dp[next][1] * ss) % mod;
        dfs2(next, now, ss);
        i++;
    }
}

int main() {
    int n;
    cin >> n >> mod;
    REP(i,n-1){
        int u = in() - 1, v = in() - 1;
        e[u].push_back(v);
        e[v].push_back(u);
    }

    dfs(0, -1);
    ans[0] = dp[0][1];
    // REP(i,n) cout << dp[i][0] << " " << dp[i][1] << endl;


    dfs2(0, -1, 1);

    REP(i,n) printf("%lld\n", ans[i]);

    return 0;
}


Measured memory_bytes: 25984
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;
int32_t x[100];
int32_t y[100];
int32_t h[100];
int32_t base_h = 1000000000;



template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	int nonzero_index = 0;
	in >> N;
	for (int i = 0; i < N; ++i)
	{
		in >> x[i] >> y[i] >> h[i];
		if (h[i] != 0) {
			nonzero_index = i;
		}
		base_h = std::min(base_h, h[i]);
	}
	if (base_h > 0) { --base_h; }
	for (int i = 0; i < N; ++i)
	{
		h[i] -= base_h;
	}


	for (int hhh = 0; hhh <= 210; ++hhh)
	{
		int D = hhh - h[nonzero_index];
		if (D < 0) { continue; }
		for (int diff = -D; diff <= D; diff++)
		{
			int ydiff = (D - std::abs(diff));
			int cx = x[nonzero_index] + diff;
			if (cx < 0 || 100 < cx) { continue; }
			int cy = y[nonzero_index] + ydiff;
			if (!(cy < 0 || 100 < cy))
			{
				bool ok = true;
				for (int i = 0; i < N; i++)
				{
					int h_tmp = hhh - std::abs(x[i] - cx) - std::abs(y[i] - cy);
					if (h[i] == 0) {
						if (h_tmp > 0) {
							ok = false;
							break;
						}
					}
					else if (h_tmp != h[i]) {
						ok = false;
						break;
					}
				}
				if (ok) {
					out << cx << ' ' << cy << ' ' << hhh + base_h << endl;
					return 0;
				}
			}


			cy = y[nonzero_index] - ydiff;
			if (!(cy < 0 || 100 < cy))
			{
				bool ok = true;
				for (int i = 0; i < N; i++)
				{
					int h_tmp = hhh - std::abs(x[i] - cx) - std::abs(y[i] - cy);
					if (h[i] == 0) {
						if (h_tmp > 0) {
							ok = false;
							break;
						}
					}
					else if (h_tmp != h[i]) {
						ok = false;
						break;
					}
				}
				if (ok) {
					out << cx << ' ' << cy << ' ' << hhh + base_h << endl;
					return 0;
				}
			}
		}
	}

	return 0;
}
#endif


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)                                                                             
#define seg_size 524288
long long gcd(long long a, long long b) {
	if (a % b == 0) return b;
	return gcd(b, a%b);
}
int main() {
	long long n, x;
	cin >> n >> x;
	cout << 3 * (n - gcd(n, x)) << endl;
	return 0;
}

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

Int n, ans = 1e9;
vector<Int> a(1, 0);
vector<Int> b(24);

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	for(Int i=0; i<n; ++i){
		Int t; cin >> t;
		a.push_back(t);
	}
	sort(a.begin(), a.end());
	for(size_t i=0; i<a.size(); ++i){
		if(i % 2 == 0){
			if(b[a[i]] > 0){
				cout << 0 << "\n";
				return 0;
			}else{
				++b[a[i]];
			}
		}else{
			if(b[(24-a[i])%24] > 0){
				cout << 0 << "\n";
				return 0;
			}else{
				++b[24-a[i]];
			}
		}
	}
//	for(Int i=0; i<24; ++i) cout << i << " " << b[i] << "\n";
	for(Int i=0; i<23; ++i)
		for(Int j=i+1; j<24; ++j)
			if(b[i] & b[j])
				ans = min({ans, j-i, 24-j});
	cout << ans << "\n";
}

Measured memory_bytes: 256
N, M, X = list(map(int, input().split()))
A = list(map(int, input().split()))
cost1 = 0
for i in range(X, 0, -1):
    if i in A:
        cost1 += 1
cost2 = 0
for i in range(X, N):
    if i in A:
        cost2 += 1
print(min(cost1, cost2))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define mod 998244353//((int)1e9+7)
#define lim 1000000000000000007
#define lim1 18446744073709551615  //Unsigned
#define sq(a) ((a)*(a))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mms(v,i) memset(v,i,sizeof(v))
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define REPN(i,a,b) for (int i = a; i >= b; i--)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pi;
typedef pair<ll,ll> PL;
typedef pair<ll,int> PLI;
typedef pair<int,ll> PIL;
typedef pair<int,pair<int,int> > pii;
typedef pair<double,double> pdd;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a,ll b) {
   ll res=1;
   while(b){
      if(b%2==1) res=(res*a)%mod;
      a=(a*a)%mod;
      b>>=1;
   }
   return res;
}
ll gcdll(ll a,ll b) {
    if (b==0) return a;
    return gcdll(b,a%b);
}
int gcd(int a,int b) {
    if (b==0) return a;
    return gcd(b,a%b);
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        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);
    }
};

const int N = (int)2e5+5;
const int M = (int)8e3+5;
const int Q = 102;
const int logN = 19;

ll f[N];
ll comb(int n,int r) {
    ll num = f[n];
    ll den = f[r]*f[n-r]%mod;
    return num*power(den,mod-2)%mod;
}
void solve() {
    f[0] = 1;
    int n,m,K;
    cin>>n>>m>>K;
    REP(i,1,n) {
        f[i] = f[i-1]*i%mod;
    }

    ll fans = 0;
    REP(k,0,K) {
        ll ans = m*power(m-1,n-k-1)%mod;
        ans = ans*comb(n-1,n-k-1)%mod;
        fans = (fans + ans)%mod;
    }

    cout<<fans;
}
int main() {
    //freopen("output.txt","r",stdin);
    //freopen("output.txt","w",stdout);

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

    int T=1;
    //cin>>T;
    REP(TC,1,T) {
        //cout<<"Case #"<<TC<<": ";
        solve();
        cout<<"\n";
    }
}


Measured memory_bytes: 5172
from bisect import bisect_right

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
#print(L)

for i in reversed(range(2, N)):
    for j in reversed(range(1, i)):
        idx = bisect_right(L, L[i] - L[j])
        #print(i, j, idx)
        if idx < j:
            ans += j - idx

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef std::pair<int, int> ipair;
#define int long long
#define pb push_back
#define ff first
#define INF INT_MAX
#define ss second
#define fr(i, j, a) for (int i = j; i < a; i++)
#define cnt_ones(x) __builtin_popcount(x)
#define all(x) x.begin(), x.end()
#define sz size()
#define endl "\n"
#define vi vector<int>
#define vvi vector<vector<int>>
#define vp vector<ipair>
#define mod 1000000007
#define ar array
#define IOS                                                                    \
  std::ios::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

void init() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (n == 1) {
    cout << 1 << endl;
    return;
  }
  int cnt = 0;
  for (int i = 0; i < n;) {
    int j = i;
    while (j + 1 < n and s[j] == s[j + 1])
      j++;
    cnt++;
    i = j + 1;
  }
  cout << cnt << endl;
}
int32_t main() {
  IOS;
  init();
  return 0;
}


Measured memory_bytes: 3776