akhauriyash/Code-Regression huggingface dataset:
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}
template<typename T> inline void in(T &e){cin>>e;}
template<typename T> inline void out(T e){cout<<e<<endl;}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

const int MAX_N=500;
int n,m,q;
int ary[MAX_N+1][MAX_N+1];

int l,r;

signed main(){
    io();
    cin>>n>>m>>q;
    rep(i,m) {
        scanf("%lld %lld",&l,&r);
        ary[l][r]++;
    }

    REP(i,1,n+1){
        REP(j,1,n+1){
            ary[i][j]+=ary[i][j-1];
        }
    }

    while(q--){
        int ans=0;
        scanf("%lld %lld",&l,&r);
        REP(i,l,r+1){
            ans+=ary[i][r]-ary[i][l-1];
        }
        out(ans);
    }
    
    return 0;
}


Measured memory_bytes: 2944
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
int main() {
  int n,k;
  string s;
  vector<char> ans;
  cin>>n>>s>>k;
  char c=s[k-1];
  for(int i=0;i<n;i++){
    if(s[i]==c){ans.push_back(c);}
    else ans.push_back('*');
  }
  for(int i=0;i<n;i++){
    cout<<ans[i];
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}

#define PRINT_VECTOR_MAX 100
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)min(v.size(),PRINT_VECTOR_MAX); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)min(v.size(),PRINT_VECTOR_MAX); i++) {for (ll j = 0; j < (ll)min(v[i].size(),PRINT_VECTOR_MAX); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

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

void Main(){
	int n, q; cin >> n >> q;
	dsu graph(n);
	Rep(q){
		int t,u,v; cin >> t >> u >> v;
		if(t == 0){
			graph.merge(u, v);
		}else{
			cout << (int)(graph.same(u, v)) << endl;
		}
	}
}


Measured memory_bytes: 3996
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

template<typename Monoid> struct Segment_Tree{
    //二項演算
    Monoid ope(Monoid a, Monoid b){
        return min(a, b);
    }
    //単位元
    Monoid unit;
    int n;
    vector<Monoid> seg;
    //要素数N(0-indexed)のxを単位元とするセグメント木を構築
    Segment_Tree(int N, Monoid x){
        unit = x;
        n = 1;
        while(n < N) n <<= 1;
        seg.assign(2*n, unit);
    }
    //i番目の要素をxに変更
    void change(int i, Monoid x){
        i += n;
        seg[i] = x;
        while(i > 0){
            i /= 2;
            seg[i] = ope(seg[2*i], seg[2*i+1]);
        }
    }
    //query(a, b)で[a, b)における演算の結果を取得
    Monoid query(int a, int b, int i = 1, int l = 0, int r = -1){
        if(r < 0) r = n;
        if(a >= r || b <= l) return unit;
        if(a <= l && r <= b) return seg[i];
        Monoid vl = query(a, b, 2*i, l, (l+r)/2);
        Monoid vr = query(a, b, 2*i+1, (l+r)/2, r);
        return ope(vl, vr);
    }
    //i番目の要素を取得
    Monoid at(int i){
        return seg[n+i]; 
    }
    //初期化する
    void clear(){
        fill(seg.begin(), seg.end(), unit);
    }
};

int main(){
    int N;
    cin >> N;
    int sum[N+1], ans = 0;
    sum[0] = 0;
    rep(i, N){
        int b; cin >> b;
        if(b) sum[i+1] = sum[i]-1, ans++;
        else sum[i+1] = sum[i]+1;
    }
    int Q;
    cin >> Q;
    pii p[Q];
    rep(i, Q) cin >> p[i].first >> p[i].second;
    sort(p, p+Q);
    Segment_Tree<int> seg1(N+1, inf), seg2(N+1, inf);
    seg1.change(0, 0), seg2.change(0, 0);
    rep(i, Q){
        int l = p[i].first-1, r = p[i].second;
        int tmp = seg1.query(0, l+1) + sum[r]-sum[l];
        chmin(tmp, seg2.query(l+1, r+1) + sum[r]);
        chmin(tmp, seg1.at(r));
        seg1.change(r, tmp), seg2.change(r, tmp-sum[r]);
    }
    cout << ans+seg1.query(0, N+1) << endl;
}

Measured memory_bytes: 6656
#include<iostream>
using namespace std;
const int LIM = 20000;
int grundy_naive(int n, int k)
{
    if(n < k)
        return 0;
    else if(n%k==0)
        return n/k;
    else
        return grundy_naive(n-n/k-1,k);
}
int grundy_jump(int n, int k)
{
    int a = n/k;
    int r = n%k;
    if(r%(a+1)==0)
        return a;
    else
        return grundy_jump(n-(a+1)*(r/(a+1)+1), k);
}
int main()
{
    int n; cin >> n;
    int x = 0;
    for(int i = 0; i < n; i++)
    {
        int a, k; cin >> a >> k;
        if(k <= LIM)
            x ^= grundy_naive(a,k);
        else
            x ^= grundy_jump(a,k);
    }
    cout<<(x==0 ? "Aoki" : "Takahashi")<<endl;

    return 0;
}

Measured memory_bytes: 3600
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;


namespace atcorder2
{
    class Program
    {
        public static long Read()
        {

            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }

       
       
        public static long gcd(long x,long y)
        {
            if (x < y) gcd(y, x);
            
            while (y > 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }

        public static long lcm(long x,long y)
        {
            return x * y / gcd(x, y);
        }



        static void Main(string[] args)
        {
            var sw = new StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);


            var l = Read();
            WriteLine(l * l * l / 27.0);
            

          
          
            Out.Flush();
        }
    }
}




Measured memory_bytes: 18488
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const int INF = 1000000007;
int N, M;
int A[1005], B[1005], C[1005];
int DP[1005][1 << 12];
//dp[ i ][ S ] := 最初の i 個の鍵からいくつか選んで、
//開いた宝箱の集合が S で表されるような場合についての、最小コスト

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

  cin >> N >> M;
  rep(i, M){
    cin >> A[i] >> B[i];
    rep(j, B[i]) {
      int c;
      cin >> c; c--;
      C[i] += (1 << c); //　開けれる箱たちをbitで表現している
    }
  }

  rep(i, M+1){
    rep(j, 1 << N) {
      DP[i][j] = INF;
    }
  }
  DP[0][0] = 0; // 箱をあけないときは0コストでできる
  rep(i, M){
    rep(j, 1 << N) {
      DP[i+1][j] = min(DP[i][j], DP[i+1][j]);
      DP[i+1][j | C[i]] = min(DP[i+1][j | C[i]], DP[i][j] + A[i]);
    }
  }
  int ans = DP[M][(1<<N)-1] != INF ? DP[M][(1<<N)-1] : -1;
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 16256
from math import factorial
M = 10**9 + 7
X, Y = map(int, input().split())
cnt = 0
while True:
    # print(X, Y)
    if X == 0 or Y == 0 or X / Y == 2:
        break
    cnt += 1
    X -= 1
    Y -= 2
if X == 0 and Y == 0:
    print(1)
elif X == 0 or Y == 0:
    print(0)
else:
    cnt2 = min(X, Y)
    maxcnt = max(cnt, cnt2)
    mincnt = min(cnt, cnt2)
    ans = 1
    for i in range(maxcnt+1, cnt+cnt2+1):
        ans = (ans * i) % M
    N = mincnt
    inv_t = [0]+[1]
    for i in range(2,mincnt+1):
        inv_t += [inv_t[M % i] * (M - int(M / i)) % M]
        ans = (ans * inv_t[i]) % M
    print(ans)

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

int asc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main() {
  int N;
  int L[5000];
  int a,b,c,a_b;
  int s=0;
  scanf("%d", &N);
  for (int i=0; i<N; i++) scanf("%d", &L[i]);
  qsort(L, N, sizeof(int), asc);

  for (int i=0; i<N-2; i++) {
    a = L[i];
    for (int j=i+1; j<N-1; j++) {
      b = L[j];
      c = L[j+1];
      a_b = a - b;
      //printf("%d %d %d\n", a, b, c);
      if (a_b < c) {
        s++;
        for (int k=j+2; k<N; k++) {
          c = L[k];
          //printf("%d %d %d\n", a, b, c);
          if (a_b < c) s++;
          else break;
        }
      } else {
        break;
      }      
    }
  }
  printf("%d\n", s);

}

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

template <class t>
using vc = vector<t>;
template <class t>
using vvc = vector<vector<t>>;
typedef long long ll;
typedef vc<int> vi;
typedef vvc<int> vvi;
typedef pair<int, int> pi;

#define uset unordered_set
#define umap unordered_map

#define endl "\n"

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()

#define all(a) a.bg, a.ed

template <class t, class u>
ostream &operator<<(ostream &os, const pair<t, u> &p) {
    return os << "( " << p.first << ", " << p.second << " )";
}

template <class t>
ostream &operator<<(ostream &os, const vc<t> &v) {
    os << "[ ";
    for (int i = 0; i < v.size(); i++) {
        os << v[i];
        if (i != v.size() - 1) {
            os << ", ";
        }
    }
    return os << " ]";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout << fixed << setprecision(18);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution

    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        string row;
        cin >> row;
        cout << row << endl;
        cout << row << endl;
    }
}


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

#define rep(i, first, to) for(int i = first; i < to; ++i)
#define REP(i, first, to) for(int i = first; i <= to; ++i)
#define MyDebug

#ifdef MyDebug
	#define debug(x) cout << #x << " : " << x << endl
	#define debugP(x) cout << x << endl
#else
	#define debug(x)
	#define debugP(x)
#endif

using namespace std;
typedef long long ll;

void solve() {
	int x, a, b;
	cin >> x >> a >> b;
	if (b <= x) cout << "delicious" << endl;
	else if (b <= x + a) cout << "safe" << endl;
	else cout << "dangerous" << endl;
}

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

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

int dx[9]={-2,-2,-2,-1,-1,-1,0,0,0};
int dy[9]={-2,-1,0,-2,-1,0,-2,-1,0};
ll cnt[10];

int main(){
  int H,W,N; cin>>H>>W>>N;
  map<pair<int,int>,int> mp;
  cnt[0]=1LL*(H-2)*(W-2);
  rep(i,N){
    int A,B; cin>>A>>B; A--,B--;
    rep(j,9){
      int r=A+dx[j],c=B+dy[j];
      if(r<0||r>H-3||c<0||c>W-3) continue;
      cnt[mp[{r,c}]]--;
      mp[{r,c}]++;
      cnt[mp[{r,c}]]++;
    }
  }
  rep(i,10) cout<<cnt[i]<<endl;
  return 0;
}

Measured memory_bytes: 59832
fun main(args: Array<String>) {
    abc074b()
}

fun abc074b() {
    val (n, k) = (1..2).map { readLine()!!.toInt() }
    val xList = readLine()!!.split(" ").map { it.toInt() }

    val answer = xList.map { Math.min(Math.abs(k - it), Math.abs(it)) * 2 }.sum()

    println(answer)
}


Measured memory_bytes: 37908
string = input()
text = []
for s in string:
    text.append(s)
    text.append('')

count = 0

for i in range(2**(len(string)-1)):
    for j in range(len(string)-1):
        if (i >> j) & 1:
            text[2*j+1] = '+'
        else:
            text[2*j+1] = ''

    formula = ''.join(text)
    count += eval(formula)

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 100000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long
/* define/include */

signed main(){
  string S;
  cin >> S;
  int cnt=0;
  int n=0;
  LOOP(i,4){
    if(S[i]==n){
      cnt++;
    }else{
      if(cnt==3)cnt=3;
      else{
      n=S[i];
      cnt=1;
    }
    }
  }
  if(cnt>=3){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}


Measured memory_bytes: 256
class Node:
    def __init__(self):
        self.left = -1
        self.right = -1
        self.p = -1

def main():
    n = int(input())
    t = [Node() for _ in range(n)]
    for _ in range(n):
        a,b,c = map(int,input().split())
        t[a].left = b
        t[a].right = c
        if b!=-1:t[b].p = a
        if c!=-1:t[c].p = a

    def preorder(i):
        print (' %d'%i,end='')
        if t[i].left!=-1:preorder(t[i].left)
        if t[i].right!=-1:preorder(t[i].right)

    def inorder(i):
        if t[i].left!=-1:inorder(t[i].left)
        print (' %d'%i,end='')
        if t[i].right!=-1:inorder(t[i].right)

    def postorder(i):
        if t[i].left!=-1:postorder(t[i].left)
        if t[i].right!=-1:postorder(t[i].right)
        print (' %d'%i,end='')

    root = -1
    for i in range(n):
        if t[i].p==-1:root = i
    
    print ('Preorder')
    preorder(root)
    print ()

    print ('Inorder')
    inorder(root)
    print ()

    print ('Postorder')
    postorder(root)
    print ()




if __name__ == '__main__':
    main()




Measured memory_bytes: 5616
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ll row, col;
    cin>>row>>col;
    vector<string> grid(row);
    vector<vl> path(row, vl(col, 0));
    
    forr(i, row)    cin>>grid[i];
    
    
    for(ll i=0; i<row; i++)
    {
        if(grid[i][0]=='#')
        {
            while(i<row)
            {
                path[i][0]=0;
                i++;
            }
        }
        else        
            path[i][0]=1;
    }
    for(ll j=0; j<col; j++)
    {
        if(grid[0][j]=='#')
        {
            while(j<col)
            {
                path[0][j]=0;
                j++;
            }
        }
        else path[0][j]=1;
    }
    for(ll i=1; i<row; i++)
    {
        for(ll j=1; j<col; j++)
        {
            if(grid[i][j]=='.')
                path[i][j]+=path[i-1][j]+path[i][j-1], path[i][j]%=MOD;
            else
            path[i][j]=0;
        }
    }
    cout<<path[row-1][col-1]%MOD;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

Measured memory_bytes: 9088
#include<iostream>
#include<cmath>

using namespace std;

typedef long long ll;

ll A, B;

int main() {
	cin >> A >> B;
	for (ll i = 1; i <= A; i++) {
		ll gaku = ceil(i * (long double)B / (long double)A) * A;
		if ((gaku % B) + (gaku / B) > gaku / A) {
			cout << gaku << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 3164
#include<stdio.h>

int main(void)
{
  long long int n,power=1,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      power *= i;
      power = power % 1000000007;
    }
  printf("%d\n",power);
  return 0;
}


Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int[] a = new int[n];
            long sum[] = new long[n + 1];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next());
                sum[i + 1] = sum[i] + a[i];
            }

            long tmp = 0;
            long ans = Long.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                tmp += a[i];
                ans = Math.min(ans, Math.abs(tmp - (sum[n] - tmp)));
            }
            // 出力
            out.println(ans);

        }

    }
}



