akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

#define ll long long
#define el '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repi(i, a, b) for (int i = a; i >= b; i--)

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

    int n, x, y;
    cin >> n >> x >> y;
    int ans[n];
    rep(i, 0, n)
    {
        ans[i] = 0;
    }

    rep(i, 1, n + 1)
    {
        rep(j, i + 1, n + 1)
        {
            int old = j - i;
            int become = abs(x - i) + 1 + abs(y - j);
            if (old < become)
            {
                ans[old]++;
            }
            else
            {
                ans[become]++;
            }
        }
    }

    // rep(i, 1, n)
    // {
    //     ans[i] = n - i;
    //     printf("original %d: %d\n", i, ans[i]);
    // }
    // rep(i, y - x, n)
    // {
    //     // y-x -> 1, 1
    //     // y-x+1 -> 2, 2
    //     // y-x+2 -> 3, 3
    //     int become = i - (y - x) + 1;
    //     int delta = min(ans[i], become);
    //     printf("move %d from %d to %d\n", delta, i, become);
    //     // cout << i << endl;
    //     assert(delta >= 0);
    //     assert(ans[i] >= delta);
    //     ans[i] -= delta;
    //     ans[become] += delta;
    // }

    // // d[x,i]>1+d[i,y]
    // rep(i, x, y + 1)
    // {
    //     rep(left, 1, x + 1)
    //     {
    //         int old = i - left;
    //         int become = x - left + 1 + y - i;
    //         if (old > become)
    //         {
    //             ans[old]--;
    //             ans[become]++;
    //         }
    //     }
    // }

    // // 1+d[x,i]<d[i,y]
    // rep(i, x, y + 1)
    // {
    //     rep(right, y, n + 1)
    //     {
    //         int old = right - i;
    //         int become = right - y + 1 + i - x;
    //         if (old > become)
    //         {
    //             ans[old]--;
    //             ans[become]++;
    //         }
    //     }
    // }
    // // d[i,j]>d[i,x]+1+d[y,j]
    // rep(i, x, y + 1)
    // {
    //     rep(j, i + 1, y + 1)
    //     {
    //         int old = j - i;
    //         int become = x - i + 1 + j - y;
    //         if (old > become)
    //         {
    //             ans[old]--;
    //             ans[become]++;
    //         }
    //     }
    // }

    rep(i, 1, n)
    {
        cout << ans[i] << el;
    }
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
cs=abs(a[0])
a.append(0)
for i in range(n):
  cs+=abs(a[i]-a[i+1])
print(cs-abs(a[0])-abs(a[0]-a[1])+abs(a[1]))
for i in range(1,n):
  print(cs-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]))

Measured memory_bytes: 20496
using System.Collections.Generic;
using System.Linq;
using System;
class Program
{
    static void Main()
    {
        string line = Console.ReadLine();
        string[] a = line.Split(' ');
        int[] b = new int[2];

        b[0] = int.Parse(a[0]);
        b[1] = int.Parse(a[1]);

        int result = b[0] - b[1];

        if (result <= 0)
            result = 0;

        Console.WriteLine(result.ToString());
    }
}

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

int main()
{
	int n;
	int ctr[5] = {0};
	scanf("%d", &n);
	
	char str[n];
	
	for(int i = 0; i < n; i++){
		scanf("%s", &str);
		if(strcmp(str, "AC") == 0){
			++ctr[0];
		}else if(strcmp(str, "WA") == 0){
			++ctr[1];
		}else if(strcmp(str, "TLE") == 0){
			++ctr[2];
		}else if(strcmp(str, "RE") == 0){
			++ctr[3];
		}
	}
	printf("AC x %d\n", ctr[0]);
	printf("WA x %d\n", ctr[1]);
	printf("TLE x %d\n", ctr[2]);
	printf("RE x %d\n", ctr[3]);
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  int S=s.size();
  for(int i=2;i<S;i+=2){
    if(s.substr(0,(S-i)/2)==s.substr((S-i)/2,(S-i)/2)){
      cout<<S-i<<endl;
      break;
    }
  }
}
     


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


const int INF=1e9;


const int MAX_N = 110, MAX_W=10010;
int dp[MAX_W];

int main(){
	int n, W;
	cin>>n>>W;
	vi v(n, 0), w(n, 0);
	rep(i, n) cin>>v[i]>>w[i];

	for(int i = 0; i < n; i++){
		for(int j = W; j >=w[i]; j--){
			dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
		}
	}
	cout<<dp[W]<<endl;
}

Measured memory_bytes: 1236
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        double A = sc.nextDouble();
        double B = sc.nextDouble();
        int H = sc.nextInt();
        int M = sc.nextInt();
        double c2 = A * A + B * B - 2.0 * A * B * Math.cos((3.141592653589793238 * (300.0 * H - 55.0 * M))/1800.0);
        double c = Math.sqrt(c2);
        System.out.printf("%.20f", c);
    }
}


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

