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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

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

template<typename T>
void chmax(T &a, T b) {
    a = max(a, b);
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, 0, N) {
        cin >> A[i];
    }
    const ll inf = 1LL << 60;
    auto dp = make_v(N, 2, -inf);
    dp[0][0] = 0;
    REP(i, 0, N - 1) {
        REP(j, 0, 2) {
            REP(k, 0, 2) {
                int s = (j + k) % 2;
                ll num = (1 - 2 * s) * A[i];
                chmax(dp[i + 1][k], dp[i][j] + num);
            }
        }
    }
    cout << max(dp[N - 1][0] + A[N - 1], dp[N - 1][1] - A[N - 1]) << endl;
    return 0;
}


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

int main(void)
{
	int n,i;
	scanf("%d",&n);
	int s[n];
	for(i=0;i<=n-1;i++)
		{scanf("%d",&s[i]);}
	int next=1,count=0;
	while(next!=2)
		{
		next=s[next-1];
		count++;
		if(count>n){count=-1;break;}
		}
	printf("%d",count);
	


	return 0;
}


Measured memory_bytes: 512
N, Q = map(int, input().split())

class Unionfind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n+1)
        
    def find(self, x):
        if(self.parents[x] < 0):
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
        
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if(x == y):
            return
        
        if(self.parents[x] > self.parents[y]):
            x, y = y, x
            
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    
    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}:{}'.format(r, self.members(r)) for r in self.roots())
    
uf = Unionfind(N)

for i in range(Q):
    t, u, v = map(int, input().split())
    
    if(t == 0):
        uf.union(u, v)
        uf.union(v, u)
    else:
        if(uf.same(u, v)):
            print(1)
        else:
            print(0)    

Measured memory_bytes: 11572
from heapq import heappush, heappop
import sys

input = sys.stdin.buffer.readline
n, m = map(int, input().split())
AB = []
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort(key=lambda x: [-x[0], -x[1]])
ans = 0
kouho = []
for d in range(1, m + 1):
    while AB and AB[-1][0] <= d:
        a, b = AB.pop()
        heappush(kouho, (-b, a))
    if kouho:
        p, q = heappop(kouho)
        ans += -p
print(ans)


Measured memory_bytes: 41768
N = int(input())
Hotel_list = list(map(int, input().split()))

ans = 1
highest_hotel = Hotel_list[0]
for i in range(1, N):
    if Hotel_list[i] >= highest_hotel:
        ans += 1
        highest_hotel = Hotel_list[i]
    else:
        pass

print(ans)

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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


int N;
const int MAX_N = 100005;
ll dp[MAX_N];;
ll h[MAX_N];

