akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//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())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

map<pair<string, string>, int> mp;

int main() {
	int n;
	string str;
	cin >> n >> str;
	LL ret = 0;
	REP(i, 1 << n) {
		string str1="", str2="";
		REP(j, n) {
			if (i & (1 << j))str1.push_back(str[j]);
			else str2.push_back(str[j]);
		}
		mp[MP(str1, str2)]++;
	}
	REP(i, 1 << n) {
		string str1 = "", str2 = "";
		REP(j, n) {
			if (i & (1 << j))str1.push_back(str[j+n]);
			else str2.push_back(str[j+n]);
		}
		reverse(ALL(str1));
		reverse(ALL(str2));
		if (mp[MP(str2, str1)] != 0) {
			ret += mp[MP(str2, str1)];
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 87040
#include <stdio.h>
int main(void){
	int h,n,i,sum=0;
	scanf("%d%d",&h,&n);
	int a[n+1];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	printf(sum<h?"No":"Yes");
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long
#define mp make_pair
int gcd(int a,int b){return b?gcd(b,a%b):a;}
signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(auto& i:a)cin>>i,--i;
  vector<int> num(n,-1);
  for(int i=0;i<n;++i){
    if(a[i]==0||num[a[i]-1]!=-1){
      num[a[i]]=i;
    }
  }
  for(int i=0;i<n;++i){
    if(num[i]<0)return cout<<(i?n-i:-1),0;
  }
  cout<<0;
}

Measured memory_bytes: 3328
# import itertools
# import math
# import sys
# sys.setrecursionlimit(500*500)
# import numpy as np

N = int(input())
# S = input()
# n, *a = map(int, open(0))
# N, M = map(int, input().split())
A = list(map(int, input().split()))
# B = list(map(int, input().split()))
# tree = [[] for _ in range(N + 1)]
# B_C = [list(map(int,input().split())) for _ in range(M)]
# S = input()

# B_C = sorted(B_C, reverse=True, key=lambda x:x[1])
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement(range(1, M + 1), N))
# itertools.product((0,1), repeat=n)

# A = np.array(A)
# cum_A = np.cumsum(A)
# cum_A = np.insert(cum_A, 0, 0)

# def dfs(tree, s):
#     for l in tree[s]:
#         if depth[l[0]] == -1:
#             depth[l[0]] = depth[s] + l[1]
#             dfs(tree, l[0])
# dfs(tree, 1)

# def factorization(n):
#     arr = []
#     temp = n
#     for i in range(2, int(-(-n**0.5//1))+1):
#         if temp%i==0:
#             cnt=0
#             while temp%i==0:
#                 cnt+=1
#                 temp //= i
#             arr.append([i, cnt])
#     if temp!=1:
#         arr.append([temp, 1])
#     if arr==[]:
#         arr.append([n, 1])
#     return arr

tot = 0
for i in A:
    tot ^=  i

for i in A:
    print(tot ^ i, sep = " ") 

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

int main(void) {
ll n,r=0,w=0;
cin >> n;
vector<char> vec(n);
rep(i,n) {
    cin >> vec.at(i);
    if (vec.at(i) == 'R') r++;
    else if (vec.at(i) == 'W') w++;
}
ll ans1 = 0,ans2 = 0;
rep(i,r) {
    if (vec.at(i) == 'W') ans1++;
}
for (int i = r;i < n;i++) {
    if (vec.at(i) == 'R') ans2++;
}
ll ans = max(ans1,ans2);
cout << ans << endl;


return 0;
}





Measured memory_bytes: 3604
fun main ( args : Array<String> ) {
  val (n, k) = readLine()!!.split(" ").map { x ->
    x.toLong()
  }
  val r = (1..n).mapIndexed {  i,x ->
    if(i == 0)
      k
    else
      k-1
  }.reduce { y,x ->
    y*x
  }
  println(r)
}


Measured memory_bytes: 37952
a,b=map(int,input().split())
if a%2==0:
  if b%2==1:
    print(((b-a+1)//2)%2)
  else:
    c=((b-a)//2)%2
    print(b^c)
else:
  if b%2 == 1:
    c=((b-a)//2)%2
    print(a^c)
  else:
    c=((b-a-1)//2)%2
    print((c^a)^b)



Measured memory_bytes: 3060
def e_rotation_matching():
    # 参考: https://maspypy.com/atcoder-参加感想-2020-05-02abc-165
    import numpy as np
    N, M = [int(i) for i in input().split()]

    A = np.arange(M)  # 剰余計算の簡便のため、0-origin とする
    B = 2 * M - 1 - A  # N >= 2*M - 1 だが、N = 2*M - 1 の場合と同じ構築でよい
    # 剰余を取ったときに mod N に対して A, B の全要素が互いに異なるようにしたい
    B[:M // 2] -= (2 * M + 1)

    A %= N  # 全要素は正整数でないといけない
    B %= N
    A += 1  # A, B は 0-origin としていたため
    B += 1
    return '\n'.join([f'{a} {b}' for a, b in zip(A.tolist(), B.tolist())])

print(e_rotation_matching())

Measured memory_bytes: 41976
n,k = map(int, input().split())
p = [ int(x) for x in input().split()]

sm = sum(p[:k])
adj_sum = [sm]
for i in range(k,n):
  sm -= p[i-k]
  sm += p[i]
  adj_sum.append(sm)
  
mx = max(adj_sum)
print((mx+k)/2)

Measured memory_bytes: 25188
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <limits>

using namespace std;

int main() {
  int N;
  double D;
  cin >> N >> D;
  
  int counter;
  counter = 0;
  
  for(int i = 0; i < N;i++){
   double X, Y;
      cin >> X >> Y ;
      if((X*X) + (Y*Y) <= D*D){
        counter = counter + 1;
      }
  }
  
  
  cout << counter <<endl;
}

Measured memory_bytes: 3796
import numpy as np

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

list_ = np.array([a, b, c, d, e])

list_mod = (list_-1) % 10

min_factor = np.argmin(list_mod)
Total =  0

for i, var in enumerate(list_):
  if i == min_factor or var % 10 == 0:
    Total += var
  else:
    Total += var + 10 - (var % 10)
    
print(Total)

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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;++i) cin >> a[i];
  auto tp=0,cnt=0;
  for(int i=0;i<n;++i){
    tp=a[tp]-1;
    cnt++;
    if(tp==1){
      cout << cnt << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};

// FHCまでにスタックオーバーフローの罠を解決する


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

    int n;
    cin>>n;
    vector<pair<int,string>> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i].second;
        a[i].first = a[i].second.size();
    }
    sort(a.begin(),a.end());

    const int mod1 = 1000000103, mod2 = 1000000483;
    int mul1=10009;
    int mul2=10007;

    unordered_map<int,int> mp1[26],mp2[26];
    ll ans = 0;
    int ma = 0;
    ll one[26]={};
    for(int i=0;i<n;i++){
        string s = a[i].second;
        if(s.size() == 1){
            one[s[0]-'a']++;
            continue;
        }
        ll h1=0;
        ll h2=0;
        int m = s.size(), c=26;
        int cnt[c][m+1]={};
        for(int j=0;j<m;j++){
            cnt[s[j]-'a'][j+1]++;
            for(int k=0;k<26;k++) cnt[k][j+1] += cnt[k][j];
        }
        // one
        for(int j=0;j<26;j++){
            if(cnt[j][m] == 0)continue;
            ans += one[j];
        }
        int now = 0;
        for(int j=m-1;j>=1;j--){
            now++;
            h1 = (ll)(h1*mul1 + s[j]) % mod1;
            h2 = (ll)(h2*mul2 + s[j]) % mod2;
            if(now > ma)continue;
            for(int k=0;k<26;k++){
                if(cnt[k][j] && mp1[k].count((int)h1) && mp2[k].count((int)h2)){
                    ans += min(mp1[k][h1],mp2[k][h2]);
                }
            }
        }
        chmax(ma,s.size());
        mp1[(int)(s[0]-'a')][h1]++;
        mp2[(int)(s[0]-'a')][h2]++;
    }
    cout << ans << endl;
    
}


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

int main() {
    int n, m;
    cin >> n >> m;
    char a[n][m];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> a[i][j];
        }
    }
    long long dp[n][m]={0};
    dp[0][0]=1;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(i==0&&j!=0){
                if(a[i][j]=='.'){
                    dp[i][j]=dp[i][j-1];
                }else{
                    dp[i][j]=0;
                }
            }else if(j==0&&i!=0){
                if(a[i][j]=='.'){
                    dp[i][j]=dp[i-1][j];
                }else{
                    dp[i][j]=0;
                }
            }
            else if(i==0&&j==0){
                dp[i][j]=1;
            }
            else{
                if(a[i][j]=='.'){
                    dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
                }else{
                    dp[i][j]=0;
                }
            }
        }
    }
    cout << dp[n-1][m-1]%1000000007 << endl;
	return 0;
}

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

int main(){
    int n;
    cin>>n;
    map<pair<int,int>,int> mp;
    for(int i=0;i<n;i++){
        int x,y,w;
        cin>>x>>y>>w;
        mp[{x,y}]=w;
    }
    ll res=0;
    for(auto &e:mp){
        int x=e.first.first,y=e.first.second;
        for(int i=-1;i<=1;i++){
            for(int j=-1;j<=1;j++){
                ll sc=0;
                for(int ii=0;ii<2;ii++){
                    for(int jj=0;jj<2;jj++){
                        if(mp.count({x+i+ii,y+j+jj})) sc+=mp[{x+i+ii,y+j+jj}];
                    }
                }        
                res=max(res,sc);
            }
        }
        
        
    }
    cout<<res<<" / 1"<<endl;
    return 0;
}


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

long long gcd(long long x, long long y){
    if(y == 0){
        return x;
    }

    return gcd(y, x%y);
}

long long lcm(long long x, long long y){

    return x/gcd(x,y)*y;
}

int main(){

    long long n;
    cin >> n;

    long long l = 1;
    long long sum = 0;
    for(long long i = 0; i < n; i++){
        long long a;
        cin >> a;
        sum += a-1;

        //l = lcm(a, l);
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
struct s{
  int num;
  char moji;
  int key;
};
struct s A[100001]; 
int Partition(int,int); 
void Quicksort(int,int);
main(){
  char c1,c2,c3;
  int n;
  int i,a,b=0;
  scanf("%d%c",&n,&c1);
  for(i=0;i<n;i++){
    scanf("%c%c%d%c",&A[i].moji,&c2,&A[i].num,&c3);
    A[i].key=i;
  }
  a = Partition(0,n-1);
  Quicksort(0,n-1);
  for(i=0;i<n;i++){
    if(A[i].key>A[i+1].key && A[i].num==A[i+1].num){
      b=1;
      break;
    }
  }
  if(b==0) printf("Stable\n");
  if(b==1) printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].moji,A[i].num);
  }
  return 0;
}