using namespace std;
int main(){
  long n;
  cin >> n;
  
  long res=0;
  for(int i=0;i<n;i++){
    long p;
    cin >>p;
    if(p!=i+1) res++;
  }
  
  if(res<=2) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  
}

Measured memory_bytes: 256
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n, _ = strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func main() {
  N := NextInt()
  S := NextLine()
  Q := NextInt()
  K := NextIntVec()
  for i := 0; i < Q; i++ {
    D := 0
    M := 0
    DM := 0
    DMC := 0
    k := K[i]
    for j := 0; j < N; j++ {
      if j > k - 1 {
        if S[j - k] == 'D' {
          D -= 1
          DM -= M
        }
        if S[j - k] == 'M' { M -= 1 }
      }
      if S[j] == 'D' { D += 1 }
      if S[j] == 'M' {
        M += 1
        DM += D
      }
      if S[j] == 'C' { DMC += DM }
    }
    Write(DMC)
  }
  Output()
}

Measured memory_bytes: 3712
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check
const ll INF = 1LL << 60;



int main(){
    ll N; cin >> N;
    vector<vll> x(N), y(N);
    REP(i, N){
        ll A; cin >> A;
        REP(j, A){
            ll tmpx, tmpy;
            cin >> tmpx >> tmpy;
            tmpx --;
            x[i].push_back(tmpx);
            y[i].push_back(tmpy);
        }
    }
    ll maxcnt=0;
    REP(S, 1LL<<N){
        bool isValid=true;
        REP(i, N){
            if(S>>i &1){ //* honest guy
                REP(j, x[i].size()){
                    if((S>>x[i][j] &1)!= y[i][j]){
                        isValid = false;
                    }
                }
            }
        }
        if(isValid){
            ll cnt = 0;
            REP(i, N){
                if(S>>i & 1)
                    cnt++;
            }
            maxcnt = max(maxcnt, cnt);
        }
    }
    cout << maxcnt<<endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int N, K; cin >> N >> K;
    cout << N - K + 1 << endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
mod = 1000000007
sum_A = 0
for i in range(N):
    A[i] = A[i] % mod
    sum_A += A[i]

ans = 0
for i in range(N-1):
    sum_A -= A[i]
    ans = (ans + (A[i] * sum_A) % mod) % mod

print(ans)


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

namespace ABC120_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var red = s.Count(x => x == '0');
            var blue = s.Count(x => x == '1');
            Console.WriteLine(Math.Min(red, blue) * 2);
        }
    }
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> R(N);
    for (int i = 0; i < N; i++) {
        cin >> R.at(i);
    }

    sort(R.begin(), R.end(), greater<int>()); // 大きい順にソート
    int length = 0;

    for (int i; i < K; i++) {
        length += R.at(i);
    }
    cout << length << endl;
    return 0;
}

Measured memory_bytes: 256
import heapq

N,M=map(int,input().split())
A=[int(i) for i in input().split()]

cost=[]
heapq.heapify(cost)

for i in range(N):
    heapq.heappush(cost,-A[i])

min_cost=sum(A)

while M>0:
    max_cost=(-1)*heapq.heappop(cost)
    cut_cost=max_cost-max_cost//2
    min_cost-=cut_cost
    max_cost-=cut_cost
    heapq.heappush(cost,(-1)*max_cost)
    M-=1

print(min_cost)

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

int main()
{
	int N,K,S;
	cin >> N >> K >> S;
	if (S != 1e9)
	{
		rep(i,K)
		{
			if (i != 0) cout << " ";
			cout << S;
		}
		rep(i,N-K)
		{
			if (K != 0 || i != 0) cout << " ";
			cout << 1000000000;
		}
	}
	else
	{
		rep(i,K)
		{
			if (i != 0) cout << " ";
			cout << S;
		}
		rep(i,N-K)
		{
			if (K != 0 || i != 0) cout << " ";
			cout << 1;
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
 int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
  
 
ll findlcm(ll arr[], int n) 
{ 
   
    ll ans = arr[0]; 
  
    
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (gcd(arr[i], ans))); 
  
    return ans; 
} 
 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
      ll n,ans=0;
      cin>>n;
      ll A[n],B[n],C[n];
      for(ll i=0;i<n;i++)cin>>A[i];
      for(ll i=0;i<n;i++)cin>>B[i];
      for(ll i=0;i<n;i++)cin>>C[i];
      sort(A,A+n);
      sort(B,B+n);
      sort(C,C+n);
     for(ll i=0;i<n;i++)
     {
        // vector<int>::iterator lower,upper; 
        ll lower = lower_bound (A,A+n,B[i])-A;  
        ll upper = upper_bound (C,C+n,B[i])-C;
        ans=ans+lower*(n-upper);
    
     }
     cout<<ans;
    }
     
     
      
    return 0;
}


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