void solve() {
    cin >> N;
    rep(i, N){
        cin >> h[i];
    }

    rep(i, N){
        dp[i] = 1e+9;
    }
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    rep(i, N){
        dp[i+2] = min(dp[i]+abs(h[i]-h[i+2]), dp[i+1]+abs(h[i+1]-h[i+2]));
    }

    cout << dp[N-1] << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 5888
#include<stdio.h>
int main()
{
    double a[105];
    int n,m,num=0;
    double sum=0.0,ans;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++){
        scanf("%lf",&a[i]);
        sum+=a[i];
    }
    ans=sum/(4*m);
    for(int i=0;i<n;i++){
        if(a[i]>=ans)
            num++;
        if(num==m){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

K = I()
S = S()

if len(S) <= K:
    print(S)
else:
    print(S[0:K]+"...")

Measured memory_bytes: 27152
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <list>
using namespace std;
typedef long long ll;

const int MAX = 1000000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    int X, Y;
    cin >> X >> Y;
    if ((X + Y) % 3 != 0) cout << 0 << endl;
    else {
        COMinit();
        int aaa = (X + Y) / 3;
        cout << COM((X - aaa) + (Y - aaa), (X - aaa)) << endl;
    }
    return 0;
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる






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

  vector<vector<int>> p(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    p[a].pb(b);
    p[b].pb(a);
  }

  vector<ll> ans(n);
  vector<ll> q(n);
  ll sum=0;
  rep(i,n){
    cin>>q[i];
    sum+=q[i];
  }
  sort(all(q));
  sum-=q[n-1];

  deque<int> que;
  int now=n-1;
  ans[0]=q[now];
  now--;
  que.pb(0);

  while(!que.empty()){
    int x=que.front();
    que.pop_front();
    for(auto z : p[x]){
      if(ans[z]!=0) continue;
      ans[z]=q[now];
      now--;
      que.pb(z);
    }
  }

  cout << sum << endl;
  rep(i,n){
    cout << ans[i];
    if(i!=n-1) cout << " ";
    else cout << endl;
  }

}

Measured memory_bytes: 1152
s = input()
ok = True
if s[0] != 'A': ok = False
if s[1] != s[1].lower(): ok = False
if s[-1] != s[-1].lower(): ok = False
c = 0
for si in s[2:-1]:
    if si == 'C': c += 1
if c != 1: ok = False
print('AC' if ok else 'WA')


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

#define SEGTREE_MAX 131072

typedef struct {
	int max_num;
	int push_num;
} segtree_t;

segtree_t segtree[SEGTREE_MAX*2-1];

/**
 * 要素の変更を下の要素に反映する 
 * @param youso 適用する要素 
 */
void segtree_push(int youso) {
	if(youso*2+1<SEGTREE_MAX*2-1) {
		segtree[youso*2+1].push_num+=segtree[youso].push_num;
		segtree[youso*2+2].push_num+=segtree[youso].push_num;
	}
	segtree[youso].max_num+=segtree[youso].push_num;
	segtree[youso].push_num=0;
}

/**
 * 内部関数。範囲に値を加える。
 * @param youso 現在見ている要素
 * @param add 加える値
 * @param start 操作対象の区間の開始地点(含む)
 * @param end 操作対象の区間の終了地点(含まない)
 * @param kstart 現在の要素に対応する区間の開始地点(含む)
 * @param kend 現在の要素に対応する区間の終了地点(含まない) 
 */
void segtree_add_internal(
		int youso,int add,int start,int end,int kstart,int kend) {
	segtree_push(youso);
	if(end<=kstart || kend<=start)return;
	if(start<=kstart && kend<=end) {
		segtree[youso].push_num+=add;
		segtree_push(youso);
	} else {
		segtree_add_internal(youso*2+1,add,start,end,
			kstart,kstart+(kend-kstart)/2);
		segtree_add_internal(youso*2+2,add,start,end,
			kstart+(kend-kstart)/2,kend);
		segtree[youso].max_num=segtree[youso*2+1].max_num;
		if(segtree[youso].max_num<segtree[youso*2+2].max_num) {
			segtree[youso].max_num=segtree[youso*2+2].max_num;
		}
	}
}

/**
 * 内部関数。範囲の最大値を取得する。 
 * @param youso 現在見ている要素
 * @param start 操作対象の区間の開始地点(含む)
 * @param end 操作対象の区間の終了地点(含まない)
 * @param kstart 現在の要素に対応する区間の開始地点(含む)
 * @param kend 現在の要素に対応する区間の終了地点(含まない) 
 * @return [start,end)の最大値 
 */
int segtree_getmax_internal(
		int youso,int start,int end,int kstart,int kend) {
	int r1,r2;
	segtree_push(youso);
	if(end<=kstart || kend<=start)return 0;
	if(start<=kstart && kend<=end) {
		return segtree[youso].max_num;
	} else {
		r1=segtree_getmax_internal(youso*2+1,start,end,
			kstart,kstart+(kend-kstart)/2);
		r2=segtree_getmax_internal(youso*2+2,start,end,
			kstart+(kend-kstart)/2,kend);
		if(r1>r2)return r1; else return r2;
	}
}

/**
 * セグメント木を初期化する。 
 */
void segtree_init(void) {
	memset(segtree,0,sizeof(segtree));
}

/**
 * セグメント木の範囲に一様に値を加える。
 * @param start 範囲の開始地点(含む)
 * @param end 範囲の終了地点(含まない)
 * @param add 加える値 
 */
void segtree_add(int start,int end,int add) {
	segtree_add_internal(0,add,start,end,0,SEGTREE_MAX);
}

/**
 * セグメント木の範囲の要素の最大値を取得する。
 * @param start 範囲の開始地点(含む)
 * @param end 範囲の終了地点(含まない)
 * @return 範囲の要素の最大値 
 */
int segtree_getmax(int start,int end) {
	return segtree_getmax_internal(0,start,end,0,SEGTREE_MAX);
}

/**
 * 時、分、秒のセットで表された時刻を秒に変換する。
 * @param h 変換する時刻の時
 * @param m 変換する時刻の分
 * @param s 変換する自国の秒
 * @return 変換された秒 
 */
int getPosition(int h,int m,int s) {
	return (h*60+m)*60+s;
}

/**
 * メイン関数。
 * @return 正常終了なら0 
 */
int main(void) {
	int n,i;
	int h1,m1,s1,h2,m2,s2;
	int p1,p2;
	while(1) {
		scanf("%d",&n);
		if(n==0)break;
		segtree_init();
		for(i=0;i<n;i++) {
			scanf("%d:%d:%d %d:%d:%d",&h1,&m1,&s1,&h2,&m2,&s2);
			p1=getPosition(h1,m1,s1);
			p2=getPosition(h2,m2,s2);
			segtree_add(p1,p2,1);
		}
		printf("%d\n",segtree_getmax(0,24*60*60));
	}
	return 0;
}

Measured memory_bytes: 2656
import java.util.*;

class Main{           
    
   public static void main(String[] args){
     
       Scanner sc = new Scanner(System.in);                                                          
       
       int n = sc.nextInt();
       
       List<List<Edge>> edges = new ArrayList<>(n);
       
       for(int i = 0 ;i < n;i++){
           edges.add(new ArrayList<>());
       }
       
       for(int i = 0;i < n-1;i++){
           int a = sc.nextInt()-1;
           int b = sc.nextInt()-1;
           int c = sc.nextInt();
           
           edges.get(a).add(new Edge(a,b,c));
           edges.get(b).add(new Edge(b,a,c));
       }
       
       int q = sc.nextInt();
       int k = sc.nextInt() - 1;

       int x[]=  new int[q];
       int y[] = new int[q];
              
       for(int i = 0;i < q;i++){
          x[i] = sc.nextInt() - 1;
          y[i] = sc.nextInt() - 1;           
       }
       
       
       long d[] = new long[n];
       
       boolean used[] = new boolean[n];
       
       Deque<Integer> st = new ArrayDeque<>();
       
       st.addLast(k);
       
       while(!st.isEmpty()){
           int e = st.pollFirst();
           
           used[e] = true;
           
           for(Edge next:edges.get(e)){
               if(used[next.v]){
                   continue;
               }
               
               d[next.v]= d[e] + next.w;
               
               st.addLast(next.v);
           }
           
       }
       
       
       for(int i = 0;i < q;i++){
           System.out.println(d[x[i]] + d[y[i]]);
       }
       
       
   }
   
   static class Edge{
       int u;
       int v;
       int w;
       
       Edge(int u,int v,int w){
           this.u = u;
           this.v = v;
           this.w = w;
       }       
   }
   
 }

Measured memory_bytes: 180316
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	ll a, b, c, d;
	scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
	printf("%lld\n", max(max(a * c, a * d), max(b * c, b * d)));
}

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

int main(){
	int H, W, K; 
    scanf("%d %d %d", &H, &W, &K);
    vector<vector<char> > a(H, vector<char> (W));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++) cin >> a[i][j];
    }

    int ans = 1e9;
    for(int bit = 0; bit < (1 << (H - 1)); bit++){
        int num = __builtin_popcount(bit);
        vector<int> data(num + 1, 0);
        int ans1 = 0;
        bool check = true;
        for(int i = 0; i < W; i++){
            int cnt = 0;
            for(int j = 0; j < H; j++){
                if(a[j][i] == '1') data[cnt]++;
                if(bit & (1 << j)) cnt++;
            }
            if(*max_element(data.begin(), data.end()) > K) check = false;
            for(int j = 0; j <= num; j++) data[j] = 0;
        }
        if(!check) continue;

        for(int i = 0; i < W; i++){
            int cnt = 0;
            for(int j = 0; j < H; j++){
                if(a[j][i] == '1') data[cnt]++;
                if(bit & (1 << j)) cnt++;
            }
            if(*max_element(data.begin(), data.end()) > K){
                ans1++;
                for(int j = 0; j <= num; j++) data[j] = 0;
                --i;
            }
        }
        ans = min(ans, ans1 + num);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 3800
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
    Scanner sc = new Scanner(System.in);
    
    int n;//全体の数
    int x;//合計した数
    int count;//ヒットした数、組合せは６通り
    
    
    int i;
    int j;
    int k;
    
    while (sc.hasNextLine()){
        count = 0;
        n = sc.nextInt();
        x = sc.nextInt();
         if( n == 0 && x ==0){
             break;
         }

         for( i = 1; i <= n; i++){
           for( j = 1; j <= n; j++){
               if(j != i){
                   for( k = 1; k <= n; k++){
                       if(k != i && k != j){
                           if(( i+ j + k )==x){
  //                             System.out.print(i);
  //                             System.out.print(j);
  //                             System.out.println(k);
                            if(i != j && k != i && k != j){
                            count++;
                            }
                           }
                       }
                   }
               }
           }
         }System.out.println(count/6);
    }
    }
}