Measured memory_bytes: 61132
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string s;
  cin >> s;
  int n  = sz(s);
  vi ans(n,0);
  rep(i,n-1){
    if(s[i] == 'R' and s[i+1] == 'L'){
      int j = i,l = 0,r = 0;
      int odd = 0, even = 0;
      while(s[j] == 'R'){
        r++;
        if(j%2)odd++;
        else even++;
        if(j == 0)break;
        j--;
      }
      j = i+1;
      while(s[j] == 'L' and j < n){
        l++;
        if(j%2)odd++;
        else even++;
        j++;
      }
      ans[i] = (l+r)/2;
      ans[i+1] = (l+r)/2;
      if(odd > even){
          if(i%2)ans[i]++;
          else ans[i+1]++;
      }
      else if(odd < even){
          if(i%2)ans[i+1]++;
          else ans[i]++;        
      }
    }
  }
  rep(i,n)cout<<ans[i]<<" ";
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3848
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		for(;sc.hasNext();){
			String s = sc.next();
			String t = sc.next();
			SuffixArray sa = new SuffixArray(s);
			int left=-1,right=t.length()+1;
			while(left<right-1){
				int len= (left+right)/2;
				boolean f = false;
				for(int i=0;i<t.length();i++){
					if(i+len>t.length())break;
					String sub = t.substring(i,i+len);
					if(sa.contain(sub)){
						f=true;
						break;
					}
				}
				if(f){
					left=len;
				}
				else{
					right=len;
				}
					
			}
			System.out.println(left);			
		}

	}

	static class SuffixArray {
		int n,k=1;
		Integer[] sa,rank,tmp;
		String s;

		SuffixArray(String _s) {
			s=_s;
			n = s.length();
			String[] S = new String[n+1];
			S[n]="";
			for(int i=n-1;i>=0;i--){
				S[i] = s.charAt(i)+S[i+1];
			}
			rank=new Integer[n+1];
			sa=new Integer[n+1];
			tmp=new Integer[n+1];
			for(int i=0;i<n;i++){
				sa[i]=i;
				rank[i]=(int) s.charAt(i);
			}
			sa[n]=n;
			rank[n]=-1;

			for(k=1;k<=n;k<<=1){
				Arrays.sort(sa,new Comparator<Integer>(){
					@Override
					public int compare(Integer o1, Integer o2) {
						int r1=rank[o1];
						int r2=rank[o2];
						if(r1!=r2)return (r1-r2);
						int r11=o1+k <= n ? rank[o1+k] : -1;
						int r22=o2+k <= n ? rank[o2+k] : -1;
						return (r11-r22);
					}
				});
				tmp[sa[0]]=0;
				for(int i=1;i<=n;i++){
					tmp[sa[i]]=tmp[sa[i-1]]+ (compare(sa[i-1],sa[i])!=0?1:0);
				}
				for(int i=0;i<=n;i++){
					rank[i]=tmp[i];
				}
			}
		}
		boolean contain(String t){
			return contain(s,sa,t);
		} 
		private boolean contain(String s,Integer[] sa,String t){
			int a=0,b=s.length();
			while(b-a>1){
				int c = (a+b)/2;
				int com = compare(s,sa[c], Math.min(sa[c]+t.length(), s.length()),t);
				if(com<0){
					a=c;
				}
				else{
					b=c;
				}
			}
			return compare(s,sa[b], Math.min(sa[b]+t.length(), s.length()),t)==0;
		}
		/*
		 * s.substring(i1,i2).compare(t)と同じ。メモリ節約
		 */
		private int compare(String s,int i1,int i2,String t){
//			if(true)
//				return s.substring(i1,i2).compareTo(t);
					
			for(int i=i1;i<i2;i++){
				if(i-i1>=t.length()){
					return 1;
				}
				if(s.charAt(i)!=t.charAt(i-i1)){
					return s.charAt(i)-t.charAt(i-i1);
				}
			}
			return (i2-i1)-t.length();
		}

		/*
		 * s.substring(i1,i2).compare(t.substring(j1,j2)と同じ。メモリ節約
		 */
		private int compare(String s,int i1,int i2,String t,int j1,int j2){
			int slen=i2-i1;
			int tlen=j2-j1;
			for(int i=0;i<slen;i++){
				if(i>=tlen){
					return 1;
				}
				if(s.charAt(i+i1)!=t.charAt(i+j1)){
					return s.charAt(i+i1)-t.charAt(i+j1);
				}
			}
			return slen-tlen;
		}

		private int compare(Integer o1, Integer o2) {
			int r1=rank[o1];
			int r2=rank[o2];
			if(r1!=r2)return (r1-r2);
			int r11=o1+k <= n ? rank[o1+k] : -1;
			int r22=o2+k <= n ? rank[o2+k] : -1;

			return (r11-r22);
		}

	}

}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    a.at(0) = 0;
    rep(i, n - 1)
    {
        cin >> a.at(i + 1);
        b.at(i) = 0;
    }
    for (int i = 1; i < n; i++)
    {
        b.at(a.at(i) - 1)++;
    }
    rep(i, n)
    {
        cout << b.at(i) << endl;
    }
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  
  int n,k;
  cin>>n>>k;
  int a[n];
  for(int i=0;i<n;++i)
    cin>>a[i];
  sort(a,a+n);
  int sum=0;
  for(int i=0;i<k;++i)
    sum+=a[i];
  cout<<sum<<"\n";
}

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