int d[105][105], a[105];
vector<int> v;

int main()
{
	int h, w, n, x;
	cin >> h >> w >> n;
	for(int i=1; i<=n; i++)
	{
		cin >> x;
		while(x--)
		{
			v.push_back(i);
		}
	}
	for(int i=1; i<=h; i++)
	{
		if(i%2 == 1)
		{
			for(int j=1; j<=w; j++)
			{
				if(v.empty()) break;
				d[i][j] = v.front();
				v.erase(v.begin());
			}
		}
		else
		{
			for(int j=w; j>=1; j--)
			{
				if(v.empty()) break;
				d[i][j] = v.front();
				v.erase(v.begin());
			}
		}
	}
	for(int i=1; i<=h; i++)
	{
		int z = 0;
		for(int j=1; j<=w; j++)
		{
			if(z) cout << " ";
			cout << d[i][j];
			z = 1;
		}
		cout << endl;
	}
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;

int main(void){
    int n;
    cin >> n;
    int a[n];
    int sum = 0;
    for(int i = 0;i < n;i++){
        cin >> a[i];
        sum+= a[i];
    }
    long long ans = 0;
    for(int i = 0;i < n-1;i++){
        sum-=a[i];
        ans += (a[i] * sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;

int main() {
	string s;
	cin >> s;
	bool a[26] = { false };
	REP(i, SZ(s)) {
		a[s[i] - 'a'] = true;
	}
	REP(i, 26) {
		if (!a[i]) {
			cout << (char)(i + 'a') << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}

Measured memory_bytes: 512
k,n = map(int,input().split())
a = list(map(int,input().split()))

max = 0

for i in range(n-1):
    if(a[i+1]-a[i])>max:
        max= a[i+1]-a[i]

if  (k-a[n-1]) + a[0] >= max:
    max = (k-a[n-1]) + a[0]

print(k-max)


Measured memory_bytes: 26444
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109311;
const long double pi = 3.1415926535897932384626433;
typedef pair<int, int> P;
struct edge { int to, cost; };
int a[200005];
P aa[200005];
int ldp[200005], rdp[200005];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	set<int>S;
	
	rep(i, n)aa[i] = P(a[i], i);
	sort(aa, aa + n);
	reverse(aa, aa + n);
	int ans = 0;
	
	for (int i = -1; i <= n; i++)S.insert(i);

	rep(i, n) {
		int x = aa[i].second;
		auto itr = S.find(x);
		auto itrp = itr, itrm = itr;
		itrp++; itrm--;
		ans += aa[i].first*(*itrp - *itr)*(*itr - *itrm);
		S.erase(itr);
		}
	cout << ans << endl;
}

Measured memory_bytes: 15360
from fractions import gcd

def main():
    N = int(input())
    A = list(map(int, input().split()))

    if len(A) == 2:
        print(max(A))
        return

    if len(A) == 3:
        gcd1 = gcd(A[0], A[1])
        gcd2 = gcd(A[0], A[2])
        gcd3 = gcd(A[1], A[2])
        print(max(gcd1, gcd2, gcd3))
        return

    gcd1 = gcd(A[0], A[1])
    gcd2 = gcd(A[0], A[2])
    gcd3 = gcd(A[1], A[2])
    yet_used_gcd = max(gcd1, gcd2, gcd3)
    not_used_gcd = gcd(gcd1, A[2])

    for i in range(3, N):
        yet_used_gcd = gcd(yet_used_gcd, A[i])
        if yet_used_gcd < not_used_gcd:
            yet_used_gcd = not_used_gcd
        not_used_gcd = gcd(not_used_gcd, A[i])

    if yet_used_gcd > not_used_gcd:
        print(yet_used_gcd)
    else:
        print(not_used_gcd)

main()

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

int main()
{
  int H,W;cin>>H>>W;
  char a[H][W];set<int> sh,sw;
  for(int i=0;i<H;i++)sh.insert(i);
  for(int i=0;i<W;i++)sw.insert(i);
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>a[i][j];
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)if(a[i][j]=='#')sh.erase(i);
  for(int i=0;i<W;i++)for(int j=0;j<H;j++)if(a[j][i]=='#')sw.erase(i);
  for(int i=0;i<H;i++){if(sh.count(i))continue;for(int j=0;j<W;j++)if(!sw.count(j))cout<<a[i][j];cout<<endl;}
}

Measured memory_bytes: 3628
n, m = map(int, input().split())
inp = [0] * n
ans = []

for i in range(1, 31):
    ans.append(i)

for i in range(n):
    inp[i] = [int(x) for x in input().split()]
    ans = set(ans) & set(inp[i][1:])

print(len(ans))

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

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



int main(){
    int h, w; cin >> h >> w;
    REP(i, h) REP(j, w){
        string s; cin >> s;
        if(s == "snuke"){
            cout << char(j + 'A') << i + 1 << "\n";
            return 0;
        }
    }
    return 0;
}


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

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        //Solve();
        return;
    }

    public static string Solve()
    {
        int N = ReadInt();
        return (N*N*N).ToString();
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 11092
// x座標が必ず異なるN点が与えられる。以下の条件を満たす最短路を求める。
// x座標が最小の点を始点、x座標が最大の点を折り返し点としてすべての点を通り一周する最短路を求める。
// 参照: http://nyanp.hatenablog.com/entry/20121014/p1
//      https://en.wikipedia.org/wiki/Bitonic_tour
//      https://stackoverflow.com/questions/874982/how-to-compute-optimal-paths-for-traveling-salesman-bitonic-tour
//      http://marcodiiga.github.io/bitonic-tour
// 方針:
//   計算量はO(N^2)

#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair

double bitonic_tour(int N, vector<pair<ll,ll>>& points) {

    sort(ALL(points));

    auto euclideanDistance = [&](int a, int b) {
        auto& pa = points[a];
        auto& pb = points[b];
        return hypot(pa.first - pb.first, pa.second - pb.second);
    };

    // Adjacency matrix for bitonic distances between points
    vector<vector<double>> bitonicDistances(N, vector<double>(N, -1));
    bitonicDistances[0][0] = 0;
    FOR(i, 1, N)
        bitonicDistances[0][i] =
        bitonicDistances[0][i - 1] + euclideanDistance(i - 1, i);

    FOR(i, 1, N) {
        FOR(j, i, N) {
            double mn = numeric_limits<double>::max();
            if (i == j || i == j - 1) {
                REP(k, i) {
                    mn = min(mn, bitonicDistances[k][i] + euclideanDistance(k, j));
                }
                bitonicDistances[i][j] = mn;
            }
            else {
                bitonicDistances[i][j] =
                    bitonicDistances[i][j - 1] + euclideanDistance(j - 1, j);
            }
            //cout << "bitonicDistances[i][j] = " << bitonicDistances[i][j] << endl;
        }
    }

    return bitonicDistances[N - 1][N - 1];
}


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

    vector<pair<ll, ll>> points(N);

    REP(n, N) {
        cin >> points[n].first >> points[n].second;
    }
    cout << std::fixed << std::setprecision(20) << bitonic_tour(N, points) << endl;

    return 0;
}



Measured memory_bytes: 10780
#include<stdio.h>

int main(void){
	int a=0,b=0;
	char enzansi;
	
	do{
	scanf("%d %c %d",&a,&enzansi,&b);
	switch(enzansi){
		case '+': printf("%d\n",a+b);
			break;
		
		case '-': printf("%d\n",a-b);
			break;
		
		case '*': printf("%d\n",a*b);
			break;
		
		case '/': printf("%d\n",a/b);
			break;
	}
	
	
	}while(enzansi!='?');
	
	return 0;
	
}

Measured memory_bytes: 600
///
// File:  dpl_3_a.cpp
// Author: ymiyamoto
//
// Created on Wed Nov  8 01:32:41 2017
//

#include <cstdint>
#include <iostream>

using namespace std;
#define MAX_H 1400
#define MAX_W 1400

static uint32_t arr[MAX_H][MAX_W];

int32_t main()
{
  uint32_t H, W;
  cin >> H >> W;
  for (uint32_t i = 0; i < H; i++) {
    for (uint32_t j = 0; j < W; j++) {
      uint32_t val;
      cin >> val;
      if (val == 0) {
        arr[i][j] = 1;
      } else {
        arr[i][j] = 0;
      }
    }
  }

  uint32_t max_val = 0;
  for (uint32_t i = 0; i < H; i++) {
    for (uint32_t j = 0; j < W; j++) {
      if (arr[i][j] != 0 && 0 < i && 0 < j) {
        arr[i][j] = 1 + min(arr[i - 1][j], min(arr[i][j - 1], arr[i - 1][j - 1]));
      }
      max_val = max(max_val, arr[i][j]);
    }
  }

  cout << max_val * max_val << endl;

  return 0;
}

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

int main(){
  long long int x;
  cin >> x;
  long long int ans = x/11*2;
  if (x % 11 == 0) ;
  else if (x % 11 <= 6) ans += 1;
  else ans += 2;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false) , cin.tie(0) ;
#define all(v) v.begin(),v.end()
#define w(x) cout << (#x) << " is " << x << "\n" ;

int main()
{
    fast ;
    int n,t,i;
    char c ;
    cin >> c ;
    if(c=='A')
        cout << "T\n";
    else if(c=='T')
        cout << "A\n";
    else if(c=='G')
        cout << "C\n";
    else if(c=='C')
        cout << "G\n";

    return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int a = sc.nextInt(), b = sc.nextInt(), k = sc.nextInt();
		for (int i = 0; i < k; i++) {
			if (i % 2 == 0) {
				a /= 2;
				b += a;
			} else {
				b /= 2;
				a += b;
			}
		}
		System.out.println(a + " " + b);
	}
}

Measured memory_bytes: 22740
// https://atcoder.jp/contests/abc178/tasks/abc178_d

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

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DEBUG 0
#if DEBUG
  #define _GLIBCXX_DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int S_MAX = 2000;
const int MOD = 1e9+7;

int S;

int main() {
  cin >> S;

  vector<int> dp = vector<int>(S + 1, 0);
  dp[0] = 1;

  FOR(i, 1, S) {
    for (int j = 0; j <= i - 3; j++) {
      dp[i] = (dp[i] + dp[j]) % MOD;
    }
  }

  DUMP(dp);

  cout << dp[S] << endl;
}


Measured memory_bytes: 3620
from collections import deque
import sys

def fnw(n,s):
    sm=deque([])
    if n<=len(s):
        for _ in range(n):
            sm.append(s.popleft())
    return sm

def jfws(s):
    # print(s)
    sm=fnw(5,s)
    # print(sm)
    if ''.join(sm)=='dream':
        sm=fnw(2,s)
        if ''.join(sm)=='er':
            if bool(s):
                if s[0]=='a':
                    s.extendleft(deque(reversed(list(sm))))
        else:
            s.extendleft(deque(reversed(list(sm))))
        return False
    elif ''.join(sm)=='erase':
        sm=fnw(1,s)
        if ''.join(sm)!='r':
            s.extendleft(sm)
        return False
    else:
        return True 

def main(s):
    while len(s)>0:
        if jfws(s):
            return 'NO'
    return 'YES'

s=deque(sys.stdin.readline().strip())
print(main(s))



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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(int, n);
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  out(accumulate(all(p), 0) - *max_element(all(p)) / 2);
}


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

int main(){
  int f,xyf;
  char h[5][4],v[4][5];
  int x,y;
  cin>>h[0];
  for(int i=0;i<4;i++){
    cin>>v[i];
    cin>>h[i+1];
  }
  f=xyf=1;
  y=0;
  x=1;cout<<"R";
  while(x!=0||y!=0){
    if(f==1){
      if(xyf==1){
	if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";f*=-1;xyf*=-1;
	}
	else if(x<4&&h[y][x]=='1'){
	  x++;cout<<"R";
	}
	else if(v[y][x]=='0'||y==4) xyf*=-1;
	else{
	  y++;f*=-1;cout<<"D";
	}
      }
      else{
	if(y<4&&v[y][x]=='1'){
	  y++;cout<<"D";f*=-1;xyf*=-1;
	}
	else if(x>0&&h[y][x-1]=='1'){
	  x--;cout<<"L";
	}
	else if(v[y-1][x]=='0'||y==0) xyf*=-1;
	else{
	  y--;cout<<"U";f*=-1;
	}
      }
    }
    else{
      if(xyf==1){
	if(x<4&&h[y][x]=='1'){
	  x++;cout<<"R";f*=-1;
	}
	else if(y<4&&v[y][x]=='1'){
	  y++;cout<<"D";
	}
	else if(h[y][x-1]=='0'||x==0) xyf*=-1;
	else{
	  x--;cout<<"L";f*=-1;xyf*=-1;
	}
      }
      else{
	if(x>0&&h[y][x-1]=='1'){
	  x--;cout<<"L";f*=-1;
	}
	else if(y>0&&v[y-1][x]=='1'){
	  y--;cout<<"U";
	}
	else if(h[y][x]=='0'||x==4) xyf*=-1;
	else{
	  x++;cout<<"R";f*=-1;xyf*=-1;
	}
      }
    }
  }
  cout<<endl;
  return 0;
}

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