Measured memory_bytes: 26828
#include <bits/stdc++.h>
using namespace std;
#define ll long long
char dp[1000][1000];
int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif
	int n, h;
	cin >> n >> h;
	for (int i = 0; i < n; i++	) {
		for (int j = 0; j < h; j++) {
			cin >> dp[i][j];
		}
	}
	ll ans[1000][1000];
	memset(ans, 0, sizeof ans);
	for (int i = 0; i < h; i++) {
		if (dp[0][i] == '#') {
			break;
		}
		ans[0][i] = 1;
	}
	for (int i = 0; i < h; i++) {
		if (dp[i][0] == '#') {
			break;
		}
		ans[i][0] = 1;
	}
	for (int i = 1; i < n; i++) {
		for (int j = 1; j < h; j++) {
			if (dp[i][j] == '#') {
				continue;
			}
			ll top = 0;
			if (dp[i - 1][j] == '#') {
				top = 0;
			} else {
				top = ans[i - 1][j];
			}
			ll down = 0;
			if (dp[i ][j - 1] == '#') {
				down = 0;
			} else {
				down = ans[i][j - 1];
			}
			ans[i][j] = (top + down) % 1000000007;
		}
	}
	cout << (ans[n - 1][h - 1]) % 1000000007;
	return 0;
}

