akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    priority_queue<pair<ll, ll>> pq;
    rep(i, m) {
        ll b, c;
        cin >> b >> c;
        pq.push(make_pair(c, b));
    }
    rep(i, n) {
        while(true) {
            if (sz(pq) == 0) break;
            auto p = pq.top(); pq.pop();
            if (a[i] >= p.first) continue;
            a[i] = p.first;
            p.second--;
            if (p.second > 0) pq.push(p);
            break;
        }
    }
    cout << accumulate(all(a), 0LL) << endl;
    return 0;
}


Measured memory_bytes: 3188
s = input()

def p_check(s):
    if s == s[::-1]:
        return True
    else:
        return False

if p_check(s) == True:
    s2 = s[:(len(s) - 1) // 2]
    if p_check(s2) == True:
        s3 = s[(len(s) + 3) // 2 - 1 : len(s)]
        if p_check(s3) == True:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 38384
# AOJ 1016: Fibonacci Sets
# Python3 2018.7.4 bal4u

f = [0]*1001
f[0], f[1] = 2, 3
for i in range(2, 1001): f[i] = (f[i-1]+f[i-2])%1001
while True:
	try: V, d = map(int, input().split())
	except: break
	ans, a = 1, sorted(f[:V])
	for i in range(1, V):
		if a[i]-a[i-1] >= d: ans += 1
	print(ans)


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





int main()
{
	int n,ans = 0;
	scanf("%d",&n);
	string s;
	cin>>s;
	int now = 0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i] == 'I') now++;
		if(s[i] == 'D') now--;
		ans = max(ans,now);
	}
	printf("%d\n",ans);
	return 0;
}

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

void Main()
{
	int a, b, c; cin >> a >> b >> c;
	if (a + b == c || a + c == b || b + c == a) cout << "Yes" << endl;
	else cout << "No" << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  char s[10];
  char sun[10] = {'S', 'u', 'n', 'n', 'y'},
       clo[10] = {'C', 'l', 'o', 'u', 'd', 'y'},
       rain[10] = {'R', 'a', 'i', 'n', 'y'};
  scanf("%s", s);
  if (s[0] == sun[0]) {
    printf("Cloudy\n");
  }else if (s[0] == clo[0]) {
    printf("Rainy\n");
  }else {
  printf("Sunny\n");
  }
  return 0;
}


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

using namespace std;
#define NIL -1
#define ll long long
#define MAX 100
#define pb push_back