int Partition(int p,int r){
  int i,j;
  struct s x,tmp;
  x.num=A[r].num;
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j].num<=x.num){
      i=i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;
  return i+1;
}

void Quicksort(int p,int r){
  int q;
  if(p<r){
    q=Partition(p,r);
    Quicksort(p,q-1);
    Quicksort(q+1,r);
  }
}

Measured memory_bytes: 1780
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        int cnt = 0;
        for (int i = a; i <= b; i ++){
            if ((c % i) == 0)
                cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 26420
a = []
for i in iter(input, '0 0'):
    a.append(list(map(int, i.split())))
for i in range(len(a)):
    for j in range(a[i][0]):
        if j%2 == 0:
            for k in range(a[i][1]):
                if k%2 == 0:
                    print('#', end='')
                else:
                    print('.', end='')
            print()
        else:
            for k in range(a[i][1]):
                if k%2 == 0:
                    print('.', end='')
                else:
                    print('#', end='')
            print()
    print()


Measured memory_bytes: 7004
import math
 
while True:
  n = int(input())
  if n == 0:
    exit()
  else:
    x = list(map(int, input().split()))
    m = sum(x) / n
    S = 0
    for i in range(n):
      S += (x[i] - m) ** 2
    S /= n
  print(math.sqrt(S))


Measured memory_bytes: 5696
// SeeAlso: 

#include <bits/stdc++.h>

#define MAX 4
#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;

int x, a;

int main() {

    cin >> x >> a;

    if (x < a) {
      cout << "0" << endl;
    } else {
        cout << "10" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=2e6+5;
int inv[maxn+5],fac[maxn+5],facInv[maxn+5];
inline int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}
void setInv(int n)
{
    inv[0]=inv[1]=1;
    for (int i=2;i<=n;i++)
        inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
}
void setFac(int n)
{
    fac[0]=1; facInv[0]=1;
    for (int i=1;i<=n;i++) {
        fac[i]=1LL*fac[i-1]*i%mod;
        facInv[i]=1LL*facInv[i-1]*inv[i]%mod;
    }
}
int C(int n,int m)
{
    if (n<m) return 0;
    if (n<0||m<0) return 0;
    int ans=fac[n];
    ans=ans*1LL*facInv[m]%mod;
    ans=ans*1LL*facInv[n-m]%mod;
    return ans;
}
int calc(int x,int y)
{
    return (C(x+y+2,y+1)-1+mod)%mod;
}
int x1,yy1,x2,yy2;
int main()
{
    setInv(maxn);
    setFac(maxn);
    scanf("%d%d%d%d",&x1,&yy1,&x2,&yy2);
    int ans=0;
    ans=(ans+calc(x2,yy2))%mod;
    ans=(ans-calc(x1-1,yy2)+mod)%mod;
    ans=(ans-calc(x2,yy1-1)+mod)%mod;
    ans=(ans+calc(x1-1,yy1-1))%mod;
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 23680
N=int(input())
A=[]
for _ in range(N):
    A.append(list(map(int,input().split())))
count=0
for i in range(N):
    if A[i][0]==A[i][1]:
        count+=1
        if count==3:
            break
    else:
        count=0
if count==3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9184
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    int kinds;
    cin >> a;
    cin >> b;
    cin >> c;
    if(a == b && b == c){
        kinds = 1;
    }else if(a == b && b != c){
        kinds = 2;
    }else if(a != b && b == c){
        kinds = 2;
    }else if(a != b && a == c){
        kinds = 2;
    }else{
        kinds = 3;
    }
    cout << kinds << endl;
    return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    tmp0 = input[0].split(" ");
    N = Number(tmp0[0]);
     n = tmp0[0].substr(0, 1);
 var word= String(n)+String(n)+String(n);
    W = Number(word);
   if(N==W){console.log(N);}
       if(N>W){ console.log(W+111);}
        else if(N<W){console.log(W);}
}
           
 
  //*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
  Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//  

Measured memory_bytes: 7372
n = int(input())
have_s = []
have_h = []
have_c = []
have_d = []

for _ in range(n):
    item = input().split()
    if item[0]=="S":
        have_s.append(int(item[1]))
    if item[0]=="H":
        have_h.append(int(item[1]))
    if item[0]=="C":
        have_c.append(int(item[1]))
    if item[0]=="D":
        have_d.append(int(item[1]))

missing_s = [num for num in range(1, 14) if not num in have_s]
missing_h = [num for num in range(1, 14) if not num in have_h]
missing_c = [num for num in range(1, 14) if not num in have_c]
missing_d = [num for num in range(1, 14) if not num in have_d]

for rank in missing_s:
    print(f"S {rank}")
for rank in missing_h:
    print(f"H {rank}")
for rank in missing_c:
    print(f"C {rank}")
for rank in missing_d:
    print(f"D {rank}")


Measured memory_bytes: 5632
N, K = map(int, input().split())
A = list(map(int, input().split()))
Asum = sum(A)

div = set()
for i in range(1, int(Asum ** 0.5 + 0.5) + 1):
    if Asum % i == 0:
        div.add(i)
        div.add(Asum//i)

ans = 1
for d in div:
    R = [a % d for a in A]
    R.sort()
    r = sum(R) // d
    l = N - r
    need = sum(R[:l])
    if need <= K:
        ans = max(ans, d)
print(ans)


Measured memory_bytes: 3188
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
using ll = long long;
const char E = '\n';
const int N = 100005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, a[N], dp[N];
	cin >> n;
	dp[0] = dp[1] = 0;
	for (int i=1; i<=n; i++) {
        cin >> a[i];
        if (i == 1) {
            a[0] = a[1];
            continue;
        }
        dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout << dp[n];
    return 0;
}


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

using namespace std;
int const N = 5e5;

string s,t;
vector<int > at[26];
int main() {
    cin>>s>>t;
    int n=s.size(),m=t.size();
    for(int i=0;i<n;i++)at[s[i]-'a'].push_back(i);
    for(int i=0;i<m;i++){
        if(at[t[i]-'a'].empty()){
            cout<<-1;
            return 0;
        }
    }
    int idx = -1;
    long long an = 0;
    for(int i=0;i<m;i++){
        while(1){
            int nxt = upper_bound(at[t[i]-'a'].begin(),at[t[i]-'a'].end(),idx)-at[t[i]-'a'].begin();
            if(nxt == (int)at[t[i]-'a'].size()){
                an+=n-idx-1;
                idx=-1;
            }else {
                an+=at[t[i]-'a'][nxt] - idx;
                idx = at[t[i]-'a'][nxt];
                break;
            }
        }
    }
    cout<<an<<endl;
    return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[100000];
  int b[99999];
  rep(i,n){
    cin>>a[i];
    if(i!=0){
      if(a[i]>a[i-1]) b[i-1]=1;
      else if(a[i]<a[i-1]) b[i-1]=2;
      else b[i-1]=0;
    }
  }
  int p=0;
  while(b[p]==0) p++;
  int now=b[p];
  int ans=1;
  repi(i,p,n-1){
    if(now!=b[i]){
      if(b[i]!=0){
	ans++;
	i++;
	while(b[i]==0) i++;
	now=b[i];
      }
    }
  }
  cout<<ans<<endl;

  return 0;
}


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

using namespace std;

int k,n, a[200005];

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

	int maxSegment = 0;

	for(int i=1; i<n; i++) {
		int segment = (abs(a[i]-a[i-1]+k)) % k;
		maxSegment = max(maxSegment, segment);
	}

	int segment = (abs(a[0]-a[n-1]+k)) % k;
	maxSegment = max(maxSegment, segment);

	cout<<k - maxSegment<<endl;
	
	return 0;
}

Measured memory_bytes: 1024
readDouble :: String -> Double
readDouble = read
x ? (a,b) = if x then a else b

main = do
    s <- map readDouble.words<$>getContents
    putStr ((show$solve s) ++ " " ++ (show$solve2 s))

solve :: [Double] -> Double
solve (w:h:_) = w*h/2

solve2 :: [Double] ->  Int
solve2 [w,h,x,y] = (ishalved [w,x] && ishalved [h,y])?(1,0)

ishalved [a,b] = a == b*2


Measured memory_bytes: 508
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    string s; cin >> s;

    if(N % 2 == 1) puts("No");
    else {
        string t = s.substr(0, N/2);
        if(t + t != s) puts("No");
        else puts("Yes");
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	
	if(a+b==c){
		printf("Yes\n");
	}else if(b+c==a){
		printf("Yes\n");
	}else if(c+a==b){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
import numpy as np
from collections import defaultdict
from collections import Counter
from collections import OrderedDict
#key = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}
# A = int(input())
A, B = (int(i) for i in input().split())
sum1 = 0
if A < B:
    sum1 += B
    B -= 1
else:
    sum1 += A
    A -= 1
if A < B:
    sum1 += B
    B -= 1
else:
    sum1 += A
    A -= 1
print(sum1)

Measured memory_bytes: 21916
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

int n;
ll k;
vector<int> a,f; 

bool func(ll x){
  ll y = 0; //修行回数総計
  rep(i,n){
    ll t;//xを達成するために必要な修行回数
    t = a[i] - x / f[i];
    y += max(t,0LL);
  }
  if(y > k) return false;
  else return true;
}

int main(){
  cin >> n >> k;
  a.resize(n);f.resize(n);
  rep(i,n) cin >> a[i];
  rep(i,n) cin >> f[i];
  
  sort(a.begin(),a.end(),greater<int>());
  sort(f.begin(),f.end());
  
  ll l = -1; ll r = 1e13;
  while(r-l>1){
    ll c = (l+r)/2;
    if(func(c)) r = c;
    else l = c;
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] h = new int[N+1];

    for (int i = 1; i < N+1; i++) {
      h[i] = sc.nextInt();
    }

    sc.close();

    int[] dp = new int[N+1];

    Arrays.fill(dp, Integer.MAX_VALUE);

    dp[0] = 0;
    dp[1] = 0;
    dp[2] = Math.abs(h[2] - h[1]);

    for (int i = 3; i < N+1; i++) {
      for (int j = 1; j <= K && 1 <= i - j; j++) {
        dp[i] = Math.min(dp[i], dp[i-j] + Math.abs(h[i]-h[i-j]));
      }
    }

    System.out.println(dp[N]);

  }

}

Measured memory_bytes: 51464
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int a,b,c,ans;
  cin >> a >> b >> c;
  if(a != 0){
    a--;
    ans=(b/c)-(a/c);
  } else{
    ans=(b/c)-(a/c);
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    a = list(map(int, input().split()))
    a.sort(reverse = True)
    ans = a[0]
    t = N - 2

    for i in range(1, N):
        for _ in range(2):
            if t > 0:
                ans += a[i]
                t -= 1
    print(ans)
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 31624
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, K;
ll f[2001];

ll pw(ll x, int y) {
	ll a = 1;
	while (y) {
		if (y & 1) {
			a = a*x%mod;
		}
		x = x*x%mod;
		y /= 2;
	}
	return a;
}

ll modinv(ll x) {
	return pw(x, mod - 2);
}

ll comb(int n, int r) {
	if (n < r)return 0;
	return f[n] * modinv(f[r]) % mod * modinv(f[n - r]) % mod;
}

int main() {
	f[0] = 1;
	for (int i = 1; i <= 2000; ++i) {
		f[i] = f[i - 1] * i%mod;
	}
	cin >> N >> K;
	for (int i = 1; i <= K; ++i) {
		cout << comb(N - K + 1, i)*comb(K - 1, i - 1) % mod << endl;
	}
}

Measured memory_bytes: 256
S_raw = input()
T_raw = input()

S_copy = S_raw
T_copy = T_raw

flag_end = False

# 文字数チェック、不一致ならNo
while S_copy != '':
    str_tmp = S_copy[0]
    if S_copy.count(str_tmp) != T_copy.count(str_tmp):
        print('No')
        flag_end = True
        break
    S_copy = S_copy.replace(str_tmp, '')
    T_copy = T_copy.replace(str_tmp, '')


if flag_end == False:
    for i in range(0, len(S_raw)):
        if S_raw[i:] in T_raw:
            if S_raw[i:]+S_raw[:i] == T_raw:
                print('Yes')
                flag_end = True
                break

if flag_end == False:
    print('No')


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

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

    if(s[0] == 'W' || s[n * 2 - 1] == 'W') {
        cout << 0 << endl;
        return 0;

    }

    vector<char> d;
    int l, r;
    l = r = 0;
    ++l;
    d.pb('L');
    for(int i = 1; i < n * 2; ++i) {
        if(s[i] == s[i - 1]) {
            if(d[i - 1] == 'L') {
                d.pb('R');
                ++r;

            } else {
                d.pb('L');
                ++l;

            }
        } else {
            if(d[i - 1] == 'L') {
                d.pb('L');
                ++l;

            } else {
                d.pb('R');
                ++r;

            }
        }
    }

    if(l != r) {
        cout << 0 << endl;
        return 0;

    }

    LL res = 1;
    l = r = 0;
    for(int i = 0; i < n * 2; ++i) {
        if(d[i] == 'L') {
            ++l;

        } else {
            ++r;
            res = res * l % MOD;
            l--;

        }
    }

    for(int i = 1; i <= n; ++i) {
        res = res * i % MOD;

    }
    cout << res << endl;
    return 0;
}



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

using namespace std;

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mkp make_pair

#define se second
#define fi first

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int n;
    cin >>n;

    map<int,int> x;

    for (int i = 1; i <= 60000; i++){
        int tax = (double)i*1.08;
        x[tax]=i;
    }

    if(x.find(n) == x.end()){
        
    }else{
        flag=true;
        ans =x[n];
    }
    

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout <<  << endl;

    if(flag)cout << ans <<endl;
    else cout << ":(" <<endl;
    
    return 0;
}


Measured memory_bytes: 3072
from collections import Counter
inf = float('inf')

N = int(input())
D = list(map(int,input().split())) + [0]
N += 1

def cal(a):
    n = len(a)
    res = inf
    for i in range(n):
        for j in range(i+1, n):
            d = abs(a[i] - a[j])
            d = min(d, 24 - d)
            res = min(res, d)
    return res

c = Counter(D)
ans = -inf
for S in range(1 << 13):
    D = []
    if c[0] > 1 or c[12] > 1:
        print(0)
        exit()
    if c[0] == 1:
        D.append(0)
    if c[12] == 1:
        D.append(12)
    for j in range(1, 12):
        if c[j] == 0:
            continue
        elif c[j] == 1:
            if (S >> j) & 1:
                D.append(j)
            else:
                D.append(24-j)
        elif c[j] == 2:
            D.append(j)
            D.append(24-j)
        else:
            print(0)
            exit()
    ans = max(ans, cal(D))

print(ans)

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

using namespace std;
int main(){
	string str = "CODEFESTIVAL2016";
	string S;
	int cnt = 0;
	cin >> S;
	for (int i = 0; i < 16; i++){
		if (str[i] != S[i]) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;
struct edge { ll from; ll to; ll cost; };



ll n;
ll dist_1[305][305];
bool dist_2[305][305];


int main() {
	cin >> n;

	rep(i, 0, n)rep(j, 0, n) {
		ll x;
		cin >> x;
		dist_1[i][j] = x;
		dist_2[i][j] = true;
	}
	
	rep(i, 0, n)rep(j, 0, n)rep(k, 0, n) {
		if (dist_1[i][j] > dist_1[i][k] + dist_1[k][j]) {
			cout << "-1" << endl;
			return 0;
		}
		else if (dist_1[i][j] == dist_1[i][k] + dist_1[k][j] && i != k && j != k) {
			dist_2[i][j] = false;
		}
	}

	ll ans = 0;
	rep(i, 0, n)rep(j, 0, n) {
		if (dist_2[i][j])ans += dist_1[i][j];
	}

	cout << ans / 2 << endl;


	return 0;
}

Measured memory_bytes: 1024
program d1;
var i,c,f:longint;
      s:string;
begin
    readln(s);
	c:=maxlongint;
	for i:=length(s) downto 1 do
		if s[i]='C' then c:=i;
	f:=0;
	for i:=1 to length(s) do
		if s[i]='F' then f:=i;
	if f>c then writeln('Yes')
		else writeln('No');
end. 

Measured memory_bytes: 128
use text_io::*;
use std::collections::HashMap;
use std::process::exit;

fn main() {
    let n:usize = read!();
    let mut sum:usize = 0;
    for i in 1..n+1 {
        for j in 1..n+1 {
            for k in 1..n+1 {
                sum += gcd(k,gcd(i,j));
            }
        }
    }
    println!("{}",sum);
}

fn gcd(a: usize, b: usize) -> usize {
    match b {
        0 => a,
        _ => gcd(b, a % b)
    }
}

Measured memory_bytes: 2124
#include <stdio.h>
#include <string.h>
int main(){
  int a, b;

  scanf("%d%d", &a, &b);

  if(a == 1){
    a = 15;
  }
  if(b == 1){
    b = 15;
  }

  if(a > b){
    printf("Alice");
  }else if(a == b){
    printf("Draw");
  }else if(a < b){
    printf("Bob");
  }
  printf("\n");
  
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    const long double pi = 3.14159265358979323846264338327950288419716939937510;
  	long double angle, hangle, mangle, a, b, h, m;
    cin >> a >> b >> h >> m;
    //times pi/180 for angle in radians
    mangle = 6*m;
    hangle = (h*60+m)/2;
    if(abs(hangle - mangle) < 180){
      angle = abs(hangle - mangle);
    }
    else{
      angle = 360-abs(hangle - mangle);
    }
  	cout << fixed << setprecision(14) << sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(angle*pi/180)) << endl;
}

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

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        int[] A = new int[N];

        int maxValue = 1;
        int secondMaxValue = 0;
        int cntMaxValue = 0;
        int currentValue;

        for(int i = 0; i < N; i++) {
            currentValue = int.Parse(Console.ReadLine());
            A[i] = currentValue;

            if(maxValue == currentValue) { 
                cntMaxValue++;
            } else if(maxValue < currentValue) {
                secondMaxValue = maxValue;
                maxValue = currentValue;
                cntMaxValue = 1;
            } else if(secondMaxValue < currentValue) {
                secondMaxValue = currentValue;
            }
        }

        for(int i = 0; i < N; i++) {
        
            if(cntMaxValue > 1) {
                Console.WriteLine(maxValue);
                continue;
            }
            
            if (A[i] == maxValue) {
                Console.WriteLine(secondMaxValue);
            }
            else {
                Console.WriteLine(maxValue);
            }

        }
    }
}

Measured memory_bytes: 17108
#include <stdio.h>
#include <math.h>
 
 
int main(void)
{
    int n, i;
    int s[1001] = {0};
    double mean, dev, tmp, sum;
 
    while (1) {
        scanf("%d", &n);
        if (n == 0) break;
        sum = 0;
        dev = 0;
        for (i = 0; i < n; ++i)
	{
            scanf("%d", &s[i]);
            sum += s[i];
        }
        mean = sum / n;
        for (i = 0; i < n; ++i)
	{
            dev += pow(mean - s[i], 2);
        }
        printf("%lf\n", sqrt(dev/n));
    }
    return 0;
}

Measured memory_bytes: 636
import * as fs from "fs";

const lines = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const inputs = lines[0].split(' ').map(x => parseInt(x));

if (inputs[1] - inputs[0] === inputs[2] - inputs[1]) {
    console.log('YES');
}
else {
    console.log('NO');
}

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

const int INF =1e9;
const int MOD =1e9+7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

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

int main()
{
int n,r;
cin>>n>>r;
cout<<r+(10-min(10,n))*100<<endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
//int mincoins(int ar[],int n,int k,int dp[]){
//	for(int i=1;i<=k;i++){
//		 dp[i] = INT_MAX;
//			for(int op=0;op<n;op++){
//				if(i-ar[op]>=0)
//				dp[i]= min(dp[i-ar[op]]+1,dp[i]);
//				
//			}
//		
//	}
//		if(dp[k]==INT_MAX){
//		return -1;
//	}
//return dp[k];
//}
int mincost(int ar[],int n,int k){
	int dp[n+1]={0};
	if(n==0){
		return 0;
	}
	if(n==1){
		dp[1]=0;
	}

	for(int i=2;i<=n;i++){
		
		dp[i]=INT_MAX;
	
		for(int j=1;j<=k;j++){
		if(i-j>=1)
		dp[i] = min(dp[i-j]+abs(ar[i]-ar[i-j]),dp[i]);
	
		}

	
	}
return dp[n];
}
int main(){
	int n,k;
	cin>>n>>k;
	int ar[n];
	for(int i=1;i<=n;i++){
		cin>>ar[i];
	}
	cout<<mincost(ar,n,k)<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define curr(P, i) P[i]
#define next(P, i) P[(i+1)%P.size()]
#define prev(P, i) P[(i+P.size()-1) % P.size()]
typedef complex<double> P;
typedef vector<P> G;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}

double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

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

G convex_hull(G &ps) {
  int n = ps.size(), k = 0;
  sort(ps.begin(), ps.end());
  G ch(2*n);
  for (int i = 0; i < n; ch[k++] = ps[i++]) // lower-hull
    while (k >= 2 && ccw(ch[k-2], ch[k-1], ps[i]) == -1) --k;
  for (int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--]) // upper-hull
    while (k >= t && ccw(ch[k-2], ch[k-1], ps[i]) == -1) --k;
  ch.resize(k-1);
  return ch;
}

int main() {
  double xa,ya,xb,yb,xc,yc,xd,yd;
  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa,&ya,&xb,&yb,&xc,&yc,&xd,&yd) != EOF){
    G ps;
    ps.push_back(P(xa, ya));
    ps.push_back(P(xb, yb));
    ps.push_back(P(xc, yc));
    ps.push_back(P(xd, yd));
    G tmp = convex_hull(ps);
    cout <<(4 == (int)(tmp.size()) ? "YES" : "NO") <<endl;
  }
  return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
   long long A,B,K;
   cin>>A>>B>>K;
   
   if(A<=K)
   {
        K=K-A;
        A=0;
        B=max(1LL*0,B-K);
   }
   
   else
   {
       A=A-K;
   }
   cout<<A<<" "<<B<<endl;
    return 0;
}