Measured memory_bytes: 12400
N = int(input())
Vs = sorted(list(map(int, input().split())), reverse=True)

def mysorted(lst, value):
    i = 0
    for i in range(len(lst)):
        if lst[i] <= value:
            break
    res = lst[:i]
    res.append(value)
    res.extend(lst[i:])
    return res

for i in range(N-1):
    composed_item = (Vs[N-2-i] + Vs[N-1-i]) / 2
    Vs = mysorted(Vs[:N-2-i], composed_item)

print(Vs[0])

Measured memory_bytes: 3064
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int main(void){
    int temp,ans=0;
    for(int i=0; i<3; i++){
        temp=getchar();
        if(temp==49)ans++;
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m )%m)
using namespace std;
using namespace __gnu_pbds;
void OJ();

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;

const int N = 2e5 + 9 , m = 1e9 + 7;
int a[N];

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

    for ( int i = 0; i < N; ++i ) a[i] = i;
    int n , k; ll ret = 0;
    cin >> n >> k;

    ll l = 0 , suml = 0;
    ll r = n , sumr = 0;

    for ( int i = 0; i < k; ++i )
        suml += a[l++] , sumr += a[r--];

    ret += sumr - suml + 1; ret %= m;
    while ( l <= n ){
        suml += a[l++] , sumr += a[r--];
        ret += sumr - suml + 1; ret %= m;
    }
    cout << ret;
    return 0;
}

void OJ(){
#ifndef ONLINE_JUDGE
    freopen( "C:\\Users\\ehab\\Desktop\\Code Forces\\CF\\in.txt" , "r" , stdin  );
   // freopen( "C:\\Users\\ehab\\Desktop\\Code Forces\\CF\\out.txt", "w" , stdout );
#endif // ONLINE_JUDGE
}
ll binEXP( ll x , ll pw , ll MOD )
{ ll res=1; while(pw>0){ pw%2 ? res *= x : 0; x *= x; x%=MOD; pw /= 2; res%= MOD; } return res%=MOD; }


Measured memory_bytes: 4432
#include <stdio.h>

int main(void)
{
	int a=0,b=0,c=0,i=0,count=0;
	scanf("%d %d %d",&a,&b,&c);
	for(i=a;i<=b;i++)
	{
		if(c%i==0)
		{
			count=count+1;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 100000000
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100000
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string s;

int main(){
    cin >> s;
    int st = s.size(), en = -1;
    rep(i,s.size()){
        if(s[i] == 'A'){
            st = i;
            break;
        }
    }
    for(int i = s.size()-1; i >= 0; i--){
        if(s[i] == 'Z'){
            en = i;
            break;
        }
    }
    cout << en-st+1 << endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> v;
  for(int i=0;i<N;i++){
    int x;
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(),v.end());
  int count = 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(v[i] < v[j]+v[k] && v[j] < v[i]+v[k] && v[k] < v[i]+v[j]){
	  count++;
	}
      }
    }
  }

  cout << count <<endl;
  return 0;
}


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

int main() {
  string str;
  vector<int> buf;
  int t;

  getline(cin, str);
  t=0;
  while ((t = str.find("apple", t)) != string::npos) {
    buf.push_back(t);
    t += 5;
  }
  t=0;
  while ((t = str.find("peach", t)) != string::npos) {
    str.replace(t, 5, "apple");
    t += 5;
  }
  for (vector<int>::iterator it=buf.begin(); it!=buf.end(); it++) {
    str.replace(*it, 5, "peach");
  }
  cout << str << endl;
  return 0;
}

Measured memory_bytes: 1196
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int AB = scanner.nextInt();
		int BC = scanner.nextInt();
		int CA = scanner.nextInt();
		System.out.println(AB * BC / 2);
		scanner.close();
	}
}

Measured memory_bytes: 23632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var n = int.Parse(s);
            int keta = (int)Math.Floor(Math.Log10(n)) + 1;
            int temp = 1;
            int output = 0;
            for (int i = 0; i < keta-1; i++)
            {
                if (i % 2 == 0)
                {
                    output += temp * 9;
                }
                temp *= 10;
            }
            if (keta % 2 == 1)
            {
                output += n - temp + 1;
            }





            Console.WriteLine(output);






#if DEBUG
            Console.ReadKey();
#endif
        }
    }
}


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

class Program {

