akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;++i)
#define MOD 1000000007

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

    ll ans = 0;
    rep(i, N){
        if(i%2==0){
            ans += A[i];
        }else{
            ans -= A[i];
        }
    }

    
    rep(i, N){
        if(i==0){
            cout << ans << " ";
        }
        else{
            ans = -ans;
            ans += 2*A[i-1];
            cout << ans << " ";
        }
        // if(i%2==0){
        //     aans = ans;
        //     aans -= A[N-1];
        //     aans += 2*A[i-1];
        // }else{
        //     aans = -ans;
        //     aans -= A[N-1];
        //     aans += 2*A[i-1];
        // }
        
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-11-5 20:21:16
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, X;
int m[110];

int main()
{
  cin >> N >> X;
  for (auto i = 0; i < N; i++)
  {
    cin >> m[i];
  }
  for (auto i = 0; i < N; i++)
  {
    X -= m[i];
  }
  int ans = N;
  int mini = *min_element(m, m + N);
  ans += X / mini;
  cout << ans << endl;
}

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

struct stack{
	int element;
	struct stack *next;
};
int top(struct stack *s){
	return s->element;
}
struct stack* pop(struct stack *s){
	struct stack *p, *q;
	q = s;
	p = s->next;
	free(q);
	s = p;
	return s;
}
struct stack* push(struct stack *s, int x){
	struct stack *p, *q;
	q = s;
	p = (struct stack*)malloc(sizeof(struct stack));
	p->element = x;
	p->next = q;
	s = p;
	return s;
}

int main(){
	struct stack *S=NULL;
	int num;
	while (cin>>num){	
		if (num==0){
			cout<<top(S)<<endl;
			S = pop(S);
		} else{
			S=push(S, num);
		}
	}
	return 0;
}

Measured memory_bytes: 1188
while True:
  a=int(input())
  I,P,Q,R,C=[],[],[],[],[]
  if a == 0: break
  for i in range(a):
    i,p,q,r=map(int,raw_input().split())
    I.append(i)
    P.append(p)
    Q.append(q)
    R.append(r)
    t=4*(p+r)+q*9
    C.append(t)
  x,y,z,o=map(int,raw_input().split())
  hoge=0
  for i in range(a):
    if C[i]>o or P[i]>x or Q[i] > y or R[i] > z:
      continue
    else:
      print I[i]
      hoge+=1
  else:
    if hoge==0: print "NA"

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    char a, b;
    cin >> a >> b;
    if (a == b) {
        cout << 'H' << endl;
    } else {
        cout << 'D' << endl;
    }
    return 0;
}


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

int main(){
  string s;
  cin >>s;
  long cont=0;
  long ans=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='W'){
      cont++;
      ans+=i+1-cont;
    }
  }
  cout << ans;
}

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

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;}

int main(){
    ll n,x,m,ans=0;
    cin >> n >> x >> m;
    vector<ll> vec(m,-1);
    vector<ll> a;
    
    ll now=x;
    
    for(ll i=0;i<n;i++){
        if(i==0){
            vec[x]=i;
            ans+=x;
            a.push_back(x);
            continue;
        }
        now=(now*now)%m;
        if(vec[now]!=-1){
            ll haba=i-vec[now];
            ll total=0;
            for(ll j=vec[now];j<i;j++){
                total+=a[j];
            }
            ll kaisu=(n-i)/haba;
            ans+=kaisu*total;
            ll nokori=(n-i)%haba;
            for(ll j=vec[now];j<vec[now]+nokori;j++){
                ans+=a[j];
            }
            break;
        }else{
            vec[now]=i;
            ans+=now;
            a.push_back(now);
            continue;
        }
    }
    
    cout << ans << endl;

    return 0;
}











Measured memory_bytes: 4688
N = int(input())
S = input()

from collections import defaultdict
d = defaultdict(list)

for i,s in enumerate(S):
    d[s].append(i)

Bs = [0] * 8000
cnt_b = len(d["B"])

for i in  d["B"]:
    Bs[i] += 1