Measured memory_bytes: 256
from fractions import gcd
from collections import Counter
a,b=map(int,input().split())
g=gcd(a,b)
L=[]
for i in range(2,int(g**0.5)+1):
    while g%i==0:
        g//=i
        L.append(i)
if L==[]:
    L.append(g)
else:
    if g!=1:
        L.append(g)
LC=Counter(L)
r=len(LC)
if 1 not in LC.keys():
   r+=1
print(r)

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

int main(){
    ll n;
    cin>>n;
    ll ans=0;
    ll num[n];
    fill(num,num+n,1000000);
    for (int i = 0; i < n-1; ++i) {
        ll t;
        cin>>t;
        num[i]=min(num[i],t);
        num[i+1]=min(num[i+1],t);
    }
    for (int j = 0; j < n; ++j) {
        ans+=num[j];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        String b=sc.next();
        String[] c=b.split("");
        int answer = 1;
        for (int i = 0; i < a; i++) {
            if (i >= 1) {
                if (!(c[i].equals(c[i - 1]))) {
                    answer++;
                }
            }
        }
        System.out.println(answer);
    }

}


Measured memory_bytes: 35568
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007 
#define MAXN 1000005

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll X[2];
    ll Y[2];
    cin>>X[0]>>X[1]>>Y[0]>>Y[1];
    
    ll ans = LLONG_MIN;
    
    for(ll i=0;i<2;++i)
    {
        for(ll j=0;j<2;++j)
        {
            ans = max(ans,X[i] * Y[j]);
        }
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<=n;i++)
#define rep2(i,k,n) for(int i=k;i>=n;i--)
#define pb push_back
using namespace std;
const int N=3005;
vector<int> tu[N];
int n,a[N],vis[N];
int main(){
	scanf("%d",&n);
	rep(i,1,n)scanf("%d",&a[i]);
	rep(i,1,n-1){
		int x,y;
		scanf("%d%d",&x,&y);
		tu[x].pb(y),tu[y].pb(x);
	}
	int lim=n;
	while(lim--){
		rep(i,1,n)if(!vis[i]){
			int op=1;
			for(int j=0;j<tu[i].size();j++){
				int v=tu[i][j];
				if(vis[v]!=1 && a[v] < a[i]){
					op=0;break;
				}
			}
			if(op)vis[i]=2;
		}
		rep(i,1,n)if(vis[i]==2){
			for(int j=0;j<tu[i].size();j++){
				int v=tu[i][j];
				if(!vis[v] && a[v] > a[i]){
					vis[v]=1;
				}
			}
		}
	}
	rep(i,1,n)if(vis[i]==1)printf("%d ",i);
}

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

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

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000
#define EPS 1e-9