    static int Main(string[] args) {
        List<int> list = new List<int>();

        while (true) {
            string v = Console.ReadLine();
            if (string.IsNullOrEmpty(v) == true) { break; }

            list.Add(int.Parse(v));
        }

        Dictionary<int, int> kumiList = new Dictionary<int, int>();
        for (int i = 0; i < 10000; i++) {
            string v = i.ToString();
            int t = 0;
            for (int c = 0; c < v.Length; c++) {
                t += int.Parse(v.Substring(c, 1));
            }
            if (kumiList.ContainsKey(t) == false) {
                kumiList.Add(t, 1);
            }
            else {
                kumiList[t]++;
            }
        }

        for (int i = 0; i < list.Count; i++) {
            if (kumiList.ContainsKey(list[i]) == false) {
                Console.WriteLine("0");
            }
            else {
                Console.WriteLine(kumiList[list[i]]);
            }
        }

        return 0;
    }
}

Measured memory_bytes: 9816
#include <bits/stdc++.h>
#define L 0
#define R 1
 
using namespace std;
 
int N;
string S;
 
int main(void){
    
    cin >> N >> S;
    
    int left = 0, right = 0, result = INT_MAX;
    for(int i = 1; i < S.size(); ++i) if(S[i] == 'E') ++right;
    result = min(result, left + right);
    for(int i = 0; i < S.size() - 1; ++i){
        if(S[i] == 'W') ++left;
        if(S[i + 1] == 'E') --right;
        result = min(result, left + right);
    }

    cout << result << endl;
 
    return 0;
}

Measured memory_bytes: 900
//  @ /\/\ BESH //

#include <bits/stdc++.h>
#define inp_out_work ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCase    int T; cin>>T; while(T--)
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,s,e) for(int i=s;i<=e;i++)
#define endl '\n'
#define debug(P) cout<<#P<<" = "<<P<<endl;
#define pb push_back


using namespace std;

typedef long long ll;

const int MAXN = 100001;
const int mod = 1000000007;

int main(){
    int n, m;
    cin>>n>>m;
    string s[n];
    fr(i,n)cin>>s[i];
    ll dp[n][m];
    dp[0][0] =1;

    fr(i,n)fr(j,m){
        if(i == 0 && j == 0)continue;
        if(s[i][j] == '#')dp[i][j] =0;
        else {
            if(i == 0)dp[i][j] = dp[i][j-1];
            else if(j == 0)dp[i][j] = dp[i-1][j];
            else dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
        }
    }

    cout<< dp[n-1][m-1] << endl;

}


Measured memory_bytes: 9088
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <bitset>
#include <queue>
#include <algorithm>
#include <ctime>
using namespace std;
 
int const MAX_N = 128 * 1024;
 
int c[16][16];
double a[16],b[16];

