akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n + 1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
// typedef pair<int,int> P;
const int MAX = 1000000;

int main(){
    int r;
    cin >> r;
    printf("%.3f\n",r*2*M_PI);
    return 0;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin>>n;
int pre[n+1];
pre[0]=0;
for(int i=0; i<n; ++i) cin>>pre[i+1], pre[i+1]+=pre[i];
int suff[n+2];
for(int i=0; i<n; ++i) cin>>suff[i+1];
suff[n+1]=0;
for(int i=n; i>0; --i) suff[i]+=suff[i+1];
int res = 0;
for(int i=1; i<=n; ++i) res=max(res, pre[i]+suff[i]);
cout<<res;
}


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

int main() {
  int N;
  cin >> N;
  int pflg, wflg, gflg, yflg = 0;

  // ここにプログラムを追記
  for(int i = 0; i < N; i++){
    string S;
    cin >> S;

    if(S=="P"){
      pflg = 1;
    }else if (S=="W") {
      wflg = 1;
    }else if (S=="G") {
      gflg = 1;
    }else if (S=="Y") {
      yflg = 1;
    }

    if( pflg+wflg+gflg+yflg == 4){
      break;
    }
  }

  int result = pflg+wflg+gflg+yflg;

  if(result == 3){
    cout << "Three" << endl;
  }else if(result == 4){
    cout << "Four" << endl;
  }


}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
        int b1 = sc.nextInt();
        int b2 = sc.nextInt();
        int in[] = new int[a];
        for (int i = 0; i < a; i++) {
          in[i] = sc.nextInt();
        }
      
      	int choco = 0;
        for (int j = 0; j < in.length; j++) {
          int cal = b1 / in[j];
          int cal2 = b1 % in[j];
          choco += (cal2 != 0 ? (cal + 1) : cal);
        }
      
		// 出力
		System.out.println(choco + b2);
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;
const int maxn = 100;
const int maxm = 1e5+10;
const int INF = 0x3f3f3f3f;
typedef long long LL;
int n;
LL f[maxm];
int w[maxn];
int v[maxn];
//f[i][j] = f[i-1][j-w[i]] + v[i]
int main()
{

	int n,W;
	memset(f, 0, sizeof(0));
	scanf("%d%d", &n, &W);
	for(int i = 0; i < n; i++)
		scanf("%d%d", &w[i], &v[i]);
	for(int i = 0; i < n; i++)
		for(int j = W; j >= w[i]; j--)
			f[j] = max(f[j], f[j-w[i]] + v[i]);
	printf("%lld\n", f[W]);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
inline void read (int &x) {
	char ch = getchar(); x = 0;
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
} const int N = 5010;
int n, q, d[N], a[N];
signed main() {
	read (n), read (q);
	for (int i = 0; i < n; ++i) read (a[i]);
	while (q--) {
		int k, x, m, cnt = 0; long long sum = 0;
		read (k), read (x), read (m);
		for (int i = 0; i < n; ++i) d[i] = a[i] % m, sum += d[i];
		for (int i = 0; i < n; ++i) {
			if (!d[i]) cnt += (k - 1) / n + (i < (k - 1) % n);
		} sum = (k - 1) / n * sum + x; 
		for (int i = 0; i < (k - 1) % n; ++i) sum += d[i];
		printf ("%d\n", k - 1 - sum / m + x / m - cnt);
	} return 0;
}

Measured memory_bytes: 384
N = int(input())
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline

lst = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    w = w%2
    lst[u].append([v, w])
    lst[v].append([u, w])
# print (lst)
ans = [-1] * (N + 1)
def dfs(x): #xについてつながりを見る
    # if ans[x] != -1: #既に見ているとき
    #     return ans[x]
    for i in lst[x]: #xからのつながりを見る
        # print (i)
        if ans[i[0]] == -1: #移動先をまだ見ていないとき
            if i[1] == 0: #距離が偶数のとき
                ans[i[0]] = ans[x] #移動先と移動前は同じ
                dfs(i[0])
            else: #距離が奇数のとき
                ans[i[0]] = (ans[x] + 1) % 2
                dfs(i[0])
    return 

ans[1] = 0
dfs(1)
for i in ans[1:]:
    print (i)

Measured memory_bytes: 82288
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;

const int mx=100010;
const ll mod=998244353;

int n,c;
ll ans=1;
map<int, int> s;

int main(){
  cin >> n;
  cin >> c;
  s[c]++;
  if(c!=0){cout << 0 << endl; return 0;}
  for(int i=1; i<n; i++){
    int d;
    cin >> d;
    s[d]++;
  }

  if(s[0]!=1){cout << 0 << endl; return 0;}

  for(int i=1, co=1; i<n && co<n; i++){
    for(int j=0; j<s[i]; j++){
      ans *= s[i-1];
      ans %= mod;
    }
    co += s[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  int count = 0;
  
  cin >> A >> B;
  
  for (int i = A; i < B + 1; i++) {
    int a, b, c, d;
    
    a = i / 10000;
    b = i / 1000 - a * 10;
    d = i % 10;
    c = (i % 100 - d) / 10;
    
    if (a == d && b == c) {
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int main()
{

    int A,B,C,x,y;
    cin>>A>>B>>C;
    y=A;
    
    for (int i=1; i<10000; i++)
    {
        x=A%B;
        A=y*i;
        if (x==C)
        {
            cout<<"YES"<<endl;
            break;
        }
        else if (i==9999)
        {
            cout<<"NO"<<endl;
            break;
        }
         else
            ;
    }
    return 0;
}
 

Measured memory_bytes: 256
N,Q=map(int,input().split())
S=input()
A=[]
C=[]
for i in range(N-1):
  if S[i]=='A' and S[i+1]=='C':
    A.append(i+1)
    C.append(i+2)
import bisect
for i in range(Q):
  l,r=map(int,input().split())
  a=bisect.bisect_left(A,l)
  c=bisect.bisect_right(C,r)
  print(c-a)

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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; cin>>N;
	vector<int> a(N), b(N);
	ll cur=0,val=0;
	for (int i=0; i<N; i++)
		cin>>a[i], cur-=a[i];
	for (int i=0; i<N; i++)
		cin>>b[i], cur+=b[i];
	for (int i=0; i<N; i++)
		if(a[i]<b[i])
			cur-=(b[i]-a[i]+1)/2;
	cout<<((cur<0)?"No":"Yes")<<"\n";
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<int> cnt(N,0);
    cnt[0]=1;
    for(int i=1; N-2*i>0; i++){
        cnt[N-2*i]=2;
    }

    long long ans=1;
    for(int i=0; i<N; i++){
        int A;
        cin >> A;
        cnt[A]++;
        if(cnt[A]>2){
            cout << 0 << endl;
            return 0;
        }else if(cnt[A]==1){
            ans*=2;
            ans%=MOD;
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 640
/*    
                                                                             
	1. Practice makes a man perfect.
	2. Let go of the past.
	3. Without pain, without sacrifice, we would have nothing.
	4. Great things never come from comfort zones.
	5. Turn your wounds into wisdom.
	6. No pain ... no palm, no throne, no glory,no cross, no crown.
	7. You never know how strong you are until being strong is your only choice.
	8. Smooth seas do not make skillful sailors.
	9. I am not what happened to me, I am what I choose to become.
	10. No matter how fail life pushes you down, No matter how much you hurt,You can always bounce back.
		
		
	--> This lines keep me motivated.		

	Author:- Gaurang_Kothiya
	
*/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  

#define data_set(type) tree<type,null_type,less<type>,rb_tree_tag,tree_order_statistics_node_update>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define ld long double
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(int i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define ook(num) order_of_key(num)
#define fbo(num) find_by_order(num)
#define gcd(a,b) __gcd(a,b)
#define bits(n) __builtin_popcountll(n)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846

const int inf= 1e9 +1;
const int inf64= 1e18 -1;
const int MOD= 1e9 +7;


 
void Solve()
{	
	int a[3];
	f(i,0,2) cin>>a[i];
	sort(a,a+3);
	if(a[0]==5 && a[1]==5 && a[2]==7) cout<<"YES";
	else cout<<"NO";
}
 
signed main() 
{
	speed		

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int q=1;
	//cin>>q;
	
	while(q--)
	Solve();
		
	return 0;
} 

Measured memory_bytes: 3596
#include <iostream>
#include<string>
using namespace std;
int main(void){
    int a,b;
    string s;
    cin>>a>>b;
    if(a==b){
        cout<<"Draw"<<endl;
    } 
    else if(a==1) cout<<"Alice"<<endl;
    else if(b==1) cout<<"Bob"<<endl;
    else{
        if(a>b) cout<<"Alice"<<endl;
        else cout<<"Bob"<<endl;
    } 
    return 0;
    // Your code here!
    
}


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

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

int main()
{
    int n, k;
    scanf("%d %d", &k, &n);

    int inp[n];
    for (int i = 0; i < n; i++)
        scanf("%d", &inp[i]);

    int ans = INT_MAX;
    for (int i = 0; i < n; i++) {
        int nxt = (i + 1) % n;

        ans = min(ans, k - (inp[nxt] - inp[i] + k) % k);
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
int a[N][3];
int dp[N][4];
int n;
int func(int index,int last){
    if(index==n)    return 0;
    if(dp[index][last]!=-1)    return dp[index][last];

    int ans=0;
    for(int k=0;k<3;k++){
        if(k==last) continue;
        ans=max(ans,a[index][k]+func(index+1,k));
    }
    return dp[index][last]=ans;
}
main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++)
            cin>>a[i][j];
    }
    memset(dp,-1,sizeof(dp));
    cout<<func(0,3)<<"\n";
}

Measured memory_bytes: 14132
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int cost[n + 2];
    int sum = 0;
    for(int i = 1; i <= n; i++) cin >> cost[i];
    cost[0] = cost[n + 1] = 0;
    for(int i = 1; i <= n + 1; i++) sum += abs(cost[i - 1] - cost[i]);
    for(int i = 1; i <= n; i++)
    {
        int ans = sum;
        ans += abs(cost[i - 1] - cost[i + 1]);
        ans -= abs(cost[i - 1] - cost[i]) + abs(cost[i] - cost[i + 1]);
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 1664
import java.util.Arrays;
import java.util.Scanner;

/**
 * https://abc064.contest.atcoder.jp/tasks/abc064_b
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i=0; i<N; i++) a[i] = sc.nextInt();
		sc.close();
		
		Arrays.sort(a);
		
		System.out.println(a[N-1]-a[0]);

	}

}

Measured memory_bytes: 22228
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let a: usize = read!();
    let b: usize = read!();
    let c: usize = read!();
    let k: usize = read!();

    let small = a;
    let mut medium = b;
    let mut big = c;

    for _ in 0..k {
        if small >= medium {
            medium *= 2;
        } else {
            big *= 2;
        }
    }

    let ans = if small < medium && medium < big {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}


Measured memory_bytes: 2120
#include<iostream>
using namespace std;
int bubbleSort(int A[], int N){
  int sw = 0;
  bool flag = 1;
  for( int i =0; flag; i++){
    flag = 0;
    for( int j = N -1; j >= i + 1; j-- ){
      if( A[j] < A[j - 1]){
	swap(A[j],A[j -1]);
	flag = 1;
	sw++;
      }
    }
  }
  return sw;
}

int main(){
  int A[100], N, sw;
  cin >> N;
  for( int i = 0; i < N; i++) cin >> A[i];
  sw = bubbleSort(A, N);
  for( int i = 0 ; i < N ; i++){
    if(i)cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
#define sz(a) int((a).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int n,m,q;
vi arr(12);
vvi Q(55, vi(4));
ll mx;

void dfs(int pos, int prev){
    if(pos==n+1){
        // print(arr);
        ll cur = 0;
        for(int i=1; i<=q; ++i){
            if(arr[Q[i][1]] - arr[Q[i][0]] == Q[i][2])
                cur+=Q[i][3];
        }

        mx = max(mx, cur);
    
        return;
    }

    for(int i=prev; i<=m; ++i){
        arr[pos] = i;
        dfs(pos+1,i);
    }
}


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

    fore(i,1,q+1){
        forn(j,4)
            cin>>Q[i][j];
    }

    // print_vv(Q);
    dfs(1,1);
    cout<<mx<<endl;
    return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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


int main(){ 
    Int N, K; cin >> N >> K;

    Int r = N % K;
    cout << min(r, K-r) << endl;
}

Measured memory_bytes: 256
import sys
import math
import bisect

def main():
    a, b, c, k = map(int, input().split())
    ans = 0
    #print('a: %d, b: %d, c: %d, k: %d, ans: %d' % (a, b, c, k, ans))
    if a <= k:
        ans += a
        k -= a
        a = 0
    else:
        a -= k
        ans += k
        k = 0
    #print('a: %d, b: %d, c: %d, k: %d, ans: %d' % (a, b, c, k, ans))
    if b <= k:
        k -= b
    else:
        b -= k
        k = 0
    #print('a: %d, b: %d, c: %d, k: %d, ans: %d' % (a, b, c, k, ans))
    if c <= k:
        ans += -c
        k -= c
        c = 0
    else:
        c -= k
        ans -= k
        k = 0
    #print('a: %d, b: %d, c: %d, k: %d, ans: %d' % (a, b, c, k, ans))
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9204
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <map>
#include <bitset>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> l, r, cnt(n, 0), ans(n, 0);
    rep(i, n) {
        if (s[i] == 'L')l.push_back(i);//Lの位置をメモ
        if (s[i] == 'R')r.push_back(i);
    }
    int k = 0, q = r.size();
    rep(i, n) {
        if (i > l[k])k++;
        int p = n - 1 - i;
        if (p < r[q - 1])q--;
        if (s[i] == 'R') {
            cnt[i] = l[k] - i;//最寄りのLまでの必要な移動回数
            if (cnt[i] % 2 == 0)ans[l[k]]++;
            else ans[l[k] - 1]++;
        }
        if(s[p] == 'L') {
            cnt[p] = p - r[q - 1];
            if (cnt[p] % 2 == 0)ans[r[q - 1]]++;
            else ans[r[q - 1] + 1]++;
        }
    }
    rep(i, n-1)cout << ans[i] << ' ';
    cout << ans[n - 1] << endl;
  
    return 0;
}

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

int N, X;
int x[(int)1e5];

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

int main() {
    cin >> N >> X;
    rep(i, N) {
        cin >> x[i];
    }

    int y[(int)1e5];
    rep(i, N) {
        y[i] = abs(X - x[i]);
    }

    // cout << gcd(24, 48) << endl;
    // return 0;

    int ans = y[0];
    for (int i = 1; i <= N - 1; i++) {
        // cout << y[i] << endl;
        // printf("ans=%d gcd(ans, y[i]) %d y[i] %d\n", ans, gcd(ans, y[i]), y[i]);
        ans = gcd(ans, y[i]);
        // cout << ans << endl;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;
int dp[1001][1001];

int main(int argc, char const* argv[])
{
	string a, b;
	cin >> a;
	cin >> b;
	for(int i = 0; i < a.size() + 1; i++)dp[i][0] = i;
	for(int i = 0; i < b.size() + 1; i++)dp[0][i] = i;
	for(int i = 0; i < a.size(); i++){
			for(int j = 0; j < b.size(); j++){
					int cost = 1;
					if(a[i] == b[j])cost = 0;
					dp[i + 1][j + 1] = min(dp[i][j] + cost, dp[i][j + 1] + 1);
					dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i + 1][j] + 1);
			}
	}
	cout << dp[a.size()][b.size()] << endl;
	return 0;
}



Measured memory_bytes: 7108
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
#include <complex>
using namespace std;

using ld = long double;
using P = complex<ld>;
using G = vector<P>;
const ld pi = acos(-1);
const ld eps = 1e-10;
const ld inf = 1e12;

ld cross(const P& a, const P& b) { return a.real()*b.imag() - a.imag()*b.real(); }
ld dot(const P& a, const P& b) { return a.real()*b.real() + a.imag()*b.imag(); }

enum { CCW = +1, CW = -1, BEHIND = +2, FRONT = -2, ON = 0 };
int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if(cross(b, c) > eps)  return CCW;    // counter clockwise
	if(cross(b, c) < -eps) return CW;     // clockwise
	if(dot(b, c) < 0)      return BEHIND; // c--a--b on line
	if(norm(b) < norm(c))  return FRONT;  // a--b--c on line
	return ON;
}

struct L : public vector<P> {
	L(const P &a = 0, const P &b = 0) {
		push_back(a); push_back(b);
	}
	L(ld A, ld B, ld C) { // Ax + By + C = 0
		if(A < eps) *this = L(P(0, -C / B), P(1, -C / B));
		else if(B < eps) *this = L(P(-C / A, 0), P(-C / A, 1));
		*this = L(P(0, -C / B), P(-C / A, 0));
	}
	int ccw(const P& p) {
		return ::ccw((*this)[0], (*this)[1], p);
	}
};

P projection(const L &l, const P &p) {
	ld t = dot(p - l[0], l[0] - l[1]) / norm(l[0] - l[1]);
	return l[0] + t*(l[0] - l[1]);
}

bool intersectSP(const L &s, const P &p) {
	return abs(s[0] - p) + abs(s[1] - p) - abs(s[1] - s[0]) < eps; // triangle inequality
}


ld distanceSP(const L &s, const P &p) {
	const P r = projection(s, p);
	if(intersectSP(s, r)) return abs(r - p);
	return min(abs(s[0] - p), abs(s[1] - p));
}

P crosspointLL(const L &l, const L &m) {
	ld A = cross(l[1] - l[0], m[1] - m[0]);
	ld B = cross(l[1] - l[0], l[1] - m[0]);
	if(abs(A) < eps && abs(B) < eps) return m[0]; // same line
	if(abs(A) < eps) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
	return m[0] + B / A * (m[1] - m[0]);
}

#define curr(pol, i) pol[i]
#define next(pol, i) pol[(i+1)%pol.size()]
G convex_cut(const G& pol, const L& l) {
	G res;
	for(int i = 0; i < pol.size(); ++i) {
		P A = curr(pol, i), B = next(pol, i);
		if(ccw(l[0], l[1], A) != -1) res.push_back(A);
		if(ccw(l[0], l[1], A)*ccw(l[0], l[1], B) < 0)
			res.push_back(crosspointLL(L(A, B), l));
	}
	return res;
}

int n;
G ps;
vector<L> ls;
bool check(double x) {
	G res = ps;
	for(int i = 0; i < n; i++) {
		P a = ls[i][1] - ls[i][0];
		P d = a * polar(x / abs(a), pi / 2);
		L lx = L(ls[i][0] + d, ls[i][1] + d);
		res = convex_cut(res, lx);
		if(res.size() < 3) return false;
	}
	return true;
}


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

	while(cin >> n, n) {
		ps.clear();
		for(int i = 0; i < n; i++) {
			ld x, y;
			cin >> x >> y;
			ps.push_back(P(x, y));
		}
		ls.clear();
		for(int i = 0; i < n; i++) {
			ls.push_back(L(ps[i], ps[(i + 1) % n]));
		}

		double ok = 0, ng = 1e9;
		for(int loop = 0; loop < 200; loop++) {
			double x = (ok + ng) / 2;
			if(check(x)) ok = x;
			else ng = x;
		}

		cout << fixed << setprecision(15) << ok << endl;
	}
}

Measured memory_bytes: 3344
import java.util.Scanner

object Main extends App{
  def warshall_floyd(d: Array[Array[Int]], v: Int) =
    for(k <- 1 to v; i <- 1 to v; j <- 1 to v){
      d(i)(j) = Math.min(d(i)(j), d(i)(k) + d(k)(j))
  }

  // input
  val sc = new Scanner(System.in)

  val n = sc.nextInt()
  val m = sc.nextInt()

  val graph = Array.ofDim[Int](n+1, n+1)
  val edges = new Array[(Int, Int, Int)](m+1)
  for(i <- 1 to n; j <- 1 to n)
    if(i == j)
      graph(i)(j) = 0
    else
      graph(i)(j) = 10000000

  for(i <- 1 to m){
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()

    edges(i) = (a, b, c)
    graph(a)(b) = c
    graph(b)(a) = c
  }


  // main process
  warshall_floyd(graph, n)

  var ans = 0
  for((a, b, c) <- edges){
    var flag = false
    for(i <- 1 to n; j <- 1 to n){
      if(graph(i)(a) + c + graph(b)(j) == graph(i)(j)
        || graph(i)(b) + c + graph(a)(j) == graph(i)(j))
        flag = true
    }

    if(!flag)
      ans += 1
  }

  println(ans)
}

Measured memory_bytes: 37280
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        a[i] = {x, i + 1};
    }
    sort(begin(a), end(a));
    vector<int> ans(n);
    for(int i = 0; i < n; i++){
        ans[i] = a[i].second;
    }
    cout << ans[0];
    for(int i = 1; i < n; i++){
        cout << " " << ans[i];
    }
    cout << endl;
    return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code
int main(int argc, char const* argv[])
{
	LL k;
	cin >> k;
	LL loop = k / 50;
	LL b = k % 50;
	VL ans(50,0);
	for (int i = b; i < 50; i++) {
		ans[i] = i-b + loop;
	}
	for (int i = 0; i < b; i++) {
		ans[i] = 50-b+i+1+loop;
	}
	cout << 50 << endl;
	for (auto&& var : ans) {
		cout << var << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
object Main {
  import java.util.Scanner

  implicit class RichScanner(sc: Scanner) {
    def readStrings(n: Int): Array[String] = Array.fill(n) { sc.next() }
    def readInts(n: Int): Array[Int] = Array.fill(n) { sc.nextInt() }
    def readLongs(n: Int): Array[Long] = Array.fill(n) { sc.nextLong() }
    def readLineStrings: Array[String] = sc.nextLine().split(' ')
    def readLineInts: Array[Int] = readLineStrings.map(_.toInt)
    def readLineLongs: Array[Long] = readLineStrings.map(_.toLong)
  }

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(sc: Scanner): Unit = {
    val Array(n, k) = sc.readInts(2)
    val possibleMods = Seq(0) ++ { if (k % 2 == 0) Seq(k / 2) else Nil }
    val answer = possibleMods.map(m => {
      val numbers = (1 to n).count(_ % k == m)
      scala.math.pow(numbers, 3).toLong
    })
    println(answer.sum)
  }
}


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

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var s = Input().ToInt();
		var k = Console.ReadLine().ToInt();
		for(int i = 0; i < k; i++)
		{
			Array.Sort(s);
			Array.Reverse(s);
			s[0] = s[0] * 2;
		}
		long wa = 0;
		for(int i = 0; i < s.Length; i++)
		{
			wa += s[i];
		}
		Console.WriteLine(wa);
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
string s1,s2;
static int t[3005][3005];
void nhap()
{
    cin>>s1>>s2;
}
void qhd()
{
    for (int i = 1; i <= (int)s1.length(); i++)
        for (int j = 1; j <= (int)s2.length(); j++)
            if (s1[i - 1] == s2[j - 1])
                t[i][j] = t[i - 1][j - 1] + 1;
            else
                t[i][j] = max(t[i][j - 1], t[i - 1][j]);

    int i = (int)s1.length();
    int j = (int)s2.length();
    string res="";
    while (i != 0 && j != 0)
    {
        if (s1[i - 1] == s2[j - 1])
        {
            res=s1[i-1]+res;
            i--;
            j--;
        }
        else if (t[i][j] == t[i - 1][j])
            i--;
        else
            j--;
    }
    cout<<res;
}
int main()
{
    nhap();
    qhd();
    return 0;
}


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a,b;cin >> n >> a >> b;
	if(a>b || (n==1 && a!=b)) cout << 0 << endl;
	else cout << (n-1)*b+a-((n-1)*a+b)+1 << endl;
}


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


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

  bool flag = false;
  int count = 0;
  int ind = 0;
  rep(i,N){
    ind = A.at(ind)-1;
    count += 1;
    if (ind == 1){
      flag = true;
      break;
    }

  }
  if (flag){
    cout << count << endl;
  }else{
    cout << -1 << endl;
  }

}       

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

signed main() {
	int n, p;
	int ncp[55][55];
	for (int i = 0; i < 55; i++) {
		ncp[0][i] = 1;
		ncp[i][0] = 1;
	}
	for (int i = 1; i < 55; i++) {
		for (int j = 1; j < 55; j++) {
			ncp[i][j] = ncp[i - 1][j] + ncp[i][j - 1];
		}
	}
	cin >> n >> p;
	int res = 0;
	vector<int> A(n);
	int no = 0;
	int ne = 0;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		if (A[i] % 2 == 0) {
			ne++;
		}
		else {
			no++;
		}
	}
	res = 0;
	for (int i = p; i <= no; i+=2) {
		res += ncp[no-i][i];
	}
	res *= ((int)1 << ne);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int l,r,mid,n,a[200005],b[200005],c[200005];
bool check(int t){
	int sum=10000000,z=-1,x,y=-1,num1=0,num2=0;
	for(int i=1; i<=n*2-1; i++){
		if(a[i]<c[t]){
			x=0;
			num1++;
		}
		else{
			x=1;
			num2++;
		}
		if((x==y)&&(min(abs(i-n),abs((i-1)-n))<sum)){
			sum=min(abs(i-n),abs((i-1)-n));
			z=x;
		}
		y=x;
	}
	if(z==-1){
		if(num1>num2)z=0;
		if(num2>num1)z=1;
	}
	if(z==1)return(true);
	else return(false);
}
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n*2-1; i++){
		scanf("%d",&a[i]);
		c[i]=a[i];
	}
	sort(c+1,c+n*2);
	l=1; r=n*2-1;
	while(l<r){
		mid=(l+r+1)/2;
		if(check(mid)==true)l=mid;
		else r=mid-1;
	}
	printf("%d",c[r]);
}

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

using namespace std;

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

  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  long minVal, maxProfit ;
  minVal = min(a.at(0), a.at(1));
  maxProfit = a.at(1) - a.at(0);
  for(int i = 2; i < n; i++) {
    if(a.at(i) - minVal > maxProfit) {
      maxProfit = a.at(i) - minVal;
    }
    if(a.at(i) < minVal) {
      minVal = a.at(i);
    }
  }
  cout << maxProfit << endl;

  return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include <bits/stdc++.h>
#include <set>
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define vii vector<pair<int, int> >
#define si stack<int>
#define pb push_back
#define mp make_pair
#define ALL(T) (T).begin(), (T).end()
#define MODU 1000000007
typedef long long ll;
using namespace std;

ll intmax = (1LL<<32)-1;
ll llmax = (1LL<<60)-1;

const int INF = 1e9 + 5;

class fastio{
public:
	fastio(){
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
	}
} __fastio;

template <typename T>
T abs(T x){
	if(x<0)	return -x;
	else return x;
}

void DFSVisit(int u, vector<int> g[], vector<bool> &visited){ 
    visited[u] = true;
    for(int i=0; i<g[u].size(); i++){
        if(!visited[g[u][i]]){
            DFSVisit(g[u][i], g, visited); 
        }
    }
} 
  
void DFS(vector<int> adj[], int V){
    vector<bool> visited(V, false); 
    for(int u=0; u<V; u++) 
        if(!visited[u]) 
            DFSVisit(u, adj, visited);
}


void solve(){
	
}

int main(){
	int n;
	cin >> n;
	int i = 1;
	int change[] = {10, 100, 1000, 10000, 100000};
	int digits = 1;
	int ans = 0;
	while(i <= n){
		if(digits % 2){
			ans++;
		}
		i++;
		for(int u : change){
			if(i == u){
				digits++;
				break;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 384
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while(getline(ss,x,c)) v.emplace_back(x); return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;
struct UF{
  vector<int> data;
  UF(int size):data(size,-1){}
  bool unite(int x,int y){
    x=root(x); y=root(y);
    if(x!=y){
      if(data[y]<data[x]) swap(x,y);
      data[x]+=data[y]; data[y]=x;
    }
    return x!=y;
  }
  bool findSet(int x,int y){return root(x)==root(y);}
  int root(int x){return data[x]<0?x:data[x]=root(data[x]);}
  int size(int x) {return -data[root(x)];}
};

bool dfs(vv<int> &g,int v,int c,vector<int> &re){
  if(re[v]>=0) return c==re[v];
  re[v]=c;
  for(int w:g[v])if(!dfs(g,w,1-c,re)) return 0;
  return 1;
}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n,m;
  cin>>n>>m;
  UF uf(n);
  vv<int> g(n);
  rep(i,m){
    int x,y;
    cin>>x>>y; --x; --y;
    uf.unite(x,y);
    g[x].pb(y);
    g[y].pb(x);
  }
  ll s=0,e=0,o=0;
  vector<int> c(n,-1);
  rep(i,n) if(uf.size(i)==1) ++s;
  else if(uf.root(i)==i){
    ++(dfs(g,i,0,c)?e:o);
  }
  //out(s,e,o,1);
  ll re=s*s+2*s*(n-s);
  re+=o*o;
  re+=o*e;
  re+=e*o;
  re+=e*e*2;
  cout<<re<<endl;
  return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int w,h;cin>>w>>h;
  vector<pll>pq(w+h);
  rep(i, w+h){
    cin>>pq[i].first;
    pq[i].second = i;
  }
  sort(pq.begin(), pq.end());

  ll cw=w+1, ch=h+1;
  ll result = 0;
  for(auto p: pq){
    if(p.second >= w){
      result += p.first*cw;
      ch--;
    }else{
      result += p.first*ch;
      cw--;
    }
  }

  cout<<result<<endl;

  return 0;
}



Measured memory_bytes: 6432
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = MAP()
G = list2d(N, N, INF)
for i in range(M):
    s, t, d = MAP()
    G[s][t] = d

# dp[bit][i] := 今iにいる時の、集合bitの最短距離
dp = list2d(1<<N, N, INF)
# 初期化：頂点0を開始位置として距離0にする
dp[1][0] = 0

for bit in range(1, (1<<N)-1):
    for i in range(N):
        # 頂点iが集合bitに含まれていない
        if not bit>>i&1: continue
        for j in range(N):
            # 頂点jは既に集合bitに含まれている
            if bit>>j&1: continue
            # 頂点iからjへの移動を遷移させる
            dp[bit+(1<<j)][j] = min(dp[bit+(1<<j)][j], dp[bit][i] + G[i][j])

mn=INF
for end in range(N):
    # 最後の頂点から戻ってくる分を足す
    mn = min(mn, dp[(1<<N)-1][end] + G[end][0])
if mn==INF:
    print(-1)
else:
    print(mn)



Measured memory_bytes: 15472
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		if(K > B) {
			System.out.println("NG");
			return;
		}


		int tmpK = K;
		for(int i=1; i<1000; i++) {

			if(tmpK >= A && tmpK <= B) {
				System.out.println("OK");
				return;
			}

			if(tmpK > B) {
				System.out.println("NG");
				return;
			}
			tmpK += K;

		}

	}

}


Measured memory_bytes: 35768
x, y = map(int, input().split())

prise_dict = {3: 100000, 2: 200000, 1: 300000}
ans = 0
if x in prise_dict.keys():
    ans += prise_dict[x]
if y in prise_dict.keys():
    ans += prise_dict[y]
if x == y == 1:
    ans += 400000
print(ans)


Measured memory_bytes: 9052
s=list(input())

flag = True
if s[0] == '0':
    flag = True
else:
    flag = False

c = 0
for i in s:
    if i == '0' and flag:
        flag = not flag
    elif i == '1' and not flag:
        flag = not flag
    else:
        flag = not flag
        c += 1

print(c)

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	int m; cin >> m;
	long long x[m];
	for(int i = 0; i < m; i++) cin >> x[i];
	sort(x, x + m);
	long long d[m-1];
	for (int i = 0; i < m-1; i++)
	{
		d[i] = x[i+1] - x[i];
	}
	sort(d, d + m - 1);
	long long sum = 0;
	for (int i = 0; i < max(m - n, 0); i++)
	{
		sum += d[i];
	}

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


Measured memory_bytes: 5204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){//予選決勝法、左と右の予選に分けてそれらの最大で決勝をする
	int n;cin>>n;
	string s;cin>>s;

	int l[n],r[n];//iから見て左側にいる人で左向いている人数がl[i],反対がr[i]
	l[0]=0;r[n-1]=0;

	for(int i=1;i<n;i++){
		if(s[i-1]=='W') l[i]=l[i-1]+1;
		else l[i]=l[i-1];
	}
	for(int i=n-2;i>=0;i--){
		if(s[i+1]=='E') r[i]=r[i+1]+1;
		else r[i]=r[i+1];
	}

	int ans=inf;
	for(int i=0;i<n;i++) ans=min(ans,r[i]+l[i]);

	cout<<ans<<endl;
}

Measured memory_bytes: 3076
#include<stdio.h>

int mod(int x, int y, int z);

int main(void){
  int a, b, c;
  int m;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  m = mod(a, b, c);
  printf("%d\n", m);
  
  return 0;
}

int mod(int x, int y, int z){
  int cnt = 0;
  int i;
  for(i = x; i <= y; ++i){
    if(z%i == 0){
      cnt += 1;
    }
  }
  return cnt;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
int main() {
    int H, W;
    cin >> H >> W;
    for (int i=0; i < H; i++) {
        string Pix;
        cin >> Pix;
        cout << Pix << endl;
        cout << Pix << endl;
    }
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split(' ')))
ans=1
calcneeded=1

for a in A:
    if (a == 0):
        print(0)
        exit()
    
    if (calcneeded == 1):
        ans*=a
    
    if (ans > 10**18):
        calcneeded=0

if (ans > 10**18):
    print(-1)
else:
    print(ans)




Measured memory_bytes: 21648
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define rep(n) for(int i=0;i<n;i+=1)
#define fill(c,v) memset(c,v,sizeof(c));
#define prarr(a,n) rep(n) cout<<a[i]<<" \n"[i==n-1]; 
#define sc(a) scanf("%d",&a);
#define scl(a) scanf("%lld",&a);
#define scf(a) ascanf("%f",&a);
#define ff first
#define ss second
#define pu push_back
#define inf 1000000001
#define MOD 1000000007 
#define INF 100000000000001
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,m;
    string s,s1;
    cin>>s;
    cin>>s1;
    n = s.length();
    if(s1.length()!=n)
    {
    	printf("%s\n","No" );
    	return 0;
    }
 	m =0;
 	bool ans = 1;
 	while(m<=s.length())
 	{
 		ans = 1;
 		rep(m)
 		{
 			if(s1[i]!=s[n-m+i])
 			{
	 			ans = 0;
	 			break;
 			}
 		}
 		if(!ans) 
 		{
 			m++;
 			continue;
 		}
 		for(int i = 0; i<n-m ;i++)
 		{
 			if(s1[i+m]!=s[i])
 			{
 				ans = 0;
 				break;
 			}
 		}
 		// printf("%d %d\n",m,ans );
 		if(ans)
 		{
 			printf("%s\n","Yes" );
 			return 0;
 		}
 		m++;
 	}	
 	printf("%s\n","No" );
 	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for ( int i=0;  i<n; i++)
#define REP(i, n) for ( int i=1; i<=n; i++)
#define fi first
#define sc second 
#define pb push_back
#define pf push_front 
#define mod 1000000007
using namespace std;
using f=float; using ll=long long; using ld=long double;
using ull=unsigned long long; using vi=vector<int>; using pii=pair<int, int>;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int A[200000];
    int ans[200000]={0};
    //rep(i, 10) {
    //    cout << ans[i] << endl;
    //}
    REP(i, n-1) {
        cin >> A[i];
        ans[A[i]-1]+=1;
    }
    rep(i, n) {
        cout << ans[i] << endl;
    }
    
    return 0;
} 


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[])
{
    int n,m;
    cin >> n >> m;
    priority_queue<pair<ll,ll>> que;
    REP(i,n)
    {
        ll a; 
        cin >> a;
        que.push(make_pair(a,1));
    }
    
    REP(i,m)
    {
        ll b,c;
        cin >> b >> c;
        que.push(make_pair(c,b));
    }

    ll ans = 0;
    REP(i,n)
    {
        auto p = que.top();
        que.pop();
        if (p.S != 1)
            que.push(make_pair(p.F,p.S-1));
        ans += p.F;
    }

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


Measured memory_bytes: 6512
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <string.h>
#include <math.h>
typedef long long ll;
#define INF			100000
#define MAX(x, y)	(((x) > (y))? (x) : (y))
#define MIN(x, y)	(((x) < (y))? (x) : (y))
#define ABS(x)		(((x) < 0)? (-1*(x)) : (x))
#define SWAP
#define REP(i,x,y)	for (int (i)=(x);(i)<(y);(i)++)
#define REP_(i,x,y)	for ((i)=(x);(i)<(y);(i)++)
#define MEMCLR(X)	memset((X),0,sizeof((X)))

using namespace std;
typedef pair<int, int> Point;
typedef vector<vector<Point>> Graph;

ll N,a[100000],maxa,mida,x,y;

int main() {
	
	cin >> N;
	
	REP(i,0,N) cin >> a[i],maxa = MAX(maxa,a[i]);
	x = maxa;
	y = maxa/2;

	REP(i,0,N) {
		if (a[i] != maxa && a[i] != 0 && x > ABS(y-a[i]) ) {
			x = ABS(y-a[i]);
			mida = a[i];
		}
	}

	cout << maxa << " " << mida;
	
	return 0;
}


Measured memory_bytes: 1024
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<atcoder/all>
#include<iostream>
#include<cstdint>
#include<vector>
#include<algorithm>
#include<cstddef>
using namespace std;
using namespace atcoder;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
i64 op(i64 a, i64 b){
    return max(a,b);
}
i64 e(){
    return 0;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
i64 n,k;
cin >> n >> k;
segtree<i64,op,e> segt(300001);
i64 ans = 0;
rep(i,n){
    i64 a;
    cin >> a;
    i64 l = max<i64>(a - k,0);
    i64 r = min<i64>(a + k,300000);
    i64 tmp = segt.prod(l,r + 1)+ 1;
    ans = max(ans,tmp);
    segt.set(a,tmp);
}
cout << ans << endl;
}

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

int main() {
  int  n; cin>>n;
  string s; cin>>s;
  vector<int>sum(n-1);
  for(int i=1;i<n;i++){
    vector<int>x(26);
    vector<int>y(26);
    string t,u;
    t=s.substr(0,i);
    u=s.substr(i);
    for(int j=0;j<t.size();j++){
      x[t[j]-'a']=1;
    }
    for(int j=0;j<u.size();j++){
      y[u[j]-'a']=1;
    }
    for(int j=0;j<26;j++){
		if(x[j]==y[j] && x[j]==1){
          sum[i-1]++; 
        }
    }
  }
  sort(sum.begin(),sum.end());
  cout<<sum[n-2]<<endl;
}

    
  


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

typedef long long ll;
const ll INF = 1LL << 60;

ll A, B, C;

int main() {
    cin >> A >> B >> C;

    string ans = "No";
    if (A == B && B != C) {
        ans = "Yes";
    } else if (A == C && B != C) {
        ans = "Yes";
    } else if (A != C && B == C) {
        ans = "Yes";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int x,y;
	scanf("%d%d",&x,&y);
	if(x%y==0){puts("-1");return 0;}
	printf("%d\n",x);
	return 0;
}


Measured memory_bytes: 128