double d;

int main(){
	cin.sync_with_stdio(false);
	cin>>d;
	double res=0;
	res=(int)d+1;
	maxch(res,sqrt(2)*d);
	printf("%.10f\n", res);
	return 0;
}

Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
typedef long long ll;
typedef pair<ll,ll> P;
#define se second
#define fi first
struct PP{ll fi;ll se;ll th;};
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n;cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    rep(i,n)v[i]*=-1;
    vi dp(n,inf);
    rep(i,n)dp[ub(dp,v[i])]=v[i];
    cout<<lb(dp,inf)<<endl;
}

Measured memory_bytes: 1792
{-# LANGUAGE ScopedTypeVariables #-}
import Data.List
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

content :: Int -> [Int] -> Int
content 1 _ = 1
content x [] = x
content x (y:ys) = content (gcd x y) ys

main = do
  n :: Int <- readLn
  xs :: U.Vector Int <- U.fromListN n . map (read . BS.unpack) . BS.words <$> BS.getLine
  let ls = U.scanl gcd 0 xs
      rs = U.scanr gcd 0 xs
  let gg = [gcd l r | i <- [0..n-1], let l = ls U.! i; r = rs U.! (i + 1)]
  print $ maximum gg


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

int main()
{
    int n=250,x,y,t;
    int a[n];
    for(int i=0;i<n;i++) a[i]=0;
    a[1]=3,a[2]=2,a[3]=1;
    cin>>x>>y;
    t=a[x]+a[y];
    if(x==1&&y==1) t+=4;
    cout<<t*100000<<endl;
}


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

import sys
import os


def frame(w, h):
    top = '#' * w

    inner = ['.'] * w
    inner[0] = '#'
    inner[-1] = '#'
    inner_str = ''.join(inner)

    print(top)
    for i in range(h - 2):
        print(inner_str)
    print(top)


for s in sys.stdin:
    H, W = list(map(int, s.split()))
    if W == H == 0:
        break
    else:
        frame(W, H)
        print()

Measured memory_bytes: 7712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q; cin >> N >> Q;
    VL A(N); REP(i,N) cin >> A[i];
    reverse(A.begin(),A.end());

    VL sum(N+1), evensum(N+1);
    REP(i,N){
        sum[i+1] = sum[i] + A[i];
        evensum[i+1] = evensum[i] + (i%2 == 0 ? A[i] : 0);
    }

    VL ths, vals;
    REP(i,(N-1)/2){
        LL th = (A[i+1] + A[i*2+2])/2 + 1;
        LL val = (sum[i+1] - sum[0]) + (evensum[N] - evensum[i*2+2]);
        ths.eb(th); vals.eb(val);
    }
    reverse(ths.begin(),ths.end());
    reverse(vals.begin(),vals.end());
    REP(_,Q){
        LL x; cin >> x;
        int it = upper_bound(ths.begin(),ths.end(),x) - ths.begin();
        if(it == 0) cout << sum[(N+1)/2] - sum[0] << endl;
        else cout << vals[it-1] << endl;
    }


}


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