int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
 
    int n = 3;
	for (int i=0; i<n; i++)
		for (int j=0; j<n; j++)
			cin>>c[i+1][j+1];
	for (int b1=-100000; b1<=100000; b1++) {
		b[1] = b1 / 100.0;
		b[2] = b1 / 100.0 +(c[1][2]-c[1][1]);
		b[3] = b1 / 100.0 + (c[1][3]-c[1][1]);
		a[1] = -b1 / 100.0 + (c[3][3]-c[3][1]-c[1][3])+2*c[1][1];
		a[2] = a[1] + (c[2][1]-c[1][1]);
		a[3] = a[1] + (c[3][1]-c[1][1]);
		int Ok = 1;
		for (int i=1; i<=n; i++)
			for (int j=1; j<=n; j++)
				if (fabs(a[i] + b[j] - c[i][j]) > 1e-5)
					Ok = 0;
		if (Ok) {
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
    return 0;
}  


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
const int inf = INT_MAX;
const ll INF = 1LL >> 60;
const ll mod = 1e9+7;

// DAME:
/*
    n, k　を引数として、上から再帰的に求めていく
*/

ll rec(ll n, ll x){
    if(n==0) return 1;
    // n-1の時のバーガーの長さ 2^(n+1) - 3
    ll len = (1LL<<(n+1)) - 3;
    // n-1の時のパティの量 2^(n) - 1
    ll num = (1LL<<n) - 1;
    if(x==1) return 0;

    // 1<x<　バンズ+n-1の時のバーガーの長さ
    if(x<=len+1) return rec(n-1, x-1);
    // x == バンズ+n-1の時のバーガーの長さ+パティ
    if(x==len+2) return num+1;
    // x<= バンズ+n-1の時のバーガーの長さ+パティ+ n-1の時のバーガーの長さ+バンズ
    if(x<=(len+1)*2) return num+1 + rec(n-1, x-len-2);
    // x == nの時のバーガーの長さ
    return num*2+1;
}

int main() {
    ll n, x;
    cin >> n >> x;
    ll ans = rec(n, x);
    cout << ans << endl;
    return 0;
}

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

int main()
{
	while(true)
	{
	  int height, width;
	  cin >> height >> width;
	  if(width == 0 && height == 0) break;
	  else
	  {
	    for(int y = 0; y < height; y++)
	    {
  	    for(int x = 0; x < width; x++)
  	    {
  	      if(y % 2 == 0) {
    	      if(x % 2 == 0) cout << "#";
    	      else cout << ".";
  	      }
  	      else {
  	        if(x % 2 == 0) cout << ".";
    	      else cout << "#";
  	      }
  	    }
  	    cout << endl;
	    }
	    cout << endl;
	  }
	}
}


Measured memory_bytes: 3100
#![allow(unused_imports)]

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::str::{self, FromStr};


fn solve(n: String) -> bool {
    n.chars().find(|&c| c == '9').is_some()
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    print_yesno(solve(sc.next()), "Yes", "No");
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(256),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        self.buf.clear();
        for c in self.bytes
            .by_ref()
            .map(|c| c.unwrap())
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
        {
            self.buf.push(c);
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
        <C as FromStr>::Err: Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


#[allow(dead_code)]
fn print_yesno(x: bool, yes: &'static str, no: &'static str) {
    println!("{}", if x { yes } else { no });
}


#[allow(dead_code)]
fn print_foreach<T: Display, I: IntoIterator<Item = T>>(xs: I) {
    for x in xs.into_iter() {
        println!("{}", x);
    }
}


#[allow(dead_code)]
fn print_or<T: Display>(x: Option<T>, or: &'static str) {
    if let Some(x) = x {
        println!("{}", x);
    } else {
        println!("{}", or);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std ; 
# define pb push_back
# define ll long long
# define mp make_pair 
# define endl "\n"
# define vi vector<int>
# define vc vector<char>
# define vll vector<ll> 
# define pi pair<int,int> 
const int MOD = 1e9 + 7 ; 
const ll inf = 1e18 ; 

void solve() {
	ll n , m ; 
	cin >> n >> m ; 
	if(abs(n-m) > 1) {
		cout << 0 ; 
		return ; 
	}
	 
	ll ans = 1 ; 
	for(ll i = 1 ; i <= n ; ++i) {
		ans = ans * i ; 
		ans = ans%MOD ;  
	}
	for(ll i = 1 ; i <= m ; ++i) {
		ans = ans * i ; 
		ans = ans%MOD ;  
	}
	if(n == m)  {
		ans *= 2 ;
		ans = ans%MOD ; 
	}
	cout << ans ; 
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
	int t ; 
	//cin >> t ; 
	t = 1 ;
	while(t--)
		solve() ; 
	return 0; 
}


Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int count =0;

		if((s.charAt(0)=='R' && s.charAt(1)=='R'&& s.charAt(2)=='R')){
			System.out.println(3);
		}
		else if((s.charAt(0)=='R' && s.charAt(1)=='R') || (s.charAt(1)=='R' && s.charAt(2)=='R')) {
			System.out.println(2);
		}

		else if((s.charAt(0)=='R') || (s.charAt(1)=='R') || (s.charAt(2)=='R')){
			System.out.println(1);
		}
		else{
			System.out.println(0);
		}

	}

}

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

int main()
{
    ll n,  sq, a, b, ok = 0 ;
    cin>>n ;
    sq = sqrt( n ) ;
    for( int i = 2; i <= sq; i++ )
    {
        if( !(n % i ) )
        {
            a = i, b = n/i ;
            ok = 1 ;
            //break ;
        }
    }
    if( ok ) cout<<(a - 1 ) + ( b - 1 )<<"\n" ;
    else cout<<n - 1<<"\n" ;
    return 0 ;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, Q = map(int, readline().split())
    uf = UnionFind(N)

    for _ in range(Q):
        t, u, v = map(int, readline().split())
        if t == 0:
            uf.union(u, v)
        else:
            if uf.same(u, v):
                print(1)
            else:
                print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 79124
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 61
#define MAX 1LL << 30
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge{ll to,cost,val;};
template<class T,class U>bool chmin(T&a,const U&b){if(a<=b)return false;a=b;return true;}
template<class T,class U>bool chmax(T&a,const U&b){if(a>=b)return false;a=b;return true;}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
#define int ll
int dx[]={1,-1,0,0},dy[]={0,0,-1,1};
double C[31000];

//T=string or vector<ll>
template<class T>
struct KMP{
    T x;
    vector<int> table;

    KMP(const T &s){
        init(s);
    }
    void init(const T &s){
        x=s;
        int m=(int)s.size();
        table.assign(m+1,-1);
        int j=-1;
        for(int i=0;i<m;i++){
            while(j>=0 && x[i]!=x[j]) j=table[j];
            table[i+1]=++j;
        }
    }
    int period(int i){ //S[0:i-1]において、どれぐらいずらしたら一致するか
        return i-table[i];
    }

    vector<int> query(const T &S){
        int n=(int)S.size(),m=(int)x.size();
        vector<int> ans;
        int k=0;
        for(int i=0;i<n;i++){
            while(k>=0 && S[i]!=x[k]) k=table[k];
            k++;
            if(k>=m) ans.push_back(i-m+1),k=table[k];
        }
        return ans;
    }
};


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin>>N;
    vector<int> a(N),b(N),A(N*2),B(N);
    for(int i=0;i<N;i++) cin>>a[i];
    for(int i=0;i<N;i++) cin>>b[i];
    for(int i=0;i<2*N;i++){
        A[i]=a[i%N]^a[(i+1)%N];
    }
    for(int i=0;i<N;i++){
        B[i]=b[i]^b[(i+1)%N];
    }

    KMP<vector<int>> k(B);
    vector<int> v=k.query(A);
    for(int x:v){
        int ans=a[x]^b[0];
        if(x>=N) continue;
        cout<<x<<" "<<ans<<endl;
    }

}

Measured memory_bytes: 16112
# -*- coding: utf-8 -*-
"""
http://abc066.contest.atcoder.jp/tasks/abc066_b

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    txt = input().strip()
    txt = txt[:-1]
    # print(txt)
    result = 0
    if len(txt) % 2 == 1:
        txt = txt[:-1]
    while txt:
        l = len(txt)
        a_part = txt[:l//2]
        b_part = txt[l//2:]
        if a_part == b_part:
            result = l
            break
        txt = txt[:-2]
    print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        final int k = scanner.nextInt();
        for (int i = 0; i < k; i++) {
            if (b <= a) {
                b *= 2;
            } else {
                c *= 2;
            }
        }
        if (b > a && c > b) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }
    }
}


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

int main() {
	int n;
	cin >> n;
	long long int r[n];
	long long int maxv=-1000000000;
	cin >> r[0];
	long long int minv = r[0];
	for(int i=1;i<n;i++){
		cin >> r[i];
		if(r[i]-minv>maxv){
			maxv = r[i] - minv;
		}
		if(r[i]<minv){
			minv = r[i];
		}
	}
	
	cout << maxv << endl;
	
	return 0;
}


Measured memory_bytes: 4660
n = int(input())
h = list(map(int, input().split()))
for i in range(n - 2, -1, -1):
  if h[i] == h[i + 1] + 1:
    h[i] -= 1
  elif h[i] - h[i + 1] >= 2:
    print('No')
    exit()
print('Yes')

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

#define N 100

int pop(void);
void push(int);

int s_sub[N];
int top = 0;
  
int main(){
  
  int fact1,fact2;
  char S[N];
  
  while(scanf("%s",S) != EOF){
    if(S[0] == '+'){
      fact1 = pop();
      fact2 = pop();
      push(fact1 + fact2);
    }else if(S[0] == '-'){
      fact2 = pop();
      fact1 = pop();
      push(fact1 - fact2);
    }else if(S[0] == '*'){
      fact1 = pop();
      fact2 = pop();
      push(fact1 * fact2);
    }else push(atoi(S));
  }
  printf("%d\n",pop());
  return 0;
}

int pop(){
  top--;
  return s_sub[top+1];
}

void push(int x){
  s_sub[++top] = x;
}




Measured memory_bytes: 2040
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	ll n;
	cin >> n;
	vll p(5);
	rep(i, 5) {
		cin >> p[i];
	}
	ll bn = p[0];
	rep(i, 5) {
		if (p[i] < bn) {
			bn = p[i];
		}
	}
	ll ans = 4 + n / bn;
	if (n % bn != 0) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
primes = 2 : f [3] [3,5..]
  where
    f (x:xs) ys = let (ps, qs) = span (< x^2) ys in ps ++ f (xs ++ ps) [z | z<-qs, mod z x /= 0]

main = do
  n <- readLn :: IO Int

  putStrLn $ unwords . map show . take n $ filter (\x -> mod x 10 == 1) $ takeWhile (<=55555) primes


Measured memory_bytes: 764
n = input()

a1 = n[0]
a2 = n[1]
a3 = n[2]
a4 = n[3]

if a1 == a2 and a2 == a3:
    print("Yes")

elif a2 == a3 and a3 == a4:
    print("Yes")

else:
    print("No")



Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main(){
  int n;
  int a[100] ;
  int b[100] ;
  int c[100] ;
  cin >> n;
  for(int i=0;i<n;i++)
    cin >> a[i];
  for(int i=0;i<n;i++)
    cin >> b[i];
  for(int i=0;i<n-1;i++)
    cin >> c[i];
  int point = b[a[0]-1];
  for(int i=1;i<n;i++){
    if (a[i] - a[i-1] == 1){
      point += b[a[i]-1] + c[a[i]-2];
    }else{
      point += b[a[i]-1];
    }
  }
  cout <<point<<endl;
 return 0; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
	cin>>a;
	for(int i=0;i<a.length();i++)
	{
		if(a[i]=='?') cout<<'D';
		else cout<<a[i]; 
	}
	/*
	I am wonder why I can not pass by char[]?  
	*/
	return 0;
}

Measured memory_bytes: 3752
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1000003 ;

pint p[100010];
int x[100010]; //x[n]:始点max(1,n%d)からdまでの消費魔力

int main(){
  int h,w,d;
  cin >> h >> w >> d;
  int a[h][w];
  rep(i,h){
    rep(j,w){
      cin >> a[i][j];
      p[a[i][j]]={i,j};
    }
  }
  int q;
  cin >> q;
  int l[q],r[q];
  rep(i,q)cin >> l[i] >> r[i];
  for(int i=d+1;i<=h*w;i++){
    x[i]=x[i-d]+abs(p[i].first-p[i-d].first)+abs(p[i].second-p[i-d].second);
  }
  rep(i,q){
    cout << x[r[i]]-x[l[i]] << endl;
  }
return 0;}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()
const long long INF = 1e18;
using namespace std;
typedef long long ll;
int main() {
  std::cout << std::fixed << std::setprecision(10);
  ll N;
  cin >> N;
  vector<double> v(N);
  REP(i, N) cin >> v[i];
  sort(ALL(v));

  double ans = (v[0] + v[1]) / 2.0;
  FOR(i, 2, N) { ans = (ans + v[i]) / 2.0; }

  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=998244353;
int main(){
  ll n;cin >> n;
  vector<ll> c(n);
  ll m=0;
  for(int i=0;i<n;i++){
    ll d;cin >> d;
    if(i==0){
      if(d!=0){
        cout << 0 << endl;
        return 0;
      }
    }
    c[d]++;
    m=max(m,d);
  }
  if(c[0]!=1){
    cout << 0 << endl;
    return 0;
  }
  ll ans=1;
  for(int i=1;i<=m;i++){
    for(int j=0;j<c[i];j++){
      ans*=c[i-1];
      ans%=mod;
    }
  }
  cout << ans << endl;
}

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

int main() {
  int H, W, count;
  cin >> H >> W;
  vector<vector<char>> S(H + 2, vector<char>(W + 2));
  vector<vector<string>> ans(H + 2, vector<string>(W + 2));
  for (int i = 0; i < W + 2; i++) S.at(0).at(i) = '.';
  for (int i = 1; i < H + 1; i++) {
    S.at(i).at(0) = '.';
    for (int j = 1; j < W + 1; j++) cin >> S.at(i).at(j);
    S.at(i).at(W + 1) = '.';
  }
  for (int i = 0; i < W + 2; i++) S.at(H + 1).at(i) = '.';
  for (int i = 1; i < H + 1; i++) {
    for (int j = 1; j < W + 1; j++) {
      if (S.at(i).at(j) == '#') {
        ans.at(i).at(j) = "#";
        continue;
      }
      count = 0;
      if (S.at(i - 1).at(j - 1) == '#') count++;
      if (S.at(i - 1).at(j) == '#') count++;
      if (S.at(i - 1).at(j + 1) == '#') count++;
      if (S.at(i).at(j - 1) == '#') count++;
      if (S.at(i).at(j + 1) == '#') count++;
      if (S.at(i + 1).at(j - 1) == '#') count++;
      if (S.at(i + 1).at(j) == '#') count++;
      if (S.at(i + 1).at(j + 1) == '#') count++;
      string countstr = to_string(count);
      ans.at(i).at(j) = countstr;
    }
  }
  for (int i = 1; i < H + 1; i++) {
    for (int j = 1; j < W + 1; j++) cout << ans.at(i).at(j);
    cout << endl;
  }  
}

Measured memory_bytes: 384
#include<stdio.h>

int main(){

	int i,n,a,b,c;

	scanf("%d",&n);

	for(i = 0; i < n; i++){
		scanf("%d%d%d",&a,&b,&c);

		if((a * a == b * b + c * c)||(b * b == a * a + c * c)||(c * c == a * a + b * b)){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}

	return 0;
}

Measured memory_bytes: 576
# coding: utf-8
DATA = """
100000
""".split("\n")

def get_debug_line():
	for i in DATA:
		yield i

if 1:
	get_line = input
else:
	get_line = get_debug_line().__next__
	get_line()

def Calc():
	K = [int(i) for i in get_line().strip().split(" ")][0]
	ret = [str(_) for _ in range(1,10)]
	size = len(ret)
	start = 0
	count = len(ret)
	while(size < K):
		for i in range(start, size):
			v = int(ret[i][-1])
			ll = ret[i]
			if not v == 0:
				count += 1
				ret.append(ll + str(v - 1))
			ret.append(ll + str(v))
			count += 1
			if not v == 9:
				count += 1
				ret.append(ll + str(v+1))

			if count >= K:
				break
		if count >= K:
			break
		start = size
		size = len(ret)
	print (ret[K-1])
Calc()

Measured memory_bytes: 10136
package main

import (
	"fmt"
)

func main() {
	var k int
	fmt.Scan(&k)
	n := 7
	for i := 1; i < int(1e6+5); i++ {
		if n%k == 0 {
			fmt.Println(i)
			return
		}
		n *= 10
		n += 7
		n %= k
	}
	fmt.Println(-1)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 1788