akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static int[] days = {31,29,31,30,31,30,31,31,30,31,30,31};
	public static String[] week = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int m = sc.nextInt();
			int d = sc.nextInt();
			if (m == 0) {
				break;
			}
			int sum = 0;
			for(int i=0;i<m-1;i++) {
				sum += days[i];
			}
			sum += d - 1;
			System.out.println(week[(3+sum)%7]);
		}
	}

}

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

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

    ll lim = M / N, ans = 1;
    for (ll i = 1; i * i <= M; ++i) {
        if (i > lim)
            break;

        if (M % i == 0) {
            ans = max(ans, i);

            if(M/i<=lim)
                ans = max(ans, M / i);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,a,b) for(int i=int(a);i<(int)b;++i)
#define Graph vector<vecctor<ll>>
#define pairs vector<pair<ll,ll>>
#define pb push_back



using namespace std;
using ll = long long;
const ll INF = 1e18;
const double PI = acos(-1);

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







int main(void)
{
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll>h(n);
    rep(i,n){
        cin >> h[i];
    }
    h[0]--;
    for(int i = 1; i < n; ++i){
        if(h[i-1] < h[i])--h[i];
        if(h[i-1] > h[i]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 4000
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a[105],d,maxi=0;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  for(int i=0;i<n;i++)
  {
    for(int j=0;j<n;j++)
    {
      if(i!=j)
      {
        int d=abs(a[i]-a[j]);
        maxi=max(maxi,d);
      }
    }
  }
  cout<<maxi<<endl;
}


Measured memory_bytes: 3512
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

S=get_nsp
N=S.size
alphabet={}
("a".."z").to_a.each do|key|
    alphabet[key]=-1
end
S.each_with_index do|c,i|
    alphabet[c]=i
end
ans=S.dup
flag=false
alphabet.each do|key,cnt|
    if cnt==-1
      ans.push(key)
      flag=true
      break
    end
end
if flag
    puts ans.join("")
else
    temp=S.dup
    25.downto(1) do|i|
      alphabet[temp[i]]=-1
      if temp[i-1]<temp[i]
          alphabet=alphabet.sort{|x,y| x[0]<=>y[0]}
          alphabet.each do|k,v|
              if v==-1 and k>temp[i-1]
                #temp.unshift(exchange[a.ord-"a".ord+1])
                temp.pop(N-i+1)
                temp.push(k)
                break
              end
          end
          if i.nonzero?
            flag=true
          end
          break
      end
      alphabet[temp[i-1]]=-1
    end
    if flag
        puts temp.join("")
    else
        puts "-1"
    end
end

Measured memory_bytes: 1788
#include <iostream>
using namespace std;
long long n, a[(1<<20)], max1[(1<<20)], max2[(1<<20)];
long long st, ans[(1<<20)];
int main () {
    cin >> st;
    n = (1<<st);
    for ( long long i = 0 ; i < n ; i ++ ) {
        cin >> a[i];
    }

    max1[0] = 0;
    max2[0] = -1;

    for ( long long i = 1 ; i < n ; i ++ ) {
        max1[i] = i;
        max2[i] = -1;
        for ( long long c = 0 ; c < st ; c ++) {
            if ( (1<<c)&i ) {

                long long c1 = max1[ i^(1<<c) ], c2 = max2[ i^(1<<c) ];

                if ( c1 != max1[i] && c1 != max2[i] ) {

                    if ( a[c1] > a[ max1[i] ] ) {

                        max2[i] = max1[i];
                        max1[i] = c1;

                    }else {
                        if ( max2[i] == -1 || a[ max2[i] ] < a[c1] ) {
                            max2[i] = c1;
                        }
                    }

                }

                if ( c2 != max1[i] && c2 != max2[i ]) {
                    if ( c2 != -1 ) {
                        if ( a[c2] > a[ max1[i] ] ) {

                            max2[i] = max1[i];
                            max1[i] = c2;

                        }else {
                            if ( max2[i] == -1 || a[ max2[i] ] < a[c2] ) {
                                max2[i] = c2;
                            }
                        }
                    }
                }


            }
        }

        ans[i] = max( ans[i-1], a[ max1[i] ] + a [ max2[i] ] );

        cout <<  ans[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 19584
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

class TLcsSolver
{
    typedef std::vector<std::vector<int> > TTable;
    TTable FTable;
    std::string FArray1;
    std::string FArray2;

    int Count(int i, int j)
    {
        if(i == 0 || j == 0) return 0;
        if(FArray1[i-1] == FArray2[j-1]){
            return FTable[i-1][j-1] + 1;
        }
        return std::max(FTable[i-1][j], FTable[i][j-1]);
    }
    void Solve()
    {
        for(std::size_t i = 1; i < FTable.size(); ++i){
            for(std::size_t j = 1; j < FTable[i].size(); ++j){
                FTable[i][j] = Count(i, j);
            }
        }
    }
public:
    TLcsSolver(const std::string& a, const std::string& b)
     : FArray1(a), FArray2(b)
     , FTable(a.size()+1, std::vector<int>(b.size()+1, 0))
    {
        Solve();
        // Print();
    }
    int Answer()const
    {
        return FTable[FArray1.size()][FArray2.size()];
    }
    void Print()const
    {
        for(std::size_t i = 0; i < FTable.size(); ++i){
            for(std::size_t j = 0; j < FTable[i].size(); ++j){
                std::cout << FTable[i][j] << '\t';
            }
            std::cout << '\n';
        }
    } 
};

int main()
{
    int n;
    std::cin >> n;
    for(int i = 0; i < n; ++i){
        std::string a, b;
        std::cin >> a >> b;
        std::cout << TLcsSolver(a, b).Answer() << std::endl;
    }
    return 0;
}

Measured memory_bytes: 6732
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#define N 20
#define M 2510
#define ls x << 1
#define rs x << 1 | 1
#define inf 0x3f3f3f3f
#define inc(i) (++ (i))
#define dec(i) (-- (i))
#define mid ((l + r) >> 1)
// #define int long long
#define debug() puts("XRZ TXDY");
#define Next(i, u) for(int i = head[u]; i ; i = e[i].nxt)
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout);
#define Rep(i, a, b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; inc(i))
#define Dep(i, a, b) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; dec(i))
using namespace std;
int n, m, f[N][N], x, y, ans, vis[N];
void work() {
	Rep(i, 1, n) Rep(j, 1, n) {
		if(f[i][j] == -1) continue;
		if(vis[i] == 1 && vis[j] == 1 && f[i][j] == 0) return;
		if(vis[i] == 1 && vis[j] == 0 && f[i][j] == 1) return;
	}
	int Ans = 0; Rep(i, 1, n) Ans += vis[i];
	ans = max(ans, Ans);
}
void dfs(int x) {
	if(x == n + 1) {work();	return;}
	vis[x] = 0; dfs(x + 1); vis[x] = 1; dfs(x + 1);
}
signed main() {
	scanf("%d", &n); memset(f, -1, sizeof(f));
	Rep(i, 1, n) {scanf("%d", &m); Rep(j, 1, m) {scanf("%d%d", &x, &y), f[i][x] = y;}}
	dfs(1); printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 1 << 18;

ll t[2*N];
void upd(int x, ll v) {
  t[x+N] = v;
  for (x += N; x > 1; x /= 2) {
    t[x/2] = max(t[x], t[x^1]);
  }
}
ll query(int l, int r) {
  ll ans = 0;
  for (l += N, r += N+1; l < r; l /= 2, r /= 2) {
    if (l%2) ans = max(ans, t[l++]);
    if (r%2) ans = max(ans, t[--r]);
  }
  return ans;
}

int n;
int h[N];
int a[N];
ll dp[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  dp[0] = a[0];
  upd(h[0], dp[0]);
  for (int i = 1; i < n; i++) {
    dp[i] = query(0, h[i]) + a[i];
    upd(h[i], dp[i]);
  }
  cout << *max_element(dp, dp + N) << nl;
  return 0;
}


Measured memory_bytes: 7936
N = int(input())

P = list(map(int, input().split()))

P = [0] + P
     
count = 0
min = 10000000000000
for i in range(1, N+1):
    if min > P[i]:
        min = P[i]
    elif min < P[i]:
        continue
    """
    for j in range(1, i+1):
        #print(i, P[i], j , P[j])
        if P[i] > P[j]:
            #print("out", i)
            break
    else:
        #print("ok", i)
        count += 1
    """
    count += 1
        
    if P[i] == 1:
        break

print(count)

Measured memory_bytes: 26012
#include <bits/stdc++.h>
#define mod 1000000007
#define mx 200007
using namespace std;
typedef long long int LL;
int main()
{
    ios_base::sync_with_stdio(false);
    LL n;
    cin >> n;
    string str;
    cin >> str;
    LL cnt[30];
    memset(cnt, 0, sizeof cnt);
    for(int i = 0; i < n; i++) {
        cnt[str[i] - 'a']++;
    }
    LL ans = 1;
    for(int i = 0; i < 30; i++) {
        ans = (ans * (cnt[i] + 1)) % mod;
    }
    cout << (ans -1 + mod) % mod << endl;
    return 0;
}


Measured memory_bytes: 512
#float型を許すな
#numpyはpythonで
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, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n,m=MI()
lis=[LI() for i in range(n)]
lis.sort(key=lambda x:x[0])
#print(lis)
j=0
ans=0
i=0
while j<n and i<m:
    #print(i,j,ans)
    if lis[j][1]>0:
        lis[j][1]-=1
        ans+=lis[j][0]
        i+=1
    else:
        j+=1
print(ans)

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


int main () {

 int a,b,c;
 cin >> a >> b >> c;

  int temp =0;
  
  temp=a;
  a=b;
  b=temp;
  
  temp=a;
  a=c;
  c=temp;
  
  cout << a << " " << b << " " << c;
 
	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 100000000000000;

int main() {
 ll H,W;
 cin >> H >> W;
  
 ll ans1  =INF;
 ll j1 = 0;
 if(H%2 ==0) j1 = H/2;
 else j1 = (H-1)/2 +1;
  
 for(ll i = 1;i<=W;i++){
   ll Smax1 = max(H*i,max((W-i)*j1,(H-j1)*(W-i)));
   ll Smin1 = min(H*i,min((W-i)*j1,(H-j1)*(W-i)));
   ll d1 = Smax1 - Smin1;
   ans1 = min(d1,ans1);
 }
   
 ll ans2  =INF;
 ll j2 = 0;
 if(W%2 ==0) j2 = W/2;
 else j2 = (W-1)/2 +1;
  
 for(ll i = 1;i<=H;i++){
   ll Smax2 = max(W*i,max((H-i)*j2,(W-j2)*(H-i)));
   ll Smin2 = min(W*i,min((H-i)*j2,(W-j2)*(H-i)));
   ll d2 = Smax2 - Smin2;
   ans2 = min(d2,ans2);
 }
    
 ll ans3  =INF;
 if(W>=3){
 for(ll i = 1;i<=W-2;i++){
   ll j3 = (W-i+1)/2;
   ll Smax3 = max(H*i,max(H*j3,H*(W-i-j3)));
   ll Smin3 = min(H*i,min(H*j3,H*(W-i-j3)));
   ll d3 = Smax3 - Smin3;
   ans3 = min(d3,ans3);
    }
  }
 ll ans4  =INF;
 if(H>=3){
 for(ll i = 1;i<=H-2;i++){
   ll j4 = (H-i+1)/2;
   ll Smax4 = max(W*i,max(W*j4,W*(H-i-j4)));
   ll Smin4 = min(W*i,min(W*j4,W*(H-i-j4)));
   ll d4 = Smax4 - Smin4;
   ans4 = min(d4,ans4);
    }
  }
    
  cout << min(min(ans1,ans2),min(ans3,ans4)) << endl;
}


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

int main()
{
    char str[10];
    scanf("%s", str);
    int i = 0;
    while(str[i] != 0){
        if(str[i] == 'A' && str [i + 1]=='C'){
            printf("Yes");
            return 0;
        }
        i++;
    }
    printf("No");
    return 0;
}


Measured memory_bytes: 128
mod = 10**9+7
N, A, B = [int(i) for i in input().split()]


def ncr(n, r):
    r = min(r, n-r)
    res = 1
    m = n
    for _ in range(r):
        res *= m
        res %= mod
        m -= 1
    m = r
    for _ in range(r):
        res *= pow(m, mod-2, mod)
        res %= mod
        m -= 1
    return res


print((pow(2, N, mod)-1-ncr(N, A)-ncr(N, B)) % mod)


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

namespace AtCoder
{
	public class Program
	{
		// ABC131-B
		static void Main(string[] args)
		{
			string str = Console.ReadLine();
			string[] vs = str.Split();

			int n = int.Parse(vs[0]), l = int.Parse(vs[1]);
			int min = l, sum = 0;
			for (int i = 0, j = l; i < n; i++, j++) {
				sum += j;
				if (Math.Abs(j) < Math.Abs(min)) {
					min = j;
				}
			}

			Console.WriteLine(sum - min);
		}
	}
}


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

int main() {
  int a,b,c,d,e,f;
  cin>>a>>b>>c>>d>>e>>f;
  set<int>water,sugar;
  for(int i=0;i<31;i++){
    for(int j=0;j<31;j++){
      if(100*a*i+100*b*j<=f){
        water.insert(100*a*i+100*b*j);
      }
    }
  }
  for(int i=0;i<30*e+1;i++){
    for(int j=0;j<30*e+1;j++){
      if(c*i+d*j<=30*e)sugar.insert(c*i+d*j);
    }
  }
  int ans1=100*a,ans2=0;
  for(auto x:water){
    for(auto y:sugar){
      if(x+y<=f&&x*e/100>=y){
        if(x*((ans1-ans2)/100*e-ans2)>(ans1-ans2)*(x/100*e-y)){
          ans1=x+y;
          ans2=y;
        }
      }
    }
  }
  cout<<ans1<<' '<<ans2<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
 
int gcd(int a, int b){
  if(b != 0){
    return gcd(b, a%b);
  }
  return a;
}
 
int main(){
  int N, p = 0;
  cin >> N;
  
  vector<int> A(N), right(N), left(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  right.at(N - 1) = A.at(N - 1);
  left.at(0) = A.at(0);
  for(int i = 1; i < N; i++){
    left.at(i) = gcd(A.at(i - 1), left.at(i - 1));
  }
  for(int i = N - 2; i >= 0; i--){
    right.at(i) = gcd(A.at(i + 1), right.at(i + 1));
  }
  
  right.at(N - 1) = left.at(0) = 0;
  int c, ma = max(right.at(0), left.at(N - 1));
  for(int i = 0; i < N; i++){
    c = gcd(right.at(i), left.at(i));
    if(c > ma){
      ma = c;
    }
  }
    
  cout << ma << endl;
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e15;
const int MOD = 1e9 + 7;

signed main() {
	int X;
	cin >> X;
	int i = 1;
	int sum = 0;
	while (1) {
		if (sum >= X)break;
		sum += i;
		i++;
	}
	cout << i - 1;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  int H[N]; rep(i,N) cin >> H[i];
  string result = "Yes";
  rep(i,N-1) {
    if (H[i+1]<H[i]) {result = "No"; continue;}
    if (H[i+1]!=H[i]) H[i+1]--;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
 
int n,cont,flag=0;
int A[1000000];
int G[1000000];
 
void insertionSort(int *A,int n,int g){
  int v,j,i;
  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j-=g;
      cont++;
    }
    A[j+g]=v;
  }
}
 
void shellSort(int *A,int n){
  int h,i;
  for(h=1; ; ){
    if(h>n) break;
    G[flag++]=h;
    h=3*h+1;
  }
  for(i=flag-1;i>=0;i--){
    insertionSort(A,n,G[i]);
  }
}
 
int main(){
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  cont=0;
  shellSort(A,n);
  printf("%d\n",flag);
  for(i=flag-1;i>=0;i--){
    printf("%d",G[i]);
    if(i) printf(" ");
  }
  printf("\n");
  printf("%d\n",cont);
  for(i=0;i<n;i++) printf("%d\n",A[i]);
  return 0;
}

Measured memory_bytes: 6372
#include <string>
#include <fstream>
#include <streambuf>
#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    int n;
    cin>>n;
    
    int *arr=new int[n]();
    for (int i=0; i<n; i++) {
        cin>>arr[i];
    }
    
    int count=0;
    for (int i=0; i<n; i++) {
        if (arr[arr[i]-1]-1==i) {
            count++;
        }
    }
    delete arr;
    
    cout<<(count/2)<<endl;
   
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <bitset>

using namespace std;

struct state{
	vector< int > bits;
	int depth;
};

vector< int > count_bits( vector< int > *b ) {
	vector< int > v;
	int cnt = 0;
	for( int i = 0; i < b ->size(); i++ ) {
		cnt ++;
		if( i < b -> size() - 1 && b -> at( i ) != b -> at( i + 1 ) ) {
			v.push_back( cnt );
			cnt = 0;
		}
	}
	v.push_back( cnt );
	return v;
}

bool isEqual( vector< int > *v, vector< int > *w ) {
	if( v->size() != w->size() ) return false;
	for( int i = 0; i < v->size(); i++ ) {
		if( v->at(i) != w->at(i) ) return false;
	}
	return true;
}

void swap_bits( vector< int > *b, int pos ) {
	int c = b -> at( pos );
	b -> at( pos ) = b -> at( pos + 1 );
	b -> at( pos + 1 ) = c;
	return;
}

int main(void){

	int N, M;
	cin >> N >> M;
	state start;
	start.bits = vector< int >( N, 0 );
	start.depth = 0;
	vector< int > p( M, 0 );
	vector< bool > visited( 1 << N, false );

	for( int i = 0; i < N; i++ )
		cin >> start.bits[i];
	for( int i = 0; i < M; i++ )
		cin >> p[i];

	queue< state > q;
	q.push( start );

	while( !q.empty() ) {
		
		state cs = q.front();
		q.pop();
		vector< int > v = count_bits( &cs.bits );
		if( isEqual( &v, &p ) ) { 
			cout << cs.depth << endl;
			break;
		}
		
		for( int i = 0; i < N - 1; i++ ) {
			state newstate;
			for( int j = 0; j < N; j++ )
				newstate.bits.push_back( cs.bits[j] );

			int n = 0;
			swap_bits( &newstate.bits, i );

			for( int j = 0; j < N; j++ ) {
				if( newstate.bits[j] ) n |= ( 1 << j );
			}

			if( visited[ n ] ) continue;
			visited[n] = true;

			newstate.depth = cs.depth + 1;
			
			q.push( newstate );
		}


	}


    return 0;
}

Measured memory_bytes: 1312
// 以下のライブラリを使ってみる.
// beet氏.
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2068814#1
// 素集合データ構造(Union-Find)
// https://ei1333.github.io/luzhiled/snippets/structure/union-find.html
#include<bits/stdc++.h>
using namespace std;
#define MAX 100000
#define MAX_E 100000
int V,E;

struct edge{
   int u; // 始点.
   int v; // 終点.
   int c; // コスト.
   bool operator < (const edge &E) const{ return (c < E.c); };
};
edge es[MAX_E];

// Union-Find木.
struct UnionFind{

    vector<int> data;
    UnionFind(int sz){ data.assign(sz, -1); }
    
    // 1. 頂点 x, y の 結合.
    bool unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y)            return false;
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }
    
    // 2. 頂点 k を 探索.
    int find(int k){
        if(data[k] < 0) return k;
        return data[k] = find(data[k]);
    }
    
    // 3. 頂点 k を含む集合 の 大きさ.
    int size(int k){ return (-data[find(k)]); }
};

// クラスカル法.
int kruskal(){

    // 1. 辺をコストで昇順ソート.
    sort(es, es + E);

    // 2. Union-Find木を作成.
    UnionFind uf(V);

    // 3. 最小全域木の辺の重みの総和を計算.
    int res = 0;
    for(int i = 0; i < E; i++){
        edge e = es[i];
        if(uf.find(e.u) != uf.find(e.v)){
            uf.unite(e.u, e.v);
            res += e.c;
        }
    }
    return res;
}

int main(){

    // 1. 入力情報.
    scanf("%d %d", &V, &E);
    
    // 2. グラフ.
    for(int i = 0; i < E; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        es[i] = (edge){a, b, c};
    }
    
    // 3. 出力.
    int ans = kruskal();
    printf("%d\n", ans);
    return 0;

}


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

int main() {
    string S; cin >> S;
    int cnt = 0;
    for(int i = 0; i < 3; i++) {
        if(S[i] == 'o') cnt++;
    }

    cout << 700 + cnt * 100 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
/*
#include<algorithm>
#include<array>
#include<cassert>
#include<cmath>
#include<cstdlib>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<typeinfo>
#include<utility>
#include<vector>
*/
#define int long long int
#define double long double
using namespace std;
#define INT_DMAX 1000000007
#define INF 1000000000000000007
const int MAX_N = 1 << 17;
#define rep(i, n) for (int(i) = 0, i##_len = (n); (i) < i##_len; (i)++)
#define reps(i, x) for (int(i) = 1; (i) <= (int)(x); (i)++)
#define rrep(i, x) for (int(i) = ((int)(x)-1); (i) >= 0; (i)--)
#define rreps(i, x) for (int(i) = ((int)(x)); (i) > 0; (i)--)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define pb push_back
#define mp make_pair
#define bit(n) ((int)(1) << (n))
#define all(x) (x).begin(), (x).end()
#define debug(x) std::cout << #x << ": " << (x) << std::endl
#define nint int
using namespace std;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
typedef pair<int, int> p;
typedef pair<double, double> dop;
template <class T>
bool chmax(T& a, const T& b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b)
{
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
struct aaa {
    aaa()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} aaaaaaa;


signed main()
{
    std::string s;
    cin >> s;
    std::vector<int> check(26, 0);
    std::vector<int> point;
    std::vector<std::vector<int>> alpoint(26, std::vector<int>(0));
    int index = 0;
    int sl = s.length();

    for (int i = 0; i < sl; i++) {
        check[(int)(s[sl - 1 - i] - 'a')]++;
        int flag = 1;
        alpoint[(int)(s[sl - 1 - i] - 'a')].pb(sl - 1 - i);
        for (int i = 0; i < 26; i++) {
            flag *= min((int)1, check[i]);
        }
        if (flag) {
            fill(check.begin(), check.end(), 0);
            point.pb(sl - 1 - i);
            index++;
        }
    }
    point.pb(s.length());

    for (int i = 0; i < 26; i++) {
        std::sort(all(alpoint[i]));
    }
    if (index == 0) {
        for (int i = 0; i < 26; i++) {
            if (alpoint[i].size() == 0) {
                cout << (char)('a' + i) << endl;
                return 0;
            }
        }
    }
    std::sort(all(point));
    std::string out;
    int now = -1;
    for (int i = 0; i <= index; i++) {
        for (int j = 0; j < 26; j++) {
            auto first = upper_bound(all(alpoint[j]), now);
            //auto get = upper_bound(all(alpoint[j]), *first);
            if (*first >= point[i] || first == alpoint[j].end()) {  //&& (*get >= point[i + 1] || get == alpoint[j].end()) && *first >= point[i]) {
                now = *first;
                out += (char)('a' + j);
                break;
            }
        }
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 2452
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 200000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = INT_MAX;
// clang-format on

int N;
int a[MAX_N];

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  REP(i, N) cin >> a[i];

  ll sum = 0;
  REP(i, N) sum += a[i];

  ll ans = INF;
  ll X = 0;
  for (int i = 0; i < N; i++) {
    X += a[i];
    if (i + 1 < N) ans = min(ans, abs(sum - 2 * X));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define range(a) a.begin(), a.end()

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

  string S; cin >> S;
  string T;
  int Q; cin >> Q;
  while(Q--){
    int type; cin >> type;
    if(type == 1){
      swap(S, T);
    }else{
      int f; char c; cin >> f >> c;
      if(f == 1){
        T.push_back(c);
      }else{
        S.push_back(c);
      }
    }
  }
  reverse(range(T));
  cout << T + S << endl;


  return 0;
}


Measured memory_bytes: 1328
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::multiprecision::cpp_int;

cpp_int Rec(int n, const cpp_int& x) {
  if (n == 0) return x >= 0;
  if (x == 0) return 0;
  cpp_int n_th_power_of_2 = (cpp_int)1 << n;
  if (x == 2 * n_th_power_of_2 - 2) return n_th_power_of_2;
  if (x <  2 * n_th_power_of_2 - 2) return Rec(n - 1, x - 1);
  return n_th_power_of_2 + Rec(n - 1, x + 1 - 2 * n_th_power_of_2);
}

int main() {
  int n; cin >> n;
  cpp_int x; cin >> x;
  cout << Rec(n, x - 1) << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner parameter = new Scanner(System.in);

        String[] line1 = parameter.nextLine().split(" ");
        String[] line2 = parameter.nextLine().split(" ");

        Integer count1 = 1;
        Integer count2 = 0;

        for (String nosString : line2) {

        	if (Integer.valueOf(nosString) != count1) {

        		count2 = count2 + 1;
        	}

        	count1 = count1 + 1;
        }

        if (count2 > 2) {

        	System.out.println("NO");
        } else {

        	System.out.println("YES");
        }
    }
}


Measured memory_bytes: 21844
n,a,b = map(int,input().split())
f = []
s = []
for i in range(a,n+1):
    c = str(i)
    for j in range(len(c)):
        s.append(int(c[j]))
    if sum(s[:5])>=a and sum(s[:5])<=b:
        f.append(i)
    s=[]
print(sum(f))

Measured memory_bytes: 3292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

ll digitSum(ll x) {
    ll sum = 0, t = x;
    while (t) {
        sum += t % 10;
        t /= 10;
    }
    return sum;
}

int main() {
    int n;
    cin >> n;
    ll ans = 1e9;
    for (ll i = 1; i <= n - 1; i++) {
        ll j = n - i;
        ans = min(ans, digitSum(i) + digitSum(j));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from numba import njit
import numpy as np

d = int(input())
cs = list(map(int, input().split()))
cs = np.array(cs, dtype=np.int64)
sm = [list(map(int, input().split())) for _ in range(d)]
sm = np.array(sm, dtype=np.int64)

@njit('i8(i8[:], i8)', cache=True)
def total_satisfaction(ts, d):
    ls = np.zeros(26, dtype=np.int64)
    s = 0
    for i in range(d):
        t = ts[i]
        t -= 1
        s += sm[i][t]
        ls[t] = i + 1

        dv = cs * ((i+1) - ls)
        s -= dv.sum()
    return s

@njit('i8(i8, i8, i8, i8, i8[:])', cache=True)
def differential(s, i, t, d, ls):
    t -= 1
    bk = ls[t]
    s += sm[i][t]
    ls[t] = i + 1

    dv = cs * ((i+1) - ls)
    s -= dv.sum()

    ls[t] = bk
    return s

# greedy
ts = np.array([], dtype=np.int64)
sc = 0
for i in range(d):
    ls = np.zeros(26, np.int64)
    for i, t in enumerate(ts, 1):
        ls[t-1] = i

    mx = -99999999
    mxt = -1
    for t in range(1, 26+1):
        df = differential(sc, len(ts), t, i + 1, ls)
        s = sc + df
        if s > mx:
            mx = s
            mxt = t
    ts = np.append(ts, [mxt])
    sc += mxt
    print(mxt)



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

typedef unsigned long long ull;
typedef long long ll;

struct point {
    ll x,y;
    bool operator < (const point& t) const {
	if( x == t.x )
	    return y < t.y;
	return x < t.x;
    }
};

ull k_in(ll xmin,ll xmax,ll ymin,ll ymax,vector<point> ps, ll K) {
    ll in = 0;
    for(auto& e : ps) {
	if( xmin <= e.x and e.x <= xmax and ymin <= e.y and e.y <= ymax )
	    in++;
    }
    if(K <= in){
	return (ull)(xmax-xmin)*(ull)(ymax-ymin);
    }
    return 18446744073709551610ULL;
}

int main () {
    ll N,K; cin >> N >> K;
    vector<ll> x;
    vector<ll> y;

    vector<point> ps;
    for(ll i=0; i<N; i++) {
	ll a,b; cin >> a >> b;
	x.push_back(a);
	y.push_back(b);
	ps.push_back(point{a,b});
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    sort(ps.begin(), ps.end());
	
    ull ans = 18446744073709551610ULL;
    for(int i=0; i<N; i++) {
	for(int j=i+1; j<N; j++) {
	    for(int k=0; k<N; k++) {
		for(int l=k+1; l<N; l++) {
		    ans = min(k_in(x[i],x[j],y[k],y[l],ps,K),ans);
		}
	    }
	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}

import GHC.TypeLits
import Data.Int
import Data.Proxy
import qualified Data.Map.Lazy as Map
import Control.Monad
import Control.Monad.State
import Data.List

import Data.Maybe
import qualified Data.ByteString.Char8 as BS

data Mint (m :: Nat) = Mint {getMintValue :: Integer} deriving (Eq, Show)

getMintMod :: forall p. KnownNat p => Mint p -> Integer
getMintMod = natVal

makeMint :: forall p. KnownNat p => Integer -> Mint p
makeMint a = let r = Mint $ fromInteger $ a `mod` (getMintMod r) in r

instance KnownNat p => Num (Mint p) where
  (Mint a) + (Mint b) = makeMint $ a + b
  (Mint a) - (Mint b) = makeMint $ a - b
  (Mint a) * (Mint b) = makeMint $ a * b
  negate (Mint a) = makeMint $ negate a
  abs = id
  signum (Mint a) = if a == 0 then 0 else 1
  fromInteger = makeMint

invMint :: forall p. KnownNat p => Mint p -> Mint p
invMint m = let p = getMintMod m in m ^ (p - 2)



factorize :: Integral a => a -> [(a, Int)]
factorize n = let (m, xs) = divideAll n 2 in if m /= 1 then reverse $ (m, 1) : (reverse xs) else xs
  where
    divide n p
      | n `mod` p == 0 = let (m, c) = divide (n `div` p) p in (m, c+1)
      | otherwise = (n, 0)

    divideAll n p
      | p * p > n = (n, [])
      | otherwise = 
          let
            x @ (m, c) = divide n p
          in
            if c == 0 then
              divideAll m (p+1)
            else
              let (q, xs) = divideAll m (p+1)
              in (q, (p, c) : xs)



type M = Mint 1000000007

getInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine


main :: IO ()
main = do
  n <- readLn :: IO Int
  a <- getInts :: IO [Int]

  let l = product .
          map (\xs @ (x:_) -> (fromIntegral (fst x) :: M) ^ (maximum $ map snd xs)) .
          groupBy (\(x, _) (y, _) -> x == y) .
          sort . concat $ (map factorize a)

  let ans = sum $ map ((l *) . invMint . (fromIntegral :: Int -> M)) a
  print $ getMintValue ans


Measured memory_bytes: 22908
#include <cstdio>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <sstream>
#include <complex>
#include <map>
#include <set>
#include <functional>
#include <vector>

using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<n;i++)
#define IREP(i,n) for(ll i=1;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define DEBUG(x) cerr << x << "\n"

int main(){
    string s, ans;
    int w;
    cin >> s >> w;
    for(int i = 0;i<s.size();i += w) ans.append(1,s.at(i));
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import bisect
primes = [0, 0] + [1] * 32767
for i in range(2, 182):
    if primes[i]:
        for j in range(i*i, 32769, i):
            primes[j] = 0

prime_values = [i for i, v in enumerate(primes) if v]
while True:
    n = int(input())
    if n == 0:
        break
    eov = bisect.bisect(prime_values, n//2)
    print(sum(primes[n-p] for p in prime_values[:eov]))


Measured memory_bytes: 6048
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};


int main()
{
    ll n,k,mod=1e9+7,c[2020][2020];
	cin>>n>>k;
	REP(i,n+1)
	{
		c[i][0]=1;c[i][i]=1;
		rep(j,1,i)c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
	}
	for(int i=1;i<=k;i++)
	{
		int ans=c[k-1][i-1]*c[n-k+1][i]%mod;
		cout<<ans<<endl;
	}
}


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

int main()
{
    ll n;
    cin >>n;
    ll ans =1e18;
    for (ll i=1;i*i<=n;++i){
        if (n%i!=0) continue;
        ll j=n/i;
        ans =min(ans,i+j-2);
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int N, A, B;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> A >> B;

  int ans = min(N * A, B);

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e5 + 100;
const LL INF = 1e9;

void print_a(VL v)
{
    if(v.size()) cout<<v[0];
    loop(i,1,v.size()) cout<<' '<<v[i];
    cout<<'\n';
}

VVI init_vvi(int n, int m, int val)
{
    return VVI(n,VI(m,val));
}

VVL init_vvl(int n, int m, LL val)
{
    return VVL(n,VL(m,val));
}

void inv_mod(LL a, LL b, LL &x, LL &y)
{
    if(a == 0)
    {
        x = 0; y = 1;
        return;
    }

    LL x1, y1;
    inv_mod(b%a,a,x1,y1);
    y = x1;
    x = y1 - (b/a)*x1;
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int k;
    string s;
    cin>>k>>s;
    int n = s.length();

    LL num[k], dv, inv[k+1], p25[k+1], p26[k+1];
    num[0] = n;
    loop(i,1,k) num[i] = (num[i-1] * (n + i)) % MOD;

    inv[0] = inv[1] = 1;
    dv = 1;
    loop(i,2,k+1)
    {
        dv = (dv * i) % MOD;
        if(dv != 1)
        {
            LL x, y;
            inv_mod(dv,MOD,x,y);
            inv[i] = (x + MOD) % MOD;
        }
    }

    p25[0] = p26[0] = 1;
    loop(i,1,k+1)
    {
        p25[i] = (p25[i-1] * 25) % MOD;
        p26[i] = (p26[i-1] * 26) % MOD;
    }

    LL ans = 0, ans1;
    loop(i,0,k+1)
    {
        if(i < k) ans1 = num[k-1-i];
        else ans1 = 1;
        ans1 = (ans1 * inv[k-i]) % MOD;
        ans1 = (ans1 * p25[k-i]) % MOD;
        ans1 = (ans1 * p26[i]) % MOD;
        ans = (ans + ans1) % MOD;

        //watch(i);
        //if(i < k) watch(num[k-i-1]);
    }

    cout<<ans<<'\n';

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n) cin>>a[i];
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n) cin>>a[i];
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 35648
#include <cstdio>

#define NMAX 200010

int a[NMAX];
int imos[NMAX];

void reset(int n) {
    for(int i = 0; i < n; i++) imos[i] = 0;
}

int max(int a, int b) {
    if(a > b) return a;
    else return b;
}

int min(int a, int b) {
    if(a > b) return b;
    else return a;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; i++) scanf("%d", &a[i]);

    for(int itr = 0; itr < k; itr++) {
        bool f = false;
        reset(n+1);
        for(int i = 0; i < n; i++){
            if(a[i] != n) f = true;
            imos[max(0, i - a[i])]++;
            imos[min(n, i + a[i] + 1)]--;
        }
        int acc = 0;
        for(int i = 0; i < n; i++){
            acc += imos[i];
            a[i] = acc;
        }
        if(!f) break;
    }

    for(int i = 0; i < n; i++) printf("%d\n", a[i]);
    return 0;
}


Measured memory_bytes: 3284
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, l int
	fmt.Scan(&n, &l)
	strings := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&strings[i])
	}
	sort.Sort(sort.StringSlice(strings))
	var s string = ""
	for i := 0; i < n; i++ {
		s = s + strings[i]
	}
	fmt.Println(s)
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 3010
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
#define INF 1000000000000
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
   int n;
   cin>>n;
   double ans=(double)((int)(n+1)/2)/n;
   printf("%.8lf\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}, dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int a,b;cin>>a>>b;
	cout<<a*b<<endl;
	return 0;
}

Measured memory_bytes: 3652
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int total =B*2;
    if(B>=A){
    	System.out.println(0);
    }else if(A<=total){
    	System.out.println(0);
    }else{
    	System.out.println(A-total);
    }
  }
}


Measured memory_bytes: 23764
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val x = sc.nextInt()
  val n = sc.nextInt()
  val p = (1..n).map { sc.nextInt() }

  if (n == 0) {
    println(x)
    return
  }

  var index = x
  var diff = Integer.MAX_VALUE
  for (i in -1..101) {
    if (p.contains(i)) {
      continue
    }

    val tmp = Math.abs(x - i)
    if (tmp < diff) {
      diff = tmp
      index = i
    }
  }

  println(index)
}


Measured memory_bytes: 37692
package main

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

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


func main() {
	N := oneInt()
	M := oneInt()

	var mins []int
	var maxs []int
	for index := 0; index < M; index++ {
		mins = append(mins, oneInt())
		maxs = append(maxs, oneInt())
	}

	lower := max(mins...)
	upper := min(maxs...)

	r := upper - lower + 1
	if r >= N {
		fmt.Print(N)
		return
	}

	if r < 0 {
		fmt.Print(0)
		return
	}
	fmt.Print(r)
}


Measured memory_bytes: 7552
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


int dp[2][100005];
const int mod=1e9+7;

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

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    int n,x;
    cin>>n>>x;
    int a[n+1];
    for(int i=1;i<=n;i++)
        cin>>a[i];
    sort(a+1,a+n+1,greater<int>());
    
    dp[0][x]=1;
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=x;j++)
            dp[i&1][j]=0;
        for(int j=0;j<=x;j++)
        {
            dp[i&1][j%a[i]]+=dp[(i+1)&1][j];
            dp[i&1][j]+=(dp[(i+1)&1][j]*(n-i))%mod; 
            dp[i&1][j]%=mod; 
            dp[i&1][j%a[i]]%=mod; 
        }
    }

    int ans=0;
    for(int i=0;i<=x;i++)
    {
        ans=(ans+dp[n&1][i]*i)%mod;
    }
    cout<<ans;

} 



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

using namespace std;


int main(void){

  int N;
  string ans = "No";

  cin >> N;

  for(int i = 1 ; i <= 9; i++){
    for(int j = 1; j <= 9; j++){

      if(i*j == N){
        ans = "Yes";
      }
    }
  }

  cout << ans << endl;

  return 0;
}




Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vishal Burman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CFennecVsMonster solver = new CFennecVsMonster();
        solver.solve(1, in, out);
        out.close();
    }

    static class CFennecVsMonster {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String str[] = in.readLine().split(" ");
            int n = Integer.parseInt(str[0]);
            long k = Long.parseLong(str[1]);
            String str2[] = in.readLine().split(" ");
            long a[] = new long[str2.length];
            for (int i = 0; i < str2.length; i++)
                a[i] = Long.parseLong(str2[i]);
            Arrays.sort(a);
            for (int i = n - 1; ; i--) {
                if (i == -1 || k == 0)
                    break;
                a[i] = 0;
                k--;
            }
            long sum = 0;
            for (int i = 0; i < n; i++) {
                sum += a[i];
            }
            out.println(sum);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        private String readLine0() {
            StringBuilder buf = new StringBuilder();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public String readLine() {
            String s = readLine0();
            while (s.trim().length() == 0) {
                s = readLine0();
            }
            return s;
        }

    }
}



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

int main() {
  int count[26] = {};
  char c;
  for (int i=0; i<4; i++) {
    cin >> c;
    count[c-'A']++;
  }
  for (int i=0; i<26; i++) {
    if (count[i] != 0 && count[i] != 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256