akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

    for(int i=0;i<=100;i+=4) {
        for(int j=0;j<=100;j+=7) {
            if((i+j) == N) {
                cout << "Yes\n";
                return 0;
            }
        }
    }

    cout << "No\n";
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> l(n);
	for (int i = 0; i < n; i++) cin >> l[i];
	
	int ans = 0;

	for (int i = 0; i < n-2; i++) {
		for (int j = i+1; j < n-1; j++) {
			for (int k = j+1; k < n; k++) {
				if (abs(l[j]-l[k]) < l[i] && l[i] < l[j]+l[k]) {
					if (l[i]!=l[j] && l[j]!=l[k] && l[k]!=l[i]) ans++;
				}
			} 
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define bs ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
int main()
{
	bs;
	string s;
	cin >> s;
	ll sum = 0;
	for(auto x: s){
		sum += (x - '0');
	}
	cout << ((sum % 9)?"No":"Yes");
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> pint;
using ll = long long;
using VI = vector<int>;

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

int H,W;
string fi[110];
int dist[110][110];//BFS用

int main(){
    cin >> H >> W;
    int wnum = 0;
    for(int i=0;i<H;i++){
        cin >> fi[i];
        for(int j=0;j<W;j++){
            if(fi[i][j]=='.') ++wnum;
        }
    }
    memset(dist,-1,sizeof(dist));
    dist[0][0] = 1;
    queue<pint> que;
    que.push(pint(0,0));
    while(!que.empty()){
        pint cur = que.front();
        que.pop();
        int x = cur.first;
        int y = cur.second;
        rep(dir,4){
            int nx = x+dx[dir];
            int ny = y+dy[dir];
            if(nx<0||nx>=W||ny<0||ny>=H) continue;
            if(fi[ny][nx]=='#') continue;
            if(dist[ny][nx]==-1){
                dist[ny][nx] = dist[y][x]+1;
                que.push(pint(nx,ny));
            }
        }
    }
    if (dist[H-1][W-1] == -1) cout << -1 << endl;
    else  cout << wnum - dist[H-1][W-1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define IO ios::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define ull unsigned long long
#define up(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define down(a,b,c) for(ll (a)=(b)-1;(a)>=(c);(a)--)
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define mii map<int,int>
#define mll map<ll,ll>
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define debug(x) cout << "\t" << (#x) << " = " << (x) << endl
#define debugl(x,y) cout << "on loop " << (#x) << " : " << (x) << ", " << (#y) << " = " << (y) << endl 
#define N 300050

using namespace std;

int pali(string s){
	string temp=s;
	reverse(temp.begin(),temp.end());
	if(temp==s) return 1;
	return 0;
}

int main(){
	IO;
	string s;
	cin >> s;
	int flag=1;
	flag=flag&pali(s);
	string temp="";
	up(i,0,(s.length()-1)/2){
		temp+=s[i];
	}
//	debug(temp);
	flag=flag&pali(temp);
	temp="";
	up(i,(s.length()+3)/2-1,s.length()){
		temp+=s[i];
	}
//	debug(temp);
	flag=flag&pali(temp);
	if(flag) cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn= new Scanner(System.in);
		long  x = scn.nextLong();
		long cur =100;
		int cnt =0;
		while(cur<x){
			cur+=cur*0.01;
			cnt++;
		}

		System.out.println(cnt);
	}

}

Measured memory_bytes: 35740
#include <iostream>
#include <queue>
#include <type_traits>
#include <functional>
#include <algorithm>

using ll=long long int;

constexpr int MAX_N=(int)1e5;

constexpr ll INF=-(ll)1e15;

template<bool B>
using Q = std::priority_queue<int,std::vector<int>,std::conditional_t<B,std::greater<>,std::less<>>>;

Q<true> firstHalf;
Q<false> secondHalf;

ll f[MAX_N*3],s[MAX_N*3];

int n;

int a[MAX_N*3];

int main() {

    std::cin.tie(0);
    std::ios::sync_with_stdio(false);

    std::cin>>n;

    for(int i=0;i<n*3;++i)
        std::cin>>a[i];

    ll res = 0;

    for(int i=0;i<n*3;++i){
        if(i<n){
            firstHalf.emplace(a[i]);
            res+=a[i];
        }
        else if(firstHalf.top()<a[i]){
            res+=a[i]-firstHalf.top();
            firstHalf.emplace(a[i]);
            firstHalf.pop();
        }
        f[i]=res;
    }

    res=0;

    for(int i=n*3-1;i>=0;--i){
        if(i>=n*2){
            secondHalf.emplace(a[i]);
            res+=a[i];
        }
        else if(secondHalf.top()>a[i]){
            res+=a[i]-secondHalf.top();
            secondHalf.emplace(a[i]);
            secondHalf.pop();
        }
        s[i]=res;
    }

    ll ans=INF;

    for(int i=n-1;i<n*2;++i){
        ans=std::max(ans,f[i]-s[i+1]);
    }

    std::cout<<ans<<std::endl;

    return 0;
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;


int main() {
  int A, B;
  cin >> A >> B;
  for(int i = 1;; i++) {
    int latte = i * (i + 1) / 2;
    int malta = (i + 1) * (i + 2) / 2;
    if(malta - latte == B - A) {
      cout << malta - B << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
let ans, n = ref min_int, read_int ()
let h m = Array.(init n @@ fun _ -> init m @@ fun _ -> Scanf.scanf " %d" (+) 0)
let fss = h 10
let pss = h 11
let f i j b = (b lsr (2 * i + j)) land 1
let c n b = let s = ref 0 in for i = 0 to 4 do for j = 0 to 1 do s := !s + fss.(n).(i * 2 + j) * f i j b done done; !s
let g b = let p = ref 0 in for i = 0 to n - 1 do p := !p + pss.(i).(c i b) done; !p
let _ = for b = 1 to 1 lsl 10 - 1 do ans := max !ans @@ g b done; Printf.printf "%d\n" !ans

Measured memory_bytes: 1024
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    N = int(input())
    H = list(map(int, input().split())) + [float('inf'), float('inf')]

    minCost = [float('inf')] * (N + 2)
    minCost[0] = 0

    for i in range(N):
        minCost[i + 1] = min(minCost[i + 1], minCost[i] + abs(H[i] - H[i + 1]))
        minCost[i + 2] = min(minCost[i + 2], minCost[i] + abs(H[i] - H[i + 2]))

    print(minCost[N - 1])


sol()

Measured memory_bytes: 14612
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
using namespace std;
int a[110],b[110],c[110];
char x[110],y[110];
void ff(char z[110])
{
    int d=strlen(z);
    for(int i=0;i<d/2;i++)
    {
        swap(z[i],z[d-1-i]);
    }

}
int main()
{
   int n;
   scanf("%d",&n);
   while(n--)
   {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       memset(c,0,sizeof(c));
       scanf("%s%s",x,y);
      ff(x),ff(y);
     for(int i=0;i<strlen(x);i++)
     {
         a[i]=x[i]-'0';
     }
     for(int i=0;i<strlen(y);i++)
     {
         b[i]=y[i]-'0';
     }
     int d=0,s;
      for(int i=0;i<110;i++)
      {
          s=a[i]+b[i]+d;
         c[i]=s%10;
         d=s/10;
      }
      int p=0;
      for(int i=109;i>=0;i--)
      {
          if(c[i])
          {
              p=i;
              break;
          }
      }
      if(p>=80)
      {
          printf("overflow\n");
         
      }
      else
        {
          for(int i=p;i>=0;i--)
          {
              printf("%d",c[i]);
          }
          printf("\n");
      }
   }
}

Measured memory_bytes: 3160
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  string s;
  cin >> n >> s;

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

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


int main(){
   int X, Y, Z;
   cin >> X >> Y >> Z;
   int tmp;
   tmp = Y;
   Y = X;
   X = Z;
   Z = tmp;
   cout << X << " " << Y  << " " << Z;
}

Measured memory_bytes: 3600
//    Have a nice day
//    ∠( ᐛ 」∠)

#include<bits/stdc++.h>

#define mp make_pair
#define pb push_back
#define x first
#define y second

using namespace std;

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

template <typename T> inline T read()
{
	T sum=0, fl=1; char ch=getchar();
	for(; !isdigit(ch); ch=getchar()) if(ch=='-') fl=-1;
	for(; isdigit(ch); ch=getchar()) sum=(sum<<3)+(sum<<1)+ch-'0';
	return sum*fl;
}

const int maxn=2e5+5;
const int inf=2147483647;
int n;
int lg[maxn], ans[maxn]; set<int>S; 
priority_queue<pii, vector<pii>, greater<pii> >Q;

inline pii min(const pii&a, const pii&b) { return a.x<b.x ? a : b; }

struct RMQ
{
	pii mn[20][maxn];
	void init()
	{
		for(int i=1; i<=lg[n]; ++i)
			for(int j=1; j+(1<<i)-1<=n; ++j)
				mn[i][j]=min(mn[i-1][j], mn[i-1][j+(1<<(i-1))]);
	}
	pii query(int l, int r)
	{
		assert(l<=r);
		int Log=lg[r-l+1]; 
		return min(mn[Log][l], mn[Log][r-(1<<Log)+1]);
	}
} k[2]; //0:   1:even

void Solve()
{
	n=read<int>();
	for(int i=2; i<=n; ++i) lg[i]=lg[i>>1]+1;
	for(int i=1; i<=n; i+=2) 
	{
		k[0].mn[0][i]=mp(read<int>(), i);
		k[1].mn[0][i+1]=mp(read<int>(), i+1);
		k[0].mn[0][i+1]=mp(inf, inf);
		k[1].mn[0][i]=mp(inf, inf);
	}
	k[0].init(), k[1].init();
	
	Q.push(k[0].query(1, n)); S.insert(0); S.insert(n+1);
	for(int i=1; i<=n; i+=2)
	{
		pii p=Q.top(); Q.pop(); 
		int r=*S.lower_bound(p.y), l=*(--S.lower_bound(p.y));
		pii t=k[p.y&1].query(p.y+1, r-1);
		ans[i]=p.x; ans[i+1]=t.x;
		S.insert(p.y); S.insert(t.y);
		if(l+1!=p.y) Q.push(k[t.y&1].query(l+1, p.y-1));
		if(p.y+1!=t.y) Q.push(k[p.y&1].query(p.y+1, t.y-1));
		if(t.y+1!=r) Q.push(k[t.y&1].query(t.y+1, r-1));
	}
	for(int i=1; i<=n; ++i) printf("%d ", ans[i]);
}

inline void proc_status ()
{
	ifstream t ("/proc/self/status");
	cerr << string (istreambuf_iterator <char> (t), istreambuf_iterator <char> ()) << endl;
}

int main()
{

//    freopen("080e.in","r",stdin);
//    freopen("080e.out","w",stdout);

    Solve();

	//proc_status();

    return 0;
}



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

d = [0] * 100
for n in range(1, N+1):
  for p in range(2, 100):
    while n % p == 0:
      d[p] += 1
      n /= p

ans = 0

# 75 = 5 * 5 * 3
for i in range(100):
  for j in range(100):
    for k in range(100):
      if i < j and i != k and j != k:
        if d[i] >= 4 and d[j] >= 4 and d[k] >= 2:
          ans += 1

# 25 * 3
for i in range(100):
  for j in range(100):
    if i != j:
      if d[i] >= 24 and d[j] >= 2:
        ans += 1

# 5 * 15
for i in range(100):
  for j in range(100):
    if i != j:
      if d[i] >= 4 and d[j] >= 14:
        ans += 1

# 75
for i in range(100):
  if d[i] >= 74:
    ans += 1

print(ans)




Measured memory_bytes: 3064
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))


def can_construct(limit):
    if limit == 1:
        m = 0
        ok = True
        for a in A:
            if a <= m:
                ok = False
            m = a
        return ok

    # (長さ、文字種)
    stack = [[0, -IINF]]
    for a in A:
        popped = False
        while a < stack[-1][0]:
            stack.pop()
            popped = True
        l, c = stack[-1]
        if a > l:
            stack.append([a, 2 if popped else 1])
        elif a == l:
            stack[-1] = [l, c + 1]
        else:
            assert False

        # limit + 1 進数みたいにする
        if stack[-1][1] > limit:
            j = 0
            n = stack[-1][0]
            while stack[-1 - j][1] > limit and stack[-1 - j][0] >= n - j:
                stack[-1 - j][1] = 1
                j += 1
                if stack[-1 - j][0] == n - j:
                    stack[-1 - j][1] += 1
                else:
                    stack.insert(- j, [n - j, 2])
        # print(stack)
        # print()
        if stack[0][1] > -IINF:
            return False
    return True


ng = 0
ok = N
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if can_construct(mid):
        ok = mid
    else:
        ng = mid
print(ok)


Measured memory_bytes: 131452
mod = 998244353
n,m,k = map(int, input().split())
def setFact(n, mod):
    global fact
    global ifact
    fact = [0]*(n+1)
    fact[0] = 1
    ifact = [0] * (n+1)
    for i in range(1, n+1):
        fact[i] = (fact[i-1]*i)%mod
    ifact[n] = pow(fact[n], mod-2, mod)
    for i in range(1, n+1):
        ifact[n-i] = ifact[n-i+1]*(n-i+1)%mod
def combination(n, k, mod):
    global fact
    global ifact
    if k < 0 or k > n:
        return 0
    else:
        return fact[n]*ifact[n-k]*ifact[k]%mod
setFact(n, mod)
ans = 0
now = pow(m-1, n-1-k, mod)
for i in range(k, -1, -1):
    ans = (ans + m*now*combination(n-1, i, mod)) %mod
    now *= m-1
    now %= mod
print(ans)

Measured memory_bytes: 74348
#include<stdio.h>
#include<iostream>
using namespace std;

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

Measured memory_bytes: 3084
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#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>;

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(){
    string s, t; cin >> s >> t;
    bool okay = true;
    int l = s.length();
    map<char, char> mps, mpt;
    // mps: key s[i], value t[i] mpt: vice versa
    REP(i, l){
        if(mps.find(s[i]) != mps.end()){
            if(t[i] != mps[s[i]]) okay = false;
        }
        else mps[s[i]] = t[i];

        if(mpt.find(t[i]) != mpt.end()){
            if(s[i] != mpt[t[i]]) okay = false;
        }
        else mpt[t[i]] = s[i];
    }
    cout << (okay ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 776
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
Scanner s = new Scanner(System.in);
		int N = Integer.valueOf(s.next());
		long D = Long.valueOf(s.next());
		long[] x = new long[N];
		long[] y = new long[N];
		for(int i = 0; i < N; i++) {
			x[i] = Long.valueOf(s.next());
			y[i] = Long.valueOf(s.next());
		}
		int ret = 0;
		long d = D * D;
		for(int i = 0; i < N; i++) {
			if(d >= ((x[i] * x[i]) + (y[i] * y[i]))) {
				ret++;
			}
		}
		System.out.println(ret);
	}
}

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

int main(){
    int N,M;
    cin>>N>>M;
    int arr[M];
    int sum = 0;
    for(int i =0;i<M;i++){
        cin>>arr[i];
        sum += arr[i];
    }
    if(sum > N)
        cout<<"-1"<<endl;
    else
    {
        cout<<N-sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 3588
import java.util.*;
public class Main{
	public void solve(){
		Scanner sc = new Scanner(System.in);
		int[] pos = new int[20];
		int[] d = new int[20];
		int[] exit = new int[20];
		while(true){
			int N = sc.nextInt();
			int L = sc.nextInt();
			if(N == 0 && L == 0) break;
			for(int i = 0; i < N; i++){
				d[i] = sc.next().equals("L") ? -1 : 1;
				pos[i] = sc.nextInt();
			}
			boolean flg = true;
			int time = 0;
			while(flg){
				flg = false;
				time++;
				for(int i = 0; i < N; i++){
					if(pos[i] != -1){
						pos[i] += d[i];
						if(pos[i] == 0 || pos[i] == L){
							pos[i] = -1;
							exit[i] = time;
						}else{
							flg = true;
						}
					}
				}
				for(int i = 0; i < N; i++){
					if(pos[i] == -1) continue;
					for(int j = i + 1; j < N; j++){
						if(pos[j] == -1) continue;
						if(pos[i] == pos[j]){
							d[i] *= -1;
							d[j] *= -1;
						}
					}
				}
			}
			int last = 0;
			int li = 0;
			for(int i = 0; i < N; i++){
				if(exit[i] > last){
					li = i;
					last = exit[i];
				}else if(exit[i] == last && d[i] == -1){
					li = i;
					last = exit[i];
				}
			}
			System.out.println(last + " " + (li + 1));
		}
	}
	
	public static void main(String[] args){
		new Main().solve();
	}
}

Measured memory_bytes: 31772
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

int main(){
  int n; cin >> n;
  vector<ull> a(n);
  for(int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  if(a[0] == 0){
    cout << 0 << endl;
    return 0;
  }
  ull ans = 1;
  for(int i = 0; i < n; i++){
    ull temp = ans;
    ans *= a[i];
    if(temp != ans/a[i]){
      cout << -1 << endl;
      return 0;
    }
    if(ans > 1000000000000000000){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N,K,num;
  num=0;
  cin >> N >> K;

  for(int i=0 ; i<N ; i++) {
    int x;
    cin >> x;
    if (0<=x && x<=K/2)
      num+=2*x;
    else
      num+=2*(K-x);
    //cout << i << ":" << num <<endl;
  }
    cout << num << endl;
}


Measured memory_bytes: 256
##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(set(b))  重複を削除
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)]  a[0,0]
##v = [s[i: i+2] for i in range(0, len(s), 2)]
##  s="12345678" を v=["12","34","56","78"] にするイメージ
##s = "".join(list)リストを文字列に変換[""]は区切り文字
##a.sort(key=itemgetter(1))リストをソートできるよ(from operator import itemgetterが必要)
##sort_p = sorted(p) 昇順ソート

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy
# stdin = open("sample.txt")


MOD = 1000000007
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr
    
def main():
    a = int(stdin.readline().rstrip())
    if a >= 30:
        print("Yes")
    else:
        print("No")
main()

Measured memory_bytes: 27204
#include <iostream>
#include <math.h>

using namespace std;

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

    while(1){
        int n;
        bool flag = false;
        n = sqrt(x);

        for(int i = 1;i <= n;i++){
            if(i == 1)continue;
            if(x % i == 0)flag = true;
        }

        if(!flag)break;
        x++;
    }

    cout << x << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

int n;
int A[16];
int x[16][16], y[16][16];
int main() {
    cin>>n;
    REP(i, 0, n){
        cin>>A[i];
        REP(j, 0, A[i]){
            cin>>x[i][j]>>y[i][j];
            x[i][j]--;
        }
    }

    int cnt=0;
    REP(bit, 0, 1<<n){
        bool allTrue=true;
        REP(i, 0, n){
            // 本当のことを言っていると仮定
            if(bit & (1<<i)){
                REP(j, 0, A[i]){
                    if((bool)y[i][j] ^ (bool)(bit & (1<<x[i][j]))){
                        allTrue=false;
                        break;
                    }
                }
            }
          
            if(!allTrue) break;
        }

        if(allTrue){
            int cntT=0;
            REP(i, 0, n){
                if(bit & (1<<i)) cntT++;
            }
            cnt=max(cnt, cntT);
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
string n;
char ch;
int main()
{
	cin>>n;
	for(int i=0;i<n.size();i++)
	{
		if(i==0)cout<<n[i];
		if(i==n.size()-1)ch=n[i];
	}
	cout<<n.size()-2<<ch<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
#include<iostream>
#include<cstring>
#include <algorithm>
using namespace std;
int main(){
    int n,a,b;
    string x,mi,xs;
    cin>>x>>n;
    for(int i=0;i<n;i++){
        cin>>mi>>a>>b;
        if(mi=="print"){
        cout<<x.substr(a,b-a+1)<<endl;
        }
        else if(mi=="reverse"){
            reverse(x.begin()+a,x.begin()+b+1);
        }
        else if(mi=="replace"){
            cin>>xs;
            x=x.replace(a,b-a+1,xs);
        }
    }
}


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

int main(){
    char a;
    char b;
    cin >> a >> b;
 
  
  if (a == b) {
    if (a == 'H' || a == 'D') {
      cout << 'H' << endl;
    }
  }
  else {
      cout << 'D' << endl;
  }
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<fstream>
#define vi vector<int>
#define vii vector<vi>
#define ll long long
#define vl vector<ll>
#define vll vector<vl>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define pb push_back
#define sz(v) (int)v.size()
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
using namespace std;
int main(){
	CIN;
	ll n,m;
	cin >> n >> m;
	vll v(n,vl(m));
	rep(i,0,n){
		rep(j,0,m){
			cin >> v[i][j];
		}
	}
	ll koko=0;
	rep(i,0,n){
		rep(j,i+1,n){
			ll sum = 0;
			rep(k,0,m){
				sum += (v[i][k]-v[j][k])*(v[i][k]-v[j][k]);
			}
			if(sqrt(sum)==ceil((double)sqrt(sum))){
				koko++;
			}
		}
	}
	cout<< koko;
}

Measured memory_bytes: 256
n = gets.to_i
as = gets.split.map(&:to_i)
tmp = []
as.each_with_index do |a, i|
  tmp << a - (i+1)
end
b = tmp.sort[n/2]
ans = 0
as.each_with_index do |a, i|
  ans +=  (a - (b+i+1)).abs
end
puts ans


Measured memory_bytes: 20792
#

import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def solve(positions, s, t):

    if not set(t) <= set(s):
        return -1

    loop = 0
    prev = -1

    for tchar in t:
        candidates = positions[tchar]
        pos = bisect.bisect_right(candidates, prev)

        if pos == len(candidates):
            loop += 1
            pos = 0
        prev = candidates[pos]

    return loop * len(s) + prev + 1


def main():
    s = input()
    t = input()

    positions = defaultdict(list)
    for i in range(len(s)):
        positions[s[i]].append(i)

    print(solve(positions, s, t))


if __name__ == '__main__':
    main()


Measured memory_bytes: 58184
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

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

	vector<int> t(d);
	rep(i, d) cin >> t[i];

	vector<int> a(n), b(n), c(n);
	rep(i, n) cin >> a[i] >> b[i] >> c[i];

	int dp[205][205];
	rep(i, 205) rep(j, 205) dp[i][j] = -1;

	rep(i, n) {
		if(a[i] <= t[0] && t[0] <= b[i]) dp[0][i] = 0;
	}

	REP(i, 1, d) {
		rep(j, n) {
			if(a[j] <= t[i] && t[i] <= b[j]) {
				rep(k, n) {
					if(dp[i-1][k] == -1) continue;
					dp[i][j] = max(dp[i][j], dp[i-1][k] + abs(c[k] - c[j]));
				}
			}
		}
	}

	// rep(i, d + 1) {
	// 	rep(j, n) cout << dp[i][j] << " ";
	// 	cout << endl;
	// }

	int ans = 0;
	rep(i, n) {
		ans = max(ans, dp[d-1][i]);
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1360
import sys
input = sys.stdin.buffer.readline

class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def nhr(self, n, r):  # 重複組合せ
        return self.ncr(n + r - 1, n - 1)

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

    def factInvN(self, n):
        if n < 0:
            return 0
        return self.factInv[n]

N = int(input())
MOD = 10**9 + 7
comb = Combination(N + 100)

edges = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    fr, to = map(int, input().split())
    edges[fr].append(to)
    edges[to].append(fr)

order = []
parent = [0] * (N + 1)
st = [1]
while st:
    now = st.pop()
    order.append(now)
    for to in edges[now]:
        if to == parent[now]:
            continue
        st.append(to)
        parent[to] = now

size = [1] * (N + 1)
for v in order[::-1]:
    size[parent[v]] += size[v]

dpLeaf = [1] * (N + 1)
for v in order[:: -1]:
    pr = parent[v]
    dpLeaf[v] = dpLeaf[v] * comb.factN(size[v] - 1) % MOD
    dpLeaf[pr] = dpLeaf[pr] * dpLeaf[v] * comb.factInvN(size[v]) % MOD

ans = [0] * (N + 1)
ans[1] = dpLeaf[1]
for v in order[1:]:
    pr = parent[v]
    ans[v] = ans[pr] * comb.factN(N - 1 - size[v]) * comb.factInvN(N - size[v]) * size[v] % MOD

print(*(ans[1:]), sep='\n')

Measured memory_bytes: 86544
import java.util.*;

public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
  int x=sc.nextInt();
  if(360%x==0){
System.out.print(360/x);
  }else{
    int i=1;
while(true){
int y=x*i;
if(y%360==0){
System.out.print(i);
  break;
}
i++;
}

  }
}
}


Measured memory_bytes: 35480
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

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

	int ans = 0;
	while (1) {
		if (ans == 100000)
			break;
		int A1 = ans * 0.08;
		int B1 = ans * 0.1;
		if (A == A1 && B == B1)
			break;
		ans++;
	}
	if (ans == 100000)
		ans = -1;

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

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int x,y;
	while(1){
		scanf("%d %d",&x,&y);
		if(x == 0 && y == 0)
		break;
		
		for(int i = 0; i < x; i++){
			for(int j = 0; j < y; j++){
				if((i + j) %2 == 0){ //偶数の場合
					printf("#");
				}else {              //奇数の場合
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2056
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

//#include<boost/circular_buffer.hpp>
using namespace std;

//cout << fixed << setprecision(10);
typedef long long ll;
#define PI 3.141592653589793
#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

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

int lcm(int a, int b) {
	long long int L;
	L = (a * b) / gcd(a, b);
	return L;
}

vector<long long  int> Prime;
void Eratosthenes(long long int n) {
	vector<bool> is_prime(n, true);
	for (int i = 2; i * i <= n; i++) {
		;
		if (is_prime.at(i)) {
			for (int j = i * i; j <= n; j += i) {
				is_prime.at(j) = false;
			}
		}
		Prime.emplace_back(i);
	}
}

/*
map<int, int> prime;
void Prime_number(long long int n) {
	for (int i = 2; i <= n; i++) {
		int count = 0;
		while (n % i == 0) {
			count++;
			n /= i;
		}
		if (count != 0) {
			prime.insert(make_pair(i, count));
		}
	}
}
*/
//std::cout.fill('0');

int keta(long long int N) {
	int k = 0;
	while (N > 0) {
		N /= 10;
		k++;
	}
	return k;
}



int Combination(int n, int m) {
	long long int s = 1, t = 1;
	int tmp = n;
	while (n - m != tmp) {
		s *= tmp;
		tmp--;
	}
	tmp = m;
	while (tmp != 1) {
		t *= tmp;
		tmp--;
	}
	return s / t;
}

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c >= 22)
		cout << "bust" << endl;
	else
		cout << "win" << endl;

	
}

Measured memory_bytes: 256
s = input()
a = int(s[:2])
b = int(s[2:])


if 1<=a<=12 and 1<=b<=12:
  print('AMBIGUOUS')
elif 1<=a<=12:
  print('MMYY')
elif 1<=b<=12:
  print('YYMM')
else:
  print('NA')

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;

int main (){
  ll n;
  ll ans=0;
  cin>>n;
  vector<ll>l(n,0);
  ll x=0;
  ll sum=0;
  for(ll i=0;i<n;i++){
    cin>>l[i];
    x=max(x,l[i]);
    sum+=l[i];
  }
  if(sum>x*2){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

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

Measured memory_bytes: 572
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define tcase int _; cin >> _; while(_--)
const int MAX = 3e6;

int n;
int v[MAX], s[MAX], vv[MAX];

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

void solve() {
	memset(v, 0, sizeof v);
	cin >> n;
	for(int i=0; i<n; i++) {
		int x;
		cin >> x;
		v[x]++;
		vv[i] = x;
	}
	
	memset(s, 0, sizeof s);
	s[0] = s[1] = 1;
	int ok=1;
	for(int i=2; i<MAX; i++) {
		if(s[i]) continue;
		int cnt = v[i];
		for(int j=2*i; j<MAX; j+=i) {
			s[j] = 1;
			cnt += v[j];
		}
		if(cnt > 1) ok = 0;
		// cout << i << endl;
	}
	// cout << "ok" << endl;
	if(ok) {
		cout << "pairwise coprime";
		return;
	}
	
	int a = vv[0];
	for(int i=1; i<n; i++) {
		a = gcd(vv[i], a);
	}

	if(a == 1) cout << "setwise coprime";
	else cout << "not coprime";
}

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

 	solve();

  	return 0;
}



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

#define DEBUG(x) cout << #x << ": " << x << endl;
#define DEBUG_VEC(v)                                      \
  cout << #v << ":";                                      \
  for (int i = 0; i < v.size(); i++) cout << " " << v[i]; \
  cout << endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int> >
#define vll vector<vector<ll> >
#define vs vector<string>
#define pii pair<int, int>
#define pis pair<int, string>
#define psi pair<string, int>
const int inf = 1000000001;
const ll INF = 1e18;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout << setprecision(15) << fixed << p << endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy2[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(){
  int n, i, j;
  cin >> n;
  vl a(n), b(n), c(n);
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  for(i=0;i<n;i++){
    cin >> b[i];
  }
  for(i=0;i<n;i++){
    cin >> c[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  vl dpb(n), dpa(n + 1);
  dpa[0] = 0;
  for (i = 0; i < n; i++){
    dpb[i] = lower_bound(b.begin(), b.end(), c[i]) - b.begin();
    dpa[i + 1] = dpa[i] + lower_bound(a.begin(), a.end(), b[i]) - a.begin();
  }
  //DEBUG_VEC(dpb);
  ll ans = 0;
  for (i = 0; i < n; i++){
    ans += dpa[dpb[i]];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4224
#include <stdio.h>

int main(void) {
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a!=b && b!=c && c!=a)
	   printf("3");
	   
	else if(a==b && b!=c)
	  printf("2");
	  
	else if(a==c && c!=b)
	   printf("2");
	   
	else if(b==c && c!=a)
	    printf("2");
	    
	else
	   printf("1");
	  
	
	return 0;
}

Measured memory_bytes: 128
# ARC090C - Candies (ABC087C)
def main():
    N = int(input())
    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(2))
    dp = [0] * N  # dp[i] := score of upside [:i+1] and downside [i:]
    for i in range(N):
        dp[i] = sum(A[0][: i + 1]) + sum(A[1][i:])
    print(max(dp))


if __name__ == "__main__":
    main()

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

int main() {
	int N, L; cin >> N >> L;
  	int cur = 0;
  	int res = 1;
  	for (int i = 0; i < N; ++i) {
    	int x; cin >> x;
      	cur += x;
      	if (cur <= L)
          	++res;
    }
 	cout << res;
}

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

int main()
{
	double a,b,h,m;
	cin>>a>>b>>h>>m;

	double k = abs(h*30+m/2-m*6);
	k = min(k,360-k);
	double pi = acos(-1.0);
	double ans = a*a+b*b-a*b*2*cos(k/180.0*pi);
	cout<<fixed<<setprecision(15)<<sqrt(ans);
	return 0;
}

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

#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d %d", &a, &b)
#define sll(a) scanf("%lld", &a)
#define sll2(a, b) scanf("%lld %lld", &a, &b)
#define mem(a, i) memset(a, i, sizeof(a))
#define pb push_back
#define int long long
#define ll long long
#define lson node << 1
#define rson (node << 1) + 1
#define endl "\n"

const int maxn = 5e4 + 10;
const int mod = 998244353;
const double pi = acos(-1);

int gcd(int a, int b)
{
  return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b)
{
  return a * b / gcd(a, b);
}

int qpow(int a, int n)
{
  int b = 1;
  while (n)
  {
    if (n & 1)
      b = a * b % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return b;
}

class Prime_Number
{
public:
  int prime[maxn], s, v[maxn];
  void prime_init(int n)
  {
    for (int i = 2; i <= n; i++)
    {
      if (!v[i])
      {
        prime[s++] = i;
        for (int j = 1; j * i <= n; j++)
          v[i * j] = 1;
      }
    }
  }
};

int p[maxn], a[maxn];
int v[maxn];
vector<int> huan[maxn];
int q[maxn];
int js(int x, int k)
{
  int K = k;
  int sz = huan[x].size();
  q[0] = a[huan[x][0]];
  for (int i = 1; i < sz; i++)
    q[i] = q[i - 1] + a[huan[x][i]];
  int ans;
  ans = (k / sz) * q[sz - 1];
  int flag = 1;
  if (k < sz)
    flag = 0;
  else if (ans < 0)
    k = min(k, sz), flag = 0;
  else
    k = min(k, sz);
  int sum = -1e18;
  for (int y = 0; y <= k; y++)
  {
    if (y == 0)
      {if (q[sz - 1] > 0 && K >= sz)
      {
        sum = (K / sz) * q[sz - 1];
      }
      continue;
      }
    for (int j = 0; j < sz; j++)
    {
      if (j < y)
      {
        if (q[sz - 1] > 0)
          sum = max(sum, q[j] + q[sz - 1] - q[sz - (y - j)] + ((K - y) / sz) * q[sz - 1]);
        else
          sum = max(sum, q[j] + q[sz - 1] - q[sz - (y - j)]);
      }
      else
      {
        if (q[sz - 1] > 0)
          sum = max(sum, q[j] - q[j - y] + ((K - y) / sz) * q[sz - 1]);
        else
          sum = max(sum, q[j] - q[j - y]);
      }
    }
  }
  return sum;
}
void solve()
{
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    sll(p[i]);
  for (int i = 1; i <= n; i++)
    sll(a[i]);
  int s = 0;
  for (int i = 1; i <= n; i++)
    if (!v[i])
    {
      int next = p[i];
      v[i] = 1;
      huan[s].push_back(i);
      while (!v[next])
      {
        v[next] = 1;
        huan[s].push_back(next);
        next = p[next];
      }
      s++;
    }
  int ans = -1e18;
  for (int i = 0; i < s; i++)
    ans = max(ans, js(i, k));
  printf("%lld\n", ans);
}
signed main()
{
  solve();
  return 0;
}


Measured memory_bytes: 5312
N,K = map(int,input().split())
H = list(map(int,input().split()))
INF = float('inf')
dp = [INF] * N
dp[0] = 0
for i in range(N-1):
    for j in range(1,K+1):
        if i+j >= N: break
        dp[i+j] = min(dp[i+j], dp[i] + abs(H[i] - H[i+j]))
print(dp[-1])

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (d >= abs(a - c) || (d >= abs(a - b) && d >= abs(b - c)))
    cout << "Yes" << '\n';
  else
    cout << "No" << '\n';
  return 0;
}


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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 3e5+23;

set<pair<int, int>> s;
pair<int, int> H[N], W[N];

void solve() {
  int h, w, m; scanf("%d%d%d", &h, &w, &m);
  for (int i = 0; i < m; ++i) {
    int x, y; scanf("%d%d", &x, &y);
    s.emplace(--x, --y);
    ++H[x].first;
    ++W[y].first;
  }
  for (int i = 0; i < h; ++i)
    H[i].second = i;
  for (int i = 0; i < w; ++i)
    W[i].second = i;
  sort(H, H+h, greater<pair<int, int>>());
  sort(W, W+w, greater<pair<int, int>>());
  int ans = 0;
  for (int i = 0; i < h; ++i) {
    if (H[i].first < H[0].first) break;
    for (int j = 0; j < w; ++j) {
      if (W[j].first < W[0].first) break;
      int cur = H[i].first+W[j].first;
      if (s.count({H[i].second, W[j].second})) --cur;
      ans = max(ans, cur);
      if (ans == H[0].first+W[0].first) {
	goto end;
      }
    }
  }
 end:;
  printf("%d", ans);
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 22628
#include <stdio.h>

int main()
{
    int N, M, x, y;
    scanf("%d %d", &N, &M);
    
    x = 0.5*N*(N-1);
    y = 0.5*M*(M-1);
    
    printf("%d\n", x+y );

	
    return 0;
}

Measured memory_bytes: 1732
# n: スイッチの数
# m: ランプの数
n, m = gets.split.map(&:to_i)

# key: ランプ 
# value: スイッチのリスト
d = []
m.times do |i| 
  k, *s = gets.split.map{|s| s.to_i - 1 }
  d[i] = s
end

mods = gets.split.map(&:to_i)

ans = 0
(0..n).each do |k|
  [*0...n].combination(k) do |turn_on|
    ans += 1 if (0...m).all?{|i| (d[i] & turn_on).size % 2 == mods[i]}
  end
end

puts ans

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

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

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

    // start
    int x, a, b;
    cin >> x >> a >> b;
    if (abs(x - a) < abs(x - b))
        cout << "A" << endl;
    else
        cout << "B" << endl;
    // end

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<tuple<string, int,int>> data(n);
    for (int i = 0; i < n; i++){
        string a;
        int b;
        cin >> a >> b;
        data.at(i) = make_tuple(a,-1*b,i+1);
    }
    sort(data.begin(), data.end());
    for (int i = 0; i < n; i++){
        cout << get<2>(data.at(i)) << endl;
    }
}


Measured memory_bytes: 3628
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]
max = 0
for i in range(1,2 ** 10):
    tmp = 0
    for j in range(N):
        count = 0
        for k in range(10):
            if (1 & i>>k) and (F[j][k] == 1):
                count += 1
        tmp += P[j][count]
    if i == 1:
        max = tmp
        continue
    if max < tmp:
        max = tmp
print(max)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
	//cin >> t;
	//while(t--) {
	s = "";
		cin >> s;
		//ans = 0;
		if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R'){
			cout << "3\n";
			return 0;
		} else if((s[0] == 'R' && s[1] == 'R') || (s[2] == 'R' && s[1] == 'R')){
			cout << "2\n";
			return 0;
		} else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R'){
			cout << "1\n";
			return 0;
		} else
			cout << "0\n";
	//}
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 200005;

// 3: no walk yet;0;1;2.
int n,a[maxn];
ll f[maxn][5];

void pd(ll&ret,ll val){
  if(ret==-1L||ret>val)ret=val;
}

void solve(int i, int l,int r){
  int add;
  if(l==0){
    if(r==0)add=a[i];
    else add = -1;
  } else if(l==1){
    if(r==0)add=a[i]&1;
    else if(r==1)add=(a[i]+1)&1;
    else if(r==2||r==3){
      add=-1;
    }
    else{
      if(a[i]<2)add=2-a[i];
      else add=a[i]&1;
    }
  } else if(l==2){
    if(r==0)add=a[i]&1;
    else if(r==1)add=(a[i]+1)&1;
    else if(r==2){
      if(a[i]<2)add=2-a[i];
      else add=a[i]&1;
    } else add = -1;
  } else if(l==3){
    if(r==0||r==2){
      if(a[i]<2)add=2-a[i];
      else add=a[i]&1;
    } else if(r==1){
      add=(a[i]+1)&1;
    } else if (r==3){
      add=a[i];
    } else {
      if(a[i]<2)add=2-a[i];
      else add=a[i]&1;
    }
  } else {
    if(r==0){
      add=a[i]&1;
    } else if(r==4){
      if(a[i]<2)add=2-a[i];
      else add=a[i]&1;
    } else add = -1;
  }
  if(add!=-1)pd(f[i][r],f[i-1][l]+add);
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i];
  memset(f,-1,sizeof(f));
  f[0][3] = 0;
  for(int i=0;i<n;i++){
    for(int j=0;j<5;j++){
      if(f[i][j]==-1L)continue;
      for(int k=0;k<5;k++){
        solve(i+1,j,k);
      }
    }
  }
  ll ret = f[n][0];
  for(int i=1;i<5;i++)if(f[n][i]!=-1L)pd(ret, f[n][i]);
  cout<<ret<<endl;
  //cout<<f[5][0]<<endl;
  return 0;
}

Measured memory_bytes: 8960
#!/usr/bin/env python3
#ABC83 D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
n = len(s)
res = inf
for i in range(n-1):
    if s[i] != s[i+1]:
        res = min(res,max(n-i-1,i+1))
if res == inf:
    print(n)
else:
    print(res)

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

int main() {
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  
  int ans = 0;
  for(int i = 0; i <= A; ++i){
    for(int j = 0; j <= B; ++j){
      for(int k = 0; k <= C; ++k){
        int tmp = i * 500 + j * 100 + k * 50;
        if(tmp == X) ans++;
    }
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// 素因数分解：nの素因数分解を{素数, 指数}の形で昇順に返す。
vector<pair<long long, long long>> primeFactorize(long long n){
    vector<pair<long long, long long>> ret;
    for(long long i=2; i*i<=n; i++){
        if(n%i != 0) continue;
        long long ex = 0;
        while(n%i == 0){ ex++; n /= i; }
        ret.push_back({i, ex});
    }
    if(n != 1) ret.push_back({n, 1});
    return ret;
}

int main(){
    Init();
    ll n; cin >> n;
    map<ll, ll> exp;
    for(ll i=2; i<=n; i++){
        auto pf = primeFactorize(i);
        for(auto it :pf) exp[it.first] += it.second;
    }
    vvi dp(exp.size()+1, vi(76, 0));
    dp[0][1] = 1; ll pNum = 0;
    for(auto it: exp){
        for(ll i=1; i<=75; i++){
            for(ll j=1; j<=it.second+1; j++){
                if(i*j>75) break;
                dp[pNum+1][i*j] += dp[pNum][i];
            }
        }
        pNum++;
    }
    cout << dp[exp.size()][75] << endl;
}

Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 12 16:38:08 2020

@author: matsui
"""

N,K=map(int,input().split())
p=[int(num) for num in input().split()]

dp=[0]
S=0
for i in range(N):
    S+=(p[i]+1)/2
    dp.append(S)

M=0
for i in range(N-K+1):
    #print(i+K,i)
    if dp[i+K]-dp[i] > M: M=dp[i+K]-dp[i]
    
print(M)

Measured memory_bytes: 24548