int main()
{
	string a, b;
	cin >> a >> b;
	int x = stoi(a+b);
	int temp = (int)sqrt(x);
	if(temp*temp==x) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  rep2(b, k + 1, n + 1) {
    ll i = b - k;
    ans += n / b * i;
    ans += max(0LL, n % b - k + 1);
  }
  if(k == 0) ans -= n;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
const int MOD = 1000000007;

void solve() {
  int x;
  cin >> x;
  for (int i = x; i <= 100003; i++) {
    for (int j = 2; j <= i; j++) {
      if ((i != j) && (i % j == 0)) break;
      if (j == i) {
        cout << i << endl;
        return;
      }
    }
  }
 }

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define M1 1000000007LL
typedef pair<int,int> ii;
typedef vector<int> vi;
#define MAXN 100010
#define MAXM 100010
int n,m;
int p[MAXM],y[MAXM];
vector <ii> plist[MAXN];
string res[MAXM];
string cstr(int x) {
	string g = "";
	while (x > 0) {
		g = char('0' + (x%10)) + g;
		x /= 10;
	}
	while (g.length() < 6) {
		g = "0" + g;
	} 
	return g;
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	cin >> n >> m;
	for (int i=1; i<=m; i++) {
		cin >> p[i] >> y[i];
		plist[p[i]].push_back(ii(y[i],i));
	}
	for (int i=1; i<=n; i++) {
		sort(plist[i].begin(), plist[i].end());
	}
	for (int i=1; i<=n; i++) {
		int k = 0,id;
		for (ii pv : plist[i]) {
			k++;
			id = pv.second;
			res[id] = cstr(i) + cstr(k);
		}
	}
	for (int i=1; i<=m; i++) {
		cout << res[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 13184
#![allow(unused_imports)]
use proconio::marker::*;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: Chars,
        t: Chars,
    }

    let res = solve(&s, &t);
    println!("{}", res);
}

fn solve(s: &[char], t: &[char]) -> usize {
    let mut res = 0;
    for i in 0..s.len() {
        if s[i] == t[i] {
            res += 1;
        }
    }
    res
}


Measured memory_bytes: 2160
#include<bits/stdc++.h>
using namespace std;
int main(){
   int i,n,t,j,b,d,p,x,y,z;
   //cin>>t;
  //while(t--){
         string s;
         cin>>s;
         vector<int>v;
        int c=0,l=0;
        for(i=0;i<s.size();i++){
         if (s[i]=='R')
            {
                c++;
            }
            else
            {
                v.push_back(c);
                c=0;
               // l++;
            }


            if(i==s.size()-1) v.push_back(c);

        }
       int ans=0;
        sort(v.begin(),v.end(),greater<int>());
        //for (i = 0; i <v.size(); i += 2)
        //{
            //ans += v[i];
            cout<<v[0]<<endl;
       // }
        //cout<<ans<<endl;



}


Measured memory_bytes: 3628
#include <iostream>
#include <limits>
#include <queue>
#include <vector>

using namespace std;

template <typename T>
struct edge {
  int from, to;
  T cost;
  edge(int t, T c) { to = t, cost = c; }
  edge(int f, int t, T c) { from = f, to = t, cost = c; }
};

template <typename T>
using Edges = vector<edge<T>>;
template <typename T>
using Graph = vector<Edges<T>>;

template <typename T>
vector<T> dijkstra(Graph<T> &G, int s) {
  const auto INF = numeric_limits<T>::max();
  vector<T> dist(G.size(), INF);
  using Pli = pair<T, int>;
  priority_queue<Pli, vector<Pli>, greater<Pli>> que;
  dist[s] = 0;
  que.emplace(dist[s], s);  // cost, to
  while (!que.empty()) {
    Pli p = que.top();
    que.pop();
    T cost = p.first;
    int cur = p.second;
    if (dist[cur] < cost) continue;
    for (auto e : G[cur]) {
      auto next_cost = dist[cur] + e.cost;
      if (dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}

int main() {
  int n, m, r;
  cin >> n >> m >> r;
  Graph<int> G(n);

  int from, to, cost;
  for (int i = 0; i < m; i++) {
    cin >> from >> to >> cost;
    G[from].emplace_back(to, cost);
  }

  auto dist = dijkstra(G, r);

  for (auto d : dist) {
    if (d == numeric_limits<int>::max()) {
      cout << "INF\n";
    } else {
      cout << d << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 15340
main() {
    int n,a,b,memo[300001]={1};
    scanf("%d%d%d",&n,&a,&b);
    if (n > 1LL*a*b || n < a+b-1) puts("-1");
    else {
        int now=b,cnt=n;
        while(1) {
            for(int i=0;i<b;++i){
                if (a == cnt) {
                    for(int k=0;k<=n;++k)if (!memo[k]) printf("%d ",k);
                    return 0;
                }
                cnt--;
                printf("%d ",now-i);
                memo[now-i] = 1;
            }
            a--;
            now = n<now+b?n:now+b;
        }
    }
}


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

int main(){
 int N; double result = 0.0;
 cin >> N;
 vector <int> v(N);
 for(int i=0; i<N; i++) cin >> v.at(i);
 std::sort(v.begin(), v.end());
 for(int i=0; i<N; i++){
  if(i == 0 || i == 1){ result = (v.at(0)+v.at(1))/2.0;continue;}
  result = (result+v.at(i))/2.0;
 }
 cout << result << endl;
 return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int T = sc.nextInt();
        int ans = 0;

        for(int i = 1;i < T+0.5;i++){
            if(i % A == 0)
            ans += B;
        }

        System.out.println(ans);

    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  string s1;
  cin>>s1;
  if(s1=="ABC"){
    cout<<"ARC";
  }
  else{
    cout<<"ABC";
  }
  
  return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
using namespace std;
static const int VMAX = 10000;
int solve(int* arr, int len){
  int ans = 0, tmin = VMAX;
  int* narr = new int[len];
  int pos[VMAX+1];
  int* marked = new int[len];
  for(int i=0;i<len;i++){
    narr[i] = arr[i];
    marked[i] = 0;
    (arr[i]<tmin)?(tmin=arr[i]):(tmin);
  }
  sort(narr,narr+len);
  // record the position of values in sorted array
  for(int i=0;i<len;i++)
    pos[narr[i]]=i;
  // check the cycle of transform
  for(int i=0;i<len;i++){
    if(marked[i]==0){
      int sum = 0, min = VMAX, n = 0;
      for(int j = i; marked[j]==0 ; j = pos[arr[j]]){
        marked[j] = 1;
        n++;
        sum+=arr[j];
        (arr[j]<min)?(min = arr[j]):(min);
      }
      int a = sum + (n-2)*min;
      int b = sum + (n+1)*tmin + min;
      ans += (a<b)?a:b;
    }
  }
  delete[] narr;
  delete[] marked;
  return ans;
}

int main(){
  int len;
  cin >> len;
  int* arr = new int[len];
  for(int i=0;i<len;i++)
    cin>>arr[i];
  cout << solve(arr,len) << endl;
  delete[] arr;
  return 0;
}



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

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

    int n, m;
    cin >> n >> m;
    vector<vector<int>> A(n, vector<int>(m));
    vector<int> B(m);

    // input
    rep(i, n) rep(j, m) cin >> A[i][j];
    rep(i, m) cin >> B[i];

    // output
    rep(i, n) {
        int row = 0;
        rep(j, m) row += A[i][j] * B[j];
        cout << row << endl;
    }
}


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

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

#define fst first
#define snd second
#define pb push_back

const int maxn=500005,maxm=55;
const double pi=acos(-1.0);
const ll mod=1000000007;
const double eps=1e-6;

int cal(int x)
{
    int r=0;
    r+=x/500*500;x%=500;
    r<<=1;
    r+=x/5*5;
    return r;
}

int x;

int main()
{
	int i,j,k;
	scanf("%d",&x);
	printf("%d\n",cal(x));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=100050;
int a[maxn],n,ans=0;
int main() {
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		if(a[a[i]]==i)
			ans++;
	cout<<ans/2<<endl;
	return 0;
}

Measured memory_bytes: 640
//VS2015エラー回避用
#define _CRT_SECURE_NO_WARNINGS 0 
//include
#include<stdio.h>
//関数プロトタイプ宣言
void probremA(void);
//メイン関数
int main(void) {
	//A問題
	probremA();

	//getchar();
	//終了
	return 0;
}
//A問題
void probremA(void) {
	int i;			//入力数値:人数
	int n=0;		//計算結果:個数
	//入力処理
	scanf("%d", &i);

	//個数の計算
	for (int j = 0; j <= i; j++) {
		n += j;
	}
	//出力処理
	printf("%d\n", n);

	return;
}

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

# 部分和の作成
l = []
for i in range(n):
    t=0
    for j in range(i, n):
        t += a[j]
        l.append(t)
ans = 0
for i in range(40, -1, -1):
    x = 2 ** i
    s = []
    for ll in l:
        if (ans + x) & ll == (ans + x):
            s.append(ll)
    if len(s) >= k:
        ans += x
print(ans)



Measured memory_bytes: 66172
#include <stdio.h>

int main(void){
	int mem, day, x, choco = 0;

	scanf("%d", &mem);
	scanf("%d", &day);
	scanf("%d", &x);

	int a[mem];

	for (int i = 0; i < mem; i++)
	{
		scanf("%d", &a[i]);
	}

	for (int i = 0; i < mem; i++)
	{
		for (int j = 1; j < day + 1; j += a[i])
		{
			choco++;
		}
	}

	printf("%d\n", choco+x);

	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int K;
int A[100000];

bool check()
{
	int min = 2;
	int max = 3;
	for (int i = K - 2; i >= 0; i--)
	{
		int a = max / A[i];
		int b = A[i] * a;
		max = b + A[i] - 1;
	}
	return true;
}

signed main()
{
	cin >> K;
	REP(i, K) cin >> A[i];

	if (A[K - 1] != 2)
	{
		cout << -1 << endl;
		return 0;
	}

	if (!check())
	{
		cout << -1 << endl;
		return 0;
	}

	int max = 3;
	for (int i = K - 2; i >= 0; i--)
	{
		if (max < A[i])
		{
			cout << -1 << endl;
			return 0;
		}

		int a = max / A[i];
		int b = A[i] * a;
		max = b + A[i] - 1;
	}

	int min = 2;
	for (int i = K - 2; i >= 0; i--)
	{
		int a = min / A[i];
		int b = A[i] * a;
		if (b < min)
		{
			min = b + A[i];
		}
		else
		{
			min = b;
		}
	}

	if (min > max)
	{
		cout << -1 << endl;
		return 0;
	}

	cout << min << " " << max << endl;
}




Measured memory_bytes: 1024
#coding:utf-8
cnt = 0

n = int(input())
p = list(map(int,input().split()))

for i in range(1,len(p)-1):
    L = [p[i-1],p[i],p[i+1]]
    L.sort()
    if L[1] == p[i]:
        cnt += 1

print(cnt)


Measured memory_bytes: 2940
n=int(input())
a=list(map(int,input().split()))
a.sort()
num=a[0]
fin=0
res=[]
i=1
while i<n:
    #print(a[i-1],a[i])
    if a[i-1]==a[i]:
        res.append(a[i])
        i+=2
    else:
        i+=1
#print(res)
if len(res)<2:
    print(0)
else:
    print(res[-1]*res[-2])

Measured memory_bytes: 14252
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_102_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 N      PIC 9(3).
    01 INP    PIC X(1100).
    01 maxlen PIC 9(3).
    01 cur    PIC 9(4)  VALUE 1.
    01 i      PIC 9(18) VALUE 1.
    01 j      PIC 9(18).
    01 len    PIC 9(4).
    01 ZS     PIC Z(10)9.
    01 ans    PIC X(10).
    01 A      PIC 9(10).
    01 df     PIC 9(10).
    01 mn     PIC 9(10).
    01 mx     PIC 9(10).
    01 DUMMY  PIC X(1).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT N.

    MOVE N TO maxlen.

    ACCEPT INP.

    MOVE 1000000001 TO mn.
    MOVE 0 TO mx.

    PERFORM maxlen TIMES

        PERFORM VARYING j FROM cur BY 1
            UNTIL INP(j:1) = SPACE
        END-PERFORM

        COMPUTE len = j - cur

        MOVE INP(cur:len) TO A

        COMPUTE mn = FUNCTION MIN(mn, A)
        COMPUTE mx = FUNCTION MAX(mx, A)

        COMPUTE cur = j + 1

        ADD 1 TO i

    END-PERFORM.

    SUBTRACT mn FROM mx GIVING df
    MOVE df TO ZS

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


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

class Program
{
    static void Main()
    {
        var s = Console.ReadLine().Split(' ');
        var x = int.Parse(s[0]);
        var n = int.Parse(s[1]);

        if (n == 0) {
            Console.WriteLine(x);
            return;
        }

        var p = Console.ReadLine().Split(' ').Select(x => int.Parse(x));
        var u = Enumerable.Range(0, 200);
        var a = u.Except(p);

        var m = 1000;
        var ans = 0;
        foreach (var ai in a) {
            var d = Math.Abs(x - ai);
            if (d < m) {
                m = d;
                ans = ai;
            }
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28284
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200005
#define int long long
#define il inline
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define  pi  acos(-1)
#define ld  double
#define mod 1000000007
#pragma GCC optimize(2)
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int c[N];
vector<ll> g[N],ans;
int sz[N],cnt[N];
void dfs1(int x,int fa){
    sz[x]=1;
    for(auto i:g[x]){
        if(i!=fa){
            dfs1(i,x);
            sz[x]+=sz[i];
        }
    }
}
void dfs2(int x,int fa){
    int tmp=cnt[c[x]];
    for(auto i:g[x]){
        if(i==fa)continue;
        int now=cnt[c[x]];
        dfs2(i,x);
        int dif=cnt[c[x]]-now;
        int d=sz[i]-dif;
        ans[c[x]]-=(d-1)*d/2;
    }
    cnt[c[x]]=tmp+sz[x];
}
signed main() {
   // IOS
    int n;
    cin>>n;
    memset(cnt,0, sizeof(cnt));
    ans.assign(n+10,n*(n-1)/2);
    for(int i=1;i<=n;i++){cin>>c[i];ans[c[i]]++;}
    for (int j = 0; j <n-1 ; ++j) {
        int u,v;
        cin>>u>>v;
        g[v].push_back(u);
        g[u].push_back(v);
    }
    dfs1(1,0);
    dfs2(1,0);
    for (int i = 1; i <=n ; ++i) {
        ans[i]-=(n-cnt[i])*(n-cnt[i]-1)/2;
    }
    for (int i = 1; i <=n ; ++i) {
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 39092
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=0
deg=[[] for i in range(n)]
for i in range(m):
  u,v=map(int,input().split())
  deg[u-1].append(v-1)
  deg[v-1].append(u-1)
for i in range(n):
  ff=0
  for j in deg[i]:
    if(a[i]>a[j]):
      continue
    ff=1
  if(ff==0):
    c+=1
print(c)


Measured memory_bytes: 94452
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	int a;cin >> a;
	for(int i = 1;i <= 1e9;i++){
		if(i*(i+1)/2 >= a){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3604
'use strict'


const pair = (x) => {
  const a = x%10 // 末尾の一桁
  let b = 0

  // 一桁目の取得
  while(x) {
    b = x
    x = Math.floor(x/10)
  }

  return [a, b]
}

function Main(input) {
  input = input.trim()
  const N = parseInt(input)
  let c = 0
  let map = {}

  // 組み合わせのマップを作成する
  for(let i = 1; i <= N; ++i) {
    let p = pair(i)
    if(!map[p]) map[p] = 0
    map[p]++
  }

  // 組み合わせマップから答えを算出する
  for(let i = 1; i <= N; ++i) {
    let p = pair(i)
    let q = [p[1], p[0]]
    if(map[q]) {
      c += map[q]
    }
  }

  console.log(c)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 26016
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    ($arg:expr) => (println!("{:?}",$arg));
}


#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}


use std::cmp;
use std::collections::HashMap;





fn main() {

    input! { 
       s: chars,
    }

    let mut ans = "Yes";

    for i in 0..s.len(){
        if i % 2 == 1 && s[i] == 'R' {
            ans = "No";
            break;

        }
        else if i % 2 == 0 && s[i] == 'L'{
            ans = "No";
            break;
        }
    }
    
    
    println!("{}",ans);


}


Measured memory_bytes: 4352
n = gets.to_s.to_i
a = gets.to_s.split.map{|t|t.to_i}.sort.reverse

# 0 1 2 3 4 5 6
# 0 1 1 2 2 3 3
ans = 0
(n-1).times do |i|
  ans += a[(i+1)/2]
end

puts ans

Measured memory_bytes: 31168
#include <bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define forn(i,a,b) for(int i=a; i<b; i++)
#define int long long 
#define MOD 1000000000+7
 
using namespace std;

void solve () {
    string s;
    cin>>s;
    int n=s.size();
    int ans=0;
    forn(i,0,n/2) if (s[i]!=s[n-i-1]) ans++;
    cout<<ans<<endl;
}
main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int ans = 0;
  char cur = '_';
  rep(i, N) {
    if (cur != S[i]) {
      ans++;
      cur = S[i];
    }
  }
  cout << ans << '\n';
  return 0;
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'
#define what_is(x) cerr << #x << " is " << x << endl;
#define what_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << e << ' '; cerr << '\n'; //vector, set
#define what_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << x[i] << ' '; cerr <<  '\n'; //n first element of array
#define cerr_pair(x) '{' << x.st << ", " << x.nd << '}'
#define pwhat_is(x) cerr << #x << " is " << cerr_pair(x) << endl;
#define pwhat_is_v(x) cerr << #x << " is "; for(auto&e: (x)) cerr << cerr_pair(e) << ' '; cerr << '\n'; //vector, set
#define pwhat_is_a(x, n) cerr << #x << " is "; for(int i=0;i<n;i++) cerr << cerr_pair(x[i]) << ' '; cerr <<  '\n'; //n first element of array
#define int long long
#define pow mypow

typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9+5;
const int MOD = 1e9+7;

int pow(int a, int b){
	int res = 1;
	while(b){
		if (b&1) res = (res*a) % MOD;
		b /= 2;
		a = (a*a) % MOD;
	}
	return res;
}

int n, m;
int fact[5*N];

void calc_fact(){
	fact[0] = 1;
	for(int i=1; i<5*N; i++) fact[i] = (fact[i-1]*i) % MOD;
}

int C(int n, int k){
	if (k < 0 || n < 0 || n < k) return 0;
	return fact[n]*pow(fact[n-k], MOD-2) % MOD * pow(fact[k], MOD-2) % MOD;
}

int32_t main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n >> m;
	calc_fact();
	int ans = 0;
	int coef = 1;
	for(int k=0; k<=n; k++){
		ans += (MOD + coef*(C(n, k)*C(m-k, n-k) %MOD *fact[n-k] %MOD)) % MOD;
		ans %= MOD;
		coef *= -1;
	}
	ans = ans*C(m, n) % MOD *fact[n] % MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7484
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;

#define ll long long

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
ll MIN(ll a, ll b) {

	if (a < b)return a;
	else return b;

}

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a < b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return a / gcd(a, b)*b;

}
//最小公倍数

int main() {

	int A, B;

	cin >> A >> B;
	if (A <= 8 && B <= 8)cout << "Yay!" << endl;
	else cout << ":(" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

using namespace std;

const int Maxn = 101010;

int a[Maxn]={0},n;

int gcd(int x,int y)
{
	while(y)
	{
		swap(x,y);
		y%=x;
	}
	return x;
}

int calcgcd()
{
	int re = a[1];
	for(int i=2;i<=n;i++)
	{
		if(re == 1)	return 1;
		re = gcd(re,a[i]);
	}
	return re;
}

short int getans()//0: first win     1:second win
{
	int l = 0;
	bool t = 0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]&1)	l++;
		else	t^=true;
	}
	if(!t && l==1)	return -1;
	return !t;
}

bool work()//0:first lose    1:second lose
{
	for(int i=1;i<=n;i++)
	{
		if(!(a[i]&1))	continue;
		if(a[i] == 1)	return 0;
		a[i]--;
		break;
	}
	int d = calcgcd();
	if(d != 1)
		for(int i=1;i<=n;i++)	a[i] /= d;
	short int p = getans();
	if(p == -1)	return work()^1;
	return p;
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)	cin>>a[i];
	short int p = getans();
	if(p == -1)	cout<<(work() ? "First" : "Second")<<endl;
	else cout<<(p ? "Second" : "First")<<endl;
	return 0;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
using namespace std;

const int MAXN = 10000;

int a[80][80];
bool dp[80][80][MAXN + 1];



int main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }

    int h, w;
    cin >> h >> w;
    for (int i = 0; i != h; ++i)
        for (int j = 0; j != w; ++j)
            cin >> a[i][j];
    for (int i = 0; i != h; ++i)
        for (int j = 0; j != w; ++j) {
            int b;
            cin >> b;
            a[i][j] = abs(a[i][j] - b);
        }
    dp[0][0][a[0][0]] = true;
    for (int i = 0; i != h; ++i)
        for (int j = 0; j != w; ++j)
            for (int k = 0; k <= MAXN; ++k)
                if (dp[i][j][k]) {
                    if (i < h - 1) {
                        int nv = abs(k - a[i + 1][j]);
                        dp[i + 1][j][nv] = true;
                        int nv2 = k + a[i + 1][j];
                        if (nv2 <= MAXN)
                            dp[i + 1][j][nv2] = true;
                        //cout << i << ' ' << j << ' ' << k << " -> " << i + 1 << ' ' << j << ' ' << nv << ' ' << nv2 << '\n';
                    }
                    if (j < w - 1) {
                        int nv = abs(k - a[i][j + 1]);
                        dp[i][j + 1][nv] = true;
                        int nv2 = k + a[i][j + 1];
                        if (nv2 <= MAXN)
                            dp[i][j + 1][nv2] = true;
                        //cout << i << ' ' << j << ' ' << k << " -> " << i << ' ' << j + 1 << ' ' << nv << ' ' << nv2 << '\n';
                    }
                }
    for (int k = 0; k <= MAXN; ++k)
        if (dp[h - 1][w - 1][k]) {
            cout << k;
            return 0;
        }
    return 0;
}

Measured memory_bytes: 62208
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);		

		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		int ans = 0;
		for (int i = a; i <= b; i++) {
			if (c % i == 0) {
				ans++;
			}
		}

		System.out.println(ans);
		scan.close();
	}
}

Measured memory_bytes: 17360
#![allow(unused_imports)]
#![allow(non_snake_case)]
use proconio::{input, fastout};
use proconio::marker::{Chars, Bytes, Usize1};

#[fastout]
fn main() {
    input!{
        k: u32
    }
    let mut c = 0;
    for i in 0..k {
        c = (c * 10 + 7) % k;
        if c == 0 {
            println!("{}", i+1);
            return
        }
    }
    println!("{}", -1);
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void solve(){
  int a,b,c;
  cin>>a>>b>>c;
  vector<int> v1={a,b,c};
  sort(all(v1));
  if(a==b && b==c){
    cout<<0<<endl;return ;
  }
  int  ans=0;
  int x= (v1[1]-v1[0])/2;
  v1[0]=v1[0]+ x*2;
  ans+=x;
  if(v1[0]==v1[1]){
    cout<<ans+(v1[2]-v1[1])<<endl;
  }
  else{
    cout<<ans+(v1[2]-v1[1])+2<<endl;
  }
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3636
#pragma GCC optimize(2)
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
#define pii pair<long long,long long>
#define ll long long
#define fi first
#define se second
#define y1 yy1
//const long long mx=1e11;
//const long long mod=1e9+7;
const long long mod=998244353;
const long long maxn=2e5+10;
 
long long p[2]={1000000007,998244353};
long long seed[2]={500000004,500000004};
 
/*long long hh[maxn],hn[maxn*2],hy[maxn*2],ht;
void link(long long x,long long y){
	ht++;
	hn[ht]=hh[x];
	hh[x]=ht;
	hy[ht]=y;
}*/ 
 
/*long long ksm(long long x,long long y){
	long long re=1,xx=x%mod;
	while(y>0){
		if(y&1){
			re*=xx;
			re%=mod;
		}
		xx*=xx;
		xx%=mod;
		y>>=1;
	} 
	return re;
}*/
 
int tt,n,m;
string s,t;
int dp[maxn][2];

void out(int x,int y){
	if(x>0){
		if(dp[x-1][0]==-1)
			out(x-1,1);
		else if(dp[x-1][1]==-1)
			out(x-1,0);
		else{
			if(y==0){
				if(dp[x-1][0]==dp[x][y])
					out(x-1,0);
				else
					out(x-1,1);
			}else{
				if(dp[x-1][0]+2==dp[x][y])
					out(x-1,0);
				else
					out(x-1,1);
			}
		}
	}	
	if(y==0){
		cout<<"P";
	}else{
		cout<<"D";
	}
	
}

int main(){
	
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);cout.tie(0);
	
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='P')
			cout<<"P";
		else
			cout<<"D";
	}
	/*if(s[0]=='?'){
		dp[0][0]=0;
		dp[0][1]=1;
	}else if(s[0]=='P'){
		dp[0][0]=0;
		dp[0][1]=-1;
	}else{
		dp[0][0]=-1;
		dp[0][1]=1;
	}
	for(int i=1;i<s.length();i++){
		if(s[i]=='?'){
			dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
			if(s[i-1]=='?'){
				dp[i][1]=max(dp[i-1][0]+1,dp[i-1][1])+1;
			}else if(s[i-1]=='P'){
				dp[i][1]=dp[i-1][0]+2;
			}else{
				dp[i][1]=dp[i-1][1]+1;
			}
		}else if(s[i]=='P'){
			dp[i][0]=max(dp[i-1][0],dp[i-1][1]);
			dp[i][1]=-1;
		}else{
			dp[i][0]=-1;
			if(s[i-1]=='?'){
				dp[i][1]=max(dp[i-1][0]+1,dp[i-1][1])+1;
			}else if(s[i-1]=='P'){
				dp[i][1]=dp[i-1][0]+2;
			}else{
				dp[i][1]=dp[i-1][1]+1;
			}
		}
	}
	if(dp[s.length()-1][0]>=dp[s.length()-1][1]){
		out(s.length()-1,0);
	}else{
		out(s.length()-1,1);
	}*/
	
	return 0;
}

Measured memory_bytes: 3724
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    P=list(map(int,input().split()))
    N=[i for i in range(0,102)]

    for p in P:
        N.pop(N.index(p))

    L=[]
    for a in N:
        l=abs(a-x)
        L.append(l)
    
    m=L.index(min(L))
    print(N[m])

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

using namespace std;

#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ff first
#define ss second

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

ll modpow(ll a, ll b){

    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return ans;
}

ll inp[100];

int main(){

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

    ll n;
    cin>>n;

    for(int i = 0; i < n; i++) {
        cin>>inp[i];
    }

    ll sum = inp[0];
    ll ans = 0;
    for(int i = 1; i < n; i++) {
        ans = ans + sum*inp[i];
        sum += inp[i];
    }

    cout<<ans<<endl;
    


}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Data.Array.IO
import Data.List
import Control.Monad

main = do
  n <- readLn :: IO Int
  a <- getIntListBC
  memoS <- newArray ((-1), 100002) 0 :: IO (IOUArray Int Int)
  memoE <- newArray ((-1), 100002) 0 :: IO (IOUArray Int Int)
  foldM memoizeS memoS a
  foldM memoizeE memoE a
  s <- getElems memoS
  e <- getElems memoE
  let table = zip s e
  putStrLn . show . maximum $ count 0 table

bsToInt :: BC.ByteString -> Int
bsToInt = fst . fromJust . BC.readInt

getIntListBC :: IO [Int]
getIntListBC = map bsToInt . BC.words <$> BC.getLine

memoizeS :: IOUArray Int Int -> Int -> IO (IOUArray Int Int)
memoizeS memo x = do
  n <- readArray memo (x-1)
  writeArray memo (x-1) (n+1)
  return memo

memoizeE :: IOUArray Int Int -> Int -> IO (IOUArray Int Int)
memoizeE memo x = do
  n <- readArray memo (x+2)
  writeArray memo (x+2) (n+1)
  return memo

count :: Int -> [(Int, Int)] -> [Int]
count n []     = []
count n (x:xs) = let nn = n + (fst x - snd x)
                    in nn : count nn xs

Measured memory_bytes: 13692
#include <iostream>
using namespace std;
int main() {
	int n,sum=0,least=100;
	int ans;
	cin>>n;
	int s[n];
	bool iszero=true;
	for(int i=0;i<n;i++) cin>>s[i];
	for(int i=0;i<n;i++){
	    if(s[i]%10!=0){
	        iszero=false; //0 points if all is mult of 10
	        least=min(least,s[i]); //gets the least non10* num
	    } 
	    sum+=s[i];
	}
	//cout<<sum<<least<<endl;
	if(iszero==false){ //gets all the score
	    if(sum%10==0) ans=sum-least;
	    else ans=sum;
	}
	else ans=0;
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

const int N = 105;
const int M = 100005;
const long long INF = 1e16 + 5;

int n, v[N];
long long b, w[N], f[N][M]; 

int main() {
  cin >> n >> b;
  for (int j = 1; j < M; ++j) {
    f[0][j] = INF;
  }
  for (int i = 1; i <= n; ++i) {
    cin >> w[i] >> v[i];
    for (int j = 0; j < M; ++j) {
      f[i][j] = f[i - 1][j];
    }
    for (int j = v[i]; j < M; ++j) {
      f[i][j] = min(f[i][j], f[i - 1][j - v[i]] + w[i]);
    }
  }
  long long ans = 0;
  for (int i = 0; i < M; ++i) {
    if (f[n][i] <= b) ans = i;
  }
  cout << ans << endl;
  return 0;
}



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

using namespace std;

const int maxN = 1e5+10;
typedef pair<int, int> ii;
int N, Q, K, par[maxN];
long long D[maxN];
vector <ii> E[maxN];

void BFS(int x)
{
    queue <int> que;
    que.push(x); par[x] = -1;
    while (!que.empty())
    {
        x = que.front(); que.pop();
        for (int i=0; i < E[x].size(); i++)
        {
            int y = E[x][i].first, w = E[x][i].second;
            if (par[y] != 0) continue;
            par[y] = x; que.push(y);
            D[y] = D[x] + w;
        }
    }
}

int main()
{
    ios_base :: sync_with_stdio(0);
    cin >> N;
    for (int i=1,x,y,z; i < N; i++)
    {
        cin >> x >> y >> z;
        E[x].push_back(ii(y, z));
        E[y].push_back(ii(x, z));
    }
    cin >> Q >> K;
    BFS(K);
    while (Q--)
    {
        int x, y;
        cin >> x >> y;
        cout << D[x] + D[y] << '\n';
    }
}


Measured memory_bytes: 9204
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
const int Mod = 1e9 + 7;
const int mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
			comp_[i] = mod_pow(fact_[i], mod - 2, mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % mod * comp_[y] % mod;
}*/
//---------------------------------------------------
int n;
int x[200000];
signed main() {
	cin >> n;
	int ans = 1, sum = 0;
	//答え、今までにゴールしていないロボットの数
	for (int i = 0; i < n; i++) {
		sum++;
		cin >> x[i];
		if (sum * 2 - 1 > x[i]) {
			ans *= sum--;
			ans %= Mod;
		}
	}
	while (sum > 0) {
		(ans *= sum--) %= Mod;
	}
	cout << ans << endl;

}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;
    ll a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll st_a[n + 1];
    st_a[0] = 0;
    for (int i = 1; i < n + 1; i++) {
        st_a[i] = st_a[i - 1] + a[i - 1];
    }
    ll stP_a[n + 1];
    stP_a[0] = 0;
    for (int i = 1; i < n + 1; i++) {
        stP_a[i] = stP_a[i - 1] + max(a[i - 1], 0LL);
    }

    ll ans = -1;

    for (int i = 0; i + k - 1 < n; i++) {
        ll tmp = stP_a[n];
        tmp -= stP_a[i + k] - stP_a[i];
        tmp += max(0LL, st_a[i + k] - st_a[i]);
        ans = max(ans, tmp);
    }
    OUT(ans);
}


Measured memory_bytes: 2560
n = int(input())

def calc(m, res):
        q, mod = divmod(m, 26)
        if (mod == 0):
            q = q - 1
            mod = 26
            res = chr(ord("a") + (mod - 1)) + res
        else:
            res = chr(ord("a") + (mod - 1)) + res
        if (q > 0):
            calc(q, res)
        else:
            print(res)
        return
    
calc(n, "")

Measured memory_bytes: 9132
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr if(0)cout
#endif
ll n,A[MAXN];
int main()
{
	FAST
	cin>>n;
	FOR(i,0,n)cin>>A[i];
	ll side1=0,side2=0;
	side2=accumulate(A,A+n,0ll);
	ll ans=LLINF;
	FOR(i,0,n-1){
		side2-=A[i];
		side1+=A[i];
		ans=min(ans,llabs(side1-side2));
	}
	cout<<ans;
}


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

using namespace std;

typedef long long               ll;
typedef unsigned long long      ull;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef pair<ll,ll>             pairll;
typedef map<ll,ll>              mapll ;
typedef map<char,ll>            mapch;
typedef map<string,ll>          mapstr;

#define si(a) scanf("%d", &a)
#define sll(a) scanf("%lld",&a)
#define sii(a,b) scanf("%d %d", &a,&b)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pt(a) printf("%d",a)
#define pll(a) printf("%lld",a)
#define ps printf(" ")
#define nln printf("\n")
#define pi acos(-1)
#define spc " "
#define nl "\n"
#define rep(i,W) for(int i = 0; i < W; i++)
#define rep1(i,W) for(int i = 1; i <= W; i++)

ll N;
ll pos, neg,z;
vll arr;
vll poss;
vll negg;
ll sum;


void input(){
    pos = 0; neg = 0; sum = 0;
    cin >> N;
    for(int i = 1; i <= N; i++)
    {
        ll in; sll(in);
        in = in-i;
        if(in>0) {pos++; poss.pb(in);}
        else if(in < 0) {neg++; negg.pb(-in);}
        arr.pb(in);
        sum += abs(in);
    }
    z = N - pos - neg;
}

int solve(){
    ll x; ll dif;
    if(pos == neg) {printf("%lld\n",sum); return 0;}
    else if(pos > neg + z){
//        if(neg == 0) {printf("%lld",sum); return 0;}
        dif = abs(pos-neg-z); dif /= 2; dif++;
        sort(poss.begin(),poss.end());
        if(dif>pos) dif = pos;
        x = poss[dif-1];
    }
    else if(pos + z < neg){
        dif = abs(neg - pos - z); dif /= 2; dif++;
//        if(pos == 0) {printf("%lld",sum); return 0;}
        sort(negg.begin(), negg.end());
        if(dif > neg) dif = neg;
        x = -negg[dif-1];
    }
    else {
        printf("%lld\n",sum); return 0;
    }
//    cout << x << " dif " << dif << endl;
    sum = 0;
    for(int i = 0; i < arr.size();i++){
        sum += abs(arr[i]-x);
    }
    cout << sum << endl;
    return 0;
}

int main(){
    input();
    solve();
    return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int cnt = 0;
    vector<int> zeros, ones;
    if (s[0] == '0') ones.push_back(0);
    for (auto c: s) {
        if (cnt > 0 && c == '1') {
            zeros.push_back(cnt);
            cnt = 0;
            continue;
        }
        if (c == '0') cnt++;
    }
    if (cnt > 0) zeros.push_back(cnt);
    cnt = 0;
    for (auto c: s) {
        if (cnt > 0 && c == '0') {
            ones.push_back(cnt);
            cnt = 0;
            continue;
        }
        if (c == '1') cnt++;
    }
    ones.push_back(cnt);
    if (k >= zeros.size()) {
        cout << n << endl;
        return 0;
    }
    int acum = ones[0];
    int ans = 0;
    for (int i = 0; i < zeros.size(); i++) {
        acum += zeros[i];
        acum += ones[i+1];
        if (i >= k) {
            acum -= zeros[i-k];
            acum -= ones[i-k];
        }
        // cout << acum << endl;
        ans = max(ans, acum);
    }
    cout << ans << endl;
    // for (auto x: zeros) cout << x << ' ';
    // cout << endl;
    // for (auto x: ones) cout << x << ' ';
    // cout << endl;
    return 0;
}

Measured memory_bytes: 3952