int main() {
    string S;
    int N;
    cin >> N >> S;

    for(int i = 0; i < S.size(); i++){
        int ascii = S.at(i) + N;
        if(ascii > 90){
            cout << (char)(ascii - 26);
        }
        else{
            cout << (char)(ascii);
        }
    }
    cout << endl;

    return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

const int mod = 1000000007;

ll f(ll i) {
    if (i % 2 == 0) {
        return i / 2;
    } else {
        return 3 * i + 1;
    }

}

int main() {
    ll s;
    cin >> s;

    set<ll> u;
    u.insert(s);
    ll before = s;
    ll count = 1;
    while (true) {
        count++;
        before = f(before);
        auto it = u.find(before);
        if (it == u.end()) {
            u.insert(before);
        } else {
            cout << count << endl;
            return 0;
        }
    }

}

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

public class P
{
    public int x { get; set; }
    public int y { get; set; }
    public bool del { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var red = setArray(n);
        var blue = setArray(n);
        var count = 0;
        foreach (var x in blue.OrderBy(y =>y.x))
        {
            var t = red.Where(z => z.x < x.x && z.y < x.y && !z.del).OrderByDescending(z => z.y);
            if (t.Count() > 0 ) { t.First().del = true; count++; }
        }
        Console.WriteLine(count);
    }
    public static P[] setArray (int  n )
    {
        var w = new P[n];
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var c = int.Parse(line[0]);
            var d = int.Parse(line[1]);
            w[i] = new P { x = c, y = d };
        }
        return w;
    }
}