int power[] = {1, 4, 8, 9, 16, 25, 27, 32, 36, 49, 64, 81, 100, 121, 125, 128, 144, 169, 196, 216, 225, 243, 256, 289, 324, 343, 361, 400, 441, 484, 512, 529, 576, 625, 676, 729, 784, 841, 900, 961, 1000, 1024, 1089, 1156, 1225};

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

    int ans = 0;
    int temp;
    for(int i = 0; ans <= X; ++i) {
        ans = power[i];
        temp = i;
    }

    if(temp == 0) {
        cout << power[temp]<< endl;
    }else {
        cout << power[temp - 1]<< endl;
    }
}

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

#define MAX 100

int d[MAX], t = 0, M[MAX][MAX] = {}, n;

void bfs(){
    queue<int> todo;
    d[0] = 0;
    todo.push(0);
    while(!todo.empty()){
        int m = todo.front();
        todo.pop();
        rep(i, n){
            if(d[i] == -1 && M[m][i]){
                d[i] = d[m] + 1;
                todo.push(i);
            }
        }
    }
    return;
}

int main(){
    cin >> n;
    fill(d, d + n, -1);
    int m, l;
    rep(i, n){
        cin >> m >> l;
        rep(j, l){
            int o;
            cin >> o;
            M[m - 1][o - 1] = 1;
        }
    }
    bfs();
    rep(i, n){
        cout << i + 1 << " " << d[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	vector<int> a(4);
	rep(i, 4) cin >> a[i];
	sort(all(a));
	if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<fstream>
#include<vector>
#include <bitset>

using namespace std;

inline int rev(int i, int N)
{
	return N - i - 1;
}


int main(){
	std::istream & c_in = cin;
	int N;
	c_in >> N;
	vector<int> sub;
	sub.resize(N / 2);

	for (int i = 0; i < N / 2; ++i)
	{
		c_in >> sub[i];
	}

	int count = 0;
	int j = N - N / 2 - 1;
	for (int i = N / 2; i < N; ++i)
	{
		int dat;
		c_in >> dat;
		sub[j] -= dat;
		count += (sub[j--] == 0);

	}
	bool b_same = (count == N / 2);

	int Q;
	c_in >> Q;

	for (int q = 0; q < Q; ++q)
	{
		int L, r, x;
		c_in >> L >> r >> x;
		if (x != 0)
		{
			//??°??????l????????????r???????????§??????????????????????´??????°???x????¶????
			//1???l???r???N
			L--;	//base 0
			r--;	//base 0

			int s, t;
			if (r < N / 2)
			{
				s = L;
				t = r;
			}
			else if (L >= N / 2)
			{
				s = rev(r, N);
				t = rev(L, N);
				x = -x;
			}
			else
			{
				r = rev(r, N);
				if (L < r)
				{
					s = L;
					t = r - 1;
				}
				else
				{
					s = r;
					t = L - 1;
					x = -x;
				}
			}
			if (s <= t)
			{
				int * p = &sub[s];
				for (int i = s; i <= t; ++i,++p)
				{
					int v = *p;
					bool pre = (v == 0);
					v += x;
					bool same = (v == 0);
					*p = v;
					if (pre != same)
					{
						count += same - pre;
					}
				}
				b_same = (count == N / 2);
			}

		}
		cout << (b_same ? '1' : '0') << endl;

	}
}

Measured memory_bytes: 3896
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    double x1,y1,x2,y2,dis;
    cin >> x1 >> y1 >> x2 >> y2;
    x1 = x1-x2;
    y1 = y1-y2;
    if(x1 < 0){
        x1 *= -1;
    }
    if(y1 < 0){
        y1 *= -1;
    }
    
    dis = sqrt(x1*x1+y1*y1);
    
    cout << fixed << dis << endl;
    
    return 0;
}


Measured memory_bytes: 3276
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int n;
vector<vector<int> > g;
bool DFS(int u, int p) {
	bool clr = true;
	int res[2] = {};
	for (int i = 0; i < g[u].size(); ++i)
		if (g[u][i] != p)
			++res[DFS(g[u][i], u)];
	if (res[0] + res[1] == 0)
		return clr;
	if (res[1]>1) {
		puts("First");
		exit(0);
	}
	if (res[1])
		return false;
	return res[0];
}
int main()
{
	scanf("%d", &n);
	g.resize(n);
	for (int i = 1, a, b; i < n; ++i) {
		scanf("%d%d", &a, &b);
		--a; --b;
		g[a].push_back(b);
		swap(a, b);
		g[a].push_back(b);
	}
	if (n == 2) {
		puts("Second");
		return 0;
	}
	if (DFS(0, -1))
		puts("First");
	else
		puts("Second");
	return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<string, int> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}

int ab[100010];

int main()
{
	ios_base::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		ab[b] = max(ab[b], a);
	}

	int k = 1;
	int ans = 0;
	REP(i, 2, n + 1) {
		if (ab[i] >= k) {
			k = i;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int n, temp, cnt, ans = INT_MAX;
    cin >> n;
    rep(i, n) {
        cin >> temp;
        cnt = 0;
        while(!(temp % 2)) {
            cnt++;
            temp /= 2;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  int N;cin>>N;
  int X=N;
  int x[100]={0};

  int c=0;
  while(X>0){
    x[c]=X%10;
    X/=10;
    c++;
  }
  int sum=0;
  for(int t=0;t<90;t++){
    sum+=x[t];
  }

  if(N%sum==0){
    cout<<"Yes"<<"\n";
  }else{
    cout<<"No"<<"\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main() {
  string s,t ;
  cin >>s >>t ;
  int k= s.size() ;
  int ans=0 ;
  rep(i,k){
  if(s.at(i)!=t.at(i))
  ans ++ ;
  }
  if(ans==0)
  cout<< "Yes" <<endl ;
  else
  cout << "No" <<endl ;
     return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int N;
int getS(int n){
  int res=0;
  while(n){
    res+=n%10;
    n/=10;
  }
  return res;
}
main(){
  cin>>N;
  const int S=getS(N);
  cout<<(N%S==0?"Yes":"No")<<endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    b[i]--;
  }

  stack<int> s;
  bool ok = true;
  for (int i = 0; i < n; i++) {
    for (int j = (int)b.size() - 1; j >= 0; j--) {
      if (b[j] == j) {
        s.push(j + 1);
        b.erase(b.begin() + j);
        break;
      }
      if (j == 0) {
        ok = false;
        break;
      }
    }

    if (!ok) {
      break;
    }
  }

  if (ok) {
    while (!s.empty()) {
      cout << s.top() << endl;
      s.pop();
    }
  } else {
    puts("-1");
  }

  return 0;
}


Measured memory_bytes: 3620
import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}
	
	int n = read.to!int;
	string[] ss;
	foreach(i; 0 .. n) ss ~= readln.chomp;
	
	int abcount, acount, bcount, bacount;
	foreach(s; ss){
		if(s[0] == 'B') bcount += 1;
		if(s[$ - 1] == 'A') acount += 1;
		if(s[0] == 'B' && s[$ - 1] == 'A') bacount += 1;
		for(int i = 0; i < s.length - 1; i ++) if(s[i] == 'A' && s[i + 1] == 'B') abcount += 1;
	}
	print!1("ab:", abcount, " a:", acount, " b:", bcount, " ba:", bacount);
	
	int ans = abcount;
	if(acount < bcount) ans += acount;
	else if(acount > bcount) ans += bcount;
	else if(acount > 0 && acount == bacount) ans += acount - 1;
	else ans += acount;
	
	ans.writeln;
}

/*
①元々文字列の内部にあるAB
②Aで終わりBで始まる

②は、Aで終わる個数とBで始まる個数の少ない方
ただしAで終わるやつの全てがBで始まる場合は場合は1つ減らす


*/


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

int main(){
	ll a,b;
	cin >> a >> b;
	cout << (a*b)/__gcd(a,b) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<long long>A;
    vector<long long>B;
    
    for(int i = 0; i <= N; ++i){
        int a;
        cin >> a;

        A.push_back(a);
    }
    
    for(int i = 0; i < N; ++i){
        int b;
        cin >> b;

        B.push_back(b);
    }

    long long result = 0;
    
    for(int i = 0; i < N; ++i){
        if(B.at(i) <= A.at(i)){
            result += B.at(i);
        }else{
            result += A.at(i);
            auto rest = B.at(i) - A.at(i);

            if(rest < A.at(i+1)){
                result += rest;
                A.at(i+1) -= rest;
            }
            else
            {
                result += A.at(i+1);
                A.at(i+1) = 0;
            }
        }
    }

    cout << result;
}

Measured memory_bytes: 2548
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val writer = new java.io.PrintWriter(System.out)
    writer.println(solve(sc))
    writer.flush()
  }

  def solve(sc: Scanner): String = {
    val (x, a) = (sc.nextInt(), sc.nextInt())
    (if (x < a) 0 else 10).toString
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}


Measured memory_bytes: 27460
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
n,m=map(int,input().split())
ans=1
for i in make_divisors(m):
    if i>=n:
        ans=max(ans,m//i)
print(ans)

Measured memory_bytes: 3060
file = File.exist?('in.in') ? File.new('in.in','r') : STDIN
n, k = file.gets.chomp.split.map(&:to_i)
vec = file.gets.chomp.split.map(&:to_i)

INF = 4611686018427387903
dp = Array.new(n, INF)

dp[0] = 0

for i in 1...vec.size
  min = dp[i]
  j=1
  while(j<=k && i-j >= 0)
    c = dp[i-j]+(vec[i-j]- vec[i]).abs
    min = c if c < min
    j+=1
  end
  dp[i]=min
end

puts dp.last

Measured memory_bytes: 9484
#include<iostream>

using namespace std;


int main() {
    int n; cin >> n;
    bool check = false;
    for (int i = 0; i <= n / 4; i++) {
        for (int j = 0; j <= n / 7; j++) {
            if (4 * i + 7 * j == n) {
                check = true;
                break;
            }
            else if (4 * i + 7 * j > n) break;
        }
        if (check == true) break;
    }
    if (check) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#-------最強ライブラリSCC(Python) ver25252------
import sys
sys.setrecursionlimit(1000000)

class scc_graph:
  # n 頂点数
  def __init__(s, n): 
    s._n = n
    s.g = {}
  def num_vertices(s): return s._n
  # 辺を追加 frm 矢元 to 矢先
  # O(1)
  def add_edge(s, frm, to): 
    if frm in s.g: s.g[frm].append(to)
    else: s.g[frm] = [to]

  # グループの個数と各頂点のグループidを返す
  def scc_ids(s):
    now_ord = group_num = 0
    visited = []
    low = [0] * s._n
    ord = [-1] * s._n
    ids = [0] * s._n
    # 再帰関数 
    def dfs(self, v, now_ord, group_num):
      low[v] = ord[v] = now_ord
      now_ord += 1
      visited.append(v)
      if v in s.g:
        for to in s.g[v]:
          if ord[to] == -1:
            now_ord, group_num = self(self, to, now_ord, group_num)
            low[v] = min(low[v], low[to])
          else:
            low[v] = min(low[v], ord[to])
      if low[v] == ord[v]:
        while True:
          u = visited.pop()
          ord[u] = s._n
          ids[u] = group_num
          if u == v: break
        group_num += 1
      return now_ord, group_num

    for i in range(s._n):
      if ord[i] == -1: now_ord, group_num = dfs(dfs, i, now_ord, group_num)
    for i in range(s._n):
      ids[i] = group_num - 1 - ids[i]
    return group_num, ids

  # 強連結成分となっている頂点のリストのリスト トポロジカルソート済み
  # O(n + m)
  def scc(s):
    ids = s.scc_ids()
    group_num = ids[0]
    counts = [0] * group_num
    for x in ids[1]: counts[x] += 1
    groups = [[] for _ in range(group_num)]
    for i in range(s._n):
      groups[ids[1][i]].append(i)
    return groups

  class edge:
    def __init__(s, frm, to):
      s.frm = frm
      s.to = to


#-------最強ライブラリここまで------

input = sys.stdin.readline

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

g = scc_graph(n)

for i in range(m):
  u, v = ab[i]
  g.add_edge(u, v)

scc = g.scc()

print(len(scc))

for v in scc:
  print(len(v), end = " ")
  for x in v:
    print(x, end = " ")
  print("")

Measured memory_bytes: 264856
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    vector<ll> l(n);
    rep(i,n) cin>>l[i];

    ll ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(l[i]==l[j] || l[j]==l[k] || l[k]==l[i]) continue;
                if(l[i]+l[j]>l[k] && l[j]+l[k]>l[i] && l[k]+l[i]>l[j]) ans++;
            }
        }
    }

    cout<<ans<<endl;
}


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

int main() {
    int h,w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w, 0));
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cin >> a[i][j];
        }
        
    }
    vector<vector<int>> tmp(h, vector<int>(w, 0));
    tmp = a;

    int cnt = 0;
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w - 1; j++)
        {
            if (tmp[i][j] % 2 != 0) {
                tmp[i][j]--;
                tmp[i][j + 1]++;
                cnt++;
            }
        }
        
    }
    for(int i = 0; i < h - 1; i++)
    {
        if (tmp[i][w - 1] % 2 != 0) {
            tmp[i][w - 1]--;
            tmp[i + 1][w - 1]++;
            cnt++;
        }
    }  

    cout << cnt << endl;

    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w - 1; j++)
        {
            if (a[i][j] % 2 != 0) {
                a[i][j]--;
                a[i][j + 1]++;
                cout << i + 1 << " " << j + 1 << " " << i + 1 << " " << j + 2 << endl;
            }
        }
        
    }
    for(int i = 0; i < h - 1; i++)
    {
        if (a[i][w - 1] % 2 != 0) {
            a[i][w - 1]--;
            a[i + 1][w - 1]++;
            cout << i + 1 << " " << w << " " << i + 2 << " " << w << endl;
        }
    }     
}

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

#define int long long
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) otp(v[i]) cte
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

string a,b;

main() {
    cin >> a >> b;
    if (a.size() > b.size()) ct("GREATER")
    else if (a.size() < b.size()) ct("LESS")
    else {
        rep(i,(int)a.size()) {
            if (a[i] > b[i]) {
                ct("GREATER")
                return 0;
            }
            if (a[i] < b[i]) {
                ct("LESS")
                return 0;
            }
        }
        ct("EQUAL")
    }
}

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

class Program
{
    static void Main(string[] args)
    {
        // 次数の配列
        int[] degrees = new int[100];
        degrees[0] = 1;
        degrees[1] = 1;

        do
        {
            var line = Console.ReadLine();
            if (line == null) break;
            var nums = line.Split().Select(str => int.Parse(str)).ToArray();
            if (nums[0] == 0)
            {
                System.Console.WriteLine(degrees.All(degree => degree % 2 == 0) ? "OK" : "NG");
                degrees = new int[100];
                degrees[0] = 1;
                degrees[1] = 1;
            }
            else
            {
                degrees[nums[0] - 1]++;
                degrees[nums[1] - 1]++;
            }
        } while(true);
    }
}



Measured memory_bytes: 9368