int main(){
    int K,X;
    int l,r;
    cin >> K >> X;
    l = X - K + 1;
    r = X + K -1;
    for(int i=l;i<=r;i++){
        cout << i;
        if(i != r){
            cout << " ";
        }else{
            cout << endl;
        }
    } 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<long long> A(N),psum(N+1);
  vector<vector<long long>> cost(N,vector<long long>(N,LLONG_MAX));
  for(int i = 0; i < N; ++i){
    cin >> A[i];
    psum[i+1] = psum[i]+A[i];
  }
  for(int b = 0; b+1 < N; ++b) cost[b][b+1] = psum[b+2]-psum[b];
  for(int l = 2; l < N; ++l){
    for(int b = 0; b+l < N; ++b){
      int e = b+l;
      cost[b][e] = min(cost[b][e],cost[b+1][e]+psum[e+1]-psum[b]);
      cost[b][e] = min(cost[b][e],cost[b][e-1]+psum[e+1]-psum[b]);
      for(int k = b+1; k < e-1; ++k)
        cost[b][e] = min(cost[b][e],cost[b][k]+cost[k+1][e]+psum[e+1]-psum[b]);
    }
  }
  cout << cost[0][N-1];
  return 0;
}

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

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            bool found = false;
            for (int i = 0; i <= x[0] && !found; i++)
            {
                for (int j = 0; j <= x[0] - i && !found; j++)
                {
                    if (i * 10000 + j * 5000 + (x[0] - i - j) * 1000 == x[1])
                    {
                        found = true;
                        Console.WriteLine(i + " " + j + " " + (x[0] - i - j));
                    }
                }
            }
            if (!found) Console.WriteLine("-1 -1 -1");
        }
    }
}

Measured memory_bytes: 13396