Measured memory_bytes: 13396
L, R = map(int,input().split())
Dif = abs(L-R)+1
if Dif >= 2020:
    Ans = 0
else:
    Box = []
    for i in range(L,R+1):
        Box.append(i%2019)
    Box.sort()
    Ans = 2020*2020
    for i in range(len(Box)-1):
        B1 = Box[i]
        for j in range(i+1,len(Box)):
            B2 = Box[j]
            Ans = min((B1*B2)%2019, Ans)
print(Ans%2019)

Measured memory_bytes: 9136
#include<bits/stdc++.h>  
    using namespace std;  
    const int maxn = 200005;  
    long long f[maxn], s[maxn];  
    long long ans;  
      
    int main(){  
        int n, x; cin >> n;  
        for(int i = 1; i <= n; i++){  
            scanf("%d", &x);  
            f[i] = f[i-1] + x;    //计算异或前缀和  
            s[i] = s[i-1] ^ x;    //计算加法前缀和  
        }  
        int l = 1;  
        ans=0;  
        for(int r = 1; r <= n; r++){         //枚举元素  
            for(; f[r] - f[l-1] != (s[r] ^ s[l-1]); l++);//如果符合条件的话 则立即退出进行计算  
            ans += r - l + 1;  
        }  
        printf("%lld\n", ans);  
        return 0;  
    }  

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

#define pb push_back
#define sz(X) ((int)(X).size())
#define all(X) (X).begin(),(X).end()
#define ll long long
#define pi pair<int,int>
const int N=3e5+5,MOD=1e9+7;

using namespace std;

int n,m;

int main() {
	

	scanf("%d %d",&n,&m);
	std::vector<int> L(m),R(m);
	for(int i=0;i<m;i++)scanf("%d %d",&L[i],&R[i]);

	sort(all(L));
	sort(all(R));
	int ans  =0;
	for(int i=1;i<=n;i++){
		if(L[m-1]<=i && R[0]>=i)ans++;
	}

	printf("%d\n",ans );
}

Measured memory_bytes: 1024
//#pragma GCC optimize("O3")

#include <bits/stdc++.h>
//#include <ctime>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 500100, MAXK = 20;
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ld PI = asin(1) * 2;

void setIO () {
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
 	freopen((s+".out").c_str(),"w",stdout);
}

int n;
ll a[MAXN];
ll k;

ll f (ll x) {
    ll ret = 0;
    FOR(i,1, n) {
        ret += ((ll)((a[i]+x-1)/x)-1);
    }
    return ret;
}

int main() {
    setIO();
	//setIO("lmio_1991_3e1_seka_01");

    cin >> n >> k;
    FOR(i,1, n) cin >> a[i];

    ll le = 1, ri = 1e9;
    while (le < ri) {
        ll mid = (le+ri)/2;
        //cout << " mid=" << mid << "  f = " << f(mid) << endl;
        if (f(mid) > k) le = mid+1;
        else ri = mid;
    }

    ll ans = le;
    cout << ans << "\n";

	return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if ((a + b) == (c + d)) {
    cout << "Balanced" << endl;
  }
  else if ((a + b) > (c + d)) {
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;

int main()
{
    string s, t;
    cin >> s >> t;
    rep(i, s.size())
    {
        if (s[i] != t[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3604
N, M = gets.chomp.split.map(&:to_i)
array =[]
M.times.map { array << gets.chomp.split.map(&:to_i) }

class Road
    attr_accessor :start_point, :end_point
end

class Node
    def initialize
        @room_num = 0
        @next_room_num = 0
        @value = 1000000
        @road_list = []
    end

    def room_num=(value)
        @room_num = value
    end

    def next_room_num=(value)
        @next_room_num = value
    end

    def next_room_num
        @next_room_num
    end

    def value=(value)
        @value = value
    end

    def value
        @value
    end

    def add_road(s, e)
        road = Road.new
        road.start_point = s
        road.end_point = e
        @road_list << road
    end

    def each_road
        @road_list.each do |road|
            yield road
        end
    end
end

@node_list = []
N.times do |i|
    node = Node.new
    node.room_num = i + 1
    @node_list << node
end

array.each do |line_array|
    s = line_array[0]
    e = line_array[1]
    @node_list[s - 1].add_road(s, e)
    @node_list[e - 1].add_road(s, e)
end

def search(index, queue)
    start_node = @node_list[index]
    start_node.each_road do |road|
        next_index = road.start_point - 1
        if next_index == index
            next_index = road.end_point - 1
        end
        next_node = @node_list[next_index]
        if next_node.value > (start_node.value + 1)
            next_node.value = start_node.value + 1
            next_node.next_room_num = index + 1
            queue << next_index
        end
    end
end

@node_list[0].value = 0
queue = [0]
while queue.size > 0
    search(queue.shift, queue)
end

puts 'Yes'
@node_list.each_index do |i|
    next if i == 0
    puts @node_list[i].next_room_num
end


Measured memory_bytes: 73272
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, mochi_num, under int
	fmt.Scan(&n)
	mochi := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&mochi[i])
	}
	// fmt.Println(mochi)
	sort.Sort(sort.Reverse(sort.IntSlice(mochi)))
	// fmt.Println(mochi)
	under = 101
	for i := 0; i < n; i++ {
		if mochi[i] < under {
			under = mochi[i]
			mochi_num++
		}
	}
	fmt.Println(mochi_num)
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string t;
    cin >> t;
    int a=0,b=0;
    for(int i=0;i<(int)t.length();i++){
        if(t[i]=="01"[i%2])a++;
        if(t[i]=="10"[i%2])b++;
        
    }
    cout << ( a < b ? a : b );
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define MAX 50
using namespace std;

int N,L[MAX];
int main(){
		cin >> N;
		for(int i=0;i<N;i++) cin >> L[i];
		int ans=0;
		for(int i=0;i<N;i++){
			for(int j=i+1;j<N;j++){
				ans += L[i]*L[j];
			}
		}
		cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//解説写経
using namespace std;
typedef long long ll;
int main(){
int N; cin >> N; vector<vector<int>> A(N,vector<int> (N-1));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N-1; j++){ cin >> A[i][j]; A[i][j]--;}
   reverse(A[i].begin(),A[i].end());}
  //vectorは末尾から操作して行ったほうが高速なため
  vector<pair<int,int>> q;
  
  auto check = [&](int i){
    if(A[i].empty()){ return ;}
    int j = A[i].back();
    if(A[j].empty()){ return ;}
    if(A[j].back() == i){ int a = i; int b = j; if( a > b){ swap(a,b);}
      q.push_back(make_pair(a,b));
                        }};
    
    for(int i = 0 ;i < N; i++){ check(i);}
    int day = 0;
    while(!q.empty()){
      day++;
      vector<pair<int,int>> preQ;
      swap(preQ,q);
      sort(preQ.begin(),preQ.end());
      preQ.erase(unique(preQ.begin(),preQ.end()),preQ.end());
      
      for(pair<int,int> p : preQ){
        int s = p.first; int t = p.second;
        A[s].pop_back(); A[t].pop_back();}

      for(pair<int,int> p : preQ){
        int s = p.first; int t = p.second;
        check(s); check(t);}
    }
    for(int i  =0; i < N; i++){ if(!A[i].empty()){ cout << -1 << endl; return 0;}}
  cout << day << endl; return 0;}
        
    
  

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

//
int bubbleSort(int A[], int N) {
	int sw = 0;
	bool flag = 1;
	for ( int i = 0; flag; i++) {
		flag = 0;
		for ( int j = N - 1; j >= i + 1; j--) {
			if ( A[j] < A[j - 1] ) {
				//
				swap(A[j], A[j - 1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
} 

int main() {
	int A[100], N, sw;
	cin >> N;
	for ( int i = 0; i < N; i++) cin >> A[i];
	
	sw = bubbleSort(A, N);
	
	for ( int i = 0; i < N; i++) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;
	
	return 0;
}



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

#define ll long long

int main() {
//#ifndef ONLINE_JUGDE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//#endif
    ios::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin>>n;
    if(n%1000>0)
    	cout<<1000-(n%1000);
    else
    	cout<<n%1000;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define re return
#define pb push_back
#define po pop_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define si size
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define pi 3.14159265359
#define er erase
#define in insert
#define em empty
#define ft front
#define fo(i,n) for(i = 0; i < n; i++)
#define ro(i,n) for(i = n - 1; i >= 0; i--)
#define fr(i,j,n) for(i = j; i < n; i++)
#define rf(i,j,n) for(i=n-1;i>=j;i--)
typedef std::vector<int> vi;
typedef std::vector<vi> vvi;
typedef std::pair<int,int> ii;
typedef std::vector<ii> vii;
typedef std::vector<std::string> vs;
typedef double dl;
typedef long double ld;
typedef long long ll;
typedef std::pair<ll, ll> pll;
typedef std::vector<ll> vll;
#define filename ""
using namespace std;
const int N=(int)1e5;
    vector<int> v[N];
    int was[N];
    int a[N];
    vector<int> d[N];
    int co[N];
    int gwas=0;
bool sss(int x,int y)
{
    if (a[x]!=a[y]) re a[x]<a[y];
    re x<y;
}
bool so(vector<int> &x,vector<int> &y)
{
    if (x.size()!=y.size()) re x.size()>y.size();
    re x[0]<y[0];
}
set<int,bool (*)(int,int)> s1(sss);
set<int,bool (*)(int,int)> s2(sss);
int f(int x)
{
    int i;
    was[x]=1;
    d[gwas].pb(x);
    fo(i,v[x].size())
    {
        if (!was[v[x][i]])
        {
            f(v[x][i]);
        }
    }
}
int main()
{
    /*
	freopen(filename".in","r",stdin);
	freopen(filename".out","w",stdout);
	*/
	/*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    */
    int n,m,c,t;
    cin>>n>>m;
    int i;
    fo(i,n)
    {
        scanf("%d",&a[i]);
    }
    fo(i,m)
    {
        scanf("%d%d",&c,&t);
        v[t].pb(c);
        v[c].pb(t);
    }
    int b;
    fo(i,n)
    {
        if (!was[i])
        {
            f(i);
            gwas++;
        }
    }
    sort(d,d+gwas,so);
    fo(i,d[0].size())
    {
        s1.in(d[0][i]);
        co[d[0][i]]=0;
    }
    int j;
    fr(i,1,gwas)
    {
        fo(j,d[i].size())
        {
            s2.in(d[i][j]);
            co[d[i][j]]=i;
        }
    }
    ll o=0;
    int r;
    fo(i,gwas-1)
    {
        if (s2.empty()||s1.empty())
        {
            cout<<"Impossible\n";
            re 0;
        }
        o+=a[*s1.begin()];
        o+=a[*s2.begin()];
        r=*s2.begin();
        s1.er(*s1.begin());
        fo(j,d[co[r]].size())
        {
            s1.in(d[co[r]][j]);
            s2.er(d[co[r]][j]);
        }
        s1.er(r);
    }
    cout<<o<<endl;
    re 0;
}

Measured memory_bytes: 14464
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
//#include <vector>
//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int A;
    int B;
    
    cin >> A;
    cin >> B;

    cout << A - B + 1;


}

Measured memory_bytes: 256
import           Control.Monad

main :: IO ()
main = do
  s <- getLine
  let ns = getInts s
  putStrLn . f s $ solve ns

getInts = map ((subtract $ fromEnum '0') . fromEnum)

f (c:cs) os = (c:(concat $ zipWith (\a b -> (a:[b])) os cs)) ++ "=7"

solve (n:ns) = case go of
                 0 -> "+++"
                 1 -> "++-"
                 2 -> "+-+"
                 3 -> "+--"
                 4 -> "-++"
                 5 -> "-+-"
                 6 -> "--+"
                 7 -> "---"
                 _ -> undefined
  where
    go = let ops = replicateM 3 [(+), (-)]
             xs :: [[Int -> Int]]
             xs = map (zipWith (\n o -> \m -> o m n) ns) ops
             f :: [Int -> Int] -> Int
             f = foldr (\a b -> a b) n
         in fst . head $ filter (\(_, n) -> n == 7) (zip [0..7] (map f xs))



Measured memory_bytes: 380
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int m[11][6];

bool downStone(int x, int y){
    if(m[y][x] == -1) return 0;
    if(m[y + 1][x] == -1){
        m[y + 1][x] = m[y][x];
        m[y][x] = -1;
        return 1;
    }
    return 0;
}

bool deleteLine(int x, int y){
    int c = m[y][x];
    if(c == -1) return 0;
    int cnt = 0;
    rep(i,5 - x){
        if(c == m[y][x + i]) cnt++;
        else break;
    }
    if(cnt >= 3){
        rep(i,cnt){
            m[y][x + i] = -1;
        }
        return 1;
    }
    return 0;
}

int main(){
    int n;
    while(cin >> n, n){
        map<int, int> p;
        rep(i,n){
            rep(j,5){
                cin >> m[i][j];
                p[m[i][j]]++;
            }
        }
        rep(j,1000){
            bool a;
            rep(i,n){
                rep(j,5){
                    deleteLine(j, i);
                }
            }
            while(1){
                if(n == 1) break;
                a = false;
                for(int i = n - 2; i >= 0; i--){
                    rep(j,5){
                        if(downStone(j, i)) a = true;
                    }
                }
                if(not a) break;
            }
        }
        rep(i,n){
            rep(j,5){
                if(m[i][j] != -1){
                    p[m[i][j]]--;
                }
            }
        }
        int sum = 0;
        for(auto it:p){
            sum+=it.first * it.second;
        }
        cout << sum << endl;
        //rep(i,n){ rep(j,5){ cout << m[i][j]; } cout << endl; }
    }
}

Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) { //gcdを返す
	if(a == 0){
		return b;
	} else if (b == 0){
		return a;
	} else {
	  if(a < b) return gcd(b, a);
	  ll r;
	  while ((r=a%b)) {
	    a = b;
	    b = r;
	  }
	  return b;
	}
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}
ll facctorialMethod(ll k){ //階乗
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
const ll mod = 1000000007;
int main(){
	ll N, M;
	cin >> N >> M;
	vl A(N);
	REP(i, N){
		cin >> A[i];
	}
	vl B(M);
	vl C(M);
	REP(i,M){
		cin >> B[i] >> C[i];
	}
	REP(i, M){
		A.push_back(C[i]);
	}
	vl Acount(N);
	REP(i, N){
		Acount[i] = 1;
	}
	REP(i, M){
		Acount.push_back(B[i]);
	}
	sort2vectors(A,Acount);
	ll ans = 0;
	ll count = 0;
	REP(i, N){
		if(count + Acount[N+M-1-i] <= N){
			ans += A[N+M-1-i]*Acount[N+M-1-i];
		} else {
			ans += A[N+M-1-i] * (N-count);
			break;
		}
		count += Acount[N+M-1-i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 12016
#include <bits/stdc++.h>
using namespace std;
int n, h[100010], dp[100010];
int main() {
	scanf("%d", &n);
	for(int i=1; i<=n; i++) {
		scanf("%d", h+i);
		if(i == 1) dp[1] = 0;
		else {
			dp[i] = 2e9;
			dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
			if(i >= 3)
				dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
		}
	}
	printf("%d", dp[n]);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define const INF 10000000000

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

    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    cout << (k % 2 ? b-a : a-b) << endl;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
typedef pair<LL, LL> Pll;
typedef pair<LL, LL> Vec2;
LL h, w, n, m, s, t, ans = 0, a[10000000], b[10000000], num = 1, sum = 0, dp[3200][3200] = {};
string str;
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	sort(a, a + n);
	sort(b, b + n);
	for (int i = n - 1; i >= 0; i--) {
		if (b[i] > a[n - 1] && m > 0) {
			m -= b[i];
			ans++;
		}
		else break;
	}
	if (m > 0)
		ans += m / a[n - 1] + (m%a[n - 1] == 0 ? 0 : 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4480
#include <cstdio>
int main(){
 int n,a,b,c,m;
 scanf("%d",&n);
 while(n>0){
  scanf("%d %d %d",&a,&b,&c);
  m=a>b?(a>c?a:c):(b>c?b:c);
  if (a*a+b*b+c*c==2*m*m){  printf("YES\n"); }
  else { printf("NO\n"); }
  --n;
 };
 return 0;
};

Measured memory_bytes: 1004
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	n := nextInt()
	fmt.Println(n*800 - (n / 15 * 200))
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640