ans = 0
for i_r in d["R"]:
    for i_g in d["G"]:
        ls = []
        mx = max(i_r,i_g)
        mn = min(i_r,i_g)
        if (mx-mn) % 2 == 0:
            ls.append((mx+mn)//2)    
        ls.append(mx + (mx-mn))
        if  mn - (mx-mn) >= 0: 
            ls.append(mn-(mx-mn)) 
        cnt = 0
        for l in ls:
            cnt += Bs[l]
        # print(i_r,i_g,ls)
        ans += cnt_b - cnt
print(ans)

Measured memory_bytes: 69004
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

struct __INIT {
    __INIT() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __init;

int main(){
    ll H, W;
    cin >> H >> W;
    ll dif = L_INF;
    if(H % 3 == 0 or W % 3 == 0) dif = 0;
    dif = min(dif, (W / 3 + 1) * H - (W / 3) * H);
    dif = min(dif, (H / 3 + 1) * W - (H / 3) * W);
    for(ll i = 1; i <= W; i++) dif = min(dif, abs(max((H - H / 2) * i, (W - i) * H) - min((W - i) * H, H / 2 * i)));
    for(ll i = 1; i <= H; i++) dif = min(dif, abs(max((W - W / 2) * i, (H - i) * W) - min((H - i) * W, W / 2 * i)));
    cout << dif << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int N = S.length();
    String X = S.substring(0,(N-1)/2);
    String Y = S.substring(((N+3)/2)-1,N);
    if(X.equals(Y)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

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

int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  int p = 0;
  
  for(int i = 0;i < n;i ++){
    cin >> vec.at(i);
    p += vec.at(i);
  }
  
  p = p / n;
  int count = 0;
  
  for(int i = 0;i < n;i ++){
    count += (max(vec.at(i),p) - min(vec.at(i),p)) * (max(vec.at(i),p) - min(vec.at(i),p));
  }
  
  p += 1;
  int ccount = 0;
  
  for(int i = 0;i < n;i ++){
    ccount += (max(vec.at(i),p) - min(vec.at(i),p)) * (max(vec.at(i),p) - min(vec.at(i),p));
  }
  
  cout << min(count,ccount) << endl;
}

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

using namespace std;

#define N_MAX 200000
#define MOD 1000000007
#define INV2 500000004
#define AB_MAX 2000

typedef long long ll;



bool memoed[8001][4001];
int memo[8001][4001];
int comb(int n,int k){
	if(k == 0 || k == n) return 1;
	if(k > n-k)k = n-k;
	if(memoed[n][k]) return memo[n][k];
	memoed[n][k] = true;
	return memo[n][k] = (comb(n-1,k) + comb(n-1,k-1)) % MOD;
}



int n;
int a[N_MAX];
int b[N_MAX];
int dp[AB_MAX*2+1][AB_MAX*2+1];

#define DP(a,b) (dp[(a)+AB_MAX][(b)+AB_MAX])

int main(){
	scanf("%d",&n);
	int maxa = 0;
	int maxb = 0;
	for(int i = 0;i < n;i++){
		scanf("%d %d", &a[i], &b[i]);
		maxa = max(maxa, a[i]);
		maxb = max(maxb, b[i]);
		DP(-a[i],-b[i])++;
	}
	for(int aa=-maxa;aa<=maxa;aa++)
	for(int bb=-maxb;bb<=maxb;bb++){
		if(bb < maxb){ DP(aa,bb+1) += DP(aa,bb); DP(aa,bb+1) %= MOD; }
		if(aa < maxa){ DP(aa+1,bb) += DP(aa,bb); DP(aa+1,bb) %= MOD; }
	}
	int ans = 0;
	for(int i = 0;i < n;i++){
		ans += DP(a[i],b[i]);
		ans %= MOD;
		ans -= comb(2*a[i]+2*b[i],2*b[i]);
		if(ans < 0) ans += MOD;
		ans %= MOD;
	}
	ans = (int)(((ll)ans * (ll)INV2) % MOD);
	printf("%d\n", (int)ans);
	return 0;
}


Measured memory_bytes: 159232
def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l

pr = [11,
 31,
 41,
 61,
 71,
 101,
 131,
 151,
 181,
 191,
 211,
 241,
 251,
 271,
 281,
 311,
 331,
 401,
 421,
 431,
 461,
 491,
 521,
 541,
 571,
 601,
 631,
 641,
 661,
 691,
 701,
 751,
 761,
 811,
 821,
 881,
 911,
 941,
 971,
 991,
 1021,
 1031,
 1051,
 1061,
 1091,
 1151,
 1171,
 1181,
 1201,
 1231,
 1291,
 1301,
 1321,
 1361,
 1381,
 1451]


N = ii()
print(' '.join(map(str, pr[:N])))


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

using namespace std;
using ll = long long;

int main() {
    int N = 0;
    cin >> N;
    int M = 0;
    cin >> M;
    int C = 0;
    cin >> C;
    vector<int> b(M);
    for(int i = 0; i < M; i++)
    {
    cin >> b.at(i);
    }
    int ansans = 0;
    int ans = 0;
    int t;
    for (size_t i = 0; i < N; i++)
    {
        ans = 0;
        for (size_t j = 0; j < M; j++)
        {
            cin >> t;
            ans += t*b.at(j);
        }
        if (ans + C > 0)
        {
            ansans++;
        }
        
        
    }
    cout << ansans << endl;
    
    

    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,s1,s2;
  cin>>s>>s1;
  s2=s1.substr(0,s1.size()-1);
  if(s.size()+1==s1.size()&&s2==s)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i]--;
  }
  int l = 0, r = 1001001001;
  auto ok = [&](int c) {
    long long cnt = 0;
    for (int i = 0; i < n; i++) cnt += a[i] / c;
    return cnt <= k;
  };
  while (r - l > 1) {
    int c = (l + r) / 2;
    (ok(c) ? r : l) = c;
  }
  cout << r << endl;
  return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll h, w;
    cin >> h >> w;
    string s[h];
    rep(i, h) { cin >> s[i]; }
    ll dp[h][w];
    if (s[0][0] == '.') {
        dp[0][0] = 0;
    } else {
        dp[0][0] = 1;
    }
    repd(i, 1, w) {
        dp[0][i] = dp[0][i - 1];
        if (s[0][i] == '#') {
            if (s[0][i - 1] == '.') {
                dp[0][i]++;
            }
        }
    }
    repd(i, 1, h) {
        dp[i][0] = dp[i - 1][0];
        if (s[i][0] == '#') {
            if (s[i - 1][0] == '.') {
                dp[i][0]++;
            }
        }

        repd(j, 1, w) {
            ll up = dp[i - 1][j], left = dp[i][j - 1];
            if (s[i][j] == '#') {
                if (s[i - 1][j] == '.') {
                    up++;
                }
                if (s[i][j - 1] == '.') {
                    left++;
                }
            }
            dp[i][j] = min(up, left);
        }
    }
    cout << dp[h - 1][w - 1] << endl;
    return 0;
}



Measured memory_bytes: 384
N = STDIN.gets.to_i

seen = {}
success = true
prev = nil
N.times do
  word = STDIN.gets.strip

  if seen[word]
    success = false
    break
  end
  seen[word] = true

  if prev
    if prev[-1] != word[0]
      success = false
      break
    end
  end
  prev = word
end

if success
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int w=max(a,c);
    int x=min(b,d);
    if(w>x){cout<<0<<endl;}
    else{cout<<x-w<<endl;}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vv vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int P[100000 + 10];
int member[100000 + 10];

int root(int a) {
    if(P[a] == a) return a;
    else return (P[a] = root(P[a]));
}

bool is_same_set(int a, int b) { return root(a) == root(b); }

int unite(int a, int b) { //不便度の減少分を返す
    if (!is_same_set(a, b)) {
        int A = member[root(a)];
        int B = member[root(b)];
        P[root(a)] = root(b);
        member[root(b)] += A;
        // cout << "A:" << A << "," << "B:" << B << endl;
        return A*B;
    } else return 0;
}

signed main(void) {
    int N, M; cin >> N >> M;
    REP(i, 1, N) {
        P[i] = i;
        member[i] = 1;
    }
    stack<int> ans;
    pi AB[M];
    rep(i, M) {
        int A, B; cin >> A >> B;
        AB[i] = mp(A, B);
    }
    
    int res = N * (N-1) / 2;
    rev(i, M) {
        ans.push(res);
        int A = AB[i].fi;
        int B = AB[i].se;
        res -= unite(A, B);
    }
    
    while(!ans.empty()) {
        cout << ans.top() << endl;
        ans.pop();
    }
    
    return 0;
}

Measured memory_bytes: 5020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
using Tree = vector<pair<int, int>>;

int main()
{
    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    vector<int> tmp(n);
    tmp = p;
    int hoge = 0;
    sort(tmp.begin(), tmp.end());
    for (int i = 0; i < n; i++)
    {
        if (tmp[i] != p[i])
            hoge++;
    }
    cout << ((hoge <= 2) ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
(let* ((n (read))
       (m (read))
       (c (read))
       (a (loop :repeat m :collect (read)))
       (lst (loop :repeat n :collect
                            (loop :repeat m :collect (read)))))
  (defun func (b)
    (< 0 (reduce #'+ (cons c (mapcar #'* a b)))))
  (princ (count t (mapcar #'func lst)))
  )

Measured memory_bytes: 9440
import java.util.*;
import java.io.*;

public class Main {

    /**
     *
     * k = 1
     *
     * 2^17+1  2^17     0
     * 1      2^17+1   1
     *
     * dp[2][2] = max(
     */

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int r = sc.nextInt();
        System.out.println(r*2.0*Math.PI);
    }

    private static void solve(int[] ans, int n, int[] arr) {

    }

    /**\
     *
     * 4
     * 2 3 4 5
     *
     *
     * 1 2 3 4 5 6 7 8
     * 2 6 3 7 4 8 5 9
     */

    // 1 1 1 0 0 0
    // 0 0 1 1 1 1


    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

/**
 * 7 3
 * 3 1 5
 * 9 6 5
 *
 * i = 1: 1
 * i = 2: 2
 * i = 3: 3
 *
 *
 * 1 2 3 3 3 3 3
 */


/**
 *
 *  1+1
 **/


Measured memory_bytes: 33228
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int count = 0;
        int n = scan.nextInt(), k = scan.nextInt();
        int man[] = new int[n];

        for (int i = 0; i < n; i++) man[i] = scan.nextInt();
        for (int tmp : man) if (tmp >= k) count++;

        System.out.println(count);
    }
}


Measured memory_bytes: 44744
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
using namespace std;
using ll=long long;

int main(){
    int piyo=0;
    ll k;
    cin>>k;
    ll x,y;
    cin>>x>>y;
    if(k%2==0 && (x+y)%2==1){
        cout<<-1<<endl;
        return 0;
    }
    vector<ll> X;
    vector<ll> Y;
    ll tmpX=0,tmpY=0;
    ll dx[]={k,0,-k,0};
    ll dy[]={0,k,0,-k};
    ll dx2[]={-1,-1,1,1};
    ll dy2[]={1,-1,-1,1};
    auto dist=[&](int x1,int y1){
        return abs(x1-x)+abs(y1-y);
    };
    while(tmpX!=x || tmpY!=y){
        if(dist(tmpX,tmpY)==k){
            tmpX=x,tmpY=y;
            X.push_back(tmpX);
            Y.push_back(tmpY);
            continue;
        }
        int id=-1;
        ll tmpD=1e15;
        for(int i=0;i<4;i++){
            ll toX=tmpX+dx[i];
            ll toY=tmpY+dy[i];
            if(dist(toX,toY)<tmpD){
                id=i;
                tmpD=dist(toX,toY);
            }
        }

        ll toX=tmpX+dx[id];
        ll toY=tmpY+dy[id];

        if(dist(tmpX,tmpY)<=2*k){
            ll tarX=toX;
            ll tarY=toY;
            vector<ll> kouhoX;
            vector<ll> kouhoY;
            for(int ix=-1;ix<=1;ix+=2){
                for(int jx=-1;jx<=1;jx+=2){
                    for(int iy=-1;iy<=1;iy+=2){
                       for(int jy=-1;jy<=1;jy+=2){
                           ll a=ix;
                           ll b=iy;
                           ll c=k+ix*tmpX+iy*tmpY;
                           ll d=jx;
                           ll e=jy;
                           ll f=k+jx*x+jy*y;
                           ll v=a*e-b*d;
                           if(v==0) continue;
                           kouhoX.push_back((c*e-f*b)/v);
                           kouhoY.push_back((-c*d+f*a)/v);
                        }
                    }       
                }
            }
            for(int i=0;i<kouhoX.size();i++){
                if(dist(kouhoX[i],kouhoY[i])==k && 
                    abs(kouhoX[i]-tmpX)+abs(kouhoY[i]-tmpY)==k){
                        tarX=kouhoX[i];
                        tarY=kouhoY[i];                                            
                    }
            }
            tmpX=tarX;
            tmpY=tarY;
            X.push_back(tarX);
            Y.push_back(tarY);
            piyo++;
            if(piyo>5){
                cout<<-1<<endl;
                return 0;
            }
            continue;
        }
        tmpX=toX;
        tmpY=toY;
        X.push_back(toX);
        Y.push_back(toY);
        if(X.size()>=1e6){
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<X.size()<<endl;
    for(int i=0;i<X.size();i++){
        cout<<X[i]<<" "<<Y[i]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 5604
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Data.Array.IArray
import           Data.Array.IO
import           Data.Array.MArray
import           Data.IORef

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

dfs :: IOUArray Int Int -- discover
    -> IOUArray Int Int -- finished
    -> Array Int [Int]  -- graph
    -> IO ()
dfs d f g = do
    let (from, to) = bounds g
    t <- newIORef 0
    forM_ [from .. to] $ \i -> go t i
  where
    go :: IORef Int -> Int -> IO ()
    go ref k = do
        dv <- readArray d k
        when (dv == -1) $ do
            modifyIORef ref (+ 1)
            writeArrayIf (== -1) d k =<< readIORef ref
            mapM_ (go ref) (g ! k)
            modifyIORef ref (+ 1)
            writeArrayIf (== -1) f k =<< readIORef ref

writeArrayIf :: (MArray a e m, Ix i) => (e -> Bool) -> a i e -> i -> e -> m ()
writeArrayIf p a i e = do
    v <- readArray a i
    when (p v) $ writeArray a i e

main :: IO ()
main = do
    n <- readLn
    xss <- fmap (fmap readi . B.words) . B.lines <$> B.getContents

    let f [i, 0]   = (i, [])
        f (i:_:ks) = (i, ks)
    let arr = array (1, n) $ fmap f xss
    discover <- newArray (1, n) (-1)
    finished <- newArray (1, n) (-1)

    dfs discover finished arr

    forM_ [1 .. n] $ \i -> do
        a <- readArray discover i
        b <- readArray finished i
        putStrLn . unwords $ fmap show [i, a, b]



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

#define MAX 100002

int n;

vector<pair<int,int> > v;
priority_queue<pair<int,int> ,vector<pair<int,int> > , greater<pair<int,int> > > mint;
priority_queue<pair<int,int> > maxt;
bool used[MAX];


int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int l,r;
		scanf("%d%d",&l,&r);
		v.push_back(make_pair(l,r));
	}
	long long int ans=0;
	for(int k=0;k<2;k++){
		memset(used,false,sizeof(used));
	for(int i=0;i<n;i++){
		int l=v[i].first;
		int r=v[i].second;
		v.push_back(make_pair(l,r));
		mint.push(make_pair(l,i));
		maxt.push(make_pair(l,i));
		mint.push(make_pair(r,i));
		maxt.push(make_pair(r,i));
	}
	bool dir=k;
	long long int cur=0;
	int pos=0;
	while(true){
		if(dir==false){
			bool ok=false;
			while(!maxt.empty()){
				auto it=maxt.top();
				maxt.pop();
				if(it.first<pos)continue;
				if(v[it.second].first<=pos&&pos<v[it.second].second)continue;
				int dist=min(abs(v[it.second].first-pos),abs(v[it.second].second-pos));
				if(dist!=abs(it.first-pos))continue;
				if(used[it.second])continue;
				used[it.second]=true;
				cur+=2*it.first;
				pos=it.first;
				ok=true;
				break;
			}
			if(ok==false)break;
		}
		else{
			bool ok=false;
			while(!mint.empty()){
				auto it=mint.top();
				mint.pop();
				if(it.first>pos)continue;
				if(v[it.second].first<=pos&&pos<=v[it.second].second)continue;
				int dist=min(abs(v[it.second].first-pos),abs(v[it.second].second-pos));
				if(dist!=abs(it.first-pos))continue;
				if(used[it.second])continue;
				used[it.second]=true;
				cur-=2*it.first;
				pos=it.first;
				ok=true;
				break;
			}
			if(ok==false)break;
		}
		ans=max(ans,cur);
		dir^=true;
	}
}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 13420
#include<cstdio>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define N 101000
using namespace std;
int last[N],nxt[N*2],to[N*2],n,tot=1,f[N],g[N],ans=0;
void putin(int x,int y)
{
	nxt[++tot]=last[x];last[x]=tot;to[tot]=y;
}
void dg(int x,int fa)
{
	int jy=0;
	for(int i=last[x];i;i=nxt[i])
	{
		int y=to[i];if(y==fa) continue;
		dg(y,x);
		jy|=g[x]&g[y];
		g[x]=g[x]|g[y];
	}
	for(f[x]=0;((1<<f[x])<=jy)||((1<<f[x])&g[x]);f[x]++);
	ans=max(ans,f[x]);
	g[x]=g[x]>>f[x]<<f[x];
	g[x]|=1<<f[x];
}
int main()
{
	scanf("%d",&n);
	fo(i,1,n-1)
	{
		int x,y;scanf("%d%d",&x,&y);
		putin(x,y);putin(y,x);
	}
	dg(1,0);
	printf("%d\n",ans);
}

Measured memory_bytes: 7424
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<long long> h;
    long long l;
    for(int i = 0; i < n; i++){
        cin >> l;
        h.push_back(l);
    }
    sort(h.begin(), h.end());
    long long ans = 1000000001;
    for(int i = 0; i <= n-k; i++){
        ans = min(ans, h[k-1+i] - h[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>
#include <map>
#include <string.h>

std::map<long long int,int> check;
char x[200010][20];
int main()
{
	int a;
	scanf("%d",&a);
	for(int i=1;i<=a;i++)
	{
		int b;
		scanf("%s",x[i]+1);
		b = strlen(x[i]+1);
		
		long long int s = 0;
		for(int j=1;j<=b;j++)
		{
			s*=27;
			s+=(x[i][j]-'a'+1);
		}
		check[s]++;
	}
	int count = 0;
	for(std::map<long long int,int> ::iterator it = check.begin();it!=check.end();it++) count++;
	printf("%d",count);
}

Measured memory_bytes: 19716
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,w=0,tl=0,r=0,a=0;
    cin>>t;
    while(t--)
    {
        string s;
        cin>>s;
        if(s[0]=='A')
        a++;
        else if(s[0]=='R')
        r++;
        else if(s[0]=='T')
        tl++;
        else
        w++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<tl<<endl;
    cout<<"RE x "<<r<<endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
int main(){
    int n,t=0,x=0,y=0;
    for(scanf("%d",&n);n--;){
        int t0,x0,y0;
        scanf("%d%d%d",&t0,&x0,&y0);
        {
            int dt=t0-t,dx=x0-x,dy=y0-y;
            if(dx+dy>dt || (dt-dx-dy)%2){
                puts("No");
                return 0;
            }
        }
        t=t0;x=x0;y=y0;
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#include<vector>
#define rep(i,x,y) for(int i=x; i<=y; ++i)
#define repd(i,x,y) for(int i=x; i>=y; --i)
#define pb push_back

using namespace std;
const int N=305,M=5000005,mod=1000000007;
int n,m,id[N][N][N],tp,f[2][M],vis[M],nw,tot,ans;
struct data{int l,x;};
vector <data> vt[N];

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

void inc(int x,int y)
{
	if(vis[x]!=nw) f[tp][x]=0,vis[x]=nw;
	f[tp][x]=(f[tp][x]+y)%mod;
}

int main()
{
	n=getint(),m=getint();
	rep(i,1,m)
	{
		int l=getint(),r=getint(),x=getint();
		vt[r].pb((data){l,x});
	}
	memset(vis,-1,sizeof(vis));
	rep(i,0,n) rep(j,0,i) rep(k,0,j) id[i][j][k]=++tot;
	f[0][id[0][0][0]]=1,vis[id[0][0][0]]=0;
	rep(i,1,n)
	{
		tp^=1,nw=i;
		rep(x,0,i-1)
			rep(y,0,max(0,x-1))
				rep(z,0,max(0,y-1))
					if(vis[id[x][y][z]]==i-1)
					{
						int tmp=f[tp^1][id[x][y][z]];
						inc(id[i][y][z],tmp);
						inc(id[i][x][z],tmp);
						inc(id[i][x][y],tmp);
					}
		rep(x,0,i)
			rep(y,0,max(0,x-1))
				rep(z,0,max(0,y-1))
				{
					int sz=vt[i].size();
					bool jdg=0;
					rep(j,0,sz-1)
					{
						int l=vt[i][j].l;
						int t=(x>=l)+(y>=l)+(z>=l);
						if(t!=vt[i][j].x) {jdg=1; break;}
					}
					if(jdg) vis[id[x][y][z]]=-1;
				}
	}
	rep(i,1,tot) if(vis[i]==n) ans=(ans+f[tp][i])%mod;
	printf("%d\n",ans);			
	return 0;
}

Measured memory_bytes: 168320
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL H,W;
char A[100][100];

string ans = "No";
 
void solve(){
	vector<int> alpha(26,0);//文字cが、Aに何個含まれるかをalpha[c]とおく
	for(int h=0;h<H;h++){
    	for(int w=0;w<W;w++){
    		alpha[A[h][w]-'a']++;
    	}
    }

    vector<int> num(4,0);//alphaのうち、4で割った余りがiのものが何個あるかをnum[i]とおく
    for(int i=0;i<26;i++){
    	num[alpha[i]%4]++;
    }

    if (H%2==1 && W%2==1) {
        if (num[3]) {
            num[3]--;
            num[1]++;
            num[2]++;
        }
        if (num[3]) return;
        if (num[1] == 1 && num[2] <= (H/2+W/2)) ans = "Yes";
        else return;
    } else if (H%2==1) {
        if (num[3] || num[1]) return;
        if (num[2] <= W/2) ans = "Yes";
        else return;
    } else if (W%2==1) {
        if (num[3] || num[1]) return;
        if (num[2] <= H/2) ans = "Yes";
        else return;
    } else {
        if (num[1] || num[2] || num[3]) return;
        else ans = "Yes";
    }
}
 
int main(){
    cin >> H >> W;
    for(int h=0;h<H;h++){
    	for(int w=0;w<W;w++) cin >> A[h][w];
    }
 
    solve();
 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
N = int(input())
c = {(str(i), str(j)):0 for i in range(10) for j in range(10)}
for i in range(1, N+1):
    s = str(i)
    c[(s[0], s[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        i, j = str(i), str(j)
        ans += c[(i, j)] * c[(j, i)]
print(ans)


Measured memory_bytes: 3064
N, K = map(int, input().split())
Vs = list(map(int, input().split()))
rs = []
for i in range(0, min(N, K)+1):
  for j in range(0, min(N, K)-i+1):
    k = max(0, K-i-j)
    Vs2 = Vs[:i]+Vs[N-j:]
    VsN = [v for v in Vs2 if v < 0]
    if len(VsN) < k:
      r = sum(Vs2)-sum(VsN)
    else:
      r = sum(Vs2)-sum(sorted(VsN)[:k])
    rs.append(r)
r = max(rs)
print(r)


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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll solve(ll N, ll M, ll K, const vector<ll>& xs, const vector<ll>& ys)
{
    ll ans = 0, sum = 0, a = 0, b = 0, c = 0;

    while (a < N and (sum + xs[a] <= K))
    {
        ++c;
        sum += xs[a++];
    }

    while (b < M and (sum + ys[b] <= K))
    {
        sum += ys[b++];
        ++c;
    }

    ans = c;
    --a;

    while (a >= 0)
    {
        sum -= xs[a--];
        --c;

        while (b < M and (sum + ys[b] <= K))
        {
            sum += ys[b++];
            ++c;
        }

        ans = max(ans, c);
    }

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    ll N, M, K;
    cin >> N >> M >> K;

    vector<ll> xs(N), ys(M);

    for (int i = 0; i < N; ++i)
        cin >> xs[i];

    for (int i = 0; i < M; ++i)
        cin >> ys[i];

    auto ans = max(solve(N, M, K, xs, ys), solve(M, N, K, ys, xs));

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 6424
from itertools import combinations

l,r = map(int, input().split())

if r//673 > (l-1)//673 and r//3 >(l-1)//3:
  print('0')

else:
    cmb = list(combinations(range(l, r+1), 2))
    mod = [(cmb[i][0] * cmb[i][1]) % 2019 for i in range(len(cmb))]
    print(min(mod))

Measured memory_bytes: 20288
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

ll dp[3001][3001][4] = {};
ll tr[3001][3001] = {};

int main() {
	ll ans = 0;
	ll tmp;
	int r, c, k; cin >> r >> c >> k;
	int X, Y;
	ll V;
	REP(no, k){
		cin >> X >> Y >> V;
		tr[X][Y] = V;
		//tr[no / c][no%c] = 1000000000;
	}
	REP1(x, r){
		REP1(y, c){
			REP(st, 4) dp[x][y][0] = max(dp[x][y][0], dp[x-1][y][st]);
			REP(st, 4) dp[x][y][1] = max(dp[x][y][1], dp[x-1][y][st]+tr[x][y]);
			REP(st, 4) dp[x][y][st] = max(dp[x][y][st], dp[x][y-1][st]);
			REP1(st, 3) dp[x][y][st] = max(dp[x][y][st], dp[x][y-1][st-1]+tr[x][y]);
			//REP(i, 4) cout << dp[x][y][i] << " ";
		}
		//cout << endl;
	}
	REP(i, 4) ans = max(ans, dp[r][c][i]);
	cout << ans << endl;
}

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

using namespace std;


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

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

  vector<vector<size_t>> idxs(10);

  for (size_t i = 0; i < s.size(); ++i) {
    idxs[s[i] - '0'].push_back(i);
  }

  int cnt = 0;
  for (int c1 = 0; c1 <= 9; ++c1) {
    if (idxs[c1].empty()) continue;
    int idx = idxs[c1][0];
    for (int c2 = 0; c2 <= 9; ++c2) {
      auto& x2 = idxs[c2];
      auto it = upper_bound(x2.begin(), x2.end(), idx);
      if (it == x2.end()) continue;
      auto idx2 = *it;
      for (int c3 = 0; c3 <= 9; ++c3) {
        auto& x3 = idxs[c3];
        auto it = upper_bound(x3.begin(), x3.end(), idx2);
        if (it == x3.end()) continue;
        ++cnt;
      }
    }
  }
  cout << cnt << endl;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>d(n); for(auto&&i:d)cin>>i;
	sort(d.begin(),d.end());
	cout<<(d.at(n/2)-d.at(n/2-1))<<"\n"s;
}

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


int main(){  
  int x[5];
  rep(i, 5) cin >> x[i];
  rep(i,5){
    if(x[i]==0){
      cout << i+1;
    }
  }

  return 0;
}

Measured memory_bytes: 3588
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter
n = ni()
s = ns()
cnt = Counter(s)

print("Yes" if cnt['R'] > cnt['B'] else "No")

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int dp[N];
int arr[N];
int n;
int k;

int calc(int x)
{
	if(x == n-1)
		return 0;
	if( x >= n)
		return 1e9;
	if(dp[x] != -1)
		return dp[x];
	//cout << x << endl;
	int mn = 1e9;
	for(int i = 1; i <= k; i++)
	{
		if(x + i < n)
		{
			int val = calc(x + i) + abs(arr[x] - arr[x + i]);
			mn = min(mn, val);
		}
	}
	return dp[x] = mn;
}
int main() {
	cin >> n >> k;
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	memset(dp, -1, sizeof dp);
	cout << calc(0);
	return 0;
}

Measured memory_bytes: 12144
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
#define fl(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
#define pob pop_back
#define int long long int
#define ff first
#define ss second
#define pi 3.1415926535898
#define vi vector<int>
#define mi map<int,int>
#define umi unordered_map<int,int>
#define endl "\n"
#define w(x) int x; cin>>x; while(x--)
#define db(x) cout<<(#x)<<" "<<(x)<<"\n";
#define ios ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;
//using namespace boost::multiprecision;
int mod=1000000007;
int gcd(int a,int b){
     return (b == 0) ? a :gcd(b, a % b);
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
}
void c_p_c(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
int32_t main(){
    
    ios
    //c_p_c();
    //w(t)
    {int n;
        cin>>n;
        int aa=INT_MIN;
        map<string,int>mp;
        fl(i,0,n-1){
            string s;
            cin>>s;
            mp[s]++;
        }
        for(auto x:mp){
            aa=max(aa,x.ss);
        }
        vector<string>ss;
        for(auto x:mp){
            if(x.ss==aa){
                ss.pb(x.ff);
            }
        }
        sort(ss.begin(),ss.end());
        for(int i=0;i<ss.size();i++){
            cout<<ss[i]<<endl;
        }
        end:;
    }

    return 0;
}



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

int main() {
  int N;
  cin >>N;
  vector<string> s(N);
  for(int i=0;i<N;i++){
  	cin >>s.at(i);
  }
  int M;
  cin >>M;
  vector<string> t(M);
  for(int i=0;i<M;i++){
  	cin >>t.at(i);
  }
  int max=0;
  int temp=0;
  for(int i=0;i<N;i++){
    temp=0;
  	for(int j=0;j<N;j++){
      if(s.at(i)==s.at(j)){temp++;}
    }
  	for(int k=0;k<M;k++){
      if(s.at(i)==t.at(k)){temp--;}
    }
    if(temp>max){max=temp;}
  }
  cout <<max<<endl;
}

Measured memory_bytes: 256
//Created Time:2019年10月05日 星期六 20时41分32秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#define N 202

using namespace std;

int n, ans;
int a[N];
char mp[N][N];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%s", mp[i] + 1);
	for(int i = 1; i <= n; ++i){
		memset(a, 0, sizeof a);
		a[i] = 1; queue < int > Q; Q.push(i);
		while(!Q.empty()){
			int u = Q.front(); Q.pop();
			for(int v = 1; v <= n; ++v){
				if(mp[u][v] == '1'){
					if(a[v] && abs(a[v] - a[u]) != 1){
						puts("-1"); return 0;
					}
					if(!a[v]) a[v] = a[u] + 1, Q.push(v);
				}
			}
		}
		for(int j = 1; j <= n; ++j) ans = max(ans, a[j]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
typedef std::vector <int> vi;
vi PRIMES;
vi prime(int n){
	vi s,p;
	int i,j,x,h;
	for (i=1;i<=n;i+=2) s.push_back(i);
	h=s.size();
	for (i=1;i<=(int)pow(n,0.5);i++)
		if (x=s[i]) for (j=i+x;j<h;j+=x) s[j]=0;
	s[0]=2;
	for (i=0;i<h;i++) if(s[i]!=0) p.push_back(s[i]);
	return p;
}
int main(void){
	int n,s,i;
	PRIMES=prime(105000);
	while (true){
		std::cin>>n; if (n==0) break;
		s=0;
		for (i=0;i<n;i++) s+=PRIMES[i];
		std::cout<<s<<"\n";
	}
}

Measured memory_bytes: 1384
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const ll mod = 1000000007;
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[100005],R[100005];
void make(){
	F[0] = 1;
	for(int i=1;i<100005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<100005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
int n;
ll a[100005],ans;
ll s[100005];
int main(){
	make();
	cin>>n;
	rep(i,n) cin >> a[i];
	rep(i,n) a[i] = a[i+1]-a[i];
	s[1] = 1;
	for(int i=2;i<100005;i++){
		s[i] = s[i-1]*i+F[i-1];
		s[i] %= mod;
	}
	for(int i=1;i<=n-1;i++){
		ll coef = s[i] * F[n-1] % mod * R[i] % mod;
		ans += coef * a[i-1] % mod;
	}
	cout <<(ans%mod+mod)%mod << endl;
}

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

int main() {
	ll a,b,n;
	cin>>a>>b>>n;
	ll x=min(b-1,n);
	ll ans=(a*x)/b-(a*(x/b));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
int main(){
    double r, p, are, cric;
    p = 3.141592653589;
    scanf("%lf", &r);
    are = r * r * p;
    cric = 2 * r * p;
    printf("%f %f\n", are, cric);
    
    return 0;
}


Measured memory_bytes: 2104
while True:
  m, f, r = list(map(int, input().split()))
  total = m + f
  if m == -1 and f == -1 and r == -1:
    break
  elif m == -1 or f == -1:
    print('F')
  elif total >= 80:
    print('A')
  elif total >= 65:
    print('B')
  elif total >= 50 or (total >= 30 and r >= 50):
    print('C')
  elif total >= 30:
    print('D')
  else:
    print('F')


Measured memory_bytes: 5596
/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define REP(i,a,n) for(i=a;i<=n;i++)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,b,a) for(i=b;i>=a;i--)
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const ll mod=1e9+7;
const ll MAXN=100200;
ll i,j,mask,test;
vector<ll> v[MAXN],vis(MAXN);
void dfs(ll p)
{
    vis[p]=1;
    for(auto x:v[p])
    {
        if(vis[x]==0)
            dfs(x);
    }
}
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE*/
ll n,m;
cin>>n>>m;
while(m--)
{
    ll x,y;
    cin>>x>>y;
    v[x].push_back(y);
    v[y].push_back(x);
}
ll cnt=0;
F(i,1,n+1)
{
    if(vis[i]==0)
    {
        dfs(i);
        cnt++;
    }
}
cout<<cnt-1;
return 0;
}


Measured memory_bytes: 10568
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k,n,ans;
  cin>>k>>n;
  vector<int> veca(n);
  for(int i=0;i<n;i++){
    cin>>veca.at(i);
  }
  vector<int> vecb(n);
  vecb.at(0)=veca.at(0)+k-veca.at(n-1);
  for(int i=1;i<n;i++){
    vecb.at(i)=veca.at(i)-veca.at(i-1);
  }
  sort(vecb.begin(), vecb.end());
  ans=k-vecb.at(n-1);
  cout<<ans<<endl;
}

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

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

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

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 81

//全部売る(k=0)/買う(k=1)/何もしない(k=2)実行時

//dp[i][j][k]:i日目にj株持っている時の最大所持金
ll dp[MAXN][200];

int main(){
  int n;cin>>n;
  vector<int>a(n);
  rep(i, n)cin>>a[i];

  bool buying=true;
  ll bp=200, sp=0, coin=1000, stocks=0;
  for(auto t: a){
//cout<<t<<' '<<bp<<' '<<sp<<' '<<coin<<' '<<stocks<<endl;
    if(buying){
      if(t>bp){
        buying=false;
        stocks += coin/bp;
        coin%=bp;
        sp=t;
        bp=300;
      }else{
        bp=t;
      }
    }else{
      if(t<sp){
        buying=true;
        bp=t;
        coin+=sp*stocks;
        stocks=0;
        sp=0;
      }else{
        sp=t;
      }
    }
  }

  if(stocks)coin+=sp*stocks;

  cout<<coin<<endl;

  return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	string s1,s2;
	cin >> s1 >> s2;
	bool flag = true;
	bool appeared[255]{};
	for(char c = 'a'; c <= 'z'; c++) {
		char s2c = '\0';
		for(int i = 0; i < s1.size(); i++) {
			if(c==s1[i]) {
				if(s2c=='\0') {
					s2c=s2[i];
					flag &= !(appeared[s2[i]]);
					appeared[s2[i]] = true;
				}
				else {
					flag &= s2c==s2[i];
				}
			}
		}
	}
	cout << ((flag)?"Yes":"No") << endl;
}


Measured memory_bytes: 776
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <array>
#include <utility>
#include <climits>
using namespace std;

int rnd(int &a, int &b){
	static const int C = ~(1u << 31);
	static const int M = (1 << 16) - 1;
	a = 36969 * (a & M) + (a >> 16);
	b = 18000 * (b & M) + (b >> 16);
	return (C & ((a << 16) + b)) % 1000000;
}

int main(){
	int m, n, a, b, x, y, z;
	while(scanf("%d%d%d%d", &m, &n, &a, &b), m | n){
		vector<array<int,3>> v(n + m);
		for(int i = 0; i < m; ++i){
			scanf("%d%d%d", &x, &y, &z);
			v[i] = {{x, -y, -z}};
		}
		for(int i = m; i < n + m; ++i){
			x = rnd(a, b);
			y = rnd(a, b);
			z = rnd(a, b);
			v[i] = {{x, -y, -z}};
		}
		sort(v.begin(), v.end());
		int ans = 0;
		vector<map<int,int>> mps(m + n + 3);
		mps[0][100] = 100;
		for(size_t i = 1; i < mps.size(); ++i){
			mps[i][INT_MIN] = INT_MAX;
		}
		for(int i = 0; i < m + n; ++i){
			y = v[i][1];
			z = v[i][2];
			int left = 1, right = ans + 2;
			while(right - left > 1){
				int mid = (left + right) >> 1;
				const auto &mpm = mps[mid - 1];
				auto it = mpm.upper_bound(y);
				if(it != mpm.end() && it->second > z){
					left = mid;
				}
				else{
					right = mid;
				}
			}
			
			auto &mpl = mps[left];
			for(auto it = mpl.upper_bound(y); ; ){
				--it;
				if(it->second > z){
					break;
				}
				it = mpl.erase(it);
			}
			
			int &t = mpl.insert(make_pair(y, z)).first->second;
			t = max(t, z);
			ans = max(ans, left);
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 37032
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n;
  cin>>n;
  int res=0;
  vecint v(n), c(n);
  REP(i,n) cin>>v[i];
  REP(i,n) cin>>c[i];
  REP(i,n) {
    if (v[i] > c[i]) {
      res += v[i] - c[i];
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long x = sc.nextLong();
		long now = 100;
		long ans = 0;

		while (now < x) {
			now +=  now / 100;
			ans++;
		}

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 35644
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(void){
    int a, b, x;
    cin >> a >> b >> x;

    std::cout<<std::fixed<<std::setprecision(10);

    if((double)x>a*a*b*0.50){
        cout << atan(2.0*b/a-2.0*x/a/a/a)/atan(1.0)*45.0 << endl;
    }else{
        cout << atan(a*b*b/2.0/x)/atan(1.0)*45.0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}


int main(){
    init();

    string N;cin>>N;
    if(N[0]==N[1] && N[0]==N[2])cout<<"Yes"<<endl;
    else if(N[1]==N[2] && N[2]==N[3])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
int a[600010],n;
long long s;
int main()
{
    scanf("%d",&n);
    for(int i=6*n;i;--i)scanf("%d",&a[i]);
    std::sort(a+1,a+6*n+1);
    for(int i=1;i<=n;++i)s+=a[6*n-2*i+1];
    printf("%lld\n",s);
    return 0;
}

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

char dp[100002];
int n;
string s;

bool check() {
  rep(i, 2, n+2) {
    if (dp[i-2]=='S') {
      if (dp[i-1]=='S') {
		if (s[i-1]=='o') dp[i]='S';
		else dp[i] = 'W';
	  }
      else {
        if (s[i-1]=='o') dp[i]='W';
        else dp[i]='S';
      }
    }
    else {
      if (dp[i-1]=='S') {
        if (s[i-1]=='o') dp[i]='W';
        else dp[i]='S';
      }
      else {
        if (s[i-1]=='o') dp[i]='S';
        else dp[i]='W';
      }
    }
  }
  if (dp[0]==dp[n]&&dp[1]==dp[n+1]) return true;
  else return false;
}

int main() {
  cin>>n>>s;
  s+=s[0];
  s+=s[1];
  dp[0]='S';
  dp[1]='S';
  if (check()) {
    rep(i, 0, n) cout << dp[i];
    cout << endl;
    return 0;
  }
  dp[0]='S';
  dp[1]='W';
  if (check()) {
    rep(i, 0, n) cout<<dp[i];
    cout<<endl;
    return 0;
  }
  dp[0]='W';
  dp[1] = 'S';
  if (check()) {
    rep(i, 0, n) cout<<dp[i];
    cout<<endl;
    return 0;
  }
  dp[0]='W';
  dp[1]='W';
  if (check()) {
    rep(i, 0, n) cout<<dp[i];
    cout<<endl;
    return 0;
  }
  cout<<-1<<endl;
  return 0;
}


Measured memory_